/// <summary> /// Checks for the existence of a specific Azure Web Site, if it doesn't exist it will create it. /// </summary> /// <param name="client">The <see cref="WebSiteManagementClient"/> that is performing the operation.</param> /// <param name="model">The DevOpsFlex rich model object that contains everything there is to know about this web site spec.</param> /// <returns>The async <see cref="Task"/> wrapper.</returns> public static async Task CreateWebSiteIfNotExistsAsync(this WebSiteManagementClient client, AzureWebSite model) { Contract.Requires(client != null); Contract.Requires(model != null); var webSpace = model.System.WebSpace.GetEnumDescription(); string webPlan; lock (HostingPlanGate) { FlexStreams.BuildEventsObserver.OnNext(new CheckForParentResourceEvent(AzureResource.HostingPlan, AzureResource.WebSite, model.Name)); webPlan = FlexConfiguration.WebPlanChooser.Choose(client, webSpace).Result; if (webPlan == null) { var response = client.WebHostingPlans.Create(webSpace, new WebHostingPlanCreateParameters { Name = model.System.LogicalName + "-" + webSpace, NumberOfWorkers = 1, SKU = SkuOptions.Standard, WorkerSize = WorkerSizeOptions.Medium }); webPlan = response.WebHostingPlan.Name; FlexStreams.BuildEventsObserver.OnNext(new ProvisionEvent(AzureResource.HostingPlan, webPlan)); } else { FlexStreams.BuildEventsObserver.OnNext(new FoundExistingEvent(AzureResource.HostingPlan, webPlan)); } } await CreateWebSiteIfNotExistsAsync( client, webSpace, new WebSiteCreateParameters { Name = FlexDataConfiguration.GetNaming<AzureWebSite>().GetSlotName(model, FlexDataConfiguration.Branch, FlexDataConfiguration.Configuration), ServerFarm = webPlan }); }
/// <summary> /// Checks for the existence of a specific Azure Web Site, if it doesn't exist it will create it. /// </summary> /// <param name="client">The <see cref="WebSiteManagementClient"/> that is performing the operation.</param> /// <param name="model">The DevOpsFlex rich model object that contains everything there is to know about this web site spec.</param> /// <returns>The async <see cref="Task"/> wrapper.</returns> public static async Task CreateWebSiteIfNotExistsAsync(this WebSiteManagementClient client, AzureWebSite model) { Contract.Requires(client != null); Contract.Requires(model != null); var webSpace = model.System.WebSpace.GetEnumDescription(); string webPlan; lock (HostingPlanGate) { FlexStreams.BuildEventsObserver.OnNext(new CheckForParentResourceEvent(AzureResource.HostingPlan, AzureResource.WebSite, model.Name)); webPlan = FlexConfiguration.WebPlanChooser.Choose(client, webSpace).Result; if (webPlan == null) { var response = client.WebHostingPlans.Create(webSpace, new WebHostingPlanCreateParameters { Name = model.System.LogicalName + "-" + webSpace, NumberOfWorkers = 1, SKU = SkuOptions.Standard, WorkerSize = WorkerSizeOptions.Medium }); webPlan = response.WebHostingPlan.Name; FlexStreams.BuildEventsObserver.OnNext(new ProvisionEvent(AzureResource.HostingPlan, webPlan)); } else { FlexStreams.BuildEventsObserver.OnNext(new FoundExistingEvent(AzureResource.HostingPlan, webPlan)); } } await CreateWebSiteIfNotExistsAsync( client, webSpace, new WebSiteCreateParameters { Name = FlexDataConfiguration.GetNaming <AzureWebSite>().GetSlotName(model, FlexDataConfiguration.Branch, FlexDataConfiguration.Configuration), ServerFarm = webPlan }); }