コード例 #1
0
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();
            ExecuteClientAction(() =>
            {
                string resourceGroupName;
                string galleryName;
                switch (this.ParameterSetName)
                {
                case "ResourceIdParameter":
                    resourceGroupName = GetResourceGroupName(this.ResourceId);
                    galleryName       = GetResourceName(this.ResourceId, "Microsoft.Compute/Galleries");
                    break;

                default:
                    resourceGroupName = this.ResourceGroupName;
                    galleryName       = this.Name;
                    break;
                }

                if (!string.IsNullOrEmpty(resourceGroupName) && !string.IsNullOrEmpty(galleryName))
                {
                    var result   = GalleriesClient.Get(resourceGroupName, galleryName);
                    var psObject = new PSGallery();
                    ComputeAutomationAutoMapperProfile.Mapper.Map <Gallery, PSGallery>(result, psObject);
                    WriteObject(psObject);
                }
                else if (!string.IsNullOrEmpty(resourceGroupName))
                {
                    var result       = GalleriesClient.ListByResourceGroup(resourceGroupName);
                    var resultList   = result.ToList();
                    var nextPageLink = result.NextPageLink;
                    while (!string.IsNullOrEmpty(nextPageLink))
                    {
                        var pageResult = GalleriesClient.ListByResourceGroupNext(nextPageLink);
                        foreach (var pageItem in pageResult)
                        {
                            resultList.Add(pageItem);
                        }
                        nextPageLink = pageResult.NextPageLink;
                    }
                    var psObject = new List <PSGalleryList>();
                    foreach (var r in resultList)
                    {
                        psObject.Add(ComputeAutomationAutoMapperProfile.Mapper.Map <Gallery, PSGalleryList>(r));
                    }
                    WriteObject(psObject, true);
                }
                else
                {
                    var result       = GalleriesClient.List();
                    var resultList   = result.ToList();
                    var nextPageLink = result.NextPageLink;
                    while (!string.IsNullOrEmpty(nextPageLink))
                    {
                        var pageResult = GalleriesClient.ListNext(nextPageLink);
                        foreach (var pageItem in pageResult)
                        {
                            resultList.Add(pageItem);
                        }
                        nextPageLink = pageResult.NextPageLink;
                    }
                    var psObject = new List <PSGalleryList>();
                    foreach (var r in resultList)
                    {
                        psObject.Add(ComputeAutomationAutoMapperProfile.Mapper.Map <Gallery, PSGalleryList>(r));
                    }
                    WriteObject(psObject, true);
                }
            });
        }
コード例 #2
0
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();
            ExecuteClientAction(() =>
            {
                string resourceGroupName;
                string galleryName;
                switch (this.ParameterSetName)
                {
                case "ResourceIdParameter":
                    resourceGroupName = GetResourceGroupName(this.ResourceId);
                    galleryName       = GetResourceName(this.ResourceId, "Microsoft.Compute/galleries");
                    break;

                case "SharedGalleryParameterSet":
                    SharedGalleryGet();
                    return;

                default:
                    resourceGroupName = this.ResourceGroupName;
                    galleryName       = this.Name;
                    break;
                }

                if (ShouldGetByName(resourceGroupName, galleryName))
                {
                    var result = GalleriesClient.Get(resourceGroupName, galleryName, null, this.Expand);

                    var psObject = new PSGallery();
                    ComputeAutomationAutoMapperProfile.Mapper.Map <Gallery, PSGallery>(result, psObject);
                    WriteObject(psObject);
                }
                else if (ShouldListByResourceGroup(resourceGroupName, galleryName))
                {
                    var result       = GalleriesClient.ListByResourceGroup(resourceGroupName);
                    var resultList   = result.ToList();
                    var nextPageLink = result.NextPageLink;
                    while (!string.IsNullOrEmpty(nextPageLink))
                    {
                        var pageResult = GalleriesClient.ListByResourceGroupNext(nextPageLink);
                        foreach (var pageItem in pageResult)
                        {
                            resultList.Add(pageItem);
                        }
                        nextPageLink = pageResult.NextPageLink;
                    }
                    var psObject = new List <PSGalleryList>();
                    foreach (var r in resultList)
                    {
                        psObject.Add(ComputeAutomationAutoMapperProfile.Mapper.Map <Gallery, PSGalleryList>(r));
                    }
                    WriteObject(TopLevelWildcardFilter(resourceGroupName, galleryName, psObject), true);
                }
                else
                {
                    if (this.IsParameterBound(c => c.Name))
                    {
                        WriteWarning("To retrieve a specific Gallery resource, please provide '-ResourceGroupName'.\nUsing '-Name' parameter without '-ResourceGroupName' will default to listing all gallery resources in your current subscription.");
                    }
                    var result       = GalleriesClient.List();
                    var resultList   = result.ToList();
                    var nextPageLink = result.NextPageLink;
                    while (!string.IsNullOrEmpty(nextPageLink))
                    {
                        var pageResult = GalleriesClient.ListNext(nextPageLink);
                        foreach (var pageItem in pageResult)
                        {
                            resultList.Add(pageItem);
                        }
                        nextPageLink = pageResult.NextPageLink;
                    }
                    var psObject = new List <PSGalleryList>();
                    foreach (var r in resultList)
                    {
                        psObject.Add(ComputeAutomationAutoMapperProfile.Mapper.Map <Gallery, PSGalleryList>(r));
                    }
                    WriteObject(TopLevelWildcardFilter(resourceGroupName, galleryName, psObject), true);
                }
            });
        }