示例#1
0
        public static void DeleteRule(InboundRule rule, InboundRulesSection section)
        {
            if (rule == null)
            {
                return;
            }

            InboundRuleCollection collection = section.InboundRules;

            // To utilize the remove functionality we must pull the element directly from the collection
            rule = (InboundRule)collection.FirstOrDefault(r => r.Name.Equals(rule.Name));

            if (rule != null)
            {
                try {
                    collection.Remove(rule);
                }
                catch (FileLoadException e) {
                    throw new LockedException(section.SectionPath, e);
                }
                catch (DirectoryNotFoundException e) {
                    throw new ConfigScopeNotFoundException(e);
                }
            }
        }
示例#2
0
        public static void AddRule(InboundRule rule, InboundRulesSection section, dynamic model)
        {
            if (rule == null)
            {
                throw new ArgumentNullException(nameof(rule));
            }

            if (rule.Name == null)
            {
                throw new ArgumentNullException("rule.Name");
            }

            InboundRuleCollection collection = section.InboundRules;

            if (collection.Any(r => r.Name.Equals(rule.Name)))
            {
                throw new AlreadyExistsException("rule");
            }

            try {
                collection.Add(rule);

                UpdatePriority(model, rule, section);
            }
            catch (FileLoadException e) {
                throw new LockedException(section.SectionPath, e);
            }
            catch (DirectoryNotFoundException e) {
                throw new ConfigScopeNotFoundException(e);
            }
        }
示例#3
0
        public object Get()
        {
            string globalRulesId = Context.Request.Query[Defines.IDENTIFIER];

            if (string.IsNullOrEmpty(globalRulesId))
            {
                return(NotFound());
            }

            var sectionId = new RewriteId(globalRulesId);

            Site site = sectionId.SiteId == null ? null : SiteHelper.GetSite(sectionId.SiteId.Value);

            InboundRuleCollection rules = GlobalRulesHelper.GetSection(site, sectionId.Path).InboundRules;

            this.Context.Response.SetItemsCount(rules.Count());

            return(new {
                rules = rules.Select(rule => GlobalRulesHelper.RuleToJsonModelRef((InboundRule)rule, site, sectionId.Path, Context.Request.GetFields()))
            });
        }
        public object Get()
        {
            string inboundRulesId = Context.Request.Query[Defines.IDENTIFIER];

            if (string.IsNullOrEmpty(inboundRulesId))
            {
                return(NotFound());
            }

            var sectionId = new RewriteId(inboundRulesId);

            // Get site rule is for if applicable
            Site site = sectionId.SiteId == null ? null : SiteHelper.GetSite(sectionId.SiteId.Value);

            InboundRuleCollection rules = InboundRulesHelper.GetSection(site, sectionId.Path).InboundRules;

            // Set HTTP header for total count
            this.Context.Response.SetItemsCount(rules.Count());

            return(new {
                rules = rules.Select(rule => InboundRulesHelper.RuleToJsonModelRef((InboundRule)rule, site, sectionId.Path, Context.Request.GetFields()))
            });
        }