예제 #1
0
        /// <summary>
        /// Create a PSBlueprint object from a BlueprintModel.
        /// </summary>
        /// <param name="model"></param>
        /// <param name="managementGroupName">Name of the management group the blueprint belongs to.</param>
        /// <returns>A new PSBlueprint object</returns>
        internal static PSBlueprint FromBlueprintModel(BlueprintModel model, string scope)
        {
            var psBlueprint = new PSBlueprint
            {
                Id   = model.Id,
                Name = model.Name,
                DefinitionLocationId = Utils.GetDefinitionLocationId(scope),
                Scope          = scope,
                DisplayName    = model.DisplayName,
                Description    = model.Description,
                Status         = new PSBlueprintStatus(),
                TargetScope    = PSBlueprintTargetScope.Unknown,
                Parameters     = new Dictionary <string, PSParameterDefinition>(),
                ResourceGroups = new Dictionary <string, PSResourceGroupDefinition>(),
                Versions       = model.Versions
            };

            if (DateTime.TryParse(model.Status.TimeCreated, out DateTime timeCreated))
            {
                psBlueprint.Status.TimeCreated = timeCreated;
            }
            else
            {
                psBlueprint.Status.TimeCreated = null;
            }

            if (DateTime.TryParse(model.Status.LastModified, out DateTime lastModified))
            {
                psBlueprint.Status.LastModified = lastModified;
            }
            else
            {
                psBlueprint.Status.LastModified = null;
            }

            if (Enum.TryParse(model.TargetScope, true, out PSBlueprintTargetScope targetScope))
            {
                psBlueprint.TargetScope = targetScope;
            }
            else
            {
                psBlueprint.TargetScope = PSBlueprintTargetScope.Unknown;
            }

            foreach (var item in model.Parameters)
            {
                var definition = new PSParameterDefinition
                {
                    Type          = item.Value.Type,
                    DisplayName   = item.Value.DisplayName,
                    Description   = item.Value.Description,
                    StrongType    = item.Value.StrongType,
                    DefaultValue  = item.Value.DefaultValue,
                    AllowedValues = (item.Value.AllowedValues != null) ? item.Value.AllowedValues.ToList() : null
                };
                psBlueprint.Parameters.Add(item.Key, definition);
            }

            foreach (var item in model.ResourceGroups)
            {
                psBlueprint.ResourceGroups.Add(item.Key,
                                               new PSResourceGroupDefinition
                {
                    Name        = item.Value.Name,
                    Location    = item.Value.Location,
                    DisplayName = item.Value.DisplayName,
                    Description = item.Value.Description,
                    StrongType  = item.Value.StrongType,
                    DependsOn   = item.Value.DependsOn.ToList()
                });
            }

            return(psBlueprint);
        }
예제 #2
0
        /// <summary>
        /// Create a PSBlueprint object from a BlueprintModel.
        /// </summary>
        /// <param name="model"></param>
        /// <param name="scope">Name of the scope the blueprint is under.</param>
        /// <returns>A new PSBlueprint object</returns>
        internal static PSBlueprint FromBlueprintModel(BlueprintModel model, string scope)
        {
            var psBlueprint = new PSBlueprint
            {
                Id             = model.Id,
                Name           = model.Name,
                Scope          = scope,
                DisplayName    = model.DisplayName,
                Description    = model.Description,
                Status         = new PSBlueprintStatus(),
                TargetScope    = PSBlueprintTargetScope.Unknown,
                Parameters     = new Dictionary <string, PSParameterDefinition>(),
                ResourceGroups = new Dictionary <string, PSResourceGroupDefinition>(),
                Versions       = null
            };

            if (model.Versions != null)
            {
                var versionsDict = JObject.FromObject(model.Versions).ToObject <Dictionary <string, object> >();
                psBlueprint.Versions = versionsDict.Keys.ToArray();
            }

            psBlueprint.Status.TimeCreated = model.Status.TimeCreated;

            psBlueprint.Status.LastModified = model.Status.LastModified;


            if (Enum.TryParse(model.TargetScope, true, out PSBlueprintTargetScope targetScope))
            {
                psBlueprint.TargetScope = targetScope;
            }
            else
            {
                psBlueprint.TargetScope = PSBlueprintTargetScope.Unknown;
            }

            foreach (var item in model.Parameters)
            {
                var definition = new PSParameterDefinition
                {
                    Type          = item.Value.Type,
                    DisplayName   = item.Value.DisplayName,
                    Description   = item.Value.Description,
                    StrongType    = item.Value.StrongType,
                    DefaultValue  = item.Value.DefaultValue,
                    AllowedValues = (item.Value.AllowedValues != null) ? item.Value.AllowedValues.ToList() : null
                };
                psBlueprint.Parameters.Add(item.Key, definition);
            }

            foreach (var item in model.ResourceGroups)
            {
                psBlueprint.ResourceGroups.Add(item.Key,
                                               new PSResourceGroupDefinition
                {
                    Name        = item.Value.Name,
                    Location    = item.Value.Location,
                    DisplayName = item.Value.DisplayName,
                    Description = item.Value.Description,
                    StrongType  = item.Value.StrongType,
                    DependsOn   = item.Value.DependsOn.ToList()
                });
            }

            if (psBlueprint.Scope.StartsWith("/subscriptions"))
            {
                psBlueprint.SubscriptionId = Utils.GetDefinitionLocationId(scope);
            }
            else
            {
                psBlueprint.ManagementGroupId = Utils.GetDefinitionLocationId(scope);
            }

            return(psBlueprint);
        }