internal static TraceEventServiceElement Read(XElement element)
        {
            var instance = new TraceEventServiceElement();

            var snpAttr = (string)element.Attribute("sessionNamePrefix");
            if (!string.IsNullOrWhiteSpace(snpAttr))
            {
                instance.SessionNamePrefix = snpAttr;
            }

            return instance;
        }
        internal static TraceEventServiceElement Read(XElement element)
        {
            var instance = new TraceEventServiceElement();

            var snpAttr = (string)element.Attribute("sessionNamePrefix");

            if (!string.IsNullOrWhiteSpace(snpAttr))
            {
                instance.SessionNamePrefix = snpAttr;
            }

            return(instance);
        }
예제 #3
0
        internal ConfigurationElement Read()
        {
            XmlSchemaSet schemas = new XmlSchemaSet();

            // load buit-in schema from resource
            schemas.Add(GetSchemaFromResource());

            if (this.loader.SchemaFileNames.Any())
            {
                AddExtensionSchemas(schemas, this.loader);
            }

            var readerSettings = new XmlReaderSettings()
            {
                Schemas         = schemas,
                CloseInput      = true,
                XmlResolver     = new SchemaConfigurationXmlResolver(),
                ValidationType  = ValidationType.Schema,
                ValidationFlags = XmlSchemaValidationFlags.ProcessIdentityConstraints |
                                  XmlSchemaValidationFlags.ReportValidationWarnings |
                                  XmlSchemaValidationFlags.ProcessSchemaLocation |
                                  XmlSchemaValidationFlags.ProcessInlineSchema
            };

            var validationExceptions = new List <Exception>();

            readerSettings.ValidationEventHandler += (s, a) =>
            {
                //// Filter out any missing schema warnings for custom elements and its child sub elements
                if (a.Severity == XmlSeverityType.Warning)
                {
                    var reader = (XmlReader)s;
                    if (!schemas.Contains(reader.NamespaceURI) || reader.NamespaceURI == Constants.Namespace)
                    {
                        return;
                    }
                }

                //// Collect all schema validation errors
                validationExceptions.Add(a.Exception);
            };

            XDocument doc = null;

            using (var reader = XmlReader.Create(this.File, readerSettings))
            {
                try
                {
                    doc = XDocument.Load(reader, LoadOptions.SetLineInfo);
                }
                catch (Exception e)
                {
                    validationExceptions.Add(e);
                }
            }

            if (validationExceptions.Count > 0)
            {
                throw new ConfigurationException(validationExceptions)
                      {
                          ConfigurationFile = this.File
                      };
            }

            var configuration = new ConfigurationElement();

            var tes = doc.Root.Element(this.traceEventServiceName);

            configuration.TraceEventService = (tes == null) ? new TraceEventServiceElement() : TraceEventServiceElement.Read(tes);

            var sinks = doc.Root.Elements(this.sinksName).Elements();

            if (sinks != null)
            {
                configuration.SinkConfigurationElements = this.LoadSinkConfigurationElements(sinks);
            }

            return(configuration);
        }