/// <summary>
 /// Update a connection.  (see
 /// http://aka.ms/azureautomationsdk/connectionoperations for more
 /// information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.Automation.IConnectionOperations.
 /// </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 a connection
 /// operation.
 /// </param>
 /// <returns>
 /// A standard service response including an HTTP status code and
 /// request ID.
 /// </returns>
 public static AzureOperationResponse Patch(this IConnectionOperations operations, string resourceGroupName, string automationAccount, ConnectionPatchParameters parameters)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IConnectionOperations)s).PatchAsync(resourceGroupName, automationAccount, parameters);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
 /// <summary>
 /// Update a connection.  (see
 /// http://aka.ms/azureautomationsdk/connectionoperations for more
 /// information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.Automation.IConnectionOperations.
 /// </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 a connection
 /// operation.
 /// </param>
 /// <returns>
 /// A standard service response including an HTTP status code and
 /// request ID.
 /// </returns>
 public static Task<AzureOperationResponse> PatchAsync(this IConnectionOperations operations, string resourceGroupName, string automationAccount, ConnectionPatchParameters parameters)
 {
     return operations.PatchAsync(resourceGroupName, automationAccount, parameters, CancellationToken.None);
 }
        public Connection UpdateConnectionFieldValue(string resourceGroupName, string automationAccountName, string name,
            string connectionFieldName, object value)
        {
            var connectionModel = this.TryGetConnectionModel(resourceGroupName, automationAccountName, name);
            if (connectionModel == null)
            {
                throw new ResourceCommonException(typeof (Connection),
                    string.Format(CultureInfo.CurrentCulture, Resources.ConnectionNotFound, name));
            }

            if (connectionModel.Properties.FieldDefinitionValues.ContainsKey(connectionFieldName))
            {
                connectionModel.Properties.FieldDefinitionValues[connectionFieldName] =
                    PowerShellJsonConverter.Serialize(value);
            }
            else
            {
                throw new ResourceCommonException(typeof (Connection),
                    string.Format(CultureInfo.CurrentCulture, Resources.ConnectionFieldNameNotFound, name));
            }

            var cuparam = new ConnectionPatchParameters()
            {
                Name = name,
                Properties = new ConnectionPatchProperties()
                {
                    Description = connectionModel.Properties.Description,
                    FieldDefinitionValues = connectionModel.Properties.FieldDefinitionValues
                }
            };

            this.automationManagementClient.Connections.Patch(resourceGroupName, automationAccountName, cuparam);

            return new Connection(resourceGroupName, automationAccountName,
                this.automationManagementClient.Connections.Get(resourceGroupName, automationAccountName, name).Connection);
        }