public void GetAndSetSiteLimits()
        {
            var handler = new RecordedDelegatingHandler() { StatusCodeToReturn = HttpStatusCode.OK };

            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                var webSitesClient = ResourceGroupHelper.GetWebSitesClient(handler);
                var resourcesClient = ResourceGroupHelper.GetResourcesClient(handler);

                string whpName = TestUtilities.GenerateName("cswhp");
                string resourceGroupName = TestUtilities.GenerateName("csmrg");

                var locationName = ResourceGroupHelper.GetResourceLocation(resourcesClient, "Microsoft.Web/sites");
                string siteName = TestUtilities.GenerateName("csmws");

                resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName,
                    new ResourceGroup
                    {
                        Location = locationName
                    });

                webSitesClient.WebHostingPlans.CreateOrUpdate(resourceGroupName, new WebHostingPlanCreateOrUpdateParameters
                {
                    WebHostingPlan = new WebHostingPlan
                    {
                        Name = whpName,
                        Location = locationName,
                        Properties = new WebHostingPlanProperties
                        {
                            NumberOfWorkers = 1,
                            WorkerSize = WorkerSizeOptions.Small
                        }
                    }
                });

                var createResponse = webSitesClient.WebSites.CreateOrUpdate(resourceGroupName, siteName, null, new WebSiteCreateOrUpdateParameters()
                {
                    WebSite = new WebSiteBase()
                    {
                        Name = siteName,
                        Location = locationName,
                        Properties = new WebSiteBaseProperties()
                        {
                            ServerFarm = whpName
                        }
                    }
                });

                #region Get/Set Site limits

                var expectedSitelimits = new SiteLimits()
                {
                    MaxDiskSizeInMb = 512,
                    MaxMemoryInMb = 1024,
                    MaxPercentageCpu = 70.5
                };
                var parameters = new WebSiteUpdateConfigurationParameters()
                {
                    Location = locationName,
                    Properties = new WebSiteUpdateConfigurationDetails()
                    {
                        Limits = expectedSitelimits
                    }
                };


                var siteUpdateConfigResponse = webSitesClient.WebSites.UpdateConfiguration(
                    resourceGroupName,
                    siteName,
                    null,
                    parameters);

                Assert.Equal(HttpStatusCode.OK, siteUpdateConfigResponse.StatusCode);

                var siteGetConfigResponse = webSitesClient.WebSites.GetConfiguration(resourceGroupName,
                    siteName, null, null);

                Assert.NotNull(siteGetConfigResponse);
                Assert.NotNull(siteGetConfigResponse.Resource);
                Assert.NotNull(siteGetConfigResponse.Resource.Properties);
                var limits = siteGetConfigResponse.Resource.Properties.Limits;
                Assert.NotNull(limits);
                Assert.Equal(expectedSitelimits.MaxDiskSizeInMb, limits.MaxDiskSizeInMb);
                Assert.Equal(expectedSitelimits.MaxMemoryInMb, limits.MaxMemoryInMb);
                Assert.Equal(expectedSitelimits.MaxPercentageCpu, limits.MaxPercentageCpu);

                #endregion Get/Set Site limits

                webSitesClient.WebSites.Delete(resourceGroupName, siteName, null, new WebSiteDeleteParameters()
                {
                    DeleteAllSlots = true,
                    DeleteMetrics = true
                });

                webSitesClient.WebHostingPlans.Delete(resourceGroupName, whpName);
            }
        }
        public void GetAndSetNonSensitiveSiteConfigs()
        {
            RunWebsiteTestScenario(
                (siteName, resourceGroupName, whpName, locationName, webSitesClient, resourcesClient) =>
                {
                    #region Get/Set PythonVersion

                    var configurationResponse = webSitesClient.WebSites.GetConfiguration(resourceGroupName,
                        siteName, null, new WebSiteGetConfigurationParameters());

                    Assert.NotNull(configurationResponse.Resource);
                    Assert.NotNull(configurationResponse.Resource.Properties);
                    Assert.True(String.IsNullOrEmpty(configurationResponse.Resource.Properties.PythonVersion));

                    var configurationParameters = new WebSiteUpdateConfigurationParameters
                    {
                        Location = configurationResponse.Resource.Location,
                        Properties = new WebSiteUpdateConfigurationDetails
                        {
                            PythonVersion = "3.4"
                        }
                    };
                    var operationResponse = webSitesClient.WebSites.UpdateConfiguration(resourceGroupName,
                        siteName, null, configurationParameters);

                    Assert.Equal(HttpStatusCode.OK, operationResponse.StatusCode);

                    configurationResponse = webSitesClient.WebSites.GetConfiguration(resourceGroupName,
                        siteName, null, new WebSiteGetConfigurationParameters());

                    Assert.NotNull(configurationResponse.Resource);
                    Assert.NotNull(configurationResponse.Resource.Properties);
                    Assert.Equal(configurationResponse.Resource.Properties.PythonVersion, configurationParameters.Properties.PythonVersion);

                    #endregion Get/Set PythonVersion
                });
        }
 /// <summary>
 /// You can retrieve the config settings for a web site by issuing an
 /// HTTP GET request, or update them by using HTTP PUT with a request
 /// body that contains the settings to be updated.  (see
 /// http://msdn.microsoft.com/en-us/library/windowsazure/dn166985.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. The Update Web Site Configuration parameters.
 /// </param>
 /// <returns>
 /// A standard service response including an HTTP status code and
 /// request ID.
 /// </returns>
 public static OperationResponse UpdateConfiguration(this IWebSiteOperations operations, string resourceGroupName, string webSiteName, string slotName, WebSiteUpdateConfigurationParameters parameters)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IWebSiteOperations)s).UpdateConfigurationAsync(resourceGroupName, webSiteName, slotName, parameters);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
 /// <summary>
 /// You can retrieve the config settings for a web site by issuing an
 /// HTTP GET request, or update them by using HTTP PUT with a request
 /// body that contains the settings to be updated.  (see
 /// http://msdn.microsoft.com/en-us/library/windowsazure/dn166985.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. The Update Web Site Configuration parameters.
 /// </param>
 /// <returns>
 /// A standard service response including an HTTP status code and
 /// request ID.
 /// </returns>
 public static Task<OperationResponse> UpdateConfigurationAsync(this IWebSiteOperations operations, string resourceGroupName, string webSiteName, string slotName, WebSiteUpdateConfigurationParameters parameters)
 {
     return operations.UpdateConfigurationAsync(resourceGroupName, webSiteName, slotName, parameters, CancellationToken.None);
 }
        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);
        }