public object GetDynamicParameters() { 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); }
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 object GetDynamicParameters() { if (!string.IsNullOrEmpty(GalleryTemplateIdentity) && !GalleryTemplateIdentity.Equals(galleryTemplateName, StringComparison.OrdinalIgnoreCase)) { galleryTemplateName = GalleryTemplateIdentity; try { dynamicParameters = GalleryTemplatesClient.GetTemplateParametersFromGallery( GalleryTemplateIdentity, TemplateParameterObject, this.TryResolvePath(TemplateParameterFile), MyInvocation.MyCommand.Parameters.Keys.ToArray()); } catch (CloudException) { throw new ArgumentException(string.Format(Resources.UnableToFindGallery, GalleryTemplateIdentity)); } } else if (!string.IsNullOrEmpty(TemplateFile) && !TemplateFile.Equals(templateFile, StringComparison.OrdinalIgnoreCase)) { try { templateFile = TemplateFile; dynamicParameters = GalleryTemplatesClient.GetTemplateParametersFromFile( this.TryResolvePath(TemplateFile), TemplateParameterObject, this.TryResolvePath(TemplateParameterFile), MyInvocation.MyCommand.Parameters.Keys.ToArray()); } catch { throw new ArgumentException(string.Format(Resources.FailedToParseProperty, "TemplateFile", TemplateFile)); } } else if (!string.IsNullOrEmpty(TemplateUri) && !TemplateUri.Equals(templateUri, StringComparison.OrdinalIgnoreCase)) { try { templateUri = TemplateUri; dynamicParameters = GalleryTemplatesClient.GetTemplateParametersFromFile( TemplateUri, TemplateParameterObject, this.TryResolvePath(TemplateParameterFile), MyInvocation.MyCommand.Parameters.Keys.ToArray()); } catch { throw new ArgumentException(string.Format(Resources.FailedToParseProperty, "TemplateUri", TemplateUri)); } } return(dynamicParameters); }
public override void ExecuteCmdlet() { string path = GalleryTemplatesClient.DownloadGalleryTemplateFile( Identity, string.IsNullOrEmpty(Path) ? System.IO.Path.Combine(CurrentPath(), Identity) : this.TryResolvePath(Path), Force, ConfirmAction); WriteObject(PowerShellUtilities.ConstructPSObject(null, "Path", path)); }
public override void ExecuteCmdlet() { WriteWarning("This cmdlet is being deprecated and will be removed in a future release."); string path = GalleryTemplatesClient.DownloadGalleryTemplateFile( Identity, string.IsNullOrEmpty(Path) ? System.IO.Path.Combine(CurrentPath(), Identity) : this.TryResolvePath(Path), Force, ConfirmAction); WriteObject(PowerShellUtilities.ConstructPSObject(null, "Path", path)); }
protected Hashtable GetTemplateParameterObject(Hashtable templateParameterObject) { // NOTE(jogao): create a new Hashtable so that user can re-use the templateParameterObject. var prameterObject = new Hashtable(); if (templateParameterObject != null) { foreach (var parameterKey in templateParameterObject.Keys) { prameterObject[parameterKey] = new Hashtable { { "value", templateParameterObject[parameterKey] } }; } } // Load parameters from the file string templateParameterFilePath = this.TryResolvePath(TemplateParameterFile); if (templateParameterFilePath != null && FileUtilities.DataStore.FileExists(templateParameterFilePath)) { var parametersFromFile = GalleryTemplatesClient.ParseTemplateParameterFileContents(templateParameterFilePath); parametersFromFile.ForEach(dp => { var parameter = new Hashtable(); if (dp.Value.Value != null) { parameter.Add("value", dp.Value.Value); } if (dp.Value.Reference != null) { parameter.Add("reference", dp.Value.Reference); } prameterObject[dp.Key] = parameter; }); } // Load dynamic parameters IEnumerable <RuntimeDefinedParameter> parameters = PowerShellUtilities.GetUsedDynamicParameters(dynamicParameters, MyInvocation); if (parameters.Any()) { parameters.ForEach(dp => prameterObject[((ParameterAttribute)dp.Attributes[0]).HelpMessage] = new Hashtable { { "value", dp.Value } }); } return(prameterObject); }
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); } } }
protected Hashtable GetTemplateParameterObject(Hashtable templateParameterObject) { templateParameterObject = templateParameterObject ?? new Hashtable(); // Load parameters from the file string templateParameterFilePath = this.TryResolvePath(TemplateParameterFile); if (templateParameterFilePath != null && FileUtilities.DataStore.FileExists(templateParameterFilePath)) { var parametersFromFile = GalleryTemplatesClient.ParseTemplateParameterFileContents(templateParameterFilePath); parametersFromFile.ForEach(dp => templateParameterObject[dp.Key] = dp.Value.Value); } // Load dynamic parameters IEnumerable <RuntimeDefinedParameter> parameters = PowerShellUtilities.GetUsedDynamicParameters(dynamicParameters, MyInvocation); if (parameters.Any()) { parameters.ForEach(dp => templateParameterObject[((ParameterAttribute)dp.Attributes[0]).HelpMessage] = dp.Value); } return(templateParameterObject); }
public GalleryTemplatesClientTests() { galleryClientMock = new Mock <IGalleryClient>(); galleryTemplatesClient = new GalleryTemplatesClient(galleryClientMock.Object); }
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); }