示例#1
0
        public async Task <object> Get()
        {
            string hrtUuid = Context.Request.Query[Defines.IDENTIFIER];

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

            var  id   = new HttpRequestTracingId(hrtUuid);
            Site site = id?.SiteId == null ? null : SiteHelper.GetSite(id.SiteId.Value);

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

            var helper = new TracesHelper(_provider, site);

            IEnumerable <TraceInfo> traces = await helper.GetTraces();

            Context.Response.SetItemsCount(traces.Count());

            return(new {
                traces = traces.Select(t => helper.ToJsonModel(t, Context.Request.GetFields()))
            });
        }
示例#2
0
        private void ConfigureHttpRequestTracing()
        {
            Environment.Host.RouteBuilder.MapWebApiRoute(Defines.Resource.Guid, $"{Defines.PATH}/{{id?}}", new { controller = "HttpRequestTracing" });

            // Self
            Environment.Hal.ProvideLink(Defines.Resource.Guid, "self", hrt => new { href = Helper.GetLocation(hrt.id) });

            // Web Server
            Environment.Hal.ProvideLink(WebServer.Defines.Resource.Guid, Defines.Resource.Name, _ => {
                var id = new HttpRequestTracingId(null, null, Helper.IsSectionLocal(null, null));
                return(new { href = Helper.GetLocation(id.Uuid) });
            });

            // Site
            Environment.Hal.ProvideLink(Sites.Defines.Resource.Guid, Defines.Resource.Name, site => {
                var siteId = new SiteId((string)site.id);
                Site s     = SiteHelper.GetSite(siteId.Id);
                var id     = new HttpRequestTracingId(siteId.Id, "/", Helper.IsSectionLocal(s, "/"));
                return(new { href = Helper.GetLocation(id.Uuid) });
            });

            // Application
            Environment.Hal.ProvideLink(Applications.Defines.Resource.Guid, Defines.Resource.Name, app => {
                var appId = new ApplicationId((string)app.id);
                Site s    = SiteHelper.GetSite(appId.SiteId);
                var id    = new HttpRequestTracingId(appId.SiteId, appId.Path, Helper.IsSectionLocal(s, appId.Path));
                return(new { href = Helper.GetLocation(id.Uuid) });
            });
        }
        public object Get(string id)
        {
            var hrtId = new HttpRequestTracingId(id);

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

            return(Helper.ToJsonModel(site, hrtId.Path));
        }
        public static object ToJsonModelRef(Site site, string path)
        {
            var section = GetTraceFailedRequestsSection(site, path);

            HttpRequestTracingId hrtId = new HttpRequestTracingId(site?.Id, path, section.IsLocallyStored);

            var obj = new {
                id    = hrtId.Uuid,
                scope = site == null ? string.Empty : site.Name + path,
            };

            return(Environment.Hal.Apply(Defines.Resource.Guid, obj, false));
        }
        public void Delete(string id)
        {
            var hrtId = new HttpRequestTracingId(id);

            Context.Response.StatusCode = (int)HttpStatusCode.NoContent;

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

            if (site == null)
            {
                return;
            }

            Helper.GetTraceFailedRequestsSection(site, hrtId.Path, ManagementUnit.ResolveConfigScope()).RevertToParent();
            Helper.GetTraceProviderDefinitionSection(site, hrtId.Path, ManagementUnit.ResolveConfigScope()).RevertToParent();

            ManagementUnit.Current.Commit();
        }
        public object Post(dynamic model)
        {
            TraceRule            rule  = null;
            Site                 site  = null;
            HttpRequestTracingId hrtId = null;

            if (model == null)
            {
                throw new ApiArgumentException("model");
            }
            if (model.request_tracing == null)
            {
                throw new ApiArgumentException("request_tracing");
            }
            if (!(model.request_tracing is JObject))
            {
                throw new ApiArgumentException("request_tracing", ApiArgumentException.EXPECTED_OBJECT);
            }
            string hrtUuid = DynamicHelper.Value(model.request_tracing.id);

            if (hrtUuid == null)
            {
                throw new ApiArgumentException("request_tracing.id");
            }

            hrtId = new HttpRequestTracingId(hrtUuid);

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

            string configPath = ManagementUnit.ResolveConfigScope(model);

            rule = RulesHelper.CreateRule(model, site, hrtId.Path, configPath);

            var section = Helper.GetTraceFailedRequestsSection(site, hrtId.Path, configPath);

            RulesHelper.AddRule(rule, section);

            ManagementUnit.Current.Commit();

            dynamic r = RulesHelper.ToJsonModel(rule, site, hrtId.Path);

            return(Created(RulesHelper.GetLocation(r.id), r));
        }
        public object Patch(string id, dynamic model)
        {
            var hrtId = new HttpRequestTracingId(id);

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

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

            string configPath = model == null ? null : ManagementUnit.ResolveConfigScope(model);

            Helper.UpdateSettings(model, site, hrtId.Path, configPath);

            ManagementUnit.Current.Commit();

            return(Helper.ToJsonModel(site, hrtId.Path));
        }
示例#8
0
        public async Task Delete(string id)
        {
            var hrtId = new HttpRequestTracingId(id);

            Context.Response.StatusCode = (int)HttpStatusCode.NoContent;

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

            if (site != null)
            {
                Helper.GetTraceFailedRequestsSection(site, hrtId.Path, ManagementUnit.ResolveConfigScope()).RevertToParent();
                ManagementUnit.Current.Commit();
            }

            if (hrtId.SiteId == null && Helper.IsFeatureEnabled())
            {
                await Helper.SetFeatureEnabled(false);
            }
        }
示例#9
0
        public object Post(dynamic model)
        {
            TraceProviderDefinition provider = null;
            Site site = null;
            HttpRequestTracingId hrtId = null;

            if (model == null)
            {
                throw new ApiArgumentException("model");
            }
            if (model.request_tracing == null)
            {
                throw new ApiArgumentException("request_tracing");
            }
            if (!(model.request_tracing is JObject))
            {
                throw new ApiArgumentException("request_tracing", ApiArgumentException.EXPECTED_OBJECT);
            }
            string hrtUuid = DynamicHelper.Value(model.request_tracing.id);

            if (hrtUuid == null)
            {
                throw new ApiArgumentException("request_tracing.id");
            }

            hrtId = new HttpRequestTracingId(hrtUuid);

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

            string configPath = ManagementUnit.ResolveConfigScope(model);
            var    section    = Helper.GetTraceProviderDefinitionSection(site, hrtId.Path, configPath);

            provider = ProvidersHelper.CreateProvider(model, section);

            ProvidersHelper.AddProvider(provider, section);

            ManagementUnit.Current.Commit();

            dynamic p = ProvidersHelper.ToJsonModel(provider, site, hrtId.Path);

            return(Created(ProvidersHelper.GetLocation(p.id), p));
        }
        internal static object ToJsonModel(Site site, string path)
        {
            var section          = GetTraceFailedRequestsSection(site, path);
            var providersSection = GetTraceProviderDefinitionSection(site, path);

            bool         isLocal               = section.IsLocallyStored;
            bool         isLocked              = section.IsLocked;
            OverrideMode overrideMode          = section.OverrideMode;
            OverrideMode overrideModeEffective = section.OverrideModeEffective;

            HttpRequestTracingId hrtId = new HttpRequestTracingId(site?.Id, path, isLocal);

            bool   enabled;
            string directory = null;
            long   maximumNumberTraceFiles;

            if (site != null)
            {
                enabled   = site.TraceFailedRequestsLogging.Enabled;
                directory = site.TraceFailedRequestsLogging.Directory;
                maximumNumberTraceFiles = site.TraceFailedRequestsLogging.MaxLogFiles;
            }
            else
            {
                var siteDefaults = ManagementUnit.ServerManager.SiteDefaults;
                enabled   = true;
                directory = siteDefaults.TraceFailedRequestsLogging.Directory;
                maximumNumberTraceFiles = siteDefaults.TraceFailedRequestsLogging.MaxLogFiles;
            }

            var obj = new {
                id        = hrtId.Uuid,
                scope     = site == null ? string.Empty : site.Name + path,
                metadata  = ConfigurationUtility.MetadataToJson(isLocal, isLocked, overrideMode, overrideModeEffective),
                enabled   = enabled,
                directory = directory,
                maximum_number_trace_files = maximumNumberTraceFiles,
                website = SiteHelper.ToJsonModelRef(site)
            };

            return(Environment.Hal.Apply(Defines.Resource.Guid, obj));
        }
示例#11
0
        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 providers = ProvidersHelper.GetProviders(site, hrtId.Path);

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

            Fields fields = Context.Request.GetFields();

            return(new {
                providers = providers.Select(p => ProvidersHelper.ToJsonModelRef(p, site, hrtId.Path, fields))
            });
        }