Ejemplo n.º 1
0
        public void FiltersGalleryTemplates()
        {
            string             filterString = FilterString.Generate <ItemListFilter>(f => f.Publisher == "Microsoft");
            ItemListParameters actual       = new ItemListParameters();

            galleryClientMock.Setup(f => f.Items.ListAsync(It.IsAny <ItemListParameters>(), new CancellationToken()))
            .Returns(Task.Factory.StartNew(() => new ItemListResult
            {
                Items = new List <GalleryItem>()
                {
                    new GalleryItem()
                    {
                        Name      = "Template1",
                        Publisher = "Microsoft"
                    },
                    new GalleryItem()
                    {
                        Name      = "Template2",
                        Publisher = "Microsoft"
                    }
                }
            }))
            .Callback((ItemListParameters p, CancellationToken c) => actual = p);

            FilterGalleryTemplatesOptions options = new FilterGalleryTemplatesOptions()
            {
                Publisher = "Microsoft"
            };

            List <PSGalleryItem> result = galleryTemplatesClient.FilterGalleryTemplates(options);

            Assert.Equal(2, result.Count);
            Assert.True(result.All(g => g.Publisher == "Microsoft"));
            Assert.Equal(filterString, actual.Filter);
        }
        public override void ExecuteCmdlet()
        {
            FilterGalleryTemplatesOptions options = new FilterGalleryTemplatesOptions()
            {
                Category  = Category,
                Identity  = Identity,
                Publisher = Publisher
            };

            List <PSGalleryItem> galleryItems = GalleryTemplatesClient.FilterGalleryTemplates(options);

            if (galleryItems != null)
            {
                if (galleryItems.Count == 1 && !string.IsNullOrEmpty(Identity))
                {
                    WriteObject(galleryItems[0]);
                }
                else
                {
                    List <PSObject> output = new List <PSObject>();
                    galleryItems.Where(gi => !gi.Identity.EndsWith("-placeholder"))
                    .OrderBy(gi => gi.Identity)
                    .ToList()
                    .ForEach(gi => output.Add(base.ConstructPSObject(
                                                  null,
                                                  "Publisher", gi.Publisher,
                                                  "Identity", gi.Identity)));
                    WriteObject(output, true);
                }
            }
        }
        public override void ExecuteCmdlet()
        {
            WriteWarning("This cmdlet is being deprecated and will be removed in a future release.");
            FilterGalleryTemplatesOptions options = new FilterGalleryTemplatesOptions()
            {
                Category        = Category,
                Identity        = Identity,
                Publisher       = Publisher,
                ApplicationName = ApplicationName,
                AllVersions     = AllVersions
            };

            if (Category == null && Identity == null && Publisher == null && ApplicationName == null)
            {
                // if there are no filter parameters, return everything
                options.AllVersions = true;
            }

            List <PSGalleryItem> galleryItems = GalleryTemplatesClient.FilterGalleryTemplates(options);

            if (galleryItems != null)
            {
                if (galleryItems.Count == 1 && !string.IsNullOrEmpty(Identity))
                {
                    WriteObject(galleryItems[0]);
                }
                else
                {
                    List <PSObject> output = new List <PSObject>();
                    galleryItems.Where(gi => !gi.Identity.EndsWith("-placeholder"))
                    .OrderBy(gi => gi.Identity)
                    .ToList()
                    .ForEach(gi => output.Add(base.ConstructPSObject(
                                                  null,
                                                  "Publisher", gi.Publisher,
                                                  "Identity", gi.Identity)));
                    WriteObject(output, true);
                }
            }
        }
Ejemplo n.º 4
0
        public object GetDynamicParameters()
        {
            if (!string.IsNullOrEmpty(GalleryTemplateIdentity))
            {
                List <PSGalleryItem> galleryItems = new List <PSGalleryItem>();
                try
                {
                    galleryItems = GalleryTemplatesClient.FilterGalleryTemplates(new FilterGalleryTemplatesOptions()
                    {
                        Identity = GalleryTemplateIdentity
                    });
                }
                catch (CloudException)
                {
                    // we could not find a template with that identity
                }

                if (galleryItems.Count == 0)
                {
                    galleryItems = GalleryTemplatesClient.FilterGalleryTemplates(new FilterGalleryTemplatesOptions()
                    {
                        ApplicationName = GalleryTemplateIdentity, AllVersions = false
                    });
                    if (galleryItems == null || galleryItems.Count == 0)
                    {
                        throw new ArgumentException(string.Format(Properties.Resources.InvalidTemplateIdentity, GalleryTemplateIdentity));
                    }

                    GalleryTemplateIdentity = galleryItems[0].Identity;
                }
            }

            if (!string.IsNullOrEmpty(GalleryTemplateIdentity) &&
                !GalleryTemplateIdentity.Equals(galleryTemplateName, StringComparison.OrdinalIgnoreCase))
            {
                galleryTemplateName = GalleryTemplateIdentity;
                dynamicParameters   = GalleryTemplatesClient.GetTemplateParametersFromGallery(
                    GalleryTemplateIdentity,
                    TemplateParameterObject,
                    this.TryResolvePath(TemplateParameterFile),
                    MyInvocation.MyCommand.Parameters.Keys.ToArray());
            }
            else if (!string.IsNullOrEmpty(TemplateFile) &&
                     !TemplateFile.Equals(templateFile, StringComparison.OrdinalIgnoreCase))
            {
                templateFile      = TemplateFile;
                dynamicParameters = GalleryTemplatesClient.GetTemplateParametersFromFile(
                    this.TryResolvePath(TemplateFile),
                    TemplateParameterObject,
                    this.TryResolvePath(TemplateParameterFile),
                    MyInvocation.MyCommand.Parameters.Keys.ToArray());
            }
            else if (!string.IsNullOrEmpty(TemplateUri) &&
                     !TemplateUri.Equals(templateUri, StringComparison.OrdinalIgnoreCase))
            {
                templateUri       = TemplateUri;
                dynamicParameters = GalleryTemplatesClient.GetTemplateParametersFromFile(
                    TemplateUri,
                    TemplateParameterObject,
                    this.TryResolvePath(TemplateParameterFile),
                    MyInvocation.MyCommand.Parameters.Keys.ToArray());
            }

            return(dynamicParameters);
        }