public static void PropagateLineInfo(XamlWriter targetWriter, IXamlLineInfo lineInfo) { if (lineInfo != null) { (targetWriter as IXamlLineInfoConsumer).SetLineInfo(lineInfo.LineNumber, lineInfo.LinePosition); } }
// This method is a workaround for TFS bug #788190, since XamlReader.ReadSubtree() should (but doesn't) preserve IXamlLineInfo on the subreader public static void Transform(XamlReader reader, XamlWriter writer, IXamlLineInfo readerLineInfo, bool closeWriter) { IXamlLineInfoConsumer consumer = writer as IXamlLineInfoConsumer; SharedFx.Assert(consumer != null && consumer.ShouldProvideLineInfo, "Should only call this function to write into a XamlNodeQueue.Writer, which is always IXamlLineInfoConsumer"); bool shouldPassLineNumberInfo = false; if (readerLineInfo != null) { shouldPassLineNumberInfo = true; } while (reader.Read()) { if (shouldPassLineNumberInfo) { consumer.SetLineInfo(readerLineInfo.LineNumber, readerLineInfo.LinePosition); } writer.WriteNode(reader); } if (closeWriter) { writer.Close(); } }
public static XamlWriter CreateBuilderWriter(XamlWriter innerWriter) { if (innerWriter == null) { throw FxTrace.Exception.ArgumentNull("innerWriter"); } return new ActivityBuilderXamlWriter(innerWriter); }
public static void PropagateLineInfo(XamlWriter targetWriter, IXamlLineInfo lineInfo) { if (lineInfo != null) { IXamlLineInfoConsumer consumer = targetWriter as IXamlLineInfoConsumer; Fx.Assert(consumer != null && consumer.ShouldProvideLineInfo, "Should only call this function to write into a XamlNodeQueue.Writer, which is always IXamlLineInfoConsumer"); consumer.SetLineInfo(lineInfo.LineNumber, lineInfo.LinePosition); } }
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 override void WriteTo(XamlWriter writer) { Log("GetObject"); writer.WriteGetObject(); Debug.Indent(); foreach (XamlNode node in this.Children) node.WriteTo(writer); Debug.Unindent(); Log("EndObject"); writer.WriteEndObject(); }
internal static void WriteNodeList(XamlWriter writer, XamlNodeList nodeList) { // We need to pass the ErrorNodes contents through as a NodeList, because XOW doesn't // currently support unknown types, even inside a DeferLoad block. // But if a NodeList is written to XOW as a Value, XOW will unpack, forcing us to re-buffer // the nodes in our deferring loader. So we wrap the NodeList value inside a dummy StartObject. writer.WriteStartObject(XamlLanguage.Object); writer.WriteStartMember(XamlLanguage.Initialization); writer.WriteValue(nodeList); writer.WriteEndMember(); writer.WriteEndObject(); }
protected override void Dispose(bool disposing) { try { if ((disposing && !base.IsDisposed) && (this._deferredWriter != null)) { this._deferredWriter.Close(); this._deferredWriter = null; } } finally { base.Dispose(disposing); } }
}//end //从[xaml]å—串得到[ActivityBuilder]对象 public static string xamlFromActivityBuilder(ActivityBuilder activityBuilder) { string xamlString = ""; StringBuilder stringBuilder = new StringBuilder(); System.IO.StringWriter stringWriter = new System.IO.StringWriter(stringBuilder); System.Xaml.XamlSchemaContext xamlSchemaContext = new System.Xaml.XamlSchemaContext(); System.Xaml.XamlXmlWriter xamlXmlWriter = new System.Xaml.XamlXmlWriter(stringWriter, xamlSchemaContext); System.Xaml.XamlWriter xamlWriter = System.Activities.XamlIntegration.ActivityXamlServices.CreateBuilderWriter(xamlXmlWriter); System.Xaml.XamlServices.Save(xamlWriter, activityBuilder); xamlString = stringBuilder.ToString(); return(xamlString); }
public static void Transform(XamlReader reader, XamlWriter writer, IXamlLineInfo readerLineInfo, bool closeWriter) { IXamlLineInfoConsumer consumer = writer as IXamlLineInfoConsumer; bool flag = false; if (readerLineInfo != null) { flag = true; } while (reader.Read()) { if (flag) { consumer.SetLineInfo(readerLineInfo.LineNumber, readerLineInfo.LinePosition); } writer.WriteNode(reader); } if (closeWriter) { writer.Close(); } }
public override void WriteTo(XamlWriter writer) { Log("NamespaceDeclaration {0}", this.Namespace); Debug.Assert(this.Children.Count == 0); writer.WriteNamespace(this.Namespace); }
public override void WriteTo(XamlWriter writer) { Log("Value {0}", this.Value); Debug.Assert(this.Children.Count == 0); // requires XamlReaderSettings.ValuesMustBeString = true to work properly writer.WriteValue(this.Value); }
public override void WriteTo(XamlWriter writer) { Log("StartMember {0}", this.Member); writer.WriteStartMember(this.Member); Debug.Indent(); foreach (XamlNode node in this.Children) node.WriteTo(writer); Debug.Unindent(); Log("EndMember"); writer.WriteEndMember(); }
public viewStateXamlWriter(XamlWriter innerWriter) { this.InnerWriter = innerWriter; this.MemberStack = new Stack<XamlMember>(); }
// Copy the root namespaces from a reader to a writer. // DesignTimeXamlWriter follows proper XAML convention by omitting the assembly name from // clr-namespaces in the local assembly. However, VB Expressions aren't local-assembly-aware, // and require an assembly name. So for every clr-namespace with no assembly name, we add an // additional namespace record with an assembly name, to support VB. // We only do this at the root level, since the designer only writes out namespaces at the root level. internal void CopyNamespacesAndAddLocalAssembly(System.Xaml.XamlReader activityBuilderReader, System.Xaml.XamlWriter objectWriter) { // Designer loads alwas provide line info IXamlLineInfo lineInfo = (IXamlLineInfo)activityBuilderReader; IXamlLineInfoConsumer lineInfoConsumer = (IXamlLineInfoConsumer)objectWriter; HashSet <string> definedPrefixes = new HashSet <string>(); List <NamespaceDeclaration> localAsmNamespaces = null; while (activityBuilderReader.Read()) { lineInfoConsumer.SetLineInfo(lineInfo.LineNumber, lineInfo.LinePosition); if (activityBuilderReader.NodeType == XamlNodeType.NamespaceDeclaration) { definedPrefixes.Add(activityBuilderReader.Namespace.Prefix); if (this.XamlSchemaContext.IsClrNamespaceWithNoAssembly(activityBuilderReader.Namespace.Namespace)) { if (localAsmNamespaces == null) { localAsmNamespaces = new List <NamespaceDeclaration>(); } localAsmNamespaces.Add(activityBuilderReader.Namespace); } objectWriter.WriteNode(activityBuilderReader); } else { if (localAsmNamespaces != null) { foreach (NamespaceDeclaration ns in localAsmNamespaces) { string prefix = null; int i = 0; do { i++; prefix = ns.Prefix + i.ToString(CultureInfo.InvariantCulture); }while (definedPrefixes.Contains(prefix)); string fullNs = this.XamlSchemaContext.AddLocalAssembly(ns.Namespace); objectWriter.WriteNamespace(new NamespaceDeclaration(fullNs, prefix)); definedPrefixes.Add(prefix); } } objectWriter.WriteNode(activityBuilderReader); return; } } }
private void Process_KeyElementStart() { Int16 typeId = _binaryReader.ReadInt16(); byte flags = _binaryReader.ReadByte(); Int32 valuePosition = _binaryReader.ReadInt32(); bool isShared = _binaryReader.ReadBoolean(); bool isSharedSet = _binaryReader.ReadBoolean(); XamlType type = _context.SchemaContext.GetXamlType(typeId); _context.PushScope(); _context.CurrentFrame.XamlType = type; // Store a key record that can be accessed later. // This is a complex scenario so we need to write to the keyList KeyRecord key = new KeyRecord(isShared, isSharedSet, valuePosition, _context.SchemaContext); key.Flags = flags; key.KeyNodeList.Writer.WriteStartObject(type); _context.InsideKeyRecord = true; // Push the current writer onto a stack and add the KeyNodeList writer. // All subsequent calls will be added to that writer. _xamlWriterStack.Push(_xamlNodesWriter); _xamlNodesWriter = key.KeyNodeList.Writer; if (_context.PreviousFrame.IsDeferredContent) { _context.KeyList.Add(key); } else { _context.PreviousFrame.Key = key; } }
private void Transform(XamlReader reader, XamlWriter myWriter) { while (!reader.IsEof) { reader.Read(); myWriter.WriteNode(reader); } }
public static void Transform (XamlReader xamlReader, XamlWriter xamlWriter, bool closeWriter) { if (xamlReader == null) throw new ArgumentNullException ("xamlReader"); if (xamlWriter == null) throw new ArgumentNullException ("xamlWriter"); if (xamlReader.NodeType == XamlNodeType.None) xamlReader.Read (); while (!xamlReader.IsEof) { xamlWriter.WriteNode (xamlReader); xamlReader.Read (); } if (closeWriter) xamlWriter.Close (); }
public static void Transform(XamlReader xamlReader, XamlWriter xamlWriter, bool closeWriter) { if (xamlReader == null) { throw new ArgumentNullException("xamlReader"); } if (xamlWriter == null) { throw new ArgumentNullException("xamlWriter"); } IXamlLineInfo info = xamlReader as IXamlLineInfo; IXamlLineInfoConsumer consumer = xamlWriter as IXamlLineInfoConsumer; bool flag = false; if (((info != null) && info.HasLineInfo) && ((consumer != null) && consumer.ShouldProvideLineInfo)) { flag = true; } while (xamlReader.Read()) { if (flag && (info.LineNumber != 0)) { consumer.SetLineInfo(info.LineNumber, info.LinePosition); } xamlWriter.WriteNode(xamlReader); } if (closeWriter) { xamlWriter.Close(); } }
private void StartSavingFirstItemInDictionary() { _lookingForAKeyOnAMarkupExtensionInADictionaryDepth = _context.CurrentFrame.Depth; _lookingForAKeyOnAMarkupExtensionInADictionaryNodeList = new XamlNodeList(_xamlNodesWriter.SchemaContext); _xamlWriterStack.Push(_xamlNodesWriter); _xamlNodesWriter = _lookingForAKeyOnAMarkupExtensionInADictionaryNodeList.Writer; }
private void InjectPropertyAndFrameIfNeeded(XamlType elementType, SByte flags) { // If we saved the Node stream for the first ME element of a dictionary to // check if it had a key then process that now. if (_lookingForAKeyOnAMarkupExtensionInADictionaryDepth == _context.CurrentFrame.Depth) { RestoreSavedFirstItemInDictionary(); } XamlType parentType = _context.CurrentFrame.XamlType; XamlMember parentProperty = _context.CurrentFrame.Member; if (parentType != null) { if (parentProperty == null) { // We have got two consecutive ElementStart records // We must insert an implicit content property between them if (_context.CurrentFrame.ContentProperty != null) { _context.CurrentFrame.Member = parentProperty = _context.CurrentFrame.ContentProperty; } else if (parentType.ContentProperty != null) { _context.CurrentFrame.Member = parentProperty = parentType.ContentProperty; } else { if (parentType.IsCollection || parentType.IsDictionary) { _context.CurrentFrame.Member = parentProperty = XamlLanguage.Items; } else if (parentType.TypeConverter != null) { _context.CurrentFrame.Member = parentProperty = XamlLanguage.Initialization; } else { throw new XamlParseException(SR.Get(SRID.RecordOutOfOrder, parentType.Name)); } } _context.CurrentFrame.Flags = Baml2006ReaderFrameFlags.HasImplicitProperty; _xamlNodesWriter.WriteStartMember(parentProperty); // if we are NOT already spooling a template if (_context.TemplateStartDepth < 0 && _isBinaryProvider) { if (parentProperty == BamlSchemaContext.FrameworkTemplateTemplateProperty) { // If this is a template then spool the template into a Node List. _context.TemplateStartDepth = _context.CurrentFrame.Depth; _xamlTemplateNodeList = new XamlNodeList(_xamlNodesWriter.SchemaContext); _xamlWriterStack.Push(_xamlNodesWriter); _xamlNodesWriter = _xamlTemplateNodeList.Writer; } } } XamlType parentPropertyType = parentProperty.Type; // Normally an error except for collections if (parentPropertyType != null && (parentPropertyType.IsCollection || parentPropertyType.IsDictionary) && !parentProperty.IsDirective && (flags & ReaderFlags_AddedToTree) == 0) { bool emitPreamble = false; // If the collection property is Readonly then "retrieve" the collection. if (parentProperty.IsReadOnly) { emitPreamble = true; } // OR if the Value isn't assignable to the Collection emit the preable. else if (!elementType.CanAssignTo(parentPropertyType)) { // UNLESS: the Value is a Markup extension, then it is assumed that // the ProvidValue type will be AssignableFrom. if (!elementType.IsMarkupExtension) { emitPreamble = true; } // EXCEPT: if the BAML said it was Retrived else if (_context.CurrentFrame.Flags == Baml2006ReaderFrameFlags.HasImplicitProperty) { emitPreamble = true; } // OR: the ME is Array else if (elementType == XamlLanguage.Array) { emitPreamble = true; } } if (emitPreamble) { EmitGoItemsPreamble(parentPropertyType); } // We may need to look for an x:Key on the ME in a dictionary. // so save up the node stream for the whole element definition and check it // for an x:Key later. if (!emitPreamble && parentPropertyType.IsDictionary && elementType.IsMarkupExtension) { StartSavingFirstItemInDictionary(); } } } }
private void RemoveImplicitFrame() { if (_context.CurrentFrame.Flags == Baml2006ReaderFrameFlags.IsImplict) { _xamlNodesWriter.WriteEndMember(); _xamlNodesWriter.WriteEndObject(); _context.PopScope(); } if (_context.CurrentFrame.Flags == Baml2006ReaderFrameFlags.HasImplicitProperty) { // If we are encoding a template there is some extra checking. if (_context.CurrentFrame.Depth == _context.TemplateStartDepth) { // If the template is done. Switch back to the previous writer. // Write the spooled Template Node List as a single Value. _xamlNodesWriter.Close(); _xamlNodesWriter = _xamlWriterStack.Pop(); _xamlNodesWriter.WriteValue(_xamlTemplateNodeList); _xamlTemplateNodeList = null; _context.TemplateStartDepth = -1; } _xamlNodesWriter.WriteEndMember(); _context.CurrentFrame.Member = null; _context.CurrentFrame.Flags = Baml2006ReaderFrameFlags.None; } }
private void Process_KeyElementEnd() { KeyRecord key = null; if (_context.PreviousFrame.IsDeferredContent) { key = _context.LastKey; } else { key = _context.PreviousFrame.Key; } key.KeyNodeList.Writer.WriteEndObject(); key.KeyNodeList.Writer.Close(); // Revert the writer _xamlNodesWriter = _xamlWriterStack.Pop(); _context.InsideKeyRecord = false; _context.PopScope(); }
public abstract void WriteTo(XamlWriter writer);
public static void Transform(XamlReader xamlReader, XamlWriter xamlWriter) { Transform(xamlReader, xamlWriter, true); }
public static void Transform(XamlReader xamlReader, XamlWriter xamlWriter) { // arguments are validated by the callee here. Transform(xamlReader, xamlWriter, true); }
private void RestoreSavedFirstItemInDictionary() { // Restore the real (previous) output node stream. _xamlNodesWriter.Close(); _xamlNodesWriter = _xamlWriterStack.Pop(); // Check in the saved nodes if the x:Key was set and if it was insert a "GO;SM _items" if (NodeListHasAKeySetOnTheRoot(_lookingForAKeyOnAMarkupExtensionInADictionaryNodeList.GetReader())) { EmitGoItemsPreamble(_context.CurrentFrame.Member.Type); } // dump the saved nodes into the real (previous) output node stream. XamlReader lookAheadNodesReader = _lookingForAKeyOnAMarkupExtensionInADictionaryNodeList.GetReader(); XamlServices.Transform(lookAheadNodesReader, _xamlNodesWriter, false); _lookingForAKeyOnAMarkupExtensionInADictionaryDepth = -1; }
private void Initialize(Stream stream, Baml2006SchemaContext schemaContext, Baml2006ReaderSettings settings) { schemaContext.Settings = settings; _settings = settings; _context = new Baml2006ReaderContext(schemaContext); _xamlMainNodeQueue = new XamlNodeQueue(schemaContext); _xamlNodesReader = _xamlMainNodeQueue.Reader; _xamlNodesWriter = _xamlMainNodeQueue.Writer; _lookingForAKeyOnAMarkupExtensionInADictionaryDepth = -1; _isBinaryProvider = !settings.ValuesMustBeString; // Since the reader owns the stream and is responsible for its lifetime // it can safely hand out shared streams. if (_settings.OwnsStream) { stream = new SharedStream(stream); } _binaryReader = new BamlBinaryReader(stream); _context.TemplateStartDepth = -1; if (!_settings.IsBamlFragment) { Process_Header(); } }
public static void Transform (XamlReader xamlReader, XamlWriter xamlWriter) { Transform (xamlReader, xamlWriter, true); }
internal XamlReader ReadObject(KeyRecord record) { // This means we're at the end of the Deferred Content // Break out and return null if (record.ValuePosition == _binaryReader.BaseStream.Length) { return null; } _binaryReader.BaseStream.Seek(record.ValuePosition, SeekOrigin.Begin); _context.CurrentKey = _context.KeyList.IndexOf(record); if (_xamlMainNodeQueue.Count > 0) { // throw new XamlParseException(); } if (Read_RecordType() != Baml2006RecordType.ElementStart) { throw new XamlParseException(); } XamlWriter oldQueueWriter = _xamlNodesWriter; // estimates from statistical examiniation of Theme Resource Data. // small RD entries appear to have about a 2.2 bytes to XamlNode ration. // larger RD entries are less dense (due to data) at about 4.25. // Presizing the XamlNodeLists save upto 50% in memory useage for same. int initialSizeOfNodeList = (record.ValueSize < 800) ? (int)(record.ValueSize / 2.2) : (int)(record.ValueSize / 4.25); initialSizeOfNodeList = (initialSizeOfNodeList < 8) ? 8 : initialSizeOfNodeList; var result = new XamlNodeList(_xamlNodesReader.SchemaContext, initialSizeOfNodeList); _xamlNodesWriter = result.Writer; Baml2006ReaderFrame baseFrame = _context.CurrentFrame; Process_ElementStart(); while (baseFrame != _context.CurrentFrame) { Process_OneBamlRecord(); } _xamlNodesWriter.Close(); _xamlNodesWriter = oldQueueWriter; return result.GetReader(); }
public static void Save (XamlWriter xamlWriter, object instance) { if (xamlWriter == null) throw new ArgumentNullException ("xamlWriter"); var r = new XamlObjectReader (instance, xamlWriter.SchemaContext); Transform (r, xamlWriter); }
private void Process_StaticResourceEnd() { XamlWriter writer = GetLastStaticResource().ResourceNodeList.Writer; writer.WriteEndObject(); writer.Close(); _context.InsideStaticResource = false; _xamlNodesWriter = _xamlWriterStack.Pop(); _context.PopScope(); }
public ActivityTemplateFactoryBuilderWriter(XamlWriter underlyingWriter, XamlSchemaContext schemaContext) { this.schemaContext = schemaContext; this.underlyingWriter = underlyingWriter; }
private void Process_StaticResourceStart() { XamlType type = BamlSchemaContext.GetXamlType(_binaryReader.ReadInt16()); byte flags = _binaryReader.ReadByte(); // StaticResource staticResource = new StaticResource(type, BamlSchemaContext); _context.LastKey.StaticResources.Add(staticResource); _context.InsideStaticResource = true; _xamlWriterStack.Push(_xamlNodesWriter); _xamlNodesWriter = staticResource.ResourceNodeList.Writer; _context.PushScope(); _context.CurrentFrame.XamlType = type; }