public override bool Read() { ThrowIfDisposed(); do { if (_nodeStream.MoveNext()) { _current = _nodeStream.Current; if (_current.NodeType == XamlNodeType.None) { if (_current.LineInfo != null) { _currentLineInfo = _current.LineInfo; } else if (_current.IsEof) { break; } else { Debug.Assert(_current.IsEof, "Xaml Parser returned an illegal internal XamlNode"); } } } else { _current = _endOfStreamNode; break; } } while (_current.NodeType == XamlNodeType.None); return(!IsEof); }
private void Initialize(XamlReader wrappedReader, int bufferSize) { _providerFullEvent = new EventWaitHandle(false, EventResetMode.AutoReset); _dataReceivedEvent = new EventWaitHandle(false, EventResetMode.AutoReset); _incoming = new XamlNode[bufferSize]; _outgoing = new XamlNode[bufferSize]; _wrappedReader = wrappedReader; _wrappedReaderHasLineInfo = ((IXamlLineInfo)_wrappedReader).HasLineInfo; var xamlNodeAddDelegate = new XamlNodeAddDelegate(Add); XamlLineInfoAddDelegate lineInfoAddDelegate = null; if (_wrappedReaderHasLineInfo) { lineInfoAddDelegate = new XamlLineInfoAddDelegate(AddLineInfo); } _writer = new WriterDelegate(xamlNodeAddDelegate, lineInfoAddDelegate, _wrappedReader.SchemaContext); XamlNodeNextDelegate xamlNodeNextDelegate; if (_wrappedReaderHasLineInfo) { xamlNodeNextDelegate = new XamlNodeNextDelegate(Next_ProcessLineInfo); } else { xamlNodeNextDelegate = new XamlNodeNextDelegate(Next); } _internalReader = new ReaderDelegate(_wrappedReader.SchemaContext, xamlNodeNextDelegate, _wrappedReaderHasLineInfo); //Standin so it won't start null _currentNode = new XamlNode(XamlNode.InternalNodeType.StartOfStream); }
public ReaderDelegate(XamlSchemaContext schemaContext, XamlNodeNextDelegate next, bool hasLineInfo) : base(schemaContext) { _nextDelegate = next; _currentNode = new XamlNode(XamlNode.InternalNodeType.StartOfStream); _currentLineInfo = null; _hasLineInfo = hasLineInfo; }
private void AddToBuffer(XamlNode node) { _incoming[_inIdx] = node; _inIdx += 1; if (IncomingFull) { _providerFullEvent.Set(); // Reader is Full _dataReceivedEvent.WaitOne(); // Wait for data to be picked up. } }
public XamlNodeQueue(XamlSchemaContext schemaContext) { if (schemaContext == null) { throw new ArgumentNullException(nameof(schemaContext)); } _nodeQueue = new Queue <XamlNode>(); _endOfStreamNode = new XamlNode(XamlNode.InternalNodeType.EndOfStream); _writer = new WriterDelegate(Add, AddLineInfo, schemaContext); }
private void AddLineInfo(int lineNumber, int linePosition) { if (IsDisposed) { return; } LineInfo lineInfo = new LineInfo(lineNumber, linePosition); XamlNode node = new XamlNode(lineInfo); AddToBuffer(node); }
// ====================================== private void Add(XamlNodeType nodeType, object data) { if (nodeType != XamlNodeType.None) { XamlNode node = new XamlNode(nodeType, data); _nodeQueue.Enqueue(node); return; } Debug.Assert(XamlNode.IsEof_Helper(nodeType, data)); _nodeQueue.Enqueue(_endOfStreamNode); }
private void Add(XamlNodeType nodeType, object data) { if (IsDisposed) { return; } if (nodeType != XamlNodeType.None) { AddToBuffer(new XamlNode(nodeType, data)); return; } Debug.Assert(XamlNode.IsEof_Helper(nodeType, data)); AddToBuffer(new XamlNode(XamlNode.InternalNodeType.EndOfStream)); _providerFullEvent.Set(); }
private void AddLineInfo(int lineNumber, int linePosition) { if (_readMode) { throw new XamlException(SR.Get(SRID.CannotWriteClosedWriter)); } XamlNode node = new XamlNode(new LineInfo(lineNumber, linePosition)); _nodeList.Add(node); if (!_hasLineInfo) { _hasLineInfo = true; } }
private void AddLineInfo(int lineNumber, int linePosition) { LineInfo lineInfo = new LineInfo(lineNumber, linePosition); XamlNode node = new XamlNode(lineInfo); _nodeQueue.Enqueue(node); if (!_hasLineInfo) { _hasLineInfo = true; } if (_reader != null && !_reader.HasLineInfo) { _reader.HasLineInfo = true; } }
private void Add(XamlNodeType nodeType, object data) { if (!_readMode) { if (nodeType != XamlNodeType.None) { XamlNode node = new XamlNode(nodeType, data); _nodeList.Add(node); return; } Debug.Assert(XamlNode.IsEof_Helper(nodeType, data)); _readMode = true; } else { throw new XamlException(SR.Get(SRID.CannotWriteClosedWriter)); } }
private XamlNode Next() { if (IsDisposed) { throw new ObjectDisposedException("XamlBackgroundReader"); } if (OutgoingEmpty) { // This is for users that read PAST the EOF record. // Don't let them hang on WaitOne() return EOF Again! if (_currentNode.IsEof) { return(_currentNode); } _providerFullEvent.WaitOne(); // Wait for provider to fill up. SwapBuffers(); _dataReceivedEvent.Set(); // Let the Reader run. } _currentNode = _outgoing[_outIdx++]; if (_currentNode.IsEof) { if (_thread != null) { // If the input ended due to an (caught) exception on the background thread, // then at the end of reading the input re-throw the exception on the // foreground thread. _thread.Join(); if (_caughtException != null) { Exception ex = _caughtException; _caughtException = null; throw ex; } } } return(_currentNode); }
private void Initialize(XmlReader givenXmlReader, XamlSchemaContext schemaContext, XamlXmlReaderSettings settings) { XmlReader myXmlReader; _mergedSettings = (settings == null) ? new XamlXmlReaderSettings() : new XamlXmlReaderSettings(settings); //Wrap the xmlreader with a XmlCompatReader instance to apply MarkupCompat rules. if (!_mergedSettings.SkipXmlCompatibilityProcessing) { XmlCompatibilityReader mcReader = new XmlCompatibilityReader(givenXmlReader, new IsXmlNamespaceSupportedCallback(IsXmlNamespaceSupported) ); mcReader.Normalization = true; myXmlReader = mcReader; } else { //Don't wrap the xmlreader with XmlCompatReader. // Useful for uses where users want to keep mc: content in the XamlNode stream. // Or have already processed the markup compat and want that extra perf. myXmlReader = givenXmlReader; } // Pick up the XmlReader settings to override the "settings" defaults. if (!String.IsNullOrEmpty(myXmlReader.BaseURI)) { _mergedSettings.BaseUri = new Uri(myXmlReader.BaseURI); } if (myXmlReader.XmlSpace == XmlSpace.Preserve) { _mergedSettings.XmlSpacePreserve = true; } if (!String.IsNullOrEmpty(myXmlReader.XmlLang)) { _mergedSettings.XmlLang = myXmlReader.XmlLang; } IXmlNamespaceResolver myXmlReaderNS = myXmlReader as IXmlNamespaceResolver; Dictionary <string, string> xmlnsDictionary = null; if (myXmlReaderNS != null) { IDictionary <string, string> rootNamespaces = myXmlReaderNS.GetNamespacesInScope(XmlNamespaceScope.Local); if (rootNamespaces != null) { foreach (KeyValuePair <string, string> ns in rootNamespaces) { if (xmlnsDictionary == null) { xmlnsDictionary = new Dictionary <string, string>(); } xmlnsDictionary[ns.Key] = ns.Value; } } } if (schemaContext == null) { schemaContext = new XamlSchemaContext(); } _endOfStreamNode = new XamlNode(XamlNode.InternalNodeType.EndOfStream); _context = new XamlParserContext(schemaContext, _mergedSettings.LocalAssembly); _context.AllowProtectedMembersOnRoot = _mergedSettings.AllowProtectedMembersOnRoot; _context.AddNamespacePrefix(KnownStrings.XmlPrefix, XamlLanguage.Xml1998Namespace); Func <string, string> namespaceResolver = myXmlReader.LookupNamespace; _context.XmlNamespaceResolver = namespaceResolver; XamlScanner xamlScanner = new XamlScanner(_context, myXmlReader, _mergedSettings); XamlPullParser parser = new XamlPullParser(_context, xamlScanner, _mergedSettings); _nodeStream = new NodeStreamSorter(_context, parser, _mergedSettings, xmlnsDictionary); _current = new XamlNode(XamlNode.InternalNodeType.StartOfStream); // user must call Read() before using properties. _currentLineInfo = new LineInfo(0, 0); }