예제 #1
0
        public void Delete(string id)
        {
            ProviderId providerId = new ProviderId(id);

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

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

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

            if (provider != null)
            {
                var section = Helper.GetTraceProviderDefinitionSection(site, providerId.Path, ManagementUnit.ResolveConfigScope());

                ProvidersHelper.DeleteProvider(provider, section);
                ManagementUnit.Current.Commit();
            }

            Context.Response.StatusCode = (int)HttpStatusCode.NoContent;
        }
예제 #2
0
        public static object AddProvider(TraceProviderDefinition provider, TraceProviderDefinitionsSection section)
        {
            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }
            if (provider.Name == null)
            {
                throw new ArgumentNullException("provider.Name");
            }

            if (section.TraceProviderDefinitions.Any(prov => prov.Name.Equals(provider.Name, StringComparison.OrdinalIgnoreCase)))
            {
                throw new AlreadyExistsException("name");
            }

            if (section.TraceProviderDefinitions.Any(prov => prov.Guid.Equals(provider.Guid)))
            {
                throw new AlreadyExistsException("guid");
            }

            try {
                section.TraceProviderDefinitions.Add(provider);
            }
            catch (FileLoadException e) {
                throw new LockedException(section.SectionPath, e);
            }
            catch (DirectoryNotFoundException e) {
                throw new ConfigScopeNotFoundException(e);
            }

            return(provider);
        }
예제 #3
0
 public static object ToJsonModelRef(TraceProviderDefinition provider, Site site, string path, Fields fields = null)
 {
     if (fields == null || !fields.HasFields)
     {
         return(ToJsonModel(provider, site, path, RefFields, false));
     }
     else
     {
         return(ToJsonModel(provider, site, path, fields, false));
     }
 }
예제 #4
0
        internal static object ToJsonModel(TraceProviderDefinition provider, Site site, string path, Fields fields = null, bool full = true)
        {
            if (provider == null)
            {
                return(null);
            }

            if (fields == null)
            {
                fields = Fields.All;
            }

            dynamic obj = new ExpandoObject();

            //
            // name
            if (fields.Exists("name"))
            {
                obj.name = provider.Name;
            }

            //
            // id
            obj.id = new ProviderId(site?.Id, path, provider.Name).Uuid;

            //
            // guid
            if (fields.Exists("guid"))
            {
                obj.guid = provider.Guid.ToString("B");
            }

            //
            // areas
            if (fields.Exists("areas"))
            {
                obj.areas = provider.Areas.Select(area => area.Name);
            }

            //
            // request_tracing
            if (fields.Exists("request_tracing"))
            {
                obj.request_tracing = Helper.ToJsonModelRef(site, path);
            }

            return(Core.Environment.Hal.Apply(Defines.ProvidersResource.Guid, obj, full));
        }
예제 #5
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));
        }
예제 #6
0
        public static TraceProviderDefinition UpdateProvider(TraceProviderDefinition provider, dynamic model, TraceProviderDefinitionsSection section)
        {
            if (model == null)
            {
                throw new ApiArgumentException("model");
            }
            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }

            string name = DynamicHelper.Value(model.name);

            if (name != null &&
                !name.Equals(provider.Name) &&
                section.TraceProviderDefinitions.Any(p => p.Name.Equals(name, StringComparison.OrdinalIgnoreCase)))
            {
                throw new AlreadyExistsException("name");
            }

            Guid guid;
            var  g = DynamicHelper.Value(model.guid);

            if (Guid.TryParse(g, out guid) &&
                !guid.Equals(provider.Guid) &&
                section.TraceProviderDefinitions.Any(prov => prov.Guid.Equals(guid)))
            {
                throw new AlreadyExistsException("guid");
            }

            try {
                SetProvider(provider, model);
            }
            catch (FileLoadException e) {
                throw new LockedException(section.SectionPath, e);
            }
            catch (DirectoryNotFoundException e) {
                throw new ConfigScopeNotFoundException(e);
            }

            return(provider);
        }
예제 #7
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));
        }
예제 #8
0
        private static void SetProvider(TraceProviderDefinition provider, dynamic model)
        {
            DynamicHelper.If((object)model.name, v => provider.Name = v);
            DynamicHelper.If((object)model.guid, v => {
                Guid guid;
                if (!Guid.TryParse(v, out guid))
                {
                    throw new ApiArgumentException("guid");
                }

                provider.Guid = guid;
            });

            if (model.areas != null)
            {
                if (!(model.areas is JArray))
                {
                    throw new ApiArgumentException("areas", ApiArgumentException.EXPECTED_ARRAY);
                }

                IEnumerable <dynamic> areas = model.areas;
                provider.Areas.Clear();
                long uniqueFlag = 1;

                foreach (var area in areas)
                {
                    string a = DynamicHelper.Value(area);

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

                    var elem = provider.Areas.CreateElement();
                    elem.Name   = a;
                    elem.Value  = uniqueFlag;
                    uniqueFlag *= 2;
                    provider.Areas.Add(elem);
                }
            }
        }
예제 #9
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);
        }
예제 #10
0
        public static void DeleteProvider(TraceProviderDefinition provider, TraceProviderDefinitionsSection section)
        {
            if (provider == null)
            {
                return;
            }

            var collection = section.TraceProviderDefinitions;

            provider = collection.FirstOrDefault(p => p.Name.Equals(provider.Name));

            if (provider != null)
            {
                try {
                    collection.Remove(provider);
                }
                catch (FileLoadException e) {
                    throw new LockedException(section.SectionPath, e);
                }
                catch (DirectoryNotFoundException e) {
                    throw new ConfigScopeNotFoundException(e);
                }
            }
        }