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)); } } } }