internal static async Task <DataFeed> GetFirstDataFeed(MetricsAdvisorAdministrationClient adminClient)
        {
            DataFeed feed = null;
            IAsyncEnumerable <Page <DataFeed> > pages = adminClient.GetDataFeedsAsync(new GetDataFeedsOptions {
                TopCount = 1
            }).AsPages();

            await foreach (var page in pages)
            {
                //Only perform a single iteration.
                feed = page.Values?.FirstOrDefault();
                break;
            }
            return(feed);
        }
        public void GetDataFeedsRespectsTheCancellationToken()
        {
            MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient();

            using var cancellationSource = new CancellationTokenSource();
            cancellationSource.Cancel();

            IAsyncEnumerator <DataFeed> asyncEnumerator = adminClient.GetDataFeedsAsync(cancellationToken: cancellationSource.Token).GetAsyncEnumerator();

            Assert.That(async() => await asyncEnumerator.MoveNextAsync(), Throws.InstanceOf <OperationCanceledException>());

            IEnumerator <DataFeed> enumerator = adminClient.GetDataFeeds(cancellationToken: cancellationSource.Token).GetEnumerator();

            Assert.That(() => enumerator.MoveNext(), Throws.InstanceOf <OperationCanceledException>());
        }
        public async Task GetDataFeedsAsync()
        {
            string endpoint        = MetricsAdvisorUri;
            string subscriptionKey = MetricsAdvisorSubscriptionKey;
            string apiKey          = MetricsAdvisorApiKey;
            var    credential      = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);

            var adminClient = new MetricsAdvisorAdministrationClient(new Uri(endpoint), credential);

            var filter = new GetDataFeedsFilter()
            {
                Status          = DataFeedStatus.Active,
                GranularityType = DataFeedGranularityType.Daily
            };
            var options = new GetDataFeedsOptions()
            {
                GetDataFeedsFilter = filter,
                TopCount           = 5
            };

            int dataFeedCount = 0;

            await foreach (DataFeed dataFeed in adminClient.GetDataFeedsAsync(options))
            {
                Console.WriteLine($"Data feed ID: {dataFeed.Id}");
                Console.WriteLine($"Name: {dataFeed.Name}");
                Console.WriteLine($"Description: {dataFeed.Description}");
                Console.WriteLine();

                // Print at most 5 data feeds.
                if (++dataFeedCount >= 5)
                {
                    break;
                }
            }
        }