/// <summary>
        /// Converts a template spec model from the Azure SDK to the powershell
        /// exposed template spec model.
        /// </summary>
        /// <param name="templateSpecVersion">The Azure SDK template spec model</param>
        /// <returns>The converted model or null if no model was specified</returns>
        internal static PSTemplateSpecVersion FromAzureSDKTemplateSpecVersion(
            TemplateSpecVersion templateSpecVersion)
        {
            if (templateSpecVersion == null)
            {
                return(null);
            }

            var psTemplateSpecVersion = new PSTemplateSpecVersion
            {
                CreationTime     = templateSpecVersion.SystemData.CreatedAt,
                Id               = templateSpecVersion.Id,
                LastModifiedTime = templateSpecVersion.SystemData.LastModifiedAt,
                Name             = templateSpecVersion.Name,
                Description      = templateSpecVersion.Description,
                Tags             = templateSpecVersion.Tags == null
                    ? new Dictionary <string, string>()
                    : new Dictionary <string, string>(templateSpecVersion.Tags),
                // Note: Cast is redundant, but present for clarity reasons:
                MainTemplate = ((JToken)templateSpecVersion.MainTemplate).ToString()
            };

            if (templateSpecVersion.LinkedTemplates?.Any() == true)
            {
                foreach (LinkedTemplateArtifact artifact in templateSpecVersion.LinkedTemplates)
                {
                    psTemplateSpecVersion.LinkedTemplates.Add(
                        PSTemplateSpecTemplateArtifact.FromAzureSDKTemplateSpecTemplateArtifact(artifact));
                }
            }

            return(psTemplateSpecVersion);
        }
Пример #2
0
        internal PSTemplateSpec(TemplateSpec templateSpec,
                                TemplateSpecVersion[] versionModels = null)
        {
            this.Id               = templateSpec.Id;
            this.Type             = templateSpec.Type;
            this.Name             = templateSpec.Name;
            this.Location         = templateSpec.Location;
            this.CreationTime     = templateSpec.SystemData.CreatedAt;
            this.LastModifiedTime = templateSpec.SystemData.LastModifiedAt;
            this.Description      = templateSpec.Description;
            this.DisplayName      = templateSpec.DisplayName;
            this.Tags             = templateSpec.Tags;

            this.Versions = versionModels?
                            .Select(v => PSTemplateSpecVersion.FromAzureSDKTemplateSpecVersion(v))
                            .ToArray();
        }
        /// <summary>
        /// Converts a template spec model from the Azure SDK to the powershell
        /// exposed template spec model.
        /// </summary>
        /// <param name="templateSpecVersion">The Azure SDK template spec model</param>
        /// <returns>The converted model or null if no model was specified</returns>
        internal static PSTemplateSpecVersion FromAzureSDKTemplateSpecVersion(
            TemplateSpecVersion templateSpecVersion)
        {
            if (templateSpecVersion == null)
            {
                return(null);
            }

            var psTemplateSpecVersion = new PSTemplateSpecVersion
            {
                CreationTime     = templateSpecVersion.SystemData.CreatedAt,
                Id               = templateSpecVersion.Id,
                LastModifiedTime = templateSpecVersion.SystemData.LastModifiedAt,
                Name             = templateSpecVersion.Name,
                Description      = templateSpecVersion.Description,
                Tags             = templateSpecVersion.Tags == null
                    ? new Dictionary <string, string>()
                    : new Dictionary <string, string>(templateSpecVersion.Tags),
                // Note: Cast is redundant, but present for clarity reasons:
                Template = ((JToken)templateSpecVersion.Template).ToString()
            };

            if (templateSpecVersion.Artifacts?.Any() == true)
            {
                foreach (TemplateSpecArtifact artifact in templateSpecVersion.Artifacts)
                {
                    switch (artifact)
                    {
                    case TemplateSpecTemplateArtifact templateArtifact:
                        psTemplateSpecVersion.Artifacts.Add(
                            PSTemplateSpecTemplateArtifact.FromAzureSDKTemplateSpecTemplateArtifact(templateArtifact)
                            );
                        break;

                    default:
                        throw new PSNotSupportedException(
                                  $"Template spec artifact type '${artifact.GetType().Name}' not supported by cmdlets."
                                  );
                    }
                }
            }

            return(psTemplateSpecVersion);
        }