public void Delete(string id)
        {
            RuleId ruleId = new RuleId(id);

            Site        site = ruleId.SiteId == null ? null : SiteHelper.GetSite(ruleId.SiteId.Value);
            Application app  = ApplicationHelper.GetApplication(ruleId.AppPath, site);

            if (ruleId.SiteId != null && site == null)
            {
                Context.Response.StatusCode = (int)HttpStatusCode.NoContent;
                return;
            }

            TraceRule rule = RulesHelper.GetRules(site, ruleId.AppPath).Where(r => r.Path.ToString().Equals(ruleId.Path)).FirstOrDefault();

            if (rule != null)
            {
                var section = Helper.GetTraceFailedRequestsSection(site, ruleId.AppPath, ManagementUnit.ResolveConfigScope());

                RulesHelper.DeleteRule(rule, section);
                ManagementUnit.Current.Commit();
            }

            Context.Response.StatusCode = (int)HttpStatusCode.NoContent;
        }
        public object Get(string id)
        {
            RuleId ruleId = new RuleId(id);

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

            if (ruleId.SiteId != null && site == null)
            {
                return(NotFound());
            }

            TraceRule rule = RulesHelper.GetRules(site, ruleId.AppPath).Where(r => r.Path.Equals(ruleId.Path)).FirstOrDefault();

            if (rule == null)
            {
                return(NotFound());
            }

            return(RulesHelper.ToJsonModel(rule, site, ruleId.AppPath));
        }
        public object Patch(string id, dynamic model)
        {
            RuleId ruleId = new RuleId(id);

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

            if (ruleId.SiteId != null && site == null)
            {
                return(NotFound());
            }

            if (model == null)
            {
                throw new ApiArgumentException("model");
            }

            string    configPath = ManagementUnit.ResolveConfigScope(model);
            TraceRule rule       = RulesHelper.GetRules(site, ruleId.AppPath, configPath).Where(r => r.Path.ToString().Equals(ruleId.Path)).FirstOrDefault();

            if (rule == null)
            {
                return(NotFound());
            }


            rule = RulesHelper.UpdateRule(rule, model, site, ruleId.AppPath, configPath);

            ManagementUnit.Current.Commit();

            dynamic rle = RulesHelper.ToJsonModel(rule, site, ruleId.AppPath);

            if (rle.id != id)
            {
                return(LocationChanged(RulesHelper.GetLocation(rle.id), rle));
            }

            return(rle);
        }
        public object Get()
        {
            string hrtUuid = Context.Request.Query[Defines.IDENTIFIER];

            if (string.IsNullOrEmpty(hrtUuid))
            {
                return(new StatusCodeResult((int)HttpStatusCode.NotFound));
            }

            HttpRequestTracingId hrtId = new HttpRequestTracingId(hrtUuid);

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

            var rules = RulesHelper.GetRules(site, hrtId.Path);

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

            Fields fields = Context.Request.GetFields();

            return(new {
                rules = rules.Select(r => RulesHelper.ToJsonModelRef(r, site, hrtId.Path, fields))
            });
        }