我想使用.NET API监视现有的Azure数据工厂管道。我一直在引用Microsoft provided .NET API。
以下是代码:
using System.Configuration;
using System.Collections.ObjectModel;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Azure;
using Microsoft.Azure.Management.DataFactories;
using Microsoft.Azure.Management.DataFactories.Models;
using Microsoft.Azure.Management.DataFactories.Common.Models;
using Microsoft.IdentityModel.Clients.ActiveDirectory;
using System;
namespace ADFv1Tutorial
{
class Program
{
static void Main(string[] args)
{
// create data factory management client
//IMPORTANT: specify the name of Azure resource group here
string resourceGroupName = "<my_resourcegroup_name>";
//IMPORTANT: the name of the data factory must be globally unique.
// Therefore, update this value. For example:APITutorialFactory05122017
string dataFactoryName = "<my data_factory name>";
DateTime PipelineActivePeriodStartTime = new DateTime(2017, 8, 9, 0, 0, 0, 0, DateTimeKind.Utc);
DateTime PipelineActivePeriodEndTime = PipelineActivePeriodStartTime.AddYears(10);// AddMinutes(60);
string Dataset_Destination = "<my dataset_name>";
TokenCloudCredentials aadTokenCredentials = new TokenCloudCredentials(
ConfigurationManager.AppSettings["SubscriptionId"],
GetAuthorizationHeader().Result);
Uri resourceManagerUri = new Uri(ConfigurationManager.AppSettings["ResourceManagerEndpoint"]);
DataFactoryManagementClient client = new DataFactoryManagementClient(aadTokenCredentials, resourceManagerUri);
Console.WriteLine("Getting run details of a data slice");
// give it a few minutes for the output slice to be ready
Console.WriteLine("\nGive it a few minutes for the output slice to be ready and press any key.");
//Console.ReadKey();
var datasliceRunListResponse = client.DataSliceRuns.List(
resourceGroupName,
dataFactoryName,
Dataset_Destination,
new DataSliceRunListParameters()
{
DataSliceStartTime = PipelineActivePeriodStartTime.ConvertToISO8601DateTimeString()
});
foreach (DataSliceRun run in datasliceRunListResponse.DataSliceRuns)
{
Console.WriteLine("Status: \t\t{0}", run.Status);
Console.WriteLine("DataSliceStart: \t{0}", run.DataSliceStart);
Console.WriteLine("DataSliceEnd: \t\t{0}", run.DataSliceEnd);
Console.WriteLine("ActivityId: \t\t{0}", run.ActivityName);
Console.WriteLine("ProcessingStartTime: \t{0}", run.ProcessingStartTime);
Console.WriteLine("ProcessingEndTime: \t{0}", run.ProcessingEndTime);
Console.WriteLine("ErrorMessage: \t{0}", run.ErrorMessage);
//var r = run.Properties.Values;
//run.
//run.
}
Console.WriteLine("\nPress any key to exit.");
Console.ReadKey();
}
public static async Task<string> GetAuthorizationHeader()
{
AuthenticationContext context = new AuthenticationContext(ConfigurationManager.AppSettings["ActiveDirectoryEndpoint"] + ConfigurationManager.AppSettings["ActiveDirectoryTenantId"]);
ClientCredential credential = new ClientCredential(
ConfigurationManager.AppSettings["ApplicationId"],
ConfigurationManager.AppSettings["Password"]);
AuthenticationResult result = await context.AcquireTokenAsync(
resource: ConfigurationManager.AppSettings["WindowsManagementUri"],
clientCredential: credential);
if (result != null)
return result.AccessToken;
throw new InvalidOperationException("Failed to acquire token");
}
}
}
我在App.Config文件中使用了正确的tenantid,applicationid,applicationkey和subscriptionid。
我面临几个问题:
var datasliceRunListResponse = client.DataSliceRuns.List(
resourceGroupName,
dataFactoryName,
Dataset_Destination,
new DataSliceRunListParameters()
{
DataSliceStartTime = PipelineActivePeriodStartTime.ConvertToISO8601DateTimeString()
});
如果我使用datasliceRunListResponse.dataslices.count
那么我的数据切片计数为0。为什么
请帮忙。
答案 0 :(得分:0)
我之前和现在都尝试过此代码,我可以获取计数。只需检查开始时间和数据集名称。并且仅在切片附加到输出数据集时提及输出数据集。
string dataFactoryName = "DataFactoryName";
DateTime PipelineActivePeriodStartTime = new DateTime(2017, 8, 29, 0, 0, 0, 0, DateTimeKind.Utc);
DateTime PipelineActivePeriodEndTime = DateTime(2017, 10, 13, 0, 0, 0, 0, DateTimeKind.Utc);
string Dataset_Destination = "Output Dataset Name";
Console.WriteLine("Getting run details of a data slice");
Console.WriteLine("\nGive it a few minutes for the output slice to be ready and press any key.");
//Console.ReadKey();
var datasliceRunListResponse = client.DataSliceRuns.List(
resourceGroupName,
dataFactoryName,
Dataset_Destination,
new DataSliceRunListParameters()
{
DataSliceStartTime = PipelineActivePeriodStartTime.ConvertToISO8601DateTimeString()
});
Console.WriteLine("count is {0}", datasliceRunListResponse.DataSliceRuns.Count()); Console.ReadKey();
foreach (DataSliceRun run in datasliceRunListResponse.DataSliceRuns)
{
Console.WriteLine("Status: \t\t{0}", run.Status);
Console.WriteLine("DataSliceStart: \t{0}", run.DataSliceStart);
Console.WriteLine("DataSliceEnd: \t\t{0}", run.DataSliceEnd);
Console.WriteLine("ActivityId: \t\t{0}", run.ActivityName);
Console.WriteLine("ProcessingStartTime: \t{0}", run.ProcessingStartTime);
Console.WriteLine("ProcessingEndTime: \t{0}", run.ProcessingEndTime);
Console.WriteLine("ErrorMessage: \t{0}", run.ErrorMessage);
//var r = run.Properties.Values;
//run.
//run.
}