in ADTTools/UploadModels/Program.cs [81:120]
private async Task UploadOrderedInterfaces(IEnumerable<DTInterfaceInfo> orderedInterfaces)
{
Log.Write("Uploaded interfaces:");
try
{
TokenCredential credential;
if (options.UseDefaultAzureCredentials)
{
credential = new DefaultAzureCredential();
}
else
{
if (string.IsNullOrEmpty(options.ClientSecret))
{
credential = new InteractiveBrowserCredential(options.TenantId, options.ClientId);
}
else
{
credential = new ClientSecretCredential(options.TenantId, options.ClientId, options.ClientSecret);
}
}
var client = new DigitalTwinsClient(new UriBuilder("https", options.HostName).Uri, credential);
for (int i = 0; i < (orderedInterfaces.Count() / options.BatchSize) + 1; i++)
{
IEnumerable<DTInterfaceInfo> batch = orderedInterfaces.Skip(i * options.BatchSize).Take(options.BatchSize);
Response<DigitalTwinsModelData[]> response = await client.CreateModelsAsync(batch.Select(i => i.GetJsonLdText()));
foreach (DTInterfaceInfo @interface in batch)
{
Log.Ok(@interface.Id.AbsoluteUri);
}
}
}
catch (Exception ex)
{
Log.Error($"Upload failed.");
Log.Error(ex.Message);
}
}