コード例 #1
0
        /// <summary>
        /// You can create a server farm by issuing an HTTP POST request. Only
        /// one server farm per webspace is permitted. You can retrieve server
        /// farm details by using HTTP GET, change server farm properties by
        /// using HTTP PUT, and delete a server farm by using HTTP DELETE. A
        /// request body is required for server farm creation (HTTP POST) and
        /// server farm update (HTTP PUT).  Warning: Creating a server farm
        /// changes your webspace’s Compute Mode from Shared to Dedicated. You
        /// will be charged from the moment the server farm is created, even
        /// if all your sites are still running in Free mode.  (see
        /// http://msdn.microsoft.com/en-us/library/windowsazure/dn194277.aspx
        /// for more information)
        /// </summary>
        /// <param name='webSpaceName'>
        /// The name of the web space.
        /// </param>
        /// <param name='parameters'>
        /// Parameters supplied to the Update Server Farm operation.
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        /// <returns>
        /// The Update Server Farm operation response.
        /// </returns>
        public async Task <ServerFarmUpdateResponse> UpdateAsync(string webSpaceName, ServerFarmUpdateParameters parameters, CancellationToken cancellationToken)
        {
            // Validate
            if (webSpaceName == null)
            {
                throw new ArgumentNullException("webSpaceName");
            }
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            // Tracing
            bool   shouldTrace  = CloudContext.Configuration.Tracing.IsEnabled;
            string invocationId = null;

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

            // Construct URL
            string url = new Uri(this.Client.BaseUri, "/").ToString() + this.Client.Credentials.SubscriptionId + "/services/WebSpaces/" + webSpaceName + "/ServerFarms/DefaultServerFarm";

            // Create HTTP transport objects
            HttpRequestMessage httpRequest = null;

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

                // Set Headers
                httpRequest.Headers.Add("x-ms-version", "2013-08-01");

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

                // Serialize Request
                string    requestContent = null;
                XDocument requestDoc     = new XDocument();

                XElement serverFarmElement = new XElement(XName.Get("ServerFarm", "http://schemas.microsoft.com/windowsazure"));
                requestDoc.Add(serverFarmElement);

                if (parameters.CurrentNumberOfWorkers != null)
                {
                    XElement currentNumberOfWorkersElement = new XElement(XName.Get("CurrentNumberOfWorkers", "http://schemas.microsoft.com/windowsazure"));
                    currentNumberOfWorkersElement.Value = parameters.CurrentNumberOfWorkers.ToString();
                    serverFarmElement.Add(currentNumberOfWorkersElement);
                }

                if (parameters.CurrentWorkerSize != null)
                {
                    XElement currentWorkerSizeElement = new XElement(XName.Get("CurrentWorkerSize", "http://schemas.microsoft.com/windowsazure"));
                    currentWorkerSizeElement.Value = parameters.CurrentWorkerSize.ToString();
                    serverFarmElement.Add(currentWorkerSizeElement);
                }

                XElement nameElement = new XElement(XName.Get("Name", "http://schemas.microsoft.com/windowsazure"));
                nameElement.Value = "DefaultServerFarm";
                serverFarmElement.Add(nameElement);

                XElement numberOfWorkersElement = new XElement(XName.Get("NumberOfWorkers", "http://schemas.microsoft.com/windowsazure"));
                numberOfWorkersElement.Value = parameters.NumberOfWorkers.ToString();
                serverFarmElement.Add(numberOfWorkersElement);

                XElement workerSizeElement = new XElement(XName.Get("WorkerSize", "http://schemas.microsoft.com/windowsazure"));
                workerSizeElement.Value = parameters.WorkerSize.ToString();
                serverFarmElement.Add(workerSizeElement);

                if (parameters.Status != null)
                {
                    XElement statusElement = new XElement(XName.Get("Status", "http://schemas.microsoft.com/windowsazure"));
                    statusElement.Value = parameters.Status.ToString();
                    serverFarmElement.Add(statusElement);
                }

                requestContent      = requestDoc.ToString();
                httpRequest.Content = new StringContent(requestContent, Encoding.UTF8);
                httpRequest.Content.Headers.ContentType = new MediaTypeHeaderValue("application/xml");

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

                    if (shouldTrace)
                    {
                        Tracing.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), CloudExceptionType.Xml);
                        if (shouldTrace)
                        {
                            Tracing.Error(invocationId, ex);
                        }
                        throw ex;
                    }

                    // Create Result
                    ServerFarmUpdateResponse result = null;
                    // Deserialize Response
                    cancellationToken.ThrowIfCancellationRequested();
                    string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

                    result = new ServerFarmUpdateResponse();
                    XDocument responseDoc = XDocument.Parse(responseContent);

                    XElement serverFarmElement2 = responseDoc.Element(XName.Get("ServerFarm", "http://schemas.microsoft.com/windowsazure"));
                    if (serverFarmElement2 != null)
                    {
                        XElement currentNumberOfWorkersElement2 = serverFarmElement2.Element(XName.Get("CurrentNumberOfWorkers", "http://schemas.microsoft.com/windowsazure"));
                        if (currentNumberOfWorkersElement2 != null)
                        {
                            int currentNumberOfWorkersInstance = int.Parse(currentNumberOfWorkersElement2.Value, CultureInfo.InvariantCulture);
                            result.CurrentNumberOfWorkers = currentNumberOfWorkersInstance;
                        }

                        XElement currentWorkerSizeElement2 = serverFarmElement2.Element(XName.Get("CurrentWorkerSize", "http://schemas.microsoft.com/windowsazure"));
                        if (currentWorkerSizeElement2 != null)
                        {
                            ServerFarmWorkerSize currentWorkerSizeInstance = (ServerFarmWorkerSize)Enum.Parse(typeof(ServerFarmWorkerSize), currentWorkerSizeElement2.Value, false);
                            result.CurrentWorkerSize = currentWorkerSizeInstance;
                        }

                        XElement nameElement2 = serverFarmElement2.Element(XName.Get("Name", "http://schemas.microsoft.com/windowsazure"));
                        if (nameElement2 != null)
                        {
                            string nameInstance = nameElement2.Value;
                            result.Name = nameInstance;
                        }

                        XElement numberOfWorkersElement2 = serverFarmElement2.Element(XName.Get("NumberOfWorkers", "http://schemas.microsoft.com/windowsazure"));
                        if (numberOfWorkersElement2 != null)
                        {
                            int numberOfWorkersInstance = int.Parse(numberOfWorkersElement2.Value, CultureInfo.InvariantCulture);
                            result.NumberOfWorkers = numberOfWorkersInstance;
                        }

                        XElement workerSizeElement2 = serverFarmElement2.Element(XName.Get("WorkerSize", "http://schemas.microsoft.com/windowsazure"));
                        if (workerSizeElement2 != null)
                        {
                            ServerFarmWorkerSize workerSizeInstance = (ServerFarmWorkerSize)Enum.Parse(typeof(ServerFarmWorkerSize), workerSizeElement2.Value, false);
                            result.WorkerSize = workerSizeInstance;
                        }

                        XElement statusElement2 = serverFarmElement2.Element(XName.Get("Status", "http://schemas.microsoft.com/windowsazure"));
                        if (statusElement2 != null)
                        {
                            ServerFarmStatus statusInstance = (ServerFarmStatus)Enum.Parse(typeof(ServerFarmStatus), statusElement2.Value, false);
                            result.Status = statusInstance;
                        }
                    }

                    result.StatusCode = statusCode;
                    if (httpResponse.Headers.Contains("x-ms-request-id"))
                    {
                        result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
                    }

                    if (shouldTrace)
                    {
                        Tracing.Exit(invocationId, result);
                    }
                    return(result);
                }
                finally
                {
                    if (httpResponse != null)
                    {
                        httpResponse.Dispose();
                    }
                }
            }
            finally
            {
                if (httpRequest != null)
                {
                    httpRequest.Dispose();
                }
            }
        }
コード例 #2
0
 /// <summary>
 /// You can create a server farm by issuing an HTTP POST request. Only
 /// one server farm per webspace is permitted. You can retrieve server
 /// farm details by using HTTP GET, change server farm properties by
 /// using HTTP PUT, and delete a server farm by using HTTP DELETE. A
 /// request body is required for server farm creation (HTTP POST) and
 /// server farm update (HTTP PUT).  Warning: Creating a server farm
 /// changes your webspace’s Compute Mode from Shared to Dedicated. You
 /// will be charged from the moment the server farm is created, even
 /// if all your sites are still running in Free mode.  (see
 /// http://msdn.microsoft.com/en-us/library/windowsazure/dn194277.aspx
 /// for more information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.WebSites.IServerFarmOperations.
 /// </param>
 /// <param name='webSpaceName'>
 /// The name of the web space.
 /// </param>
 /// <param name='parameters'>
 /// Parameters supplied to the Update Server Farm operation.
 /// </param>
 /// <returns>
 /// The Update Server Farm operation response.
 /// </returns>
 public static ServerFarmUpdateResponse Update(this IServerFarmOperations operations, string webSpaceName, ServerFarmUpdateParameters parameters)
 {
     try
     {
         return(operations.UpdateAsync(webSpaceName, parameters).Result);
     }
     catch (AggregateException ex)
     {
         if (ex.InnerExceptions.Count > 1)
         {
             throw;
         }
         else
         {
             throw ex.InnerException;
         }
     }
 }
コード例 #3
0
 /// <summary>
 /// You can create a server farm by issuing an HTTP POST request. Only
 /// one server farm per webspace is permitted. You can retrieve server
 /// farm details by using HTTP GET, change server farm properties by
 /// using HTTP PUT, and delete a server farm by using HTTP DELETE. A
 /// request body is required for server farm creation (HTTP POST) and
 /// server farm update (HTTP PUT).  Warning: Creating a server farm
 /// changes your webspace’s Compute Mode from Shared to Dedicated. You
 /// will be charged from the moment the server farm is created, even
 /// if all your sites are still running in Free mode.  (see
 /// http://msdn.microsoft.com/en-us/library/windowsazure/dn194277.aspx
 /// for more information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.WebSites.IServerFarmOperations.
 /// </param>
 /// <param name='webSpaceName'>
 /// The name of the web space.
 /// </param>
 /// <param name='parameters'>
 /// Parameters supplied to the Update Server Farm operation.
 /// </param>
 /// <returns>
 /// The Update Server Farm operation response.
 /// </returns>
 public static Task <ServerFarmUpdateResponse> UpdateAsync(this IServerFarmOperations operations, string webSpaceName, ServerFarmUpdateParameters parameters)
 {
     return(operations.UpdateAsync(webSpaceName, parameters, CancellationToken.None));
 }
コード例 #4
0
 /// <summary>
 /// You can create a server farm by issuing an HTTP POST request. Only
 /// one server farm per webspace is permitted. You can retrieve server
 /// farm details by using HTTP GET, change server farm properties by
 /// using HTTP PUT, and delete a server farm by using HTTP DELETE. A
 /// request body is required for server farm creation (HTTP POST) and
 /// server farm update (HTTP PUT). Warning: Creating a server farm
 /// changes your webspace's Compute Mode from Shared to Dedicated. You
 /// will be charged from the moment the server farm is created, even
 /// if all your sites are still running in Free mode.  (see
 /// http://msdn.microsoft.com/en-us/library/windowsazure/dn194277.aspx
 /// for more information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.WebSites.IServerFarmOperations.
 /// </param>
 /// <param name='webSpaceName'>
 /// Required. The name of the web space.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to the Update Server Farm operation.
 /// </param>
 /// <returns>
 /// The Update Server Farm operation response.
 /// </returns>
 public static ServerFarmUpdateResponse Update(this IServerFarmOperations operations, string webSpaceName, ServerFarmUpdateParameters parameters)
 {
     return(Task.Factory.StartNew((object s) =>
     {
         return ((IServerFarmOperations)s).UpdateAsync(webSpaceName, parameters);
     }
                                  , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }