Example #1
0
        /// <summary> Gets all resource providers for a subscription. </summary>
        /// <param name="top"> The number of results to return. If null is passed returns all deployments. </param>
        /// <param name="expand"> The properties to include in the results. For example, use &amp;$expand=metadata in the query string to retrieve resource provider metadata. To include property aliases in response, use $expand=resourceTypes/aliases. </param>
        /// <param name="cancellationToken"> The cancellation token to use. </param>
        public virtual AsyncPageable <ProviderInfo> GetProvidersAsync(int?top = null, string expand = null, CancellationToken cancellationToken = default)
        {
            async Task <Page <ProviderInfo> > FirstPageFunc(int?pageSizeHint)
            {
                using var scope = Diagnostics.CreateScope("TenantOperations.GetProviders");
                scope.Start();

                try
                {
                    Response <ProviderInfoListResult> response = await _providerRestOperations.ListAtTenantScopeAsync(top, expand, cancellationToken).ConfigureAwait(false);

                    return(Page.FromValues(response.Value.Value, response.Value.NextLink, response.GetRawResponse()));
                }
                catch (Exception e)
                {
                    scope.Failed(e);
                    throw;
                }
            }

            async Task <Page <ProviderInfo> > NextPageFunc(string nextLink, int?pageSizeHint)
            {
                using var scope = Diagnostics.CreateScope("TenantOperations.GetProviders");
                scope.Start();

                try
                {
                    Response <ProviderInfoListResult> response = await _providerRestOperations.ListAtTenantScopeNextPageAsync(nextLink, cancellationToken).ConfigureAwait(false);

                    return(Page.FromValues(response.Value.Value, response.Value.NextLink, response.GetRawResponse()));
                }
                catch (Exception e)
                {
                    scope.Failed(e);
                    throw;
                }
            }

            return(PageableHelpers.CreateAsyncEnumerable(FirstPageFunc, NextPageFunc));
        }