/// <summary>
 /// Update source control for user.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.WebSites.ISourceControlOperations.
 /// </param>
 /// <param name='name'>
 /// Required. The name of the source control (can be: GitHub,
 /// Bitbucket, CodePlex, Dropbox)
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to the Update Source Control
 /// operation.
 /// </param>
 /// <returns>
 /// The update source control operation response.
 /// </returns>
 public static Task <SourceControlUpdateResponse> UpdateAsync(this ISourceControlOperations operations, string name, SourceControlUpdateParameters parameters)
 {
     return(operations.UpdateAsync(name, parameters, CancellationToken.None));
 }
 /// <summary>
 /// Update source control for user.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.WebSites.ISourceControlOperations.
 /// </param>
 /// <param name='name'>
 /// Required. The name of the source control (can be: GitHub,
 /// Bitbucket, CodePlex, Dropbox)
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to the Update Source Control
 /// operation.
 /// </param>
 /// <returns>
 /// The update source control operation response.
 /// </returns>
 public static SourceControlUpdateResponse Update(this ISourceControlOperations operations, string name, SourceControlUpdateParameters parameters)
 {
     return(Task.Factory.StartNew((object s) =>
     {
         return ((ISourceControlOperations)s).UpdateAsync(name, parameters);
     }
                                  , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
 /// <summary>
 /// Update a source control.
 /// <see href="http://aka.ms/azureautomationsdk/sourcecontroloperations" />
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Name of an Azure Resource group.
 /// </param>
 /// <param name='automationAccountName'>
 /// The name of the automation account.
 /// </param>
 /// <param name='sourceControlName'>
 /// The source control name.
 /// </param>
 /// <param name='parameters'>
 /// The parameters supplied to the update source control operation.
 /// </param>
 public static SourceControl Update(this ISourceControlOperations operations, string resourceGroupName, string automationAccountName, string sourceControlName, SourceControlUpdateParameters parameters)
 {
     return(operations.UpdateAsync(resourceGroupName, automationAccountName, sourceControlName, parameters).GetAwaiter().GetResult());
 }
        /// <summary>
        /// Update source control for user.
        /// </summary>
        /// <param name='name'>
        /// Required. The name of the source control (can be: GitHub,
        /// Bitbucket, CodePlex, Dropbox)
        /// </param>
        /// <param name='parameters'>
        /// Required. Parameters supplied to the Update Source Control
        /// operation.
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        /// <returns>
        /// The update source control operation response.
        /// </returns>
        public async Task <SourceControlUpdateResponse> UpdateAsync(string name, SourceControlUpdateParameters parameters, CancellationToken cancellationToken)
        {
            // Validate
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }
            if (parameters.Properties == null)
            {
                throw new ArgumentNullException("parameters.Properties");
            }

            // Tracing
            bool   shouldTrace  = TracingAdapter.IsEnabled;
            string invocationId = null;

            if (shouldTrace)
            {
                invocationId = TracingAdapter.NextInvocationId.ToString();
                Dictionary <string, object> tracingParameters = new Dictionary <string, object>();
                tracingParameters.Add("name", name);
                tracingParameters.Add("parameters", parameters);
                TracingAdapter.Enter(invocationId, this, "UpdateAsync", tracingParameters);
            }

            // Construct URL
            string url = "";

            url = url + "/providers/";
            url = url + "Microsoft.Web";
            url = url + "/SourceControls/";
            url = url + Uri.EscapeDataString(name);
            List <string> queryParameters = new List <string>();

            queryParameters.Add("api-version=2014-06-01");
            if (queryParameters.Count > 0)
            {
                url = url + "?" + string.Join("&", queryParameters);
            }
            string baseUrl = this.Client.BaseUri.AbsoluteUri;

            // Trim '/' character from the end of baseUrl and beginning of url.
            if (baseUrl[baseUrl.Length - 1] == '/')
            {
                baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
            }
            if (url[0] == '/')
            {
                url = url.Substring(1);
            }
            url = baseUrl + "/" + url;
            url = url.Replace(" ", "%20");

            // Create HTTP transport objects
            HttpRequestMessage httpRequest = null;

            try
            {
                httpRequest            = new HttpRequestMessage();
                httpRequest.Method     = HttpMethod.Put;
                httpRequest.RequestUri = new Uri(url);

                // Set Headers

                // Set Credentials
                cancellationToken.ThrowIfCancellationRequested();
                await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);

                // Serialize Request
                string requestContent = null;
                JToken requestDoc     = null;

                JObject sourceControlUpdateParametersValue = new JObject();
                requestDoc = sourceControlUpdateParametersValue;

                JObject propertiesValue = new JObject();
                sourceControlUpdateParametersValue["properties"] = propertiesValue;

                if (parameters.Properties.Token != null)
                {
                    propertiesValue["token"] = parameters.Properties.Token;
                }

                if (parameters.Properties.TokenSecret != null)
                {
                    propertiesValue["tokenSecret"] = parameters.Properties.TokenSecret;
                }

                requestContent      = requestDoc.ToString(Newtonsoft.Json.Formatting.Indented);
                httpRequest.Content = new StringContent(requestContent, Encoding.UTF8);
                httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");

                // Send Request
                HttpResponseMessage httpResponse = null;
                try
                {
                    if (shouldTrace)
                    {
                        TracingAdapter.SendRequest(invocationId, httpRequest);
                    }
                    cancellationToken.ThrowIfCancellationRequested();
                    httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);

                    if (shouldTrace)
                    {
                        TracingAdapter.ReceiveResponse(invocationId, httpResponse);
                    }
                    HttpStatusCode statusCode = httpResponse.StatusCode;
                    if (statusCode != HttpStatusCode.OK)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        CloudException ex = CloudException.Create(httpRequest, requestContent, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
                        if (shouldTrace)
                        {
                            TracingAdapter.Error(invocationId, ex);
                        }
                        throw ex;
                    }

                    // Create Result
                    SourceControlUpdateResponse result = null;
                    // Deserialize Response
                    if (statusCode == HttpStatusCode.OK)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

                        result = new SourceControlUpdateResponse();
                        JToken responseDoc = null;
                        if (string.IsNullOrEmpty(responseContent) == false)
                        {
                            responseDoc = JToken.Parse(responseContent);
                        }

                        JToken sourceControlValue = responseDoc["SourceControl"];
                        if (sourceControlValue != null && sourceControlValue.Type != JTokenType.Null)
                        {
                            SourceControlUpdateResponse sourceControlInstance = new SourceControlUpdateResponse();

                            SourceControl sourceControlInstance2 = new SourceControl();
                            result.SourceControl = sourceControlInstance2;

                            JToken propertiesValue2 = sourceControlValue["properties"];
                            if (propertiesValue2 != null && propertiesValue2.Type != JTokenType.Null)
                            {
                                SourceControlProperties propertiesInstance = new SourceControlProperties();
                                sourceControlInstance2.Properties = propertiesInstance;

                                JToken tokenValue = propertiesValue2["token"];
                                if (tokenValue != null && tokenValue.Type != JTokenType.Null)
                                {
                                    string tokenInstance = ((string)tokenValue);
                                    propertiesInstance.Token = tokenInstance;
                                }

                                JToken tokenSecretValue = propertiesValue2["tokenSecret"];
                                if (tokenSecretValue != null && tokenSecretValue.Type != JTokenType.Null)
                                {
                                    string tokenSecretInstance = ((string)tokenSecretValue);
                                    propertiesInstance.TokenSecret = tokenSecretInstance;
                                }
                            }

                            JToken idValue = sourceControlValue["id"];
                            if (idValue != null && idValue.Type != JTokenType.Null)
                            {
                                string idInstance = ((string)idValue);
                                sourceControlInstance2.Id = idInstance;
                            }

                            JToken nameValue = sourceControlValue["name"];
                            if (nameValue != null && nameValue.Type != JTokenType.Null)
                            {
                                string nameInstance = ((string)nameValue);
                                sourceControlInstance2.Name = nameInstance;
                            }

                            JToken locationValue = sourceControlValue["location"];
                            if (locationValue != null && locationValue.Type != JTokenType.Null)
                            {
                                string locationInstance = ((string)locationValue);
                                sourceControlInstance2.Location = locationInstance;
                            }

                            JToken tagsSequenceElement = ((JToken)sourceControlValue["tags"]);
                            if (tagsSequenceElement != null && tagsSequenceElement.Type != JTokenType.Null)
                            {
                                foreach (JProperty property in tagsSequenceElement)
                                {
                                    string tagsKey   = ((string)property.Name);
                                    string tagsValue = ((string)property.Value);
                                    sourceControlInstance2.Tags.Add(tagsKey, tagsValue);
                                }
                            }

                            JToken typeValue = sourceControlValue["type"];
                            if (typeValue != null && typeValue.Type != JTokenType.Null)
                            {
                                string typeInstance = ((string)typeValue);
                                sourceControlInstance2.Type = typeInstance;
                            }
                        }
                    }
                    result.StatusCode = statusCode;
                    if (httpResponse.Headers.Contains("x-ms-request-id"))
                    {
                        result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
                    }

                    if (shouldTrace)
                    {
                        TracingAdapter.Exit(invocationId, result);
                    }
                    return(result);
                }
                finally
                {
                    if (httpResponse != null)
                    {
                        httpResponse.Dispose();
                    }
                }
            }
            finally
            {
                if (httpRequest != null)
                {
                    httpRequest.Dispose();
                }
            }
        }
 /// <summary>
 /// Update a source control.
 /// <see href="http://aka.ms/azureautomationsdk/sourcecontroloperations" />
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Name of an Azure Resource group.
 /// </param>
 /// <param name='automationAccountName'>
 /// The name of the automation account.
 /// </param>
 /// <param name='sourceControlName'>
 /// The source control name.
 /// </param>
 /// <param name='parameters'>
 /// The parameters supplied to the update source control operation.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <SourceControl> UpdateAsync(this ISourceControlOperations operations, string resourceGroupName, string automationAccountName, string sourceControlName, SourceControlUpdateParameters parameters, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.UpdateWithHttpMessagesAsync(resourceGroupName, automationAccountName, sourceControlName, parameters, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }