Exemple #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));
        }
Exemple #2
0
        public object Get(string id)
        {
            ProviderId providerId = new ProviderId(id);

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

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

            TraceProviderDefinition provider = ProvidersHelper.GetProviders(site, providerId.Path).Where(p => p.Name.Equals(providerId.Name)).FirstOrDefault();

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

            return(ProvidersHelper.ToJsonModel(provider, site, providerId.Path));
        }
Exemple #3
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);
        }