public override void ExecuteCmdlet() { PsDeploymentScriptLog deploymentScriptLog; try { switch (ParameterSetName) { case GetDeploymentScriptLogByName: deploymentScriptLog = DeploymentScriptsSdkClient.GetDeploymentScriptLog(Name, ResourceGroupName); break; case GetDeploymentScriptLogByResourceId: deploymentScriptLog = DeploymentScriptsSdkClient.GetDeploymentScriptLog( ResourceIdUtility.GetResourceName(this.DeploymentScriptResourceId), ResourceIdUtility.GetResourceGroupName(this.DeploymentScriptResourceId)); break; case GetDeploymentScriptLogByInputObject: deploymentScriptLog = DeploymentScriptsSdkClient.GetDeploymentScriptLog(DeploymentScriptInputObject.Name, ResourceIdUtility.GetResourceGroupName(DeploymentScriptInputObject.Id)); break; default: throw new PSInvalidOperationException(); } WriteObject(deploymentScriptLog); } catch (Exception ex) { WriteExceptionError(ex); } }
public override void ExecuteCmdlet() { try { switch (ParameterSetName) { case GetDeploymentScriptByName: WriteObject(DeploymentScriptsSdkClient.GetDeploymentScript(Name, ResourceGroupName)); break; case GetDeploymentScriptByResourceId: WriteObject(DeploymentScriptsSdkClient.GetDeploymentScript(ResourceIdUtility.GetResourceName(this.Id), ResourceIdUtility.GetResourceGroupName(this.Id))); break; case ListDeploymentScript: WriteObject(!string.IsNullOrEmpty(ResourceGroupName) ? DeploymentScriptsSdkClient.ListDeploymentScriptsByResourceGroup(ResourceGroupName) : DeploymentScriptsSdkClient.ListDeploymentScriptsBySubscription()); break; default: throw new PSInvalidOperationException(); } } catch (Exception ex) { WriteExceptionError(ex); } }
public override void ExecuteCmdlet() { PsDeploymentScriptLog deploymentScriptLog; try { switch (ParameterSetName) { case SaveDeploymentScriptLogByName: deploymentScriptLog = DeploymentScriptsSdkClient.GetDeploymentScriptLog(Name, ResourceGroupName); break; case SaveDeploymentScriptLogByResourceId: deploymentScriptLog = DeploymentScriptsSdkClient.GetDeploymentScriptLog( ResourceIdUtility.GetResourceName(this.DeploymentScriptResourceId), ResourceIdUtility.GetResourceGroupName(this.DeploymentScriptResourceId)); break; case SaveDeploymentScriptLogByInputObject: deploymentScriptLog = DeploymentScriptsSdkClient.GetDeploymentScriptLog( DeploymentScriptInputObject.Name, ResourceIdUtility.GetResourceGroupName(DeploymentScriptInputObject.Id)); break; default: throw new PSInvalidOperationException(); } if (!string.IsNullOrEmpty(OutputPath) && !string.IsNullOrEmpty(deploymentScriptLog?.Log)) { var outputPathWithFileName = Path.Combine(GetValidatedFolderPath(OutputPath), $"{deploymentScriptLog.DeploymentScriptName}.txt"); // if a file with the same name exists and -Force is not provided, let's ask if we can replace the file. this.ConfirmAction( this.Force || !AzureSession.Instance.DataStore.FileExists(outputPathWithFileName), string.Format( Properties.Resources.DeploymentScriptLogFileExists, Name, OutputPath), Properties.Resources.DeploymentScriptShouldProcessString, OutputPath, () => { AzureSession.Instance.DataStore.WriteFile(outputPathWithFileName, deploymentScriptLog.Log); WriteObject(new PsDeploymentScriptLogPath() { Path = outputPathWithFileName }); }); } } catch (Exception ex) { WriteExceptionError(ex); } }
public override void ExecuteCmdlet() { try { string scriptName = ""; switch (ParameterSetName) { case RemoveDeploymentScriptByName: scriptName = Name; if (ShouldProcess(scriptName, "Remove Deployment Script")) { DeploymentScriptsSdkClient.DeleteDeploymentScript(scriptName, ResourceGroupName); } break; case RemoveDeploymentScriptByResourceId: scriptName = ResourceIdUtility.GetResourceName(this.Id); if (ShouldProcess(scriptName, "Remove Deployment Script")) { DeploymentScriptsSdkClient.DeleteDeploymentScript(scriptName, ResourceIdUtility.GetResourceGroupName(this.Id)); } break; case RemoveDeploymentScriptByInputObject: scriptName = InputObject.Name; if (ShouldProcess(scriptName, "Remove Deployment Script")) { DeploymentScriptsSdkClient.DeleteDeploymentScript(scriptName, ResourceIdUtility.GetResourceGroupName(InputObject.Id)); } break; default: throw new PSInvalidOperationException(); } if (PassThru.IsPresent) { WriteObject(true); } } catch (Exception ex) { WriteExceptionError(ex); } }
public override void ExecuteCmdlet() { PsDeploymentScriptLog deploymentScriptLog; int tailParam = this.IsParameterBound(c => c.Tail) ? Tail : 0; string scriptName = ""; try { switch (ParameterSetName) { case SaveDeploymentScriptLogByName: scriptName = Name; deploymentScriptLog = DeploymentScriptsSdkClient.GetDeploymentScriptLog(scriptName, ResourceGroupName, tailParam); break; case SaveDeploymentScriptLogByResourceId: scriptName = ResourceIdUtility.GetResourceName(this.DeploymentScriptResourceId); deploymentScriptLog = DeploymentScriptsSdkClient.GetDeploymentScriptLog(scriptName, ResourceIdUtility.GetResourceGroupName(this.DeploymentScriptResourceId), tailParam); break; case SaveDeploymentScriptLogByInputObject: scriptName = DeploymentScriptObject.Name; deploymentScriptLog = DeploymentScriptsSdkClient.GetDeploymentScriptLog( scriptName, ResourceIdUtility.GetResourceGroupName(DeploymentScriptObject.Id), tailParam); break; default: throw new PSInvalidOperationException(); } if (!string.IsNullOrEmpty(OutputPath) && !string.IsNullOrEmpty(deploymentScriptLog?.Log)) { var outputPathWithFileName = Path.Combine(GetValidatedFolderPath(OutputPath), $"{deploymentScriptLog.DeploymentScriptName}.txt"); // if a file with the same name exists and -Force is not provided, let's ask if we can replace the file. this.ConfirmAction( this.Force || !AzureSession.Instance.DataStore.FileExists(outputPathWithFileName), string.Format( Properties.Resources.DeploymentScriptLogFileExists, scriptName, OutputPath), Properties.Resources.DeploymentScriptShouldProcessString, OutputPath, () => { //Standardize newline character to be written into file StringBuilder logs = new StringBuilder(); StringReader stringReader = new StringReader(deploymentScriptLog.Log); String line = stringReader.ReadLine(); while (line != null) { logs.Append(line); line = stringReader.ReadLine(); if (line != null) { logs.Append(Environment.NewLine); } } AzureSession.Instance.DataStore.WriteFile(outputPathWithFileName, logs.ToString()); WriteObject(new PsDeploymentScriptLogPath() { Path = outputPathWithFileName }); }); } } catch (Exception ex) { WriteExceptionError(ex); } }