public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();
            switch (ParameterSetName)
            {
            case ParameterSet1Name:
                AppServicePlan              = new PSAppServicePlan(WebsitesClient.GetAppServicePlan(ResourceGroupName, Name));
                AppServicePlan.Sku.Tier     = string.IsNullOrWhiteSpace(Tier) ? AppServicePlan.Sku.Tier : Tier;
                AppServicePlan.Sku.Capacity = NumberofWorkers > 0 ? NumberofWorkers : AppServicePlan.Sku.Capacity;
                int workerSizeAsNumber = 0;
                int.TryParse(Regex.Match(AppServicePlan.Sku.Name, @"\d+").Value, out workerSizeAsNumber);
                AppServicePlan.Sku.Name       = string.IsNullOrWhiteSpace(WorkerSize) ? CmdletHelpers.GetSkuName(AppServicePlan.Sku.Tier, workerSizeAsNumber) : CmdletHelpers.GetSkuName(AppServicePlan.Sku.Tier, WorkerSize);
                AppServicePlan.PerSiteScaling = PerSiteScaling;
                if (Tag != null && AppServicePlan.Tags != null)
                {
                    CmdletHelpers.ConvertToStringDictionary(Tag).ForEach(item => AppServicePlan.Tags?.Add(item));
                }
                else
                {
                    AppServicePlan.Tags = (IDictionary <string, string>)CmdletHelpers.ConvertToStringDictionary(Tag);
                }
                break;
            }

            // Fix Server Farm SKU description
            AppServicePlan.Sku.Size   = AppServicePlan.Sku.Name;
            AppServicePlan.Sku.Family = AppServicePlan.Sku.Name.Substring(0, 1);

            WriteObject(new PSAppServicePlan(WebsitesClient.CreateOrUpdateAppServicePlan(ResourceGroupName, Name, AppServicePlan)), true);
        }
        public override void ExecuteCmdlet()
        {
            if (HyperV.IsPresent &&
                (Tier != "PremiumContainer" && Tier != "PremiumV3"))
            {
                throw new Exception("HyperV switch is only allowed for PremiumContainer or PremiumV3 tiers");
            }
            if (!HyperV.IsPresent && Tier == "PremiumContainer")
            {
                throw new Exception("PremiumContainer tier is only allowed if HyperV switch is present");
            }

            if (string.IsNullOrWhiteSpace(Tier))
            {
                Tier = "Free";
            }

            if (string.IsNullOrWhiteSpace(WorkerSize))
            {
                WorkerSize = "Small";
            }

            var aseResourceGroupName = AseResourceGroupName;

            if (!string.IsNullOrEmpty(AseName) &&
                string.IsNullOrEmpty(aseResourceGroupName))
            {
                aseResourceGroupName = ResourceGroupName;
            }

            var capacity = NumberofWorkers < 1 ? 1 : NumberofWorkers;
            var skuName  = CmdletHelpers.GetSkuName(Tier, WorkerSize);

            var sku = new SkuDescription
            {
                Tier     = Tier,
                Name     = skuName,
                Capacity = capacity
            };

            var appServicePlan = new AppServicePlan
            {
                Location       = Location,
                Sku            = sku,
                PerSiteScaling = PerSiteScaling,
                IsXenon        = HyperV.IsPresent,
                Tags           = (IDictionary <string, string>)CmdletHelpers.ConvertToStringDictionary(Tag),
                Reserved       = Linux.IsPresent
            };

            AppServicePlan   retPlan = WebsitesClient.CreateOrUpdateAppServicePlan(ResourceGroupName, Name, appServicePlan, AseName, aseResourceGroupName);
            PSAppServicePlan psPlan  = new PSAppServicePlan(retPlan);

            WriteObject(psPlan, true);
        }
 public override void ExecuteCmdlet()
 {
     if (!string.IsNullOrWhiteSpace(ResourceGroupName) && !string.IsNullOrWhiteSpace(WebAppName))
     {
         var        webApp     = new PSSite(WebsitesClient.GetWebApp(ResourceGroupName, WebAppName, null));
         SiteConfig siteConfig = webApp.SiteConfig;
         if (RoutingRule != null)
         {
             var        routingRule = CmdletHelpers.ConvertToStringDictionary(RoutingRule);
             RampUpRule rampUpRule  = new RampUpRule();
             foreach (var item in routingRule)
             {
                 CmdletHelpers.SetObjectProperty(rampUpRule, item.Key, item.Value);
             }
             //Check for Rule existance with the given name.
             var givenRampUpRuleObj = siteConfig.Experiments.RampUpRules.FirstOrDefault(item => item.Name == rampUpRule.Name);
             if (givenRampUpRuleObj == null)
             {
                 if (this.ShouldProcess(this.WebAppName, string.Format("Creating a new Routing Rule for slot '{0}' in Web Application - {1}.", rampUpRule.Name, this.WebAppName)))
                 {
                     //Add the given rule to the existing config
                     siteConfig.Experiments.RampUpRules.Add(rampUpRule);
                     // Update web app configuration
                     WebsitesClient.UpdateWebAppConfiguration(ResourceGroupName, webApp.Location, WebAppName, null, siteConfig, null, null, null);
                     //var app = WebsitesClient.GetWebApp(ResourceGroupName, WebAppName, null);
                     //WriteObject(app.SiteConfig.Experiments.RampUpRules.FirstOrDefault(rule => rule.Name == rampUpRule.Name));
                     WriteObject(rampUpRule);
                 }
             }
             else
             {
                 throw new ValidationMetadataException(string.Format(Properties.Resources.AddRoutingRuleErrorMessage, rampUpRule.Name, WebAppName));
             }
         }
     }
 }