public Variable CreateVariable(string automationAccountName, Variable variable) { bool variableExists = true; try { this.GetVariable(automationAccountName, variable.Name); } catch (ResourceNotFoundException) { variableExists = false; } if (variableExists) { throw new AzureAutomationOperationException(string.Format(CultureInfo.CurrentCulture, Resources.VariableAlreadyExists, variable.Name)); } if (variable.Encrypted) { var createParams = new AutomationManagement.Models.EncryptedVariableCreateParameters() { Name = variable.Name, Properties = new AutomationManagement.Models.EncryptedVariableCreateProperties() { Value = variable.Value, Description = variable.Description } }; var sdkCreatedVariable = this.automationManagementClient.EncryptedVariables.Create(automationAccountName, createParams) .EncryptedVariable; return(new Variable(sdkCreatedVariable, automationAccountName)); } else { var createParams = new AutomationManagement.Models.VariableCreateParameters() { Name = variable.Name, Properties = new AutomationManagement.Models.VariableCreateProperties() { Value = variable.Value, Description = variable.Description } }; var sdkCreatedVariable = this.automationManagementClient.Variables.Create(automationAccountName, createParams).Variable; return(new Variable(sdkCreatedVariable, automationAccountName)); } }
public Variable CreateVariable(Variable variable) { bool variableExists = true; try { this.GetVariable(variable.AutomationAccountName, variable.Name); } catch (ResourceNotFoundException) { variableExists = false; } if (variableExists) { throw new AzureAutomationOperationException(string.Format(CultureInfo.CurrentCulture, Resources.VariableAlreadyExists, variable.Name)); } var createParams = new AutomationManagement.Models.VariableCreateParameters() { Name = variable.Name, Properties = new AutomationManagement.Models.VariableCreateProperties() { Value = PowerShellJsonConverter.Serialize(variable.Value), Description = variable.Description, IsEncrypted = variable.Encrypted } }; var sdkCreatedVariable = this.automationManagementClient.Variables.Create(variable.AutomationAccountName, createParams).Variable; return new Variable(sdkCreatedVariable, variable.AutomationAccountName); }