/// <summary> /// Creates a new Web Hosting Plan. (see /// http://azure.microsoft.com/en-us/documentation/articles/azure-web-sites-web-hosting-plans-in-depth-overview/ /// for more information) /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.WindowsAzure.Management.WebSites.IWebHostingPlanOperations. /// </param> /// <param name='webSpaceName'> /// Required. The name of the web space. /// </param> /// <param name='parameters'> /// Required. Web Hosting Plan Parameters. /// </param> /// <returns> /// The Create Web Web Hosting Plan operation response. /// </returns> public static WebHostingPlanCreateResponse Create(this IWebHostingPlanOperations operations, string webSpaceName, WebHostingPlanCreateParameters parameters) { return Task.Factory.StartNew((object s) => { return ((IWebHostingPlanOperations)s).CreateAsync(webSpaceName, parameters); } , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult(); }
private async static Task<WebSiteCreateResponse> CreateWebSite(SubscriptionCloudCredentials credentials) { Console.WriteLine("Creating new Azure Web Site . . ."); WebSiteCreateResponse response = null; using (var client = new WebSiteManagementClient(credentials)) { var webspaces = await client.WebSpaces.ListAsync(); var myWebSpace = webspaces.First(x => x.GeoRegion == LocationNames.EastUS); var whp = new WebHostingPlanCreateParameters { Name = string.Format("{0}_whp", ResourceName.ToLower()), NumberOfWorkers = 1, SKU = SkuOptions.Free, WorkerSize = WorkerSizeOptions.Small }; var whpCreateResponse = await client.WebHostingPlans.CreateAsync(myWebSpace.Name,whp); WebSiteCreateParameters siteCreateParameters = new WebSiteCreateParameters { Name = string.Format("{0}{1}", ResourceName, new Random().Next(1, 200)), ServerFarm = whp.Name, WebSpace = new WebSiteCreateParameters.WebSpaceDetails { GeoRegion = LocationNames.EastUS, Name = myWebSpace.Name, Plan = "VirtualDedicatedPlan" } }; response = await client.WebSites.CreateAsync(myWebSpace.Name, siteCreateParameters); WebSiteGetPublishProfileResponse publishProfileResult = await client.WebSites.GetPublishProfileAsync(myWebSpace.Name, siteCreateParameters.Name); WebSiteGetPublishProfileResponse.PublishProfile profile = publishProfileResult.PublishProfiles.First(x => x.MSDeploySite != null); new WebDeployPublishingHelper( profile.PublishUrl, profile.MSDeploySite, profile.UserName, profile.UserPassword, WebSitePath).PublishFolder(); } return response; }
private void CreateTestServerFarmIfNeeded() { WebHostingPlanCreateParameters parameter = new WebHostingPlanCreateParameters(); parameter.Name = WebsiteServerFarmName; parameter.NumberOfWorkers = 2; parameter.WorkerSize = WorkerSizeOptions.Medium; try { WebsiteManagementClient.WebHostingPlans.Create(WebSpaceName, parameter); } catch (CloudException ce) { if (ce.Response.StatusCode == System.Net.HttpStatusCode.Conflict) { Console.WriteLine("A server farm already exists. Continuing."); } else { throw; } } }
/// <summary> /// Creates a new Web Hosting Plan. (see /// http://azure.microsoft.com/en-us/documentation/articles/azure-web-sites-web-hosting-plans-in-depth-overview/ /// for more information) /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.WindowsAzure.Management.WebSites.IWebHostingPlanOperations. /// </param> /// <param name='webSpaceName'> /// Required. The name of the web space. /// </param> /// <param name='parameters'> /// Required. Web Hosting Plan Parameters. /// </param> /// <returns> /// The Create Web Web Hosting Plan operation response. /// </returns> public static Task<WebHostingPlanCreateResponse> CreateAsync(this IWebHostingPlanOperations operations, string webSpaceName, WebHostingPlanCreateParameters parameters) { return operations.CreateAsync(webSpaceName, parameters, CancellationToken.None); }