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); }
public static TraceProviderDefinition CreateProvider(dynamic model, TraceProviderDefinitionsSection section) { // // model if (model == null) { throw new ApiArgumentException("model"); } // // name string name = DynamicHelper.Value(model.name); if (string.IsNullOrEmpty(name)) { throw new ApiArgumentException("name"); } // // guid Guid guid; string g = DynamicHelper.Value(model.guid); if (!Guid.TryParse(g, out guid)) { throw new ApiArgumentException("guid"); } // // areas if (model.areas == null) { throw new ApiArgumentException("areas"); } var provider = section.TraceProviderDefinitions.CreateElement(); SetProvider(provider, model); return(provider); }
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); } } }
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); }