Example #1
0
 /// <summary>
 /// Initializes a new instance of the DeploymentWhatIfProperties class.
 /// </summary>
 /// <param name="mode">The mode that is used to deploy resources. This
 /// value can be either Incremental or Complete. In Incremental mode,
 /// resources are deployed without deleting existing resources that are
 /// not included in the template. In Complete mode, resources are
 /// deployed and existing resources in the resource group that are not
 /// included in the template are deleted. Be careful when using
 /// Complete mode as you may unintentionally delete resources. Possible
 /// values include: 'Incremental', 'Complete'</param>
 /// <param name="template">The template content. You use this element
 /// when you want to pass the template syntax directly in the request
 /// rather than link to an existing template. It can be a JObject or
 /// well-formed JSON string. Use either the templateLink property or
 /// the template property, but not both.</param>
 /// <param name="templateLink">The URI of the template. Use either the
 /// templateLink property or the template property, but not
 /// both.</param>
 /// <param name="parameters">Name and value pairs that define the
 /// deployment parameters for the template. You use this element when
 /// you want to provide the parameter values directly in the request
 /// rather than link to an existing parameter file. Use either the
 /// parametersLink property or the parameters property, but not both.
 /// It can be a JObject or a well formed JSON string.</param>
 /// <param name="parametersLink">The URI of parameters file. You use
 /// this element to link to an existing parameters file. Use either the
 /// parametersLink property or the parameters property, but not
 /// both.</param>
 /// <param name="debugSetting">The debug setting of the
 /// deployment.</param>
 /// <param name="onErrorDeployment">The deployment on error
 /// behavior.</param>
 /// <param name="whatIfSettings">Optional What-If operation
 /// settings.</param>
 public DeploymentWhatIfProperties(DeploymentMode mode, object template = default(object), TemplateLink templateLink = default(TemplateLink), object parameters = default(object), ParametersLink parametersLink = default(ParametersLink), DebugSetting debugSetting = default(DebugSetting), OnErrorDeployment onErrorDeployment = default(OnErrorDeployment), DeploymentWhatIfSettings whatIfSettings = default(DeploymentWhatIfSettings))
     : base(mode, template, templateLink, parameters, parametersLink, debugSetting, onErrorDeployment)
 {
     WhatIfSettings = whatIfSettings;
     CustomInit();
 }
        private Deployment CreateBasicDeployment(ValidatePSResourceGroupDeploymentParameters parameters, DeploymentMode deploymentMode)
        {
            Deployment deployment = new Deployment
            {
                Properties = new DeploymentProperties {
                    Mode = deploymentMode,
                    Template = GetTemplate(parameters.TemplateFile, parameters.GalleryTemplateIdentity),
                    Parameters = GetDeploymentParameters(parameters.TemplateParameterObject)
                }
            };

            return deployment;
        }
Example #3
0
        private Deployment CreateBasicDeployment(ValidatePSResourceGroupDeploymentParameters parameters, DeploymentMode deploymentMode)
        {
            Deployment deployment = new Deployment
            {
                Properties = new DeploymentProperties {
                    Mode       = deploymentMode,
                    Template   = GetTemplate(parameters.TemplateFile, parameters.GalleryTemplateIdentity),
                    Parameters = GetDeploymentParameters(parameters.TemplateParameterObject)
                }
            };

            return(deployment);
        }
 public TestAzureResourceGroupDeploymentCmdlet()
 {
     this.Mode = DeploymentMode.Incremental;
 }
 public DeploymentProperties(DeploymentMode mode)
 {
     Mode = mode;
 }
 public TestAzureResourceGroupTemplateCommand()
 {
     this.Mode = DeploymentMode.Incremental;
 }
Example #7
0
 public ApplicationDeploymentPolicy(DeploymentMode deploymentMode)
 {
     DeploymentMode = deploymentMode;
 }
        /// <summary>
        /// Validates a given deployment.
        /// </summary>
        /// <param name="parameters">The deployment create options</param>
        /// <returns>True if valid, false otherwise.</returns>
        public virtual List<PSResourceManagerError> ValidatePSResourceGroupDeployment(PSValidateResourceGroupDeploymentParameters parameters, DeploymentMode deploymentMode)
        {
            Deployment deployment = CreateBasicDeployment(parameters, deploymentMode, null);
            TemplateValidationInfo validationInfo = CheckBasicDeploymentErrors(parameters.ResourceGroupName, Guid.NewGuid().ToString(), deployment);

            if (validationInfo.Errors.Count == 0)
            {
                WriteVerbose(ProjectResources.TemplateValid);
            }
            return validationInfo.Errors.Select(e => e.ToPSResourceManagerError()).ToList();
        }
 internal DeploymentWhatIfProperties(object template, TemplateLink templateLink, object parameters, ParametersLink parametersLink, DeploymentMode mode, DebugSetting debugSetting, OnErrorDeployment onErrorDeployment, DeploymentWhatIfSettings whatIfSettings) : base(template, templateLink, parameters, parametersLink, mode, debugSetting, onErrorDeployment)
 {
     WhatIfSettings = whatIfSettings;
 }
Example #10
0
 public TestAzureResourceGroupTemplateCommand()
 {
     this.Mode = DeploymentMode.Incremental;
 }
        private Deployment CreateBasicDeployment(PSDeploymentCmdletParameters parameters, DeploymentMode deploymentMode, string debugSetting)
        {
            Deployment deployment = new Deployment
            {
                Properties = new DeploymentProperties
                {
                    Mode = deploymentMode
                }
            };

            if (!string.IsNullOrEmpty(debugSetting))
            {
                deployment.Properties.DebugSetting = new DebugSetting
                {
                    DetailLevel = debugSetting
                };
            }

            if (Uri.IsWellFormedUriString(parameters.TemplateFile, UriKind.Absolute))
            {
                deployment.Properties.TemplateLink = new TemplateLink
                {
                    Uri = parameters.TemplateFile
                };
            }
            else
            {
                if (!string.IsNullOrEmpty(parameters.TemplateFile))
                {
                    deployment.Properties.Template = JObject.Parse(FileUtilities.DataStore.ReadFileAsText(parameters.TemplateFile));
                }
                else
                {
                    deployment.Properties.Template = JObject.Parse(JsonConvert.SerializeObject(parameters.TemplateObject));
                }
            }

            if (Uri.IsWellFormedUriString(parameters.ParameterUri, UriKind.Absolute))
            {
                deployment.Properties.ParametersLink = new ParametersLink
                {
                    Uri = parameters.ParameterUri
                };
            }
            else
            {
                string templateParams = GetDeploymentParameters(parameters.TemplateParameterObject);
                deployment.Properties.Parameters = string.IsNullOrEmpty(templateParams) ? null : JObject.Parse(templateParams);
            }

            deployment.Location = parameters.Location;
            deployment.Properties.OnErrorDeployment = parameters.OnErrorDeployment;

            return(deployment);
        }
Example #12
0
 public static string ToSerialString(this DeploymentMode value) => value switch
 {
        private async Task <object> GetDeploymentPayloadAsync(Guid deploymentId, AzureDeploymentTemplate template, string location, DeploymentMode deploymentMode)
        {
            if (string.IsNullOrEmpty(template.Template))
            {
                throw new ArgumentException("Unable to create deployment payload by an empty template.", nameof(template));
            }

            if (template.LinkedTemplates?.Any() ?? false)
            {
                var deploymentContainer = await azureDeploymentArtifactsStorage
                                          .UploadArtifactsAsync(deploymentId, template)
                                          .ConfigureAwait(false);

                template.Parameters[IAzureDeploymentTemplate.ArtifactsLocationParameterName]         = deploymentContainer.Location;
                template.Parameters[IAzureDeploymentTemplate.ArtifactsLocationSasTokenParameterName] = deploymentContainer.Token;
            }

            IDictionary <string, object> deploymentParameters = null;

            if (template.Parameters?.Any() ?? false)
            {
                deploymentParameters = template.Parameters
                                       .Where(param => param.Value != null)
                                       .Aggregate(new ExpandoObject() as IDictionary <string, object>, (a, kv) => { a.Add(kv.Key, new { value = kv.Value }); return(a); });
            }

            var properties = new DeploymentProperties()
            {
                Mode       = deploymentMode,
                Template   = JObject.Parse(template.Template),
                Parameters = deploymentParameters is null ? new JObject() : JObject.FromObject(deploymentParameters)
            };

            if (string.IsNullOrEmpty(location))
            {
                return new { properties }
            }
            ;

            return(new { location, properties });
        }
    }
}
Example #14
0
        private Deployment CreateBasicDeployment(ValidatePSResourceGroupDeploymentParameters parameters, DeploymentMode deploymentMode)
        {
            Deployment deployment = new Deployment
            {
                Properties = new DeploymentProperties {
                    Mode = deploymentMode
                }
            };

            if (Uri.IsWellFormedUriString(parameters.TemplateFile, UriKind.Absolute))
            {
                deployment.Properties.TemplateLink = new TemplateLink
                {
                    Uri = new Uri(parameters.TemplateFile)
                };
            }
            else if (!string.IsNullOrEmpty(parameters.GalleryTemplateIdentity))
            {
                deployment.Properties.TemplateLink = new TemplateLink
                {
                    Uri = new Uri(GalleryTemplatesClient.GetGalleryTemplateFile(parameters.GalleryTemplateIdentity))
                };
            }
            else
            {
                deployment.Properties.Template = FileUtilities.DataStore.ReadFileAsText(parameters.TemplateFile);
            }

            if (Uri.IsWellFormedUriString(parameters.ParameterUri, UriKind.Absolute))
            {
                deployment.Properties.ParametersLink = new ParametersLink
                {
                    Uri = new Uri(parameters.ParameterUri)
                };
            }
            else
            {
                deployment.Properties.Parameters = GetDeploymentParameters(parameters.TemplateParameterObject);
            }

            return(deployment);
        }
 public TestAzureResourceGroupDeploymentCmdlet()
 {
     this.Mode = DeploymentMode.Incremental;
 }
Example #16
0
        private Deployment CreateBasicDeployment(ValidatePSResourceGroupDeploymentParameters parameters, DeploymentMode deploymentMode)
        {
            Deployment deployment = new Deployment
            {
                Properties = new DeploymentProperties {
                    Mode = deploymentMode
                }
            };

            if (Uri.IsWellFormedUriString(parameters.TemplateFile, UriKind.Absolute))
            {
                deployment.Properties.TemplateLink = new TemplateLink
                {
                    Uri = new Uri(parameters.TemplateFile)
                };
            }
            else if (!string.IsNullOrEmpty(parameters.GalleryTemplateIdentity))
            {
                deployment.Properties.TemplateLink = new TemplateLink
                {
                    Uri = new Uri(GalleryTemplatesClient.GetGalleryTemplateFile(parameters.GalleryTemplateIdentity))
                };
            }
            else
            {
                deployment.Properties.Template = FileUtilities.DataStore.ReadFileAsText(parameters.TemplateFile);
            }

            if (Uri.IsWellFormedUriString(parameters.ParameterUri, UriKind.Absolute))
            {
                deployment.Properties.ParametersLink = new ParametersLink
                {
                    Uri = new Uri(parameters.ParameterUri)
                };
            }
            else
            {
                deployment.Properties.Parameters = GetDeploymentParameters(parameters.TemplateParameterObject);
            }

            return deployment;
        }
 public DeploymentWhatIfProperties(DeploymentMode mode) : base(mode)
 {
 }
        /// <summary>
        /// Validates a given deployment.
        /// </summary>
        /// <param name="parameters">The deployment create options</param>
        /// <returns>True if valid, false otherwise.</returns>
        public virtual List <PSResourceManagerError> ValidatePSResourceGroupDeployment(PSValidateResourceGroupDeploymentParameters parameters, DeploymentMode deploymentMode)
        {
            Deployment             deployment     = CreateBasicDeployment(parameters, deploymentMode, null);
            TemplateValidationInfo validationInfo = CheckBasicDeploymentErrors(parameters.ResourceGroupName, Guid.NewGuid().ToString(), deployment);

            if (validationInfo.Errors.Count == 0)
            {
                WriteVerbose(ProjectResources.TemplateValid);
            }
            return(validationInfo.Errors.Select(e => e.ToPSResourceManagerError()).ToList());
        }
Example #19
0
 internal DeploymentProperties(object template, TemplateLink templateLink, object parameters, ParametersLink parametersLink, DeploymentMode mode, DebugSetting debugSetting, OnErrorDeployment onErrorDeployment)
 {
     Template          = template;
     TemplateLink      = templateLink;
     Parameters        = parameters;
     ParametersLink    = parametersLink;
     Mode              = mode;
     DebugSetting      = debugSetting;
     OnErrorDeployment = onErrorDeployment;
 }
        private Deployment CreateBasicDeployment(PSValidateResourceGroupDeploymentParameters parameters, DeploymentMode deploymentMode, string debugSetting)
        {
            Deployment deployment = new Deployment
            {
                Properties = new DeploymentProperties
                {
                    Mode = deploymentMode
                }
            };

            if (!string.IsNullOrEmpty(debugSetting))
            {
                deployment.Properties.DebugSetting = new DebugSetting
                {
                    DetailLevel = debugSetting
                };
            }

            if (Uri.IsWellFormedUriString(parameters.TemplateFile, UriKind.Absolute))
            {
                deployment.Properties.TemplateLink = new TemplateLink
                {
                    Uri = parameters.TemplateFile
                };
            }
            else
            {
                deployment.Properties.Template = JObject.Parse(FileUtilities.DataStore.ReadFileAsText(parameters.TemplateFile));
            }

            if (Uri.IsWellFormedUriString(parameters.ParameterUri, UriKind.Absolute))
            {
                deployment.Properties.ParametersLink = new ParametersLink
                {
                    Uri = parameters.ParameterUri
                };
            }
            else
            {
                string templateParams = GetDeploymentParameters(parameters.TemplateParameterObject);
                deployment.Properties.Parameters = string.IsNullOrEmpty(templateParams) ? null : JObject.Parse(templateParams);
            }

            return(deployment);
        }
 public PublishDirInfo(string dirName, string dirPath, DeploymentMode deploymentMode)
 {
     Name           = dirName;
     Path           = dirPath;
     DeploymentMode = deploymentMode;
 }
        private Deployment CreateBasicDeployment(ValidatePSResourceGroupDeploymentParameters parameters, DeploymentMode deploymentMode, string debugSetting)
        {
            Deployment deployment = new Deployment
            {
                Properties = new DeploymentProperties {
                    Mode = deploymentMode
                }
            };

            if(!string.IsNullOrEmpty(debugSetting))
            {
                deployment.Properties.DebugSetting = new DeploymentDebugSetting
                {
                    DeploymentDebugDetailLevel = debugSetting
                };
            }

            if (Uri.IsWellFormedUriString(parameters.TemplateFile, UriKind.Absolute))
            {
                deployment.Properties.TemplateLink = new TemplateLink
                {
                    Uri = new Uri(parameters.TemplateFile)
                };
            }
            else
            {
                deployment.Properties.Template = FileUtilities.DataStore.ReadFileAsText(parameters.TemplateFile);
            }

            if (Uri.IsWellFormedUriString(parameters.ParameterUri, UriKind.Absolute))
            {
                deployment.Properties.ParametersLink = new ParametersLink
                {
                    Uri = new Uri(parameters.ParameterUri)
                };
            }
            else
            {
                deployment.Properties.Parameters = GetDeploymentParameters(parameters.TemplateParameterObject);
            }

            return deployment;
        }
Example #23
0
        static PublishDirInfo[]? Handler(DeploymentMode d, string[] val, bool dev)
        {
            if (!val.Any_Nullable())
            {
                Console.WriteLine(InputPubDirNameError);
                return(null);
            }

            var pubPath = d switch
            {
                DeploymentMode.SCD => DirPublish_,
                DeploymentMode.FDE => DirPublish_FDE_,
                _ => throw new ArgumentOutOfRangeException(nameof(d), d, null),
            };

            var dirBasePath = projPath + string.Format(pubPath, GetConfiguration(dev, isLower: false));
            var dirNames    = val.Select(x => new PublishDirInfo(x, Path.Combine(dirBasePath, x), d)).Where(x => Directory.Exists(x.Path)).ToArray();

            var publish_json_path = PublishJsonFilePath;

            IOPath.FileIfExistsItDelete(publish_json_path);

            foreach (var item in dirNames)
            {
                var isMacOS = item.Name.StartsWith("osx");
                // ASP.NET Core Runtime 6.0.0 缺少 macOS Installers
                if (isMacOS && d == DeploymentMode.FDE)
                {
                    continue;
                }

                if (!Directory.Exists(item.Path))
                {
                    Console.WriteLine($"错误:找不到发布文件夹({item.Name}),{item.Path}");
                    return(null);
                }

                List <Action> lazyActions = new();

                lazyActions.Add(() =>
                {
                    ScanPath(item.Path, item.Files, ignoreRootDirNames: ignoreDirNames);
                });

                //if (item.Name.StartsWith("win", StringComparison.OrdinalIgnoreCase))
                //{
                //    #region 适用于 Windwos 7 OS 的 疑难解答助手

                //    string win7Path;
                //    if (IsAigioPC)
                //    {
                //        win7Path = @"G:\Steam++.Win7";
                //    }
                //    else
                //    {
                //        win7Path = Path.Combine(item.Path, "..", "Steam++.Win7");
                //    }

                //    var win7ExePath = Path.Combine(win7Path, "Steam++.Win7.exe");
                //    if (!File.Exists(win7ExePath) || !File.Exists(win7ExePath + ".config"))
                //    {
                //        Console.WriteLine($"错误:Win7疑难助手程序不存在!{win7ExePath}");
                //        return;
                //    }

                //    lazyActions.Add(() =>
                //    {
                //        ScanPath(win7Path, item.Files);
                //    });

                //    #endregion

                //    var consoleExeFileName = Path.Combine(item.Path, "Steam++.Console.exe");
                //    if (!File.Exists(consoleExeFileName))
                //    {
                //        Console.WriteLine($"错误:Steam++.Console.exe 不存在!");
                //        return;
                //    }
                //}

                //if (item.Name.Equals("win-x86", StringComparison.OrdinalIgnoreCase))
                //{
                //    #region Win10SDK.NET

                //    const string netSDKFileName = "Microsoft.Windows.SDK.NET.dll";
                //    var netSDKFileRefPath = Path.Combine(projPath, "references", netSDKFileName);

                //    if (!File.Exists(netSDKFileRefPath))
                //    {
                //        Console.WriteLine($"错误:Microsoft.Windows.SDK.NET.dll不存在!{netSDKFileRefPath}");
                //        return;
                //    }

                //    var netSDKFileRefInfoVersion = GetInfoVersion(netSDKFileRefPath);
                //    var netSDKFilePath = Path.Combine(item.Path, netSDKFileName);
                //    var netSDKFileInfoVersion = GetInfoVersion(netSDKFilePath);
                //    if (netSDKFileRefInfoVersion != netSDKFileInfoVersion)
                //    {
                //        Console.WriteLine("错误:Microsoft.Windows.SDK.NET.dll 版本不正确!");
                //        Console.WriteLine($"Version: {netSDKFileInfoVersion}");
                //        Console.WriteLine($"Version(Ref): {netSDKFileRefInfoVersion}");
                //        return;
                //    }

                //    lazyActions.Add(() =>
                //    {
                //        foreach (var file in item.Files)
                //        {
                //            if (file.Path == netSDKFilePath)
                //            {
                //                file.Path = netSDKFileRefPath;
                //                file.Length = new FileInfo(netSDKFileRefPath).Length;
                //            }
                //        }
                //    });

                //    #endregion
                //}

                //string cefRootPath;
                //if (IsAigioPC)
                //{
                //    cefRootPath = @"G:\";
                //}
                //else
                //{
                //    cefRootPath = Path.Combine(item.Path, "..");
                //}

                //var cefPath = Path.Combine(cefRootPath, "CEF", item.Name);

                //if (!Directory.Exists(cefPath))
                //{
                //    Console.WriteLine($"错误:CEF库文件夹不存在!{cefPath}");
                //    return;
                //}
                //else if (!Directory.GetFiles(cefPath).Any())
                //{
                //    Console.WriteLine($"错误:CEF库文件不存在!{cefPath}");
                //    return;
                //}

                //lazyActions.Add(() =>
                //{
                //    ScanPath(cefPath, item.Files, cefRootPath);
                //});

                lazyActions.ForEach(x => x());

                Console.WriteLine($"{item.Name}, count: {item.Files.Count}");

                if (calcHash)
                {
                    foreach (var file in item.Files)
                    {
                        Console.WriteLine($"正在计算哈希值:{file.Path}");
                        using var fileStream = File.OpenRead(file.Path);
                        file.SHA256          = Hashs.String.SHA256(fileStream);
                    }
                }
            }

            return(dirNames);
        }