コード例 #1
0
        public bool createWebHostingPlan(string resourceGroupName)
        {
            serverFarmParameters                              = new ServerFarmCreateOrUpdateParameters();
            serverFarmParameters.ServerFarm                   = new ServerFarm();
            serverFarmParameters.ServerFarm.Properties        = new ServerFarmProperties();
            serverFarmParameters.ServerFarm.Properties.Status = ServerFarmStatus.Ready;

            Console.WriteLine("...:::Collect Server Farm Parameters:::...");

            Console.Write("Server Farm Name:");
            serverFarmParameters.ServerFarm.Name = Console.ReadLine();

            Console.Write("Location:");
            serverFarmParameters.ServerFarm.Location = Regions.getRegion();

            Console.Write("Server Farm SKU: ");
            serverFarmParameters.ServerFarm.Properties.Sku = SKU.getSKU();

            if (SKU.isDeidicated(serverFarmParameters.ServerFarm.Properties.Sku))
            {
                Console.Write("Worker Size: ");
                var size = SIZE.getSize();
                serverFarmParameters.ServerFarm.Properties.WorkerSize        = size;
                serverFarmParameters.ServerFarm.Properties.CurrentWorkerSize = size;

                Console.Write("Number of Workers:");
                var number = 1;
                int.TryParse(Console.ReadLine(), out number);
                serverFarmParameters.ServerFarm.Properties.NumberOfWorkers        = number;
                serverFarmParameters.ServerFarm.Properties.CurrentNumberOfWorkers = number;
            }
            ServerFarmCreateOrUpdateResponse response = client.ServerFarms.CreateOrUpdate(resourceGroupName, serverFarmParameters);

            Console.WriteLine("Request ID \t" + response.RequestId + "\n" + "HTTP Status Code : \t" + response.StatusCode);

            listWebHostingPlan(resourceGroupName);

            return(true);
        }
コード例 #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='resourceGroupName'>
        /// Required. The name of the resource group.
        /// </param>
        /// <param name='parameters'>
        /// Required. Parameters supplied to the Create Server Farm operation.
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        /// <returns>
        /// The Create Server Farm operation response.
        /// </returns>
        public async Task <ServerFarmCreateOrUpdateResponse> CreateOrUpdateAsync(string resourceGroupName, ServerFarmCreateOrUpdateParameters parameters, CancellationToken cancellationToken)
        {
            // Validate
            if (resourceGroupName == null)
            {
                throw new ArgumentNullException("resourceGroupName");
            }
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }
            if (parameters.ServerFarm == null)
            {
                throw new ArgumentNullException("parameters.ServerFarm");
            }
            if (parameters.ServerFarm.Location == null)
            {
                throw new ArgumentNullException("parameters.ServerFarm.Location");
            }

            // 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("resourceGroupName", resourceGroupName);
                tracingParameters.Add("parameters", parameters);
                Tracing.Enter(invocationId, this, "CreateOrUpdateAsync", tracingParameters);
            }

            // Construct URL
            string url = "/subscriptions/" + (this.Client.Credentials.SubscriptionId != null ? this.Client.Credentials.SubscriptionId.Trim() : "") + "/resourceGroups/" + resourceGroupName.Trim() + "/providers/Microsoft.Web/serverFarms/" + parameters.ServerFarm.Name.Trim() + "?";

            url = url + "api-version=2014-04-01";
            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 serverFarmCreateOrUpdateParametersValue = new JObject();
                requestDoc = serverFarmCreateOrUpdateParametersValue;

                if (parameters.ServerFarm.Properties != null)
                {
                    JObject propertiesValue = new JObject();
                    serverFarmCreateOrUpdateParametersValue["properties"] = propertiesValue;

                    if (parameters.ServerFarm.Properties.CurrentNumberOfWorkers != null)
                    {
                        propertiesValue["currentNumberOfWorkers"] = parameters.ServerFarm.Properties.CurrentNumberOfWorkers;
                    }

                    if (parameters.ServerFarm.Properties.CurrentWorkerSize != null)
                    {
                        propertiesValue["currentWorkerSize"] = parameters.ServerFarm.Properties.CurrentWorkerSize.ToString();
                    }

                    propertiesValue["numberOfWorkers"] = parameters.ServerFarm.Properties.NumberOfWorkers;

                    if (parameters.ServerFarm.Properties.Sku != null)
                    {
                        propertiesValue["sku"] = parameters.ServerFarm.Properties.Sku;
                    }

                    propertiesValue["workerSize"] = parameters.ServerFarm.Properties.WorkerSize.ToString();

                    propertiesValue["status"] = parameters.ServerFarm.Properties.Status.ToString();

                    if (parameters.ServerFarm.Properties.ProvisioningState != null)
                    {
                        propertiesValue["provisioningState"] = parameters.ServerFarm.Properties.ProvisioningState;
                    }
                }

                if (parameters.ServerFarm.Id != null)
                {
                    serverFarmCreateOrUpdateParametersValue["id"] = parameters.ServerFarm.Id;
                }

                if (parameters.ServerFarm.Name != null)
                {
                    serverFarmCreateOrUpdateParametersValue["name"] = parameters.ServerFarm.Name;
                }

                serverFarmCreateOrUpdateParametersValue["location"] = parameters.ServerFarm.Location;

                JObject tagsDictionary = new JObject();
                if (parameters.ServerFarm.Tags != null)
                {
                    foreach (KeyValuePair <string, string> pair in parameters.ServerFarm.Tags)
                    {
                        string tagsKey   = pair.Key;
                        string tagsValue = pair.Value;
                        tagsDictionary[tagsKey] = tagsValue;
                    }
                }
                serverFarmCreateOrUpdateParametersValue["tags"] = tagsDictionary;

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

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

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

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

                    JToken serverFarmValue = responseDoc["ServerFarm"];
                    if (serverFarmValue != null && serverFarmValue.Type != JTokenType.Null)
                    {
                        ServerFarmCreateOrUpdateResponse serverFarmInstance = new ServerFarmCreateOrUpdateResponse();

                        ServerFarm serverFarmInstance2 = new ServerFarm();
                        result.ServerFarm = serverFarmInstance2;

                        JToken propertiesValue2 = serverFarmValue["properties"];
                        if (propertiesValue2 != null && propertiesValue2.Type != JTokenType.Null)
                        {
                            ServerFarmProperties propertiesInstance = new ServerFarmProperties();
                            serverFarmInstance2.Properties = propertiesInstance;

                            JToken currentNumberOfWorkersValue = propertiesValue2["currentNumberOfWorkers"];
                            if (currentNumberOfWorkersValue != null && currentNumberOfWorkersValue.Type != JTokenType.Null)
                            {
                                int currentNumberOfWorkersInstance = ((int)currentNumberOfWorkersValue);
                                propertiesInstance.CurrentNumberOfWorkers = currentNumberOfWorkersInstance;
                            }

                            JToken currentWorkerSizeValue = propertiesValue2["currentWorkerSize"];
                            if (currentWorkerSizeValue != null && currentWorkerSizeValue.Type != JTokenType.Null)
                            {
                                ServerFarmWorkerSize currentWorkerSizeInstance = ((ServerFarmWorkerSize)Enum.Parse(typeof(ServerFarmWorkerSize), ((string)currentWorkerSizeValue), true));
                                propertiesInstance.CurrentWorkerSize = currentWorkerSizeInstance;
                            }

                            JToken numberOfWorkersValue = propertiesValue2["numberOfWorkers"];
                            if (numberOfWorkersValue != null && numberOfWorkersValue.Type != JTokenType.Null)
                            {
                                int numberOfWorkersInstance = ((int)numberOfWorkersValue);
                                propertiesInstance.NumberOfWorkers = numberOfWorkersInstance;
                            }

                            JToken skuValue = propertiesValue2["sku"];
                            if (skuValue != null && skuValue.Type != JTokenType.Null)
                            {
                                string skuInstance = ((string)skuValue);
                                propertiesInstance.Sku = skuInstance;
                            }

                            JToken workerSizeValue = propertiesValue2["workerSize"];
                            if (workerSizeValue != null && workerSizeValue.Type != JTokenType.Null)
                            {
                                ServerFarmWorkerSize workerSizeInstance = ((ServerFarmWorkerSize)Enum.Parse(typeof(ServerFarmWorkerSize), ((string)workerSizeValue), true));
                                propertiesInstance.WorkerSize = workerSizeInstance;
                            }

                            JToken statusValue = propertiesValue2["status"];
                            if (statusValue != null && statusValue.Type != JTokenType.Null)
                            {
                                ServerFarmStatus statusInstance = ((ServerFarmStatus)Enum.Parse(typeof(ServerFarmStatus), ((string)statusValue), true));
                                propertiesInstance.Status = statusInstance;
                            }

                            JToken provisioningStateValue = propertiesValue2["provisioningState"];
                            if (provisioningStateValue != null && provisioningStateValue.Type != JTokenType.Null)
                            {
                                string provisioningStateInstance = ((string)provisioningStateValue);
                                propertiesInstance.ProvisioningState = provisioningStateInstance;
                            }
                        }

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

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

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

                        JToken tagsSequenceElement = ((JToken)serverFarmValue["tags"]);
                        if (tagsSequenceElement != null && tagsSequenceElement.Type != JTokenType.Null)
                        {
                            foreach (JProperty property in tagsSequenceElement)
                            {
                                string tagsKey2   = ((string)property.Name);
                                string tagsValue2 = ((string)property.Value);
                                serverFarmInstance2.Tags.Add(tagsKey2, tagsValue2);
                            }
                        }
                    }

                    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();
                }
            }
        }
コード例 #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.Azure.Management.WebSites.IServerFarmOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of the resource group.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to the Create Server Farm operation.
 /// </param>
 /// <returns>
 /// The Create Server Farm operation response.
 /// </returns>
 public static ServerFarmCreateOrUpdateResponse CreateOrUpdate(this IServerFarmOperations operations, string resourceGroupName, ServerFarmCreateOrUpdateParameters parameters)
 {
     return(Task.Factory.StartNew((object s) =>
     {
         return ((IServerFarmOperations)s).CreateOrUpdateAsync(resourceGroupName, parameters);
     }
                                  , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
コード例 #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.Azure.Management.WebSites.IServerFarmOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of the resource group.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to the Create Server Farm operation.
 /// </param>
 /// <returns>
 /// The Create Server Farm operation response.
 /// </returns>
 public static Task <ServerFarmCreateOrUpdateResponse> CreateOrUpdateAsync(this IServerFarmOperations operations, string resourceGroupName, ServerFarmCreateOrUpdateParameters parameters)
 {
     return(operations.CreateOrUpdateAsync(resourceGroupName, parameters, CancellationToken.None));
 }