internal static Site ToSite(this WebSiteGetResponse response) { return(new Site { Name = response.WebSite.Name, State = response.WebSite.State.ToString(), HostNames = response.WebSite.HostNames.ToArray(), WebSpace = response.WebSite.WebSpace, SelfLink = response.WebSite.Uri, RepositorySiteName = response.WebSite.RepositorySiteName, Owner = response.WebSite.Owner, UsageState = (UsageState)(int)response.WebSite.UsageState, Enabled = response.WebSite.Enabled, AdminEnabled = response.WebSite.AdminEnabled, EnabledHostNames = response.WebSite.EnabledHostNames.ToArray(), SiteProperties = new SiteProperties { Metadata = response.WebSite.SiteProperties.Metadata.Select(ToNameValuePair).ToList(), Properties = response.WebSite.SiteProperties.Properties.Select(ToNameValuePair).ToList() }, AvailabilityState = (SiteAvailabilityState)(int)response.WebSite.AvailabilityState, SSLCertificates = response.WebSite.SslCertificates.Select(ToCertificate).ToArray(), SiteMode = response.WebSite.SiteMode.ToString(), HostNameSslStates = new HostNameSslStates(response.WebSite.HostNameSslStates.Select(ToNameSslState).ToList()) }); }
/// <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="webSpace">The name of the Web Space where the site should be.</param> /// <param name="parameters">The <see cref="WebSiteCreateParameters"/> that define the site we want to create.</param> /// <returns>The async <see cref="Task"/> wrapper.</returns> public static async Task CreateWebSiteIfNotExistsAsync(this WebSiteManagementClient client, string webSpace, WebSiteCreateParameters parameters) { Contract.Requires(client != null); Contract.Requires(!string.IsNullOrWhiteSpace(webSpace)); Contract.Requires(parameters != null); WebSiteGetResponse service = null; FlexStreams.BuildEventsObserver.OnNext(new CheckIfExistsEvent(AzureResource.WebSite, parameters.Name)); try { service = await client.WebSites.GetAsync(webSpace, parameters.Name, null); } catch (CloudException cex) { if (cex.Error.Code != "NotFound") { throw; } } if (service != null) { FlexStreams.BuildEventsObserver.OnNext(new FoundExistingEvent(AzureResource.WebSite, parameters.Name)); return; } await client.WebSites.CreateAsync(webSpace, parameters); FlexStreams.BuildEventsObserver.OnNext(new ProvisionEvent(AzureResource.WebSite, parameters.Name)); }
private IList <String> GetWebsiteHostNames(string websiteName) { WebSiteGetResponse response = WebsiteManagementClient.WebSites.Get(WebSpaceName, websiteName, new WebSiteGetParameters { PropertiesToInclude = { "HostNames" } }); return(response.WebSite.HostNames); }
public void CreateAndDeleteWebsite() { RunWebsiteTestScenario( (webSiteName, resourceGroupName, whpName, locationName, webSitesClient, resourcesClient) => { #region Start/Stop website AzureOperationResponse stopResponse = webSitesClient.WebSites.Stop(resourceGroupName, webSiteName, null); Assert.Equal(HttpStatusCode.OK, stopResponse.StatusCode); WebSiteGetParameters parameters = new WebSiteGetParameters() { PropertiesToInclude = null }; WebSiteGetResponse getWebSiteResponse = webSitesClient.WebSites.Get(resourceGroupName, webSiteName, null, parameters); Assert.NotNull(getWebSiteResponse); Assert.NotNull(getWebSiteResponse.WebSite); Assert.NotNull(getWebSiteResponse.WebSite.Properties); Assert.Equal(getWebSiteResponse.WebSite.Properties.State, WebSiteState.Stopped); AzureOperationResponse startResponse = webSitesClient.WebSites.Start(resourceGroupName, webSiteName, null); Assert.Equal(HttpStatusCode.OK, startResponse.StatusCode); getWebSiteResponse = webSitesClient.WebSites.Get(resourceGroupName, webSiteName, null, null); Assert.NotNull(getWebSiteResponse); Assert.NotNull(getWebSiteResponse.WebSite); Assert.NotNull(getWebSiteResponse.WebSite.Properties); Assert.Equal(getWebSiteResponse.WebSite.Properties.State, WebSiteState.Running); #endregion Start/Stop website webSitesClient.WebSites.Delete(resourceGroupName, webSiteName, null, new WebSiteDeleteParameters { DeleteAllSlots = true }); var webSites = webSitesClient.WebSites.List(resourceGroupName, null, null); Assert.Equal(0, webSites.WebSites.Count); }); }