【发布时间】:2017-10-31 15:29:26
【问题描述】:
我想使用 .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 作为数据切片计数。为什么?
- 另一个问题是,我想获得由 ADF 拉取和推送的数据的 大小。我如何获得这些信息?
请帮忙。
【问题讨论】: