private string ExecuteWhatIf() { const string statusMessage = "Getting the latest status of all resources..."; var clearMessage = new string(' ', statusMessage.Length); var information = new HostInformationMessage { Message = statusMessage, NoNewLine = true }; var clearInformation = new HostInformationMessage { Message = $"\r{clearMessage}\r", NoNewLine = true }; var tags = new[] { "PSHOST" }; try { // Write status message. this.WriteInformation(information, tags); var parameters = new PSDeploymentWhatIfCmdletParameters { DeploymentName = this.Name, Location = this.Location, Mode = DeploymentMode.Incremental, TemplateUri = TemplateUri ?? this.TryResolvePath(TemplateFile), TemplateObject = this.TemplateObject, TemplateParametersUri = this.TemplateParameterUri, TemplateParametersObject = GetTemplateParameterObject(this.TemplateParameterObject), ResultFormat = this.WhatIfResultFormat }; PSWhatIfOperationResult whatIfResult = ResourceManagerSdkClient.ExecuteDeploymentWhatIf(parameters, this.WhatIfExcludeChangeType); string whatIfMessage = WhatIfOperationResultFormatter.Format(whatIfResult); // Clear status before returning result. this.WriteInformation(clearInformation, tags); // Use \r to override the built-in "What if:" in output. return($"\r \r{Environment.NewLine}{whatIfMessage}{Environment.NewLine}"); } catch (Exception) { // Clear status before handling exception. this.WriteInformation(clearInformation, tags); throw; } }
protected override void OnProcessRecord() { const string statusMessage = "Getting the latest status of all resources..."; var clearMessage = new string(' ', statusMessage.Length); var information = new HostInformationMessage { Message = statusMessage, NoNewLine = true }; var clearInformation = new HostInformationMessage { Message = $"\r{clearMessage}\r", NoNewLine = true }; var tags = new[] { "PSHOST" }; try { // Write status message. this.WriteInformation(information, tags); var parameters = new PSDeploymentWhatIfCmdletParameters { DeploymentName = this.Name, Location = this.Location, Mode = DeploymentMode.Incremental, TemplateUri = TemplateUri ?? this.TryResolvePath(TemplateFile), TemplateObject = this.TemplateObject, TemplateParametersUri = this.TemplateParameterUri, TemplateParametersObject = GetTemplateParameterObject(this.TemplateParameterObject), ResultFormat = this.ResultFormat }; PSWhatIfOperationResult whatIfResult = ResourceManagerSdkClient.ExecuteDeploymentWhatIf(parameters); // Clear status before returning result. this.WriteInformation(clearInformation, tags); this.WriteObject(whatIfResult); } catch (Exception) { // Clear status on exception. this.WriteInformation(clearInformation, tags); throw; } }