public static void UpdateRule(dynamic model, InboundRule rule, Site site, string path, string configPath = null) { InboundRulesSection section = GetSection(site, path, configPath); AllowedServerVariablesSection serverVariablesSection = ServerVariablesHelper.GetSection(site, path, configPath); SetRule(model, rule, section, serverVariablesSection); }
public static void UpdateFeatureSettings(dynamic model, Site site, string path, string configPath = null) { if (model == null) { throw new ApiArgumentException("model"); } AllowedServerVariablesSection section = ServerVariablesHelper.GetSection(site, path, configPath); try { if (model.entries != null) { IEnumerable <dynamic> variables = model.entries as IEnumerable <dynamic>; if (variables == null) { throw new ApiArgumentException("entries", ForbiddenArgumentException.EXPECTED_ARRAY); } List <string> variableList = new List <string>(); // Validate all verbs provided foreach (dynamic variable in variables) { string var = DynamicHelper.Value(variable); if (string.IsNullOrEmpty(var)) { throw new ApiArgumentException("entries.item"); } variableList.Add(var); } // Clear configuration's collection section.AllowedServerVariables.Clear(); // Move from temp list to the configuration's collection variableList.ForEach(v => section.AllowedServerVariables.Add(v)); } if (model.metadata != null) { DynamicHelper.If <OverrideMode>((object)model.metadata.override_mode, v => { section.OverrideMode = v; }); } } catch (FileLoadException e) { throw new LockedException(section.SectionPath, e); } catch (DirectoryNotFoundException e) { throw new ConfigScopeNotFoundException(e); } }
public void Delete(string id) { var serverVariablesId = new RewriteId(id); Context.Response.StatusCode = (int)HttpStatusCode.NoContent; Site site = (serverVariablesId.SiteId != null) ? SiteHelper.GetSite(serverVariablesId.SiteId.Value) : null; if (site != null) { var section = ServerVariablesHelper.GetSection(site, serverVariablesId.Path, ManagementUnit.ResolveConfigScope()); section.RevertToParent(); ManagementUnit.Current.Commit(); } }
public static InboundRule CreateRule(dynamic model, Site site, string path, string configPath = null) { if (model == null) { throw new ApiArgumentException("model"); } if (string.IsNullOrEmpty(DynamicHelper.Value(model.name))) { throw new ApiArgumentException("name"); } if (string.IsNullOrEmpty(DynamicHelper.Value(model.pattern))) { throw new ApiArgumentException("pattern"); } if (model.action == null) { throw new ApiArgumentException("action"); } if (!(model.action is JObject)) { throw new ApiArgumentException("action", ApiArgumentException.EXPECTED_OBJECT); } if (string.IsNullOrEmpty(DynamicHelper.Value(model.action.url))) { throw new ApiArgumentException("action.url"); } InboundRulesSection section = GetSection(site, path, configPath); AllowedServerVariablesSection serverVariablesSection = ServerVariablesHelper.GetSection(site, path, configPath); var rule = (InboundRule)section.InboundRules.CreateElement(); // // Defaults rule.PatternSyntax = PatternSyntax.ECMAScript; rule.Action.Type = ActionType.Rewrite; SetRule(model, rule, section, serverVariablesSection); return(rule); }