/// <summary>
/// Get metrics for a Media Services Channel in in asynchronous mode.
/// </summary>
/// <param name="endpointAddress">The Telemetry endpoint address</param>
/// <param name="storageAccountKey">The Storage account key.</param>
/// <param name="mediaServicesAccountId">The Media Services account Id.</param>
/// <param name="channelId">The Channel ID</param>
/// <param name="start">The start time.</param>
/// <param name="end">The end time.</param>
/// <returns>The Task of the Channel metrics for the given channel within the given time range.</returns>
public Task <ICollection <IChannelHeartbeat> > GetChannelMetricsAsync(
string endpointAddress,
string storageAccountKey,
string mediaServicesAccountId,
string channelId,
DateTime start,
DateTime end)
{
if (endpointAddress == null)
{
throw new ArgumentNullException("endpointAddress");
}
if (storageAccountKey == null)
{
throw new ArgumentNullException("storageAccountKey");
}
if (mediaServicesAccountId == null)
{
throw new ArgumentNullException("mediaServicesAccountId");
}
Guid accountId;
if (!Guid.TryParse(mediaServicesAccountId, out accountId))
{
throw new ArgumentException(StringTable.InvalidMediaServicesAccountIdInput);
}
var channelGuid = TelemetryUtilities.ParseChannelId(channelId);
if (start.Kind != DateTimeKind.Utc)
{
throw new ArgumentException(StringTable.NonUtcDateTime, "start");
}
if (end.Kind != DateTimeKind.Utc)
{
throw new ArgumentException(StringTable.NonUtcDateTime, "end");
}
if (start >= end)
{
throw new ArgumentException(StringTable.InvalidTimeRange, "start");
}
var storageAccount = TelemetryUtilities.GetStorageAccountName(endpointAddress);
if (MediaContext.StorageAccounts.Where(c => c.Name == storageAccount).FirstOrDefault() == null)
{
throw new ArgumentException(StringTable.InvalidStorageAccount);
}
return(Task.Factory.StartNew(() =>
{
var telemetryStorage = new TelemetryStorage(new StorageCredentials(storageAccount, storageAccountKey), new Uri(endpointAddress));
return telemetryStorage.GetChannelMetrics(
accountId,
channelGuid,
start,
end);
}));
}