public static Activity Load(XamlReader xamlReader, ActivityXamlServicesSettings settings) { if (xamlReader == null) { throw FxTrace.Exception.ArgumentNull("xamlReader"); } if (settings == null) { throw FxTrace.Exception.ArgumentNull("settings"); } DynamicActivityXamlReader dynamicActivityReader = new DynamicActivityXamlReader(xamlReader); object xamlObject = XamlServices.Load(dynamicActivityReader); Activity result = xamlObject as Activity; if (result == null) { throw FxTrace.Exception.Argument("reader", SR.ActivityXamlServicesRequiresActivity( xamlObject != null ? xamlObject.GetType().FullName : string.Empty)); } IDynamicActivity dynamicActivity = result as IDynamicActivity; if (dynamicActivity != null && settings.CompileExpressions) { Compile(dynamicActivity, settings.LocationReferenceEnvironment); } return result; }
public void BufferDefinitions(DynamicActivityXamlReader parent) { XamlReader reader = parent.innerReader.ReadSubtree(); IXamlLineInfo innerReaderLineInfo = parent.innerReaderLineInfo; reader.Read(); this.outerNodes.Writer.WriteStartMember(parent.activityReplacementXamlType.GetMember("Properties"), innerReaderLineInfo); this.outerNodes.Writer.WriteGetObject(innerReaderLineInfo); this.outerNodes.Writer.WriteStartMember(XamlLanguage.Items, innerReaderLineInfo); bool flag = reader.Read(); while (flag) { if ((reader.NodeType == XamlNodeType.StartObject) && (reader.Type == XamlLanguage.Property)) { ActivityPropertyHolder holder = new ActivityPropertyHolder(parent, reader.ReadSubtree()); this.PropertyHolders.Add(holder.Name, holder); this.outerNodes.Writer.WriteValue(holder, innerReaderLineInfo); } else { this.outerNodes.Writer.WriteNode(reader, innerReaderLineInfo); flag = reader.Read(); } } this.outerNodes.Writer.WriteEndObject(innerReaderLineInfo); this.outerNodes.Writer.WriteEndMember(innerReaderLineInfo); reader.Close(); this.alreadyBufferedDefinitions = true; this.FlushValueHolders(parent); }
public static Activity Load(XamlReader xamlReader, ActivityXamlServicesSettings settings) { if (xamlReader == null) { throw FxTrace.Exception.ArgumentNull(nameof(xamlReader)); } if (settings == null) { throw FxTrace.Exception.ArgumentNull(nameof(settings)); } DynamicActivityXamlReader dynamicActivityReader = new DynamicActivityXamlReader(xamlReader); object xamlObject = XamlServices.Load(dynamicActivityReader); if (!(xamlObject is Activity result)) { throw FxTrace.Exception.Argument("reader", SR.ActivityXamlServicesRequiresActivity( xamlObject != null ? xamlObject.GetType().FullName : string.Empty)); } if (result is IDynamicActivity dynamicActivity && settings.CompileExpressions) { Compile(dynamicActivity, settings); } return(result); }
public void ProcessDefaultValue(string propertyName, XamlMember propertyValue, XamlReader reader, IXamlLineInfo lineInfo) { ActivityPropertyHolder holder; if (!this.PropertyHolders.TryGetValue(propertyName, out holder)) { throw FxTrace.Exception.AsError(DynamicActivityXamlReader.CreateXamlException(System.Activities.SR.InvalidProperty(propertyName), lineInfo)); } holder.ProcessDefaultValue(propertyValue, reader, lineInfo); }
private void FlushValueHolders(DynamicActivityXamlReader parent) { if (this.valueHolders != null) { foreach (KeyValuePair <string, ValueHolder> pair in this.valueHolders) { this.ProcessDefaultValue(pair.Key, pair.Value.PropertyValue, pair.Value.ValueReader, parent.innerReaderLineInfo); } this.valueHolders = null; } }
public BuilderMemberNode(DynamicActivityXamlReader parent, int depth) { this.parent = parent; this.Depth = depth; this.currentMember = parent.innerReader.Member; if (parent.hasLineInfo) { this.currentMemberLineNumber = parent.innerReaderLineInfo.LineNumber; this.currentMemberLinePosition = parent.innerReaderLineInfo.LinePosition; } this.bufferedNodes = new XamlNodeQueue(parent.SchemaContext); }
public void ProcessDefaultValue(XamlMember propertyValue, XamlReader subReader, IXamlLineInfo lineInfo) { XamlReader reader; bool flag = false; subReader.Read(); if (!subReader.Member.IsNameValid) { throw FxTrace.Exception.AsError(DynamicActivityXamlReader.CreateXamlException(System.Activities.SR.InvalidXamlMember(subReader.Member.Name), lineInfo)); } this.nodes.Writer.WriteStartMember(propertyValue, lineInfo); subReader.Read(); if (subReader.NodeType == XamlNodeType.GetObject) { subReader.Read(); subReader.Read(); reader = subReader.ReadSubtree(); reader.Read(); } else { reader = subReader; } if ((reader.NodeType != XamlNodeType.EndMember) && (reader.NodeType != XamlNodeType.StartObject)) { flag = true; this.nodes.Writer.WriteStartObject(this.Type, lineInfo); this.nodes.Writer.WriteStartMember(XamlLanguage.Initialization, lineInfo); } while (!reader.IsEof) { this.nodes.Writer.WriteNode(reader, lineInfo); reader.Read(); } reader.Close(); if (!object.ReferenceEquals(reader, subReader)) { subReader.Read(); while (subReader.Read()) { this.nodes.Writer.WriteNode(subReader, lineInfo); } } if (flag) { this.nodes.Writer.WriteEndObject(lineInfo); this.nodes.Writer.WriteEndMember(lineInfo); } subReader.Close(); }
public static Activity Load(XamlReader xamlReader) { if (xamlReader == null) { throw FxTrace.Exception.ArgumentNull("xamlReader"); } DynamicActivityXamlReader reader = new DynamicActivityXamlReader(xamlReader); object obj2 = XamlServices.Load(reader); Activity activity = obj2 as Activity; if (activity == null) { throw FxTrace.Exception.Argument("reader", System.Activities.SR.ActivityXamlServicesRequiresActivity((obj2 != null) ? obj2.GetType().FullName : string.Empty)); } return(activity); }
public void FlushTo(XamlNodeQueue targetNodeQueue, DynamicActivityXamlReader parent) { this.FlushValueHolders(parent); XamlReader reader = this.outerNodes.Reader; IXamlLineInfo readerInfo = parent.hasLineInfo ? (reader as IXamlLineInfo) : null; while (reader.Read()) { if (reader.NodeType == XamlNodeType.Value) { ActivityPropertyHolder holder = reader.Value as ActivityPropertyHolder; if (holder != null) { holder.CopyTo(targetNodeQueue, readerInfo); continue; } } targetNodeQueue.Writer.WriteNode(reader, readerInfo); } }
public static Activity Load(XamlReader xamlReader) { if (xamlReader == null) { throw FxTrace.Exception.ArgumentNull("xamlReader"); } DynamicActivityXamlReader reader = new DynamicActivityXamlReader(xamlReader); object obj2 = XamlServices.Load(reader); Activity activity = obj2 as Activity; if (activity == null) { throw FxTrace.Exception.Argument("reader", System.Activities.SR.ActivityXamlServicesRequiresActivity((obj2 != null) ? obj2.GetType().FullName : string.Empty)); } return activity; }
public BuilderStack(DynamicActivityXamlReader parent) { this.parent = parent; this.stack = new Stack<Frame>(); this.activityPropertyReferenceXamlType = parent.schemaContext.GetXamlType(typeof(ActivityPropertyReference)); this.activityPropertyReferenceSourceProperty = this.activityPropertyReferenceXamlType.GetMember("SourceProperty"); this.activityPropertyReferenceTargetProperty = this.activityPropertyReferenceXamlType.GetMember("TargetProperty"); XamlType typeOfActivityBuilder = parent.schemaContext.GetXamlType(typeof(ActivityBuilder)); this.activityBuilderPropertyReferencesMember = typeOfActivityBuilder.GetAttachableMember("PropertyReferences"); }
// Called inside of an x:Members--read up to </x:Members>, buffering definitions public void BufferDefinitions(DynamicActivityXamlReader parent) { XamlReader subReader = parent.innerReader.ReadSubtree(); IXamlLineInfo readerLineInfo = parent.innerReaderLineInfo; // 1) swap out the start member with <DynamicActivity.Properties> subReader.Read(); Fx.Assert(subReader.NodeType == XamlNodeType.StartMember && subReader.Member == XamlLanguage.Members, "Should be inside of x:Members before calling BufferDefinitions"); this.outerNodes.Writer.WriteStartMember(parent.activityReplacementXamlType.GetMember("Properties"), readerLineInfo); // x:Members directive has no following GetObject, but Properties does since it's not a directive this.outerNodes.Writer.WriteGetObject(readerLineInfo); this.outerNodes.Writer.WriteStartMember(XamlLanguage.Items, readerLineInfo); // 2) process the subnodes and store them in either ActivityPropertyHolders, // or exigent nodes in the outer node list bool continueReading = subReader.Read(); while (continueReading) { if (subReader.NodeType == XamlNodeType.StartObject && subReader.Type == XamlLanguage.Property) { // we found an x:Property. Store it in an ActivityPropertyHolder ActivityPropertyHolder newProperty = new ActivityPropertyHolder(parent, subReader.ReadSubtree()); this.PropertyHolders.Add(newProperty.Name, newProperty); // and stash away a proxy node to map later this.outerNodes.Writer.WriteValue(newProperty, readerLineInfo); // ActivityPropertyHolder consumed the subtree, so we don't need to pump a Read() in this path } else { // it's not an x:Property. Store it in our extra node list this.outerNodes.Writer.WriteNode(subReader, readerLineInfo); continueReading = subReader.Read(); } } // close the GetObject added above. Note that we are doing EndObject/EndMember after the last node (EndMember) // rather than inserting EndMember/EndObject before the last EndMember since all EndMembers are interchangable from a state perspective this.outerNodes.Writer.WriteEndObject(readerLineInfo); this.outerNodes.Writer.WriteEndMember(readerLineInfo); subReader.Close(); this.alreadyBufferedDefinitions = true; FlushValueHolders(); }
public void FlushTo(XamlNodeQueue targetNodeQueue, DynamicActivityXamlReader parent) { FlushValueHolders(); XamlReader sourceReader = this.outerNodes.Reader; IXamlLineInfo sourceReaderLineInfo = parent.hasLineInfo ? sourceReader as IXamlLineInfo : null; while (sourceReader.Read()) { if (sourceReader.NodeType == XamlNodeType.Value) { ActivityPropertyHolder propertyHolder = sourceReader.Value as ActivityPropertyHolder; if (propertyHolder != null) { // replace ActivityPropertyHolder with its constituent nodes propertyHolder.CopyTo(targetNodeQueue, sourceReaderLineInfo); continue; } } targetNodeQueue.Writer.WriteNode(sourceReader, sourceReaderLineInfo); } }
public ActivityPropertyHolder(DynamicActivityXamlReader parent, XamlReader reader) { this.parent = parent; this.nodes = new XamlNodeQueue(parent.SchemaContext); IXamlLineInfo innerReaderLineInfo = parent.innerReaderLineInfo; reader.Read(); this.nodes.Writer.WriteStartObject(parent.activityPropertyXamlType, innerReaderLineInfo); int num = 1; int a = 0; int num3 = 0; bool flag = reader.Read(); while (flag) { XamlMember activityPropertyName; switch (reader.NodeType) { case XamlNodeType.StartObject: case XamlNodeType.GetObject: { num++; DynamicActivityXamlReader.IncrementIfPositive(ref a); DynamicActivityXamlReader.IncrementIfPositive(ref num3); if ((num3 <= 0) || !(reader.Type == parent.xamlTypeXamlType)) { goto Label_0231; } this.nodes.Writer.WriteStartObject(parent.typeXamlType, innerReaderLineInfo); flag = reader.Read(); continue; } case XamlNodeType.EndObject: { num--; if (num != 0) { goto Label_0213; } flag = reader.Read(); continue; } case XamlNodeType.StartMember: if (!(reader.Member.DeclaringType == XamlLanguage.Property)) { goto Label_0231; } activityPropertyName = reader.Member; if (!(activityPropertyName == DynamicActivityXamlReader.xPropertyName)) { break; } activityPropertyName = parent.activityPropertyName; if (a == 0) { a = 1; } goto Label_0115; case XamlNodeType.EndMember: DynamicActivityXamlReader.DecrementIfPositive(ref a); DynamicActivityXamlReader.DecrementIfPositive(ref num3); goto Label_0231; case XamlNodeType.Value: if (a != 1) { goto Label_014F; } this.Name = reader.Value as string; goto Label_0231; default: goto Label_0231; } if (activityPropertyName == DynamicActivityXamlReader.xPropertyType) { activityPropertyName = parent.activityPropertyType; if (num3 == 0) { num3 = 1; } } else { if (activityPropertyName != DynamicActivityXamlReader.xPropertyAttributes) { throw FxTrace.Exception.AsError(DynamicActivityXamlReader.CreateXamlException(System.Activities.SR.PropertyMemberNotSupportedByActivityXamlServices(activityPropertyName.Name), innerReaderLineInfo)); } activityPropertyName = parent.activityPropertyAttributes; } Label_0115: this.nodes.Writer.WriteStartMember(activityPropertyName, innerReaderLineInfo); flag = reader.Read(); continue; Label_014F: if (num3 == 1) { XamlTypeName xamlTypeName = XamlTypeName.Parse(reader.Value as string, parent.namespaceTable); XamlType xamlType = parent.SchemaContext.GetXamlType(xamlTypeName); if (xamlType == null) { throw FxTrace.Exception.AsError(DynamicActivityXamlReader.CreateXamlException(System.Activities.SR.InvalidPropertyType(reader.Value as string, this.Name), innerReaderLineInfo)); } this.Type = xamlType; } goto Label_0231; Label_0213: DynamicActivityXamlReader.DecrementIfPositive(ref a); DynamicActivityXamlReader.DecrementIfPositive(ref num3); Label_0231: this.nodes.Writer.WriteNode(reader, innerReaderLineInfo); flag = reader.Read(); } reader.Close(); }
public BufferedPropertyList(DynamicActivityXamlReader parent) { this.parent = parent; this.outerNodes = new XamlNodeQueue(parent.SchemaContext); }
public ActivityPropertyHolder(DynamicActivityXamlReader parent, XamlReader reader) { this.parent = parent; this.nodes = new XamlNodeQueue(parent.SchemaContext); IXamlLineInfo readerLineInfo = parent.innerReaderLineInfo; // parse the subtree, and extract out the Name and Type for now. // keep the node-list open for now, just in case a default value appears // later in the document // Rewrite "<x:Property>" to "<DynamicActivityProperty>" reader.Read(); this.nodes.Writer.WriteStartObject(parent.activityPropertyXamlType, readerLineInfo); int depth = 1; int nameDepth = 0; int typeDepth = 0; bool continueReading = reader.Read(); while (continueReading) { switch (reader.NodeType) { case XamlNodeType.StartMember: // map <x:Property> membes to the appropriate <DynamicActivity.Property> members if (reader.Member.DeclaringType == XamlLanguage.Property) { XamlMember mappedMember = reader.Member; if (mappedMember == xPropertyName) { mappedMember = parent.activityPropertyName; if (nameDepth == 0) { nameDepth = 1; } } else if (mappedMember == xPropertyType) { mappedMember = parent.activityPropertyType; if (typeDepth == 0) { typeDepth = 1; } } else if (mappedMember == xPropertyAttributes) { mappedMember = parent.activityPropertyAttributes; } else { throw FxTrace.Exception.AsError(CreateXamlException(SR.PropertyMemberNotSupportedByActivityXamlServices(mappedMember.Name), readerLineInfo)); } this.nodes.Writer.WriteStartMember(mappedMember, readerLineInfo); continueReading = reader.Read(); continue; } break; case XamlNodeType.Value: if (nameDepth == 1) { // We only support property name as an attribute (nameDepth == 1) this.Name = reader.Value as string; } else if (typeDepth == 1) { // We only support property type as an attribute (typeDepth == 1) XamlTypeName xamlTypeName = XamlTypeName.Parse(reader.Value as string, parent.namespaceTable); XamlType xamlType = parent.SchemaContext.GetXamlType(xamlTypeName); if (xamlType == null) { throw FxTrace.Exception.AsError(CreateXamlException(SR.InvalidPropertyType(reader.Value as string, this.Name), readerLineInfo)); } this.Type = xamlType; } break; case XamlNodeType.StartObject: case XamlNodeType.GetObject: depth++; IncrementIfPositive(ref nameDepth); IncrementIfPositive(ref typeDepth); if (typeDepth > 0 && reader.Type == parent.xamlTypeXamlType) { this.nodes.Writer.WriteStartObject(parent.typeXamlType, readerLineInfo); continueReading = reader.Read(); continue; } break; case XamlNodeType.EndObject: depth--; if (depth == 0) { continueReading = reader.Read(); continue; // skip this node, we'll close it by hand in CopyTo() } DecrementIfPositive(ref nameDepth); DecrementIfPositive(ref typeDepth); break; case XamlNodeType.EndMember: DecrementIfPositive(ref nameDepth); DecrementIfPositive(ref typeDepth); break; } // if we didn't continue (from a mapped case), just copy over this.nodes.Writer.WriteNode(reader, readerLineInfo); continueReading = reader.Read(); } reader.Close(); }
private void FlushValueHolders(DynamicActivityXamlReader parent) { if (this.valueHolders != null) { foreach (KeyValuePair<string, ValueHolder> pair in this.valueHolders) { this.ProcessDefaultValue(pair.Key, pair.Value.PropertyValue, pair.Value.ValueReader, parent.innerReaderLineInfo); } this.valueHolders = null; } }