/// <summary>
 /// Update 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 patch variable operation.
 /// </param>
 /// <returns>
 /// A standard service response including an HTTP status code and
 /// request ID.
 /// </returns>
 public static Task<AzureOperationResponse> PatchAsync(this IVariableOperations operations, string resourceGroupName, string automationAccount, VariablePatchParameters parameters)
 {
     return operations.PatchAsync(resourceGroupName, automationAccount, parameters, CancellationToken.None);
 }
Пример #2
0
        public Variable UpdateVariable(Variable variable, VariableUpdateFields updateFields)
        {
            var existingVariable = this.GetVariable(variable.ResourceGroupName, variable.AutomationAccountName, variable.Name);

            if (existingVariable.Encrypted != variable.Encrypted && updateFields == VariableUpdateFields.OnlyValue)
            {
                throw new ResourceNotFoundException(typeof(Variable),
                    string.Format(CultureInfo.CurrentCulture, Resources.VariableEncryptionCannotBeChanged, variable.Name,
                        existingVariable.Encrypted));
            }

            var updateParams = new AutomationManagement.Models.VariablePatchParameters()
            {
                Name = variable.Name,
            };

            if (updateFields == VariableUpdateFields.OnlyDescription)
            {
                updateParams.Properties = new AutomationManagement.Models.VariablePatchProperties()
                {
                    Description = variable.Description
                };
            }
            else
            {
                updateParams.Properties = new AutomationManagement.Models.VariablePatchProperties()
                {
                    Value = PowerShellJsonConverter.Serialize(variable.Value)
                };
            }

            this.automationManagementClient.Variables.Patch(variable.ResourceGroupName, variable.AutomationAccountName, updateParams);

            return this.GetVariable(variable.ResourceGroupName, variable.AutomationAccountName, variable.Name);
        }
 /// <summary>
 /// Update 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 patch variable operation.
 /// </param>
 /// <returns>
 /// A standard service response including an HTTP status code and
 /// request ID.
 /// </returns>
 public static AzureOperationResponse Patch(this IVariableOperations operations, string resourceGroupName, string automationAccount, VariablePatchParameters parameters)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IVariableOperations)s).PatchAsync(resourceGroupName, automationAccount, parameters);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }