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 override bool Read() { this.ThrowIfDisposed(); Label_0006: if (this._nodeStream.MoveNext()) { this._current = this._nodeStream.Current; if (this._current.NodeType != XamlNodeType.None) { goto Label_006E; } if (this._current.LineInfo != null) { this._currentLineInfo = this._current.LineInfo; goto Label_006E; } if (!this._current.IsEof) { goto Label_006E; } } else { this._current = this._endOfStreamNode; } goto Label_007B; Label_006E: if (this._current.NodeType == XamlNodeType.None) { goto Label_0006; } Label_007B: return(!this.IsEof); }
private void Initialize(XamlReader wrappedReader, int bufferSize) { XamlNodeNextDelegate delegate4; this._providerFullEvent = new EventWaitHandle(false, EventResetMode.AutoReset); this._dataReceivedEvent = new EventWaitHandle(false, EventResetMode.AutoReset); this._incoming = new XamlNode[bufferSize]; this._outgoing = new XamlNode[bufferSize]; this._wrappedReader = wrappedReader; this._wrappedReaderHasLineInfo = ((IXamlLineInfo)this._wrappedReader).HasLineInfo; XamlNodeAddDelegate add = new XamlNodeAddDelegate(this.Add); XamlLineInfoAddDelegate addlineInfoDelegate = null; if (this._wrappedReaderHasLineInfo) { addlineInfoDelegate = new XamlLineInfoAddDelegate(this.AddLineInfo); } this._writer = new WriterDelegate(add, addlineInfoDelegate, this._wrappedReader.SchemaContext); if (this._wrappedReaderHasLineInfo) { delegate4 = new XamlNodeNextDelegate(this.Next_ProcessLineInfo); } else { delegate4 = new XamlNodeNextDelegate(this.Next); } this._internalReader = new ReaderDelegate(this._wrappedReader.SchemaContext, delegate4, this._wrappedReaderHasLineInfo); this._currentNode = new XamlNode(XamlNode.InternalNodeType.StartOfStream); }
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 XamlNode Next() { if (base.IsDisposed) { throw new ObjectDisposedException("XamlBackgroundReader"); } if (this.OutgoingEmpty) { if (this._currentNode.IsEof) { return(this._currentNode); } this._providerFullEvent.WaitOne(); this.SwapBuffers(); this._dataReceivedEvent.Set(); } this._currentNode = this._outgoing[this._outIdx++]; if (this._currentNode.IsEof && (this._thread != null)) { this._thread.Join(); if (this._caughtException != null) { Exception exception = this._caughtException; this._caughtException = null; throw exception; } } return(this._currentNode); }
public ReaderDelegate(XamlSchemaContext schemaContext, XamlNodeNextDelegate next, bool hasLineInfo) : base(schemaContext) { _nextDelegate = next; _currentNode = new XamlNode(XamlNode.InternalNodeType.StartOfStream); _currentLineInfo = null; _hasLineInfo = hasLineInfo; }
private void AddLineInfo(int lineNumber, int linePosition) { if (!base.IsDisposed) { LineInfo lineInfo = new LineInfo(lineNumber, linePosition); XamlNode node = new XamlNode(lineInfo); this.AddToBuffer(node); } }
private void AddToBuffer(XamlNode node) { this._incoming[this._inIdx] = node; this._inIdx++; if (this.IncomingFull) { this._providerFullEvent.Set(); this._dataReceivedEvent.WaitOne(); } }
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("schemaContext"); } this._nodeQueue = new Queue <XamlNode>(); this._endOfStreamNode = new XamlNode(XamlNode.InternalNodeType.EndOfStream); this._writer = new WriterDelegate(new XamlNodeAddDelegate(this.Add), new XamlLineInfoAddDelegate(this.AddLineInfo), schemaContext); }
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); }
public XamlNodeQueue(XamlSchemaContext schemaContext) { if (schemaContext == null) { throw new ArgumentNullException("schemaContext"); } this._nodeQueue = new Queue<XamlNode>(); this._endOfStreamNode = new XamlNode(XamlNode.InternalNodeType.EndOfStream); this._writer = new WriterDelegate(new XamlNodeAddDelegate(this.Add), new XamlLineInfoAddDelegate(this.AddLineInfo), schemaContext); }
// ====================================== 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 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 item = new XamlNode(nodeType, data); this._nodeQueue.Enqueue(item); } else { this._nodeQueue.Enqueue(this._endOfStreamNode); } }
private void AddLineInfo(int lineNumber, int linePosition) { if (this._readMode) { throw new XamlException(System.Xaml.SR.Get("CannotWriteClosedWriter")); } XamlNode item = new XamlNode(new LineInfo(lineNumber, linePosition)); this._nodeList.Add(item); if (!this._hasLineInfo) { this._hasLineInfo = true; } }
private void AddLineInfo(int lineNumber, int linePosition) { LineInfo lineInfo = new LineInfo(lineNumber, linePosition); XamlNode item = new XamlNode(lineInfo); this._nodeQueue.Enqueue(item); if (!this._hasLineInfo) { this._hasLineInfo = true; } if ((this._reader != null) && !this._reader.HasLineInfo) { this._reader.HasLineInfo = true; } }
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 (IsDisposed) { return; } if (nodeType != XamlNodeType.None) { AddToBuffer(new XamlNode(nodeType, data)); return; } System.Diagnostics.Debug.Assert(XamlNode.IsEof_Helper(nodeType, data)); AddToBuffer(new XamlNode(XamlNode.InternalNodeType.EndOfStream)); _providerFullEvent.Set(); }
private void Add(XamlNodeType nodeType, object data) { if (this._readMode) { throw new XamlException(System.Xaml.SR.Get("CannotWriteClosedWriter")); } if (nodeType != XamlNodeType.None) { XamlNode item = new XamlNode(nodeType, data); this._nodeList.Add(item); } else { this._readMode = 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); }
void AvoidContentProperties(XamlNode node) { foreach (XamlNode child in node.Children) AvoidContentProperties(child); XamlObjectNode obj = node as XamlObjectNode; if (obj != null) { // Visit all except for the last child: for (int i = 0; i < obj.Children.Count - 1; i++) { // Avoids using content property syntax for simple string values, if the content property is not the last member. // Without this, we cannot decompile <GridViewColumn Header="Culture" DisplayMemberBinding="{Binding Culture}" />, // because the Header property is the content property, but there is no way to represent the Binding as an element. XamlMemberNode memberNode = obj.Children[i] as XamlMemberNode; if (memberNode != null && memberNode.Member == obj.Type.ContentProperty) { if (memberNode.Children.Count == 1 && memberNode.Children[0] is XamlValueNode) { // By creating a clone of the XamlMember, we prevent WPF from knowing that it's the content property. XamlMember member = memberNode.Member; memberNode.Member = new XamlMember(member.Name, member.DeclaringType, member.IsAttachable); } } } // We also need to avoid using content properties that have a markup extension as value, as the XamlXmlWriter would always expand those: for (int i = 0; i < obj.Children.Count; i++) { XamlMemberNode memberNode = obj.Children[i] as XamlMemberNode; if (memberNode != null && memberNode.Member == obj.Type.ContentProperty && memberNode.Children.Count == 1) { XamlObjectNode me = memberNode.Children[0] as XamlObjectNode; if (me != null && me.Type.IsMarkupExtension) { // By creating a clone of the XamlMember, we prevent WPF from knowing that it's the content property. XamlMember member = memberNode.Member; memberNode.Member = new XamlMember(member.Name, member.DeclaringType, member.IsAttachable); } } } } }
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); }
private XamlNode Next() { if (base.IsDisposed) { throw new ObjectDisposedException("XamlBackgroundReader"); } if (this.OutgoingEmpty) { if (this._currentNode.IsEof) { return this._currentNode; } this._providerFullEvent.WaitOne(); this.SwapBuffers(); this._dataReceivedEvent.Set(); } this._currentNode = this._outgoing[this._outIdx++]; if (this._currentNode.IsEof && (this._thread != null)) { this._thread.Join(); if (this._caughtException != null) { Exception exception = this._caughtException; this._caughtException = null; throw exception; } } return this._currentNode; }
private void Initialize(XamlReader wrappedReader, int bufferSize) { XamlNodeNextDelegate delegate4; this._providerFullEvent = new EventWaitHandle(false, EventResetMode.AutoReset); this._dataReceivedEvent = new EventWaitHandle(false, EventResetMode.AutoReset); this._incoming = new XamlNode[bufferSize]; this._outgoing = new XamlNode[bufferSize]; this._wrappedReader = wrappedReader; this._wrappedReaderHasLineInfo = ((IXamlLineInfo) this._wrappedReader).HasLineInfo; XamlNodeAddDelegate add = new XamlNodeAddDelegate(this.Add); XamlLineInfoAddDelegate addlineInfoDelegate = null; if (this._wrappedReaderHasLineInfo) { addlineInfoDelegate = new XamlLineInfoAddDelegate(this.AddLineInfo); } this._writer = new WriterDelegate(add, addlineInfoDelegate, this._wrappedReader.SchemaContext); if (this._wrappedReaderHasLineInfo) { delegate4 = new XamlNodeNextDelegate(this.Next_ProcessLineInfo); } else { delegate4 = new XamlNodeNextDelegate(this.Next); } this._internalReader = new ReaderDelegate(this._wrappedReader.SchemaContext, delegate4, this._wrappedReaderHasLineInfo); this._currentNode = new XamlNode(XamlNode.InternalNodeType.StartOfStream); }
void RemoveConnectionIds(XamlNode node, Dictionary<int, EventRegistration[]> eventMappings, XamlSchemaContext context) { foreach (XamlNode child in node.Children) RemoveConnectionIds(child, eventMappings, context); XamlObjectNode obj = node as XamlObjectNode; if (obj != null && obj.Children.Count > 0) { var removableNodes = new List<XamlMemberNode>(); var addableNodes = new List<XamlMemberNode>(); foreach (XamlMemberNode memberNode in obj.Children.OfType<XamlMemberNode>()) { if (memberNode.Member == XamlLanguage.ConnectionId && memberNode.Children.Single() is XamlValueNode) { var value = memberNode.Children.Single() as XamlValueNode; int id; if (value.Value is string && int.TryParse(value.Value as string, out id) && eventMappings.ContainsKey(id)) { var map = eventMappings[id]; foreach (var entry in map) { if (entry.IsAttached) { var type = context.GetXamlType(Type.GetType(entry.AttachSourceType)); var member = new XamlMemberNode(new XamlMember(entry.EventName, type, true)); member.Children.Add(new XamlValueNode(entry.MethodName)); addableNodes.Add(member); } else { var member = new XamlMemberNode(obj.Type.GetMember(entry.EventName)); member.Children.Add(new XamlValueNode(entry.MethodName)); addableNodes.Add(member); } } removableNodes.Add(memberNode); } } } foreach (var rnode in removableNodes) node.Children.Remove(rnode); node.Children.InsertRange(node.Children.Count > 1 ? node.Children.Count - 1 : 0, addableNodes); } }
/// <summary> /// It seems like BamlReader will always output 'x:Key' as last property. However, it must be specified as attribute in valid .xaml, so we move it to the front /// of the attribute list. /// </summary> void MoveXKeyToFront(XamlNode node) { foreach (XamlNode child in node.Children) MoveXKeyToFront(child); XamlObjectNode obj = node as XamlObjectNode; if (obj != null && obj.Children.Count > 0) { XamlMemberNode memberNode = obj.Children[obj.Children.Count - 1] as XamlMemberNode; if (memberNode != null && memberNode.Member == XamlLanguage.Key) { // move memberNode in front of the first member node: for (int i = 0; i < obj.Children.Count; i++) { if (obj.Children[i] is XamlMemberNode) { obj.Children.Insert(i, memberNode); obj.Children.RemoveAt(obj.Children.Count - 1); break; } } } } }
private void Initialize(XmlReader givenXmlReader, XamlSchemaContext schemaContext, XamlXmlReaderSettings settings) { XmlReader reader; this._mergedSettings = (settings == null) ? new XamlXmlReaderSettings() : new XamlXmlReaderSettings(settings); if (!this._mergedSettings.SkipXmlCompatibilityProcessing) { XmlCompatibilityReader reader2 = new XmlCompatibilityReader(givenXmlReader, new IsXmlNamespaceSupportedCallback(this.IsXmlNamespaceSupported)) { Normalization = true }; reader = reader2; } else { reader = givenXmlReader; } if (!string.IsNullOrEmpty(reader.BaseURI)) { this._mergedSettings.BaseUri = new Uri(reader.BaseURI); } if (reader.XmlSpace == XmlSpace.Preserve) { this._mergedSettings.XmlSpacePreserve = true; } if (!string.IsNullOrEmpty(reader.XmlLang)) { this._mergedSettings.XmlLang = reader.XmlLang; } IXmlNamespaceResolver resolver = reader as IXmlNamespaceResolver; Dictionary <string, string> xmlnsDictionary = null; if (resolver != null) { IDictionary <string, string> namespacesInScope = resolver.GetNamespacesInScope(XmlNamespaceScope.Local); if (namespacesInScope != null) { foreach (KeyValuePair <string, string> pair in namespacesInScope) { if (xmlnsDictionary == null) { xmlnsDictionary = new Dictionary <string, string>(); } xmlnsDictionary[pair.Key] = pair.Value; } } } if (schemaContext == null) { schemaContext = new XamlSchemaContext(); } this._endOfStreamNode = new XamlNode(XamlNode.InternalNodeType.EndOfStream); this._context = new XamlParserContext(schemaContext, this._mergedSettings.LocalAssembly); this._context.AllowProtectedMembersOnRoot = this._mergedSettings.AllowProtectedMembersOnRoot; this._context.AddNamespacePrefix("xml", "http://www.w3.org/XML/1998/namespace"); Func <string, string> func = new Func <string, string>(reader.LookupNamespace); this._context.XmlNamespaceResolver = func; XamlScanner scanner = new XamlScanner(this._context, reader, this._mergedSettings); XamlPullParser parser = new XamlPullParser(this._context, scanner, this._mergedSettings); this._nodeStream = new NodeStreamSorter(this._context, parser, this._mergedSettings, xmlnsDictionary); this._current = new XamlNode(XamlNode.InternalNodeType.StartOfStream); this._currentLineInfo = new System.Xaml.LineInfo(0, 0); }