Example #1
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));
        }
Example #2
0
        public object Patch(string id, dynamic model)
        {
            ProviderId providerId = new ProviderId(id);

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

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

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

            string configPath = ManagementUnit.ResolveConfigScope(model);
            TraceProviderDefinition provider = ProvidersHelper.GetProviders(site, providerId.Path, configPath).Where(p => p.Name.ToString().Equals(providerId.Name)).FirstOrDefault();

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


            provider = ProvidersHelper.UpdateProvider(provider, model, Helper.GetTraceProviderDefinitionSection(site, providerId.Path, configPath));

            ManagementUnit.Current.Commit();

            dynamic prov = ProvidersHelper.ToJsonModel(provider, site, providerId.Path);

            if (prov.id != id)
            {
                return(LocationChanged(ProvidersHelper.GetLocation(prov.id), prov));
            }

            return(prov);
        }
Example #3
0
        private void ConfigureProviders()
        {
            Environment.Host.RouteBuilder.MapWebApiRoute(Defines.ProvidersResource.Guid, $"{ Defines.PROVIDERS_PATH}/{{id?}}", new { controller = "TraceProviders" });

            Environment.Hal.ProvideLink(Defines.ProvidersResource.Guid, "self", p => new { href = ProvidersHelper.GetLocation(p.id) });

            Environment.Hal.ProvideLink(Defines.Resource.Guid, Defines.ProvidersResource.Name, hrt => new { href = $"/{Defines.PROVIDERS_PATH}?{Defines.IDENTIFIER}={hrt.id}" });
        }