Пример #1
0
        /// <summary>
        /// Get storage accounts according to the query params
        /// </summary>
        /// <param name="storageAccountName">Name of the container to unregister</param>
        /// <param name="subscriptionId"></param>
        /// <returns>Generic resource returned from the service</returns>
        public GenericResource GetStorageAccountResource(string storageAccountName, string subscriptionId = null)
        {
            List <GenericResource> storageAccounts = null;
            GenericResource        storageAccount  = null;

            storageAccountName = storageAccountName.ToLower();
            ODataQuery <GenericResourceFilter> getItemQueryParams =
                new ODataQuery <GenericResourceFilter>(q =>
                                                       q.ResourceType == "Microsoft.ClassicStorage/storageAccounts");

            // switch subscription context
            string subscriptionContext = RMAdapter.Client.SubscriptionId;

            RMAdapter.Client.SubscriptionId = (subscriptionId != null)? subscriptionId: RMAdapter.Client.SubscriptionId;

            Func <RestAzureNS.IPage <GenericResource> > listAsync =
                () => RMAdapter.Client.Resources.ListWithHttpMessagesAsync(
                    getItemQueryParams,
                    cancellationToken: RMAdapter.CmdletCancellationToken).Result.Body;

            Func <string, RestAzureNS.IPage <GenericResource> > listNextAsync =
                nextLink => RMAdapter.Client.Resources.ListNextWithHttpMessagesAsync(
                    nextLink,
                    cancellationToken: RMAdapter.CmdletCancellationToken).Result.Body;

            storageAccounts = HelperUtils.GetPagedRMList(listAsync, listNextAsync);
            storageAccount  = storageAccounts.Find(account =>
                                                   string.Compare(account.Name, storageAccountName) == 0);

            if (storageAccount == null)
            {
                getItemQueryParams = new ODataQuery <GenericResourceFilter>(q =>
                                                                            q.ResourceType == "Microsoft.Storage/storageAccounts");
                listAsync = () => RMAdapter.Client.Resources.ListWithHttpMessagesAsync(
                    getItemQueryParams,
                    cancellationToken: RMAdapter.CmdletCancellationToken).Result.Body;

                listNextAsync = nextLink => RMAdapter.Client.Resources.ListNextWithHttpMessagesAsync(
                    nextLink,
                    cancellationToken: RMAdapter.CmdletCancellationToken).Result.Body;

                storageAccounts = HelperUtils.GetPagedRMList(listAsync, listNextAsync);
                storageAccount  = storageAccounts.Find(account =>
                                                       string.Compare(account.Name, storageAccountName) == 0);
            }

            RMAdapter.Client.SubscriptionId = subscriptionContext;

            return(storageAccount);
        }