public override void ExecuteCmdlet()
        {
            if (this.ParameterSetName.Equals(ParameterSetNames.ResourceIdParameterSet, StringComparison.OrdinalIgnoreCase))
            {
                var parsedResourceId = new ResourceIdentifier(this.ResourceId);
                this.ResourceGroupName = parsedResourceId.ResourceGroupName;
                this.AccountName       = parsedResourceId.GetAccountName();
                this.Name = parsedResourceId.GetShareSubscriptionName();
            }

            if (this.AccountName != null && this.ResourceGroupName != null)
            {
                if (this.Name != null)
                {
                    try
                    {
                        ShareSubscription shareSubscription = this.DataShareManagementClient.ShareSubscriptions.Get(
                            this.ResourceGroupName,
                            this.AccountName,
                            this.Name);

                        this.WriteObject(shareSubscription.ToPsObject());
                    }
                    catch (DataShareErrorException ex) when(ex.Response.StatusCode.Equals(HttpStatusCode.NotFound))
                    {
                        throw new PSArgumentException(string.Format(Resources.ResourceNotFoundMessage, this.Name));
                    }
                }
                else
                {
                    string nextPageLink = null;
                    List <ShareSubscription> shareSubscriptionList = new List <ShareSubscription>();

                    do
                    {
                        IPage <ShareSubscription> shareSubscriptions = string.IsNullOrEmpty(nextPageLink)
                            ? this.DataShareManagementClient.ShareSubscriptions.ListByAccount(this.ResourceGroupName, this.AccountName)
                            : this.DataShareManagementClient.ShareSubscriptions.ListByAccountNext(nextPageLink);

                        shareSubscriptionList.AddRange(shareSubscriptions.AsEnumerable());
                        nextPageLink = shareSubscriptions.NextPageLink;
                    } while (nextPageLink != null);

                    IEnumerable <PSDataShareSubscription> shareSubscriptionsInAccount = shareSubscriptionList.Select(shareSubscription => shareSubscription.ToPsObject());
                    this.WriteObject(shareSubscriptionsInAccount, true);
                }
            }
        }
Example #2
0
        public override void ExecuteCmdlet()
        {
            if (this.ShouldProcess(this.Name, string.Format(Resources.ResourceCreateMessage, NewAzDataShareSubscription.ResourceType)))
            {
                ShareSubscription shareSubscription = this.DataShareManagementClient.ShareSubscriptions.Create(
                    this.ResourceGroupName,
                    this.AccountName,
                    this.Name,
                    new ShareSubscription()
                {
                    InvitationId = this.InvitationId
                });

                this.WriteObject(shareSubscription.ToPsObject());
            }
        }