public static CreateFromStream ( SparseReaderDispatchTable dispatchTable, Stream stream ) : |
||
dispatchTable | SparseReaderDispatchTable | The dispatch table used to fire delegates for XML elements on /// this instance. |
stream | Stream | The stream from which XML shall be retrieved. The SparseReader takes /// ownership of this stream and is responsible for destroying it. |
Результат |
public void Read(Context context, Stream input) { XmlSchemaSet schemaSet = new XmlSchemaSet(); Assembly assembly = typeof(FxCopLogReader).Assembly; var settings = new XmlReaderSettings { XmlResolver = null }; using (var stream = assembly.GetManifestResourceStream(FxCopLogReader.FxCopReportSchema)) using (var reader = XmlReader.Create(stream, settings)) { XmlSchema schema = XmlSchema.Read(reader, new ValidationEventHandler(ReportError)); schemaSet.Add(schema); } using (var sparseReader = SparseReader.CreateFromStream(_dispatchTable, input, schemaSet)) { if (sparseReader.LocalName.Equals(SchemaStrings.ElementFxCopReport)) { ReadFxCopReport(sparseReader, context); } else { throw new XmlException(String.Format(CultureInfo.InvariantCulture, "Invalid root element in FxCop log file: {0}", sparseReader.LocalName)); } } }
public void Read(Context context, Stream input) { XmlSchemaSet schemaSet = new XmlSchemaSet(); Assembly assembly = typeof(FxCopLogReader).Assembly; var settings = new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore, XmlResolver = null }; using (var stream = assembly.GetManifestResourceStream(FxCopLogReader.FxCopReportSchema)) using (var reader = XmlReader.Create(stream, settings)) { XmlSchema schema = XmlSchema.Read(reader, new ValidationEventHandler(ReportError)); schemaSet.Add(schema); } using (var sparseReader = SparseReader.CreateFromStream(_dispatchTable, input, schemaSet)) { // FxCop distinctions between project and report files. // // 1. Project files are designed to be deterministic in output and therefore // do not emit any file locations, only logical locations. // 2. Project files do not emit fully-constructed messages, only dynamic // arguments that can be used with rule format strings to construct a message. // 3. Project files by default persist excluded message but not absent // messages. Report files by default persist neither excluded or absent // messages. if (sparseReader.LocalName.Equals(SchemaStrings.ElementFxCopProject)) { _readingProjectFile = true; // Skip project information, which should lead us to the report that // holds emitted messages. sparseReader.ReadChildren(SchemaStrings.ElementFxCopProject, context); } else if (sparseReader.LocalName.Equals(SchemaStrings.ElementFxCopReport)) { ReadFxCopReport(sparseReader, context); } else { throw new XmlException(String.Format(CultureInfo.InvariantCulture, "Invalid root element in FxCop log file: {0}", sparseReader.LocalName)); } } }