/// <summary>
 /// Create a variable.  (see
 /// http://aka.ms/azureautomationsdk/variableoperations for more
 /// information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.Automation.IVariableOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of the resource group
 /// </param>
 /// <param name='automationAccount'>
 /// Required. The automation account name.
 /// </param>
 /// <param name='parameters'>
 /// Required. The parameters supplied to the create or update variable
 /// operation.
 /// </param>
 /// <returns>
 /// The response model for the create or update variable operation.
 /// </returns>
 public static VariableCreateOrUpdateResponse CreateOrUpdate(this IVariableOperations operations, string resourceGroupName, string automationAccount, VariableCreateOrUpdateParameters parameters)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IVariableOperations)s).CreateOrUpdateAsync(resourceGroupName, automationAccount, parameters);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
Esempio n. 2
0
        public async Task<bool> SaveVariableAsync(VariableModelProxy variable)
        {
            var variableToSave = new VariableCreateOrUpdateParameters();
            variableToSave.Name = variable.Name;

            variableToSave.Properties = new VariableCreateOrUpdateProperties();
            variableToSave.Properties.IsEncrypted = variable.IsEncrypted;
            variableToSave.Properties.Value = variable.Value;

            var response = await _client.Variables.CreateOrUpdateAsync(_connectionData.AzureRMGroupName, _connectionData.AzureAutomationAccount, variableToSave);

            if (response.StatusCode == System.Net.HttpStatusCode.InternalServerError)
            {
                _output.AppendLine("Unable to save the variable at the moment, please verify your connectivity and try again.");
                return false;
            }

            return true;
        }
Esempio n. 3
0
        public Variable CreateVariable(Variable variable)
        {
            bool variableExists = true;

            try
            {
                this.GetVariable(variable.ResourceGroupName, 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.VariableCreateOrUpdateParameters()
            {
                Name = variable.Name,
                Properties = new AutomationManagement.Models.VariableCreateOrUpdateProperties()
                {
                    Value = PowerShellJsonConverter.Serialize(variable.Value),
                    Description = variable.Description,
                    IsEncrypted = variable.Encrypted
                }
            };

            var sdkCreatedVariable =
                this.automationManagementClient.Variables.CreateOrUpdate(variable.ResourceGroupName, variable.AutomationAccountName, createParams).Variable;

            return new Variable(sdkCreatedVariable, variable.AutomationAccountName, variable.ResourceGroupName);
        }
 /// <summary>
 /// Create a variable.  (see
 /// http://aka.ms/azureautomationsdk/variableoperations for more
 /// information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.Automation.IVariableOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of the resource group
 /// </param>
 /// <param name='automationAccount'>
 /// Required. The automation account name.
 /// </param>
 /// <param name='parameters'>
 /// Required. The parameters supplied to the create or update variable
 /// operation.
 /// </param>
 /// <returns>
 /// The response model for the create or update variable operation.
 /// </returns>
 public static Task<VariableCreateOrUpdateResponse> CreateOrUpdateAsync(this IVariableOperations operations, string resourceGroupName, string automationAccount, VariableCreateOrUpdateParameters parameters)
 {
     return operations.CreateOrUpdateAsync(resourceGroupName, automationAccount, parameters, CancellationToken.None);
 }