/// <summary>
 /// You can create a web site by using a POST request that includes the
 /// name of the web site and other information in the request body.
 /// (see
 /// http://msdn.microsoft.com/en-us/library/windowsazure/dn166986.aspx
 /// for more information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.WebSites.IWebSiteOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of the resource group.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to the Create Web Site operation.
 /// </param>
 /// <returns>
 /// The Create Web Space operation response.
 /// </returns>
 public static WebSiteCreateResponse CreateOrUpdate(this IWebSiteOperations operations, string resourceGroupName, WebSiteCreateOrUpdateParameters parameters)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IWebSiteOperations)s).CreateOrUpdateAsync(resourceGroupName, parameters);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
        public bool createWebsite(string resourceGroupName)
        {
            websiteParameters = new WebSiteCreateOrUpdateParameters();
            websiteParameters.WebSite = new WebSiteBase();
            websiteParameters.WebSite.Properties = new WebSiteBaseProperties();
            var hostnames = new List<string>();

            var ServerFarmSample = new ARM_WebHostingPlan_Sample();
            ServerFarmSample.client = client;

            Console.WriteLine("...:::Collect Server Farm Parameters:::...");
            Console.WriteLine("Site Name: ");
            websiteParameters.WebSite.Name = Console.ReadLine();
            hostnames.Add(websiteParameters.WebSite.Name + ".azurewebsites.net");
            websiteParameters.WebSite.Properties.HostNames = hostnames;

            Console.WriteLine("Web Hosting Plan: ");
            var serverFarm = ServerFarmSample.getWebHostingPlan(resourceGroupName, Console.ReadLine());

            if (serverFarm != null)
            {
                websiteParameters.WebSite.Location = serverFarm.Location;
                websiteParameters.WebSite.Properties.ServerFarm = serverFarm.Name;
            }

            var response = client.WebSites.CreateOrUpdate(resourceGroupName, websiteParameters);

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                Console.WriteLine(JsonConvert.SerializeObject(response.WebSite, Formatting.Indented));
            }
            else {
                Console.WriteLine("ERROR: " + response.StatusCode);
            }

            listSites(resourceGroupName);

            return true;
        }
 /// <summary>
 /// You can create a web site by using a POST request that includes the
 /// name of the web site and other information in the request body.
 /// (see
 /// http://msdn.microsoft.com/en-us/library/windowsazure/dn166986.aspx
 /// for more information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.WebSites.IWebSiteOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of the resource group.
 /// </param>
 /// <param name='webSiteName'>
 /// Required. The name of the web site.
 /// </param>
 /// <param name='slotName'>
 /// Optional. The name of the slot.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to the Create Web Site operation.
 /// </param>
 /// <returns>
 /// The Create Web Space operation response.
 /// </returns>
 public static Task<WebSiteCreateResponse> CreateOrUpdateAsync(this IWebSiteOperations operations, string resourceGroupName, string webSiteName, string slotName, WebSiteCreateOrUpdateParameters parameters)
 {
     return operations.CreateOrUpdateAsync(resourceGroupName, webSiteName, slotName, parameters, CancellationToken.None);
 }
예제 #4
0
        static async Task CreateSite(string rgName, string whpName, string siteName, string location)
        {
            // Create/Update the resource group
            var rgCreateResult = await _resourceGroupClient.ResourceGroups.CreateOrUpdateAsync(rgName, new ResourceGroup { Location = location });

            // Create/Update the Web Hosting Plan
            var whpCreateParams = new WebHostingPlanCreateOrUpdateParameters
            {
                WebHostingPlan = new WebHostingPlan
                {
                    Name = whpName,
                    Location = location,
                    Properties = new WebHostingPlanProperties
                    {
                        Sku = SkuOptions.Free
                    }
                }
            };
            var whpCreateResult = await _websiteClient.WebHostingPlans.CreateOrUpdateAsync(rgName, whpCreateParams);

            // Create/Update the Website
            var createParams = new WebSiteCreateOrUpdateParameters
            {
                WebSite = new WebSiteBase
                {
                    Name = siteName,
                    Location = location,
                    Properties = new WebSiteBaseProperties
                    {
                        ServerFarm = whpName
                    }
                }
            };
            var siteCreateResult = await _websiteClient.WebSites.CreateOrUpdateAsync(rgName, siteName, null /*slot*/, createParams);

            // Create/Update the Website configuration
            var siteUpdateParams = new WebSiteUpdateConfigurationParameters
            {
                Location = location,
                Properties = new WebSiteUpdateConfigurationDetails
                {
                    PhpVersion = "5.6",
                }
            };
            var siteUpdateRes = await _websiteClient.WebSites.UpdateConfigurationAsync(rgName, siteName, null /*slot*/, siteUpdateParams);

            // List current App Settings
            var appSettingsRes = await _websiteClient.WebSites.GetAppSettingsAsync(rgName, siteName, null /*slot*/);
            foreach (var appSetting in appSettingsRes.Resource.Properties)
            {
                Console.WriteLine("{0} = {1}", appSetting.Name, appSetting.Value);
            }

            // Create/Update some App Settings
            var appSettingsParams = new WebSiteNameValueParameters
            {
                Location = location,
                Properties = new List<NameValuePair>
                {
                    new NameValuePair { Name = "MyFirstKey", Value = "My first value"},
                    new NameValuePair { Name = "MySecondKey", Value = "My second value"}
                }
            };
            appSettingsRes = await _websiteClient.WebSites.UpdateAppSettingsAsync(rgName, siteName, null /*slot*/, appSettingsParams);

            // Create/Update some Connection Strings
            var connStringsParams = new WebSiteUpdateConnectionStringsParameters
            {
                Location = location,
                Properties = new List<ConnectionStringInfo>
                {
                    new ConnectionStringInfo { Name = "MyFirstConnString", ConnectionString = "My SQL conn string", Type = DatabaseServerType.SQLAzure},
                    new ConnectionStringInfo { Name = "MySecondConnString", ConnectionString = "My custom conn string", Type = DatabaseServerType.Custom}
                }
            };
            var connStringsRes = await _websiteClient.WebSites.UpdateConnectionStringsAsync(rgName, siteName, null /*slot*/, connStringsParams);
        }