Esempio n. 1
0
        public WebHostingPlan CreateWebPlan(ResourceGroupExtended group, string servicePlanName)
        {
            var hostingPlan = new WebHostingPlan()
            {
                Location   = this.Location,
                Name       = servicePlanName,
                Properties = new WebHostingPlanProperties()
                {
                    Sku             = SkuOptions.Shared,
                    NumberOfWorkers = 1,
                    WorkerSize      = WorkerSizeOptions.Small,
                }
            };

            var plan   = new WebHostingPlanCreateOrUpdateParameters(hostingPlan);
            var result = this.Client.WebHostingPlans.CreateOrUpdate(group.Name, plan);

            if (result.StatusCode != HttpStatusCode.OK)
            {
                throw null;
            }
            else if (result.WebHostingPlan != null)
            {
                hostingPlan = result.WebHostingPlan;
            }

            return(hostingPlan);
        }
Esempio n. 2
0
        public WebHostingPlanCreateOrUpdateResponse CreateAppServicePlan(string resourceGroupName, string whpName, string location, string adminSiteName, int numberOfWorkers, SkuOptions sku, WorkerSizeOptions workerSize)
        {
            WebHostingPlanProperties webHostingPlanProperties = new WebHostingPlanProperties();

            webHostingPlanProperties.Sku             = sku;
            webHostingPlanProperties.AdminSiteName   = adminSiteName;
            webHostingPlanProperties.NumberOfWorkers = numberOfWorkers;
            webHostingPlanProperties.WorkerSize      = workerSize;
            WebHostingPlan webHostingPlan = new WebHostingPlan();
            WebHostingPlanCreateOrUpdateParameters webHostingPlanCreateOrUpdateParameters = new WebHostingPlanCreateOrUpdateParameters(webHostingPlan);

            webHostingPlanCreateOrUpdateParameters.WebHostingPlan.Location   = location;
            webHostingPlanCreateOrUpdateParameters.WebHostingPlan.Name       = whpName;
            webHostingPlanCreateOrUpdateParameters.WebHostingPlan.Properties = webHostingPlanProperties;

            var createdWHP = WrappedWebsitesClient.WebHostingPlans.CreateOrUpdate(resourceGroupName, webHostingPlanCreateOrUpdateParameters);

            //proper return type need to be discussed
            return(createdWHP);
        }
        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);
        }
 /// <summary>
 /// Creates a new Web Hosting Plan or updates an existing one.  (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.Azure.Management.WebSites.IWebHostingPlanOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of the resource group.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to the Create Server Farm operation.
 /// </param>
 /// <returns>
 /// The Create Web Hosting Plan operation response.
 /// </returns>
 public static Task <WebHostingPlanCreateOrUpdateResponse> CreateOrUpdateAsync(this IWebHostingPlanOperations operations, string resourceGroupName, WebHostingPlanCreateOrUpdateParameters parameters)
 {
     return(operations.CreateOrUpdateAsync(resourceGroupName, parameters, CancellationToken.None));
 }
 /// <summary>
 /// Creates a new Web Hosting Plan or updates an existing one.  (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.Azure.Management.WebSites.IWebHostingPlanOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of the resource group.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to the Create Server Farm operation.
 /// </param>
 /// <returns>
 /// The Create Web Hosting Plan operation response.
 /// </returns>
 public static WebHostingPlanCreateOrUpdateResponse CreateOrUpdate(this IWebHostingPlanOperations operations, string resourceGroupName, WebHostingPlanCreateOrUpdateParameters parameters)
 {
     return(Task.Factory.StartNew((object s) =>
     {
         return ((IWebHostingPlanOperations)s).CreateOrUpdateAsync(resourceGroupName, parameters);
     }
                                  , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }