protected internal override string SerializeToString(WorkflowMarkupSerializationManager serializationManager, object value) { if (serializationManager == null) { throw new ArgumentNullException("serializationManager"); } if (value == null) { throw new ArgumentNullException("value"); } CodeTypeReference reference = value as CodeTypeReference; if (reference == null) { return(string.Empty); } // make the typename as best we can, and try to get the fully qualified name // if a type is used in an assembly not referenced, GetType will complain string typeName = ConvertTypeReferenceToString(reference); Type type = serializationManager.GetType(typeName); if (type == null) { // TypeProvider can't find it, see if it's a common type in mscorlib type = Type.GetType(typeName, false); if (type == null) { // still no luck finding it, so simply save the name without assembly information // this is equivalent to what happened before return(typeName); } } // // If we get a real type make sure that we get the correct fully qualified name for the target framework version string assemblyFullName = null; TypeProvider typeProvider = serializationManager.GetService(typeof(ITypeProvider)) as TypeProvider; if (typeProvider != null) { assemblyFullName = typeProvider.GetAssemblyName(type); } // // If we didn't find an assembly value it is either a local type or something is wrong // However per the general guidance on multi-targeting it is up to the caller // to make sure that writers (such as Xoml) are given types that exist in the target framework // This makes it the job of the rules designer or rules validator to not call the Xoml stack // with types that do not exist in the target framework if (string.IsNullOrEmpty(assemblyFullName)) { typeName = type.AssemblyQualifiedName; } else { typeName = string.Format(CultureInfo.InvariantCulture, "{0}, {1}", type.FullName, assemblyFullName); } return(typeName); }
protected override object CreateInstance(WorkflowMarkupSerializationManager serializationManager, Type type) { if (serializationManager == null) { throw new ArgumentNullException("serializationManager"); } if (type == null) { throw new ArgumentNullException("type"); } Connector connector = null; IReferenceService service = serializationManager.GetService(typeof(IReferenceService)) as IReferenceService; FreeformActivityDesigner designer = serializationManager.Context[typeof(FreeformActivityDesigner)] as FreeformActivityDesigner; if ((designer != null) && (service != null)) { ConnectionPoint source = null; ConnectionPoint target = null; try { Dictionary<string, string> connectorConstructionArguments = this.GetConnectorConstructionArguments(serializationManager, type); if ((connectorConstructionArguments.ContainsKey("SourceActivity") && connectorConstructionArguments.ContainsKey("SourceConnectionIndex")) && connectorConstructionArguments.ContainsKey("SourceConnectionEdge")) { ActivityDesigner associatedDesigner = ActivityDesigner.GetDesigner(service.GetReference(connectorConstructionArguments["SourceActivity"]) as Activity); DesignerEdges designerEdge = (DesignerEdges) Enum.Parse(typeof(DesignerEdges), connectorConstructionArguments["SourceConnectionEdge"]); int connectionIndex = Convert.ToInt32(connectorConstructionArguments["SourceConnectionIndex"], CultureInfo.InvariantCulture); if (((associatedDesigner != null) && (designerEdge != DesignerEdges.None)) && (connectionIndex >= 0)) { source = new ConnectionPoint(associatedDesigner, designerEdge, connectionIndex); } } if ((connectorConstructionArguments.ContainsKey("TargetActivity") && connectorConstructionArguments.ContainsKey("TargetConnectionIndex")) && connectorConstructionArguments.ContainsKey("TargetConnectionEdge")) { ActivityDesigner designer3 = ActivityDesigner.GetDesigner(service.GetReference(connectorConstructionArguments["TargetActivity"]) as Activity); DesignerEdges edges2 = (DesignerEdges) Enum.Parse(typeof(DesignerEdges), connectorConstructionArguments["TargetConnectionEdge"]); int num2 = Convert.ToInt32(connectorConstructionArguments["TargetConnectionIndex"], CultureInfo.InvariantCulture); if (((designer3 != null) && (edges2 != DesignerEdges.None)) && (num2 >= 0)) { target = new ConnectionPoint(designer3, edges2, num2); } } } catch { } if ((source != null) && (target != null)) { connector = designer.AddConnector(source, target); } } return connector; }
protected internal override string SerializeToString(WorkflowMarkupSerializationManager serializationManager, object value) { if (serializationManager == null) throw new ArgumentNullException("serializationManager"); if (value == null) throw new ArgumentNullException("value"); CodeTypeReference reference = value as CodeTypeReference; if (reference == null) return string.Empty; // make the typename as best we can, and try to get the fully qualified name // if a type is used in an assembly not referenced, GetType will complain string typeName = ConvertTypeReferenceToString(reference); Type type = serializationManager.GetType(typeName); if (type == null) { // TypeProvider can't find it, see if it's a common type in mscorlib type = Type.GetType(typeName, false); if (type == null) { // still no luck finding it, so simply save the name without assembly information // this is equivalent to what happened before return typeName; } } // // If we get a real type make sure that we get the correct fully qualified name for the target framework version string assemblyFullName = null; TypeProvider typeProvider = serializationManager.GetService(typeof(ITypeProvider)) as TypeProvider; if (typeProvider != null) { assemblyFullName = typeProvider.GetAssemblyName(type); } // // If we didn't find an assembly value it is either a local type or something is wrong // However per the general guidance on multi-targeting it is up to the caller // to make sure that writers (such as Xoml) are given types that exist in the target framework // This makes it the job of the rules designer or rules validator to not call the Xoml stack // with types that do not exist in the target framework if (string.IsNullOrEmpty(assemblyFullName)) { typeName = type.AssemblyQualifiedName; } else { typeName = string.Format(CultureInfo.InvariantCulture, "{0}, {1}", type.FullName, assemblyFullName); } return typeName; }
private static string GetAssemblyName(Type type, WorkflowMarkupSerializationManager manager) { TypeProvider service = manager.GetService(typeof(ITypeProvider)) as TypeProvider; if (service != null) { return(service.GetAssemblyName(type)); } if (type.Assembly == null) { return(string.Empty); } return(type.Assembly.FullName); }
private static string GetAssemblyName(Type type, WorkflowMarkupSerializationManager manager) { TypeProvider typeProvider = manager.GetService(typeof(ITypeProvider)) as TypeProvider; if (typeProvider != null) { return(typeProvider.GetAssemblyName(type)); } // // Handle DesignTimeType if (type.Assembly == null) { return(string.Empty); } else { return(type.Assembly.FullName); } }
protected internal override string SerializeToString(WorkflowMarkupSerializationManager serializationManager, object value) { if (serializationManager == null) { throw new ArgumentNullException("serializationManager"); } if (value == null) { throw new ArgumentNullException("value"); } CodeTypeReference reference = value as CodeTypeReference; if (reference == null) { return(string.Empty); } string typeName = ConvertTypeReferenceToString(reference); Type type = serializationManager.GetType(typeName); if (type == null) { type = Type.GetType(typeName, false); if (type == null) { return(typeName); } } string assemblyName = null; TypeProvider service = serializationManager.GetService(typeof(ITypeProvider)) as TypeProvider; if (service != null) { assemblyName = service.GetAssemblyName(type); } if (string.IsNullOrEmpty(assemblyName)) { return(type.AssemblyQualifiedName); } return(string.Format(CultureInfo.InvariantCulture, "{0}, {1}", new object[] { type.FullName, assemblyName })); }
protected internal override string SerializeToString(WorkflowMarkupSerializationManager serializationManager, object value) { if (serializationManager == null) { throw new ArgumentNullException("serializationManager"); } if (value == null) { throw new ArgumentNullException("value"); } CodeTypeReference reference = value as CodeTypeReference; if (reference == null) { return string.Empty; } string typeName = ConvertTypeReferenceToString(reference); Type type = serializationManager.GetType(typeName); if (type == null) { type = Type.GetType(typeName, false); if (type == null) { return typeName; } } string assemblyName = null; TypeProvider service = serializationManager.GetService(typeof(ITypeProvider)) as TypeProvider; if (service != null) { assemblyName = service.GetAssemblyName(type); } if (string.IsNullOrEmpty(assemblyName)) { return type.AssemblyQualifiedName; } return string.Format(CultureInfo.InvariantCulture, "{0}, {1}", new object[] { type.FullName, assemblyName }); }
internal static void GetMappingsFromXmlNamespace(WorkflowMarkupSerializationManager serializationManager, string xmlNamespace, out IList<WorkflowMarkupSerializerMapping> matchingMappings, out IList<WorkflowMarkupSerializerMapping> collectedMappings) { matchingMappings = new List<WorkflowMarkupSerializerMapping>(); collectedMappings = new List<WorkflowMarkupSerializerMapping>(); XmlReader reader = serializationManager.WorkflowMarkupStack[typeof(XmlReader)] as XmlReader; if (reader != null) { if (xmlNamespace.StartsWith("clr-namespace:", StringComparison.OrdinalIgnoreCase)) { bool flag = false; string clrNamespace = xmlNamespace.Substring("clr-namespace:".Length).Trim(); string assemblyName = string.Empty; int index = clrNamespace.IndexOf(';'); if (index != -1) { assemblyName = ((index + 1) < clrNamespace.Length) ? clrNamespace.Substring(index + 1).Trim() : string.Empty; clrNamespace = clrNamespace.Substring(0, index).Trim(); if (!assemblyName.StartsWith("Assembly=", StringComparison.OrdinalIgnoreCase)) { flag = true; } assemblyName = assemblyName.Substring("Assembly=".Length); } if (!flag) { if (clrNamespace.Equals("{Global}", StringComparison.OrdinalIgnoreCase)) { clrNamespace = string.Empty; } matchingMappings.Add(new WorkflowMarkupSerializerMapping(reader.Prefix, xmlNamespace, clrNamespace, assemblyName)); } } else { List<Assembly> list = new List<Assembly>(); if (serializationManager.LocalAssembly != null) { list.Add(serializationManager.LocalAssembly); } ITypeProvider service = serializationManager.GetService(typeof(ITypeProvider)) as ITypeProvider; if (service != null) { list.AddRange(service.ReferencedAssemblies); } foreach (Assembly assembly in list) { object[] customAttributes = assembly.GetCustomAttributes(typeof(XmlnsDefinitionAttribute), true); if (customAttributes != null) { foreach (XmlnsDefinitionAttribute attribute in customAttributes) { string fullName = string.Empty; if (serializationManager.LocalAssembly != assembly) { if ((attribute.AssemblyName != null) && (attribute.AssemblyName.Trim().Length > 0)) { fullName = attribute.AssemblyName; } else { fullName = assembly.FullName; } } if (attribute.XmlNamespace.Equals(xmlNamespace, StringComparison.Ordinal)) { matchingMappings.Add(new WorkflowMarkupSerializerMapping(reader.Prefix, xmlNamespace, attribute.ClrNamespace, fullName)); } else { collectedMappings.Add(new WorkflowMarkupSerializerMapping(reader.Prefix, xmlNamespace, attribute.ClrNamespace, fullName)); } } } } } } }
public override object ProvideValue(IServiceProvider provider) { if (this.type != null) { return(this.type); } if (provider == null) { throw new ArgumentNullException("provider"); } if (this.typeName == null) { throw new InvalidOperationException("typename"); } WorkflowMarkupSerializationManager manager = provider as WorkflowMarkupSerializationManager; if (manager == null) { throw new ArgumentNullException("provider"); } XmlReader reader = manager.WorkflowMarkupStack[typeof(XmlReader)] as XmlReader; if (reader != null) { string name = this.typeName.Trim(); string prefix = string.Empty; int index = name.IndexOf(':'); if (index >= 0) { prefix = name.Substring(0, index); name = name.Substring(index + 1); this.type = manager.GetType(new XmlQualifiedName(name, reader.LookupNamespace(prefix))); if (this.type != null) { return(this.type); } List <WorkflowMarkupSerializerMapping> list = null; if ((manager.XmlNamespaceBasedMappings.TryGetValue(reader.LookupNamespace(prefix), out list) && (list != null)) && (list.Count > 0)) { return(list[0].ClrNamespace + "." + name); } return(name); } this.type = manager.GetType(new XmlQualifiedName(name, reader.LookupNamespace(string.Empty))); if (this.type == null) { ITypeProvider service = provider.GetService(typeof(ITypeProvider)) as ITypeProvider; if (service != null) { this.type = service.GetType(name); } if ((this.type == null) && (manager.GetService(typeof(ITypeResolutionService)) == null)) { this.type = manager.SerializationManager.GetType(name); } } if (this.type != null) { return(this.type); } } return(this.typeName); }
public override object ProvideValue(IServiceProvider provider) { if (this.type != null) { return(this.type); } if (provider == null) { throw new ArgumentNullException("provider"); } if (this.typeName == null) { throw new InvalidOperationException("typename"); } WorkflowMarkupSerializationManager manager = provider as WorkflowMarkupSerializationManager; if (manager == null) { throw new ArgumentNullException("provider"); } XmlReader reader = manager.WorkflowMarkupStack[typeof(XmlReader)] as XmlReader; if (reader == null) { Debug.Assert(false); return(this.typeName); } string typename = this.typeName.Trim(); string prefix = String.Empty; int typeIndex = typename.IndexOf(':'); if (typeIndex >= 0) { prefix = typename.Substring(0, typeIndex); typename = typename.Substring(typeIndex + 1); type = manager.GetType(new XmlQualifiedName(typename, reader.LookupNamespace(prefix))); if (type != null) { return(type); } // To Support types whose assembly is not available, we need to still resolve the clr namespace List <WorkflowMarkupSerializerMapping> xmlnsMappings = null; if (manager.XmlNamespaceBasedMappings.TryGetValue(reader.LookupNamespace(prefix), out xmlnsMappings) && xmlnsMappings != null && xmlnsMappings.Count > 0) { return(xmlnsMappings[0].ClrNamespace + "." + typename); } else { return(typename); } } type = manager.GetType(new XmlQualifiedName(typename, reader.LookupNamespace(string.Empty))); // To Support Beta2 format if (type == null) { ITypeProvider typeProvider = provider.GetService(typeof(ITypeProvider)) as ITypeProvider; if (typeProvider != null) { type = typeProvider.GetType(typename); } // If not design mode, get the value from serialization manager // At design time, we need to get the type from ITypeProvider else // we need to store the string in the hashtable we maintain internally if (type == null && manager.GetService(typeof(ITypeResolutionService)) == null) { type = manager.SerializationManager.GetType(typename); } } if (type != null) { return(type); } return(this.typeName); }
protected override object CreateInstance(WorkflowMarkupSerializationManager serializationManager, Type type) { Activity activity3; if (serializationManager == null) { throw new ArgumentNullException("serializationManager"); } if (type == null) { throw new ArgumentNullException("type"); } object obj2 = null; IDesignerHost service = serializationManager.GetService(typeof(IDesignerHost)) as IDesignerHost; XmlReader reader = serializationManager.WorkflowMarkupStack[typeof(XmlReader)] as XmlReader; if ((service == null) || (reader == null)) { return obj2; } string str = string.Empty; while (reader.MoveToNextAttribute() && !reader.LocalName.Equals("Name", StringComparison.Ordinal)) { } if (reader.LocalName.Equals("Name", StringComparison.Ordinal) && reader.ReadAttributeValue()) { str = reader.Value; } reader.MoveToElement(); if (string.IsNullOrEmpty(str)) { serializationManager.ReportError(SR.GetString("Error_LayoutSerializationAssociatedActivityNotFound", new object[] { reader.LocalName, "Name" })); return obj2; } CompositeActivityDesigner designer = serializationManager.Context[typeof(CompositeActivityDesigner)] as CompositeActivityDesigner; if (designer != null) { CompositeActivity activity2 = designer.Activity as CompositeActivity; if (activity2 == null) { goto Label_01D0; } activity3 = null; foreach (Activity activity4 in activity2.Activities) { if (str.Equals(activity4.Name, StringComparison.Ordinal)) { activity3 = activity4; break; } } } else { Activity rootComponent = service.RootComponent as Activity; if ((rootComponent != null) && !str.Equals(rootComponent.Name, StringComparison.Ordinal)) { foreach (IComponent component in service.Container.Components) { rootComponent = component as Activity; if ((rootComponent != null) && str.Equals(rootComponent.Name, StringComparison.Ordinal)) { break; } } } if (rootComponent != null) { obj2 = service.GetDesigner(rootComponent); } goto Label_01D0; } if (activity3 != null) { obj2 = service.GetDesigner(activity3); } Label_01D0: if (obj2 == null) { serializationManager.ReportError(SR.GetString("Error_LayoutSerializationActivityNotFound", new object[] { reader.LocalName, str, "Name" })); } return obj2; }
internal static void GetMappingsFromXmlNamespace(WorkflowMarkupSerializationManager serializationManager, string xmlNamespace, out IList <WorkflowMarkupSerializerMapping> matchingMappings, out IList <WorkflowMarkupSerializerMapping> collectedMappings) { matchingMappings = new List <WorkflowMarkupSerializerMapping>(); collectedMappings = new List <WorkflowMarkupSerializerMapping>(); XmlReader reader = serializationManager.WorkflowMarkupStack[typeof(XmlReader)] as XmlReader; if (reader != null) { if (xmlNamespace.StartsWith(StandardXomlKeys.CLRNamespaceQualifier, StringComparison.OrdinalIgnoreCase)) { //Format for the xmlnamespace: clr-namespace:[Namespace][;Assembly=[AssemblyName]] bool invalidXmlnsFormat = false; string clrNamespace = xmlNamespace.Substring(StandardXomlKeys.CLRNamespaceQualifier.Length).Trim(); string assemblyName = String.Empty; int index = clrNamespace.IndexOf(';'); if (index != -1) { assemblyName = (index + 1 < clrNamespace.Length) ? clrNamespace.Substring(index + 1).Trim() : String.Empty; clrNamespace = clrNamespace.Substring(0, index).Trim(); if (!assemblyName.StartsWith(StandardXomlKeys.AssemblyNameQualifier, StringComparison.OrdinalIgnoreCase)) { invalidXmlnsFormat = true; } assemblyName = assemblyName.Substring(StandardXomlKeys.AssemblyNameQualifier.Length); } if (!invalidXmlnsFormat) { if (clrNamespace.Equals(StandardXomlKeys.GlobalNamespace, StringComparison.OrdinalIgnoreCase)) { clrNamespace = String.Empty; } matchingMappings.Add(new WorkflowMarkupSerializerMapping(reader.Prefix, xmlNamespace, clrNamespace, assemblyName)); } } else { List <Assembly> referencedAssemblies = new List <Assembly>(); if (serializationManager.LocalAssembly != null) { referencedAssemblies.Add(serializationManager.LocalAssembly); } ITypeProvider typeProvider = serializationManager.GetService(typeof(ITypeProvider)) as ITypeProvider; if (typeProvider != null) { referencedAssemblies.AddRange(typeProvider.ReferencedAssemblies); } foreach (Assembly assembly in referencedAssemblies) { object[] xmlnsDefinitions = assembly.GetCustomAttributes(typeof(XmlnsDefinitionAttribute), true); if (xmlnsDefinitions != null) { foreach (XmlnsDefinitionAttribute xmlnsDefinition in xmlnsDefinitions) { string assemblyName = String.Empty; if (serializationManager.LocalAssembly != assembly) { if (xmlnsDefinition.AssemblyName != null && xmlnsDefinition.AssemblyName.Trim().Length > 0) { assemblyName = xmlnsDefinition.AssemblyName; } else { assemblyName = assembly.FullName; } } if (xmlnsDefinition.XmlNamespace.Equals(xmlNamespace, StringComparison.Ordinal)) { matchingMappings.Add(new WorkflowMarkupSerializerMapping(reader.Prefix, xmlNamespace, xmlnsDefinition.ClrNamespace, assemblyName)); } else { collectedMappings.Add(new WorkflowMarkupSerializerMapping(reader.Prefix, xmlNamespace, xmlnsDefinition.ClrNamespace, assemblyName)); } } } } } } }
private object InternalDeserializeFromString(WorkflowMarkupSerializationManager serializationManager, Type propertyType, string value) { if (serializationManager == null) throw new ArgumentNullException("serializationManager"); if (propertyType == null) throw new ArgumentNullException("propertyType"); if (value == null) throw new ArgumentNullException("value"); object propVal = null; XmlReader reader = serializationManager.WorkflowMarkupStack[typeof(XmlReader)] as XmlReader; if (reader == null) { Debug.Assert(false, "XmlReader not available."); return null; } if (IsValidCompactAttributeFormat(value)) { propVal = DeserializeFromCompactFormat(serializationManager, reader, value); } else { if (value.StartsWith("{}", StringComparison.Ordinal)) value = value.Substring(2); // Check for Nullable types if (propertyType.IsGenericType && propertyType.GetGenericTypeDefinition() == typeof(Nullable<>)) { Type genericType = (Type)propertyType.GetGenericArguments()[0]; Debug.Assert(genericType != null); propertyType = genericType; } if (propertyType.IsPrimitive || propertyType == typeof(System.String)) { propVal = Convert.ChangeType(value, propertyType, CultureInfo.InvariantCulture); } else if (propertyType.IsEnum) { propVal = Enum.Parse(propertyType, value, true); } else if (typeof(Delegate).IsAssignableFrom(propertyType)) { // Just return the method name. This must happen after Bind syntax has been checked. propVal = value; } else if (typeof(TimeSpan) == propertyType) { propVal = TimeSpan.Parse(value, CultureInfo.InvariantCulture); } else if (typeof(DateTime) == propertyType) { propVal = DateTime.Parse(value, CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind); } else if (typeof(Guid) == propertyType) { propVal = Utility.CreateGuid(value); } else if (typeof(Type).IsAssignableFrom(propertyType)) { propVal = serializationManager.GetType(value); if (propVal != null) { Type type = propVal as Type; if (type.IsPrimitive || type.IsEnum || type == typeof(System.String)) return type; } ITypeProvider typeProvider = serializationManager.GetService(typeof(ITypeProvider)) as ITypeProvider; if (typeProvider != null) { Type type = typeProvider.GetType(value); if (type != null) return type; } return value; } else if (typeof(IConvertible).IsAssignableFrom(propertyType)) { propVal = Convert.ChangeType(value, propertyType, CultureInfo.InvariantCulture); } else if (propertyType.IsAssignableFrom(value.GetType())) { propVal = value; } else { throw CreateSerializationError(SR.GetString(SR.Error_SerializerPrimitivePropertyNoLogic, new object[] { "", value.Trim(), "" }), reader); } } return propVal; }
private static string GetAssemblyName(Type type, WorkflowMarkupSerializationManager manager) { TypeProvider service = manager.GetService(typeof(ITypeProvider)) as TypeProvider; if (service != null) { return service.GetAssemblyName(type); } if (type.Assembly == null) { return string.Empty; } return type.Assembly.FullName; }
private static string GetAssemblyName(Type type, WorkflowMarkupSerializationManager manager) { TypeProvider typeProvider = manager.GetService(typeof(ITypeProvider)) as TypeProvider; if (typeProvider != null) { return typeProvider.GetAssemblyName(type); } // // Handle DesignTimeType if (type.Assembly == null) { return string.Empty; } else { return type.Assembly.FullName; } }
internal static void GetMappingsFromXmlNamespace(WorkflowMarkupSerializationManager serializationManager, string xmlNamespace, out IList<WorkflowMarkupSerializerMapping> matchingMappings, out IList<WorkflowMarkupSerializerMapping> collectedMappings) { matchingMappings = new List<WorkflowMarkupSerializerMapping>(); collectedMappings = new List<WorkflowMarkupSerializerMapping>(); XmlReader reader = serializationManager.WorkflowMarkupStack[typeof(XmlReader)] as XmlReader; if (reader != null) { if (xmlNamespace.StartsWith(StandardXomlKeys.CLRNamespaceQualifier, StringComparison.OrdinalIgnoreCase)) { //Format for the xmlnamespace: clr-namespace:[Namespace][;Assembly=[AssemblyName]] bool invalidXmlnsFormat = false; string clrNamespace = xmlNamespace.Substring(StandardXomlKeys.CLRNamespaceQualifier.Length).Trim(); string assemblyName = String.Empty; int index = clrNamespace.IndexOf(';'); if (index != -1) { assemblyName = (index + 1 < clrNamespace.Length) ? clrNamespace.Substring(index + 1).Trim() : String.Empty; clrNamespace = clrNamespace.Substring(0, index).Trim(); if (!assemblyName.StartsWith(StandardXomlKeys.AssemblyNameQualifier, StringComparison.OrdinalIgnoreCase)) invalidXmlnsFormat = true; assemblyName = assemblyName.Substring(StandardXomlKeys.AssemblyNameQualifier.Length); } if (!invalidXmlnsFormat) { if (clrNamespace.Equals(StandardXomlKeys.GlobalNamespace, StringComparison.OrdinalIgnoreCase)) clrNamespace = String.Empty; matchingMappings.Add(new WorkflowMarkupSerializerMapping(reader.Prefix, xmlNamespace, clrNamespace, assemblyName)); } } else { List<Assembly> referencedAssemblies = new List<Assembly>(); if (serializationManager.LocalAssembly != null) referencedAssemblies.Add(serializationManager.LocalAssembly); ITypeProvider typeProvider = serializationManager.GetService(typeof(ITypeProvider)) as ITypeProvider; if (typeProvider != null) referencedAssemblies.AddRange(typeProvider.ReferencedAssemblies); foreach (Assembly assembly in referencedAssemblies) { object[] xmlnsDefinitions = assembly.GetCustomAttributes(typeof(XmlnsDefinitionAttribute), true); if (xmlnsDefinitions != null) { foreach (XmlnsDefinitionAttribute xmlnsDefinition in xmlnsDefinitions) { string assemblyName = String.Empty; if (serializationManager.LocalAssembly != assembly) { if (xmlnsDefinition.AssemblyName != null && xmlnsDefinition.AssemblyName.Trim().Length > 0) assemblyName = xmlnsDefinition.AssemblyName; else assemblyName = assembly.FullName; } if (xmlnsDefinition.XmlNamespace.Equals(xmlNamespace, StringComparison.Ordinal)) matchingMappings.Add(new WorkflowMarkupSerializerMapping(reader.Prefix, xmlNamespace, xmlnsDefinition.ClrNamespace, assemblyName)); else collectedMappings.Add(new WorkflowMarkupSerializerMapping(reader.Prefix, xmlNamespace, xmlnsDefinition.ClrNamespace, assemblyName)); } } } } } }
protected override object CreateInstance(WorkflowMarkupSerializationManager serializationManager, Type type) { if (serializationManager == null) throw new ArgumentNullException("serializationManager"); if (type == null) throw new ArgumentNullException("type"); object designer = null; IDesignerHost host = serializationManager.GetService(typeof(IDesignerHost)) as IDesignerHost; XmlReader reader = serializationManager.WorkflowMarkupStack[typeof(XmlReader)] as XmlReader; if (host != null && reader != null) { //Find the associated activity string associatedActivityName = String.Empty; while (reader.MoveToNextAttribute() && !reader.LocalName.Equals("Name", StringComparison.Ordinal)); if (reader.LocalName.Equals("Name", StringComparison.Ordinal) && reader.ReadAttributeValue()) associatedActivityName = reader.Value; reader.MoveToElement(); if (!String.IsNullOrEmpty(associatedActivityName)) { CompositeActivityDesigner parentDesigner = serializationManager.Context[typeof(CompositeActivityDesigner)] as CompositeActivityDesigner; if (parentDesigner == null) { Activity activity = host.RootComponent as Activity; if (activity != null && !associatedActivityName.Equals(activity.Name, StringComparison.Ordinal)) { foreach (IComponent component in host.Container.Components) { activity = component as Activity; if (activity != null && associatedActivityName.Equals(activity.Name, StringComparison.Ordinal)) break; } } if (activity != null) designer = host.GetDesigner(activity); } else { CompositeActivity compositeActivity = parentDesigner.Activity as CompositeActivity; if (compositeActivity != null) { Activity matchingActivity = null; foreach (Activity activity in compositeActivity.Activities) { if (associatedActivityName.Equals(activity.Name, StringComparison.Ordinal)) { matchingActivity = activity; break; } } if (matchingActivity != null) designer = host.GetDesigner(matchingActivity); } } if (designer == null) serializationManager.ReportError(SR.GetString(SR.Error_LayoutSerializationActivityNotFound, reader.LocalName, associatedActivityName, "Name")); } else { serializationManager.ReportError(SR.GetString(SR.Error_LayoutSerializationAssociatedActivityNotFound, reader.LocalName, "Name")); } } return designer; }
protected override object CreateInstance(WorkflowMarkupSerializationManager serializationManager, Type type) { if (serializationManager == null) throw new ArgumentNullException("serializationManager"); if (type == null) throw new ArgumentNullException("type"); Connector connector = null; IReferenceService referenceService = serializationManager.GetService(typeof(IReferenceService)) as IReferenceService; FreeformActivityDesigner freeformDesigner = serializationManager.Context[typeof(FreeformActivityDesigner)] as FreeformActivityDesigner; if (freeformDesigner != null && referenceService != null) { ConnectionPoint sourceConnection = null; ConnectionPoint targetConnection = null; try { Dictionary<string, string> constructionArguments = GetConnectorConstructionArguments(serializationManager, type); if (constructionArguments.ContainsKey("SourceActivity") && constructionArguments.ContainsKey("SourceConnectionIndex") && constructionArguments.ContainsKey("SourceConnectionEdge")) { ActivityDesigner sourceDesigner = ActivityDesigner.GetDesigner(referenceService.GetReference(constructionArguments["SourceActivity"] as string) as Activity); DesignerEdges sourceEdge = (DesignerEdges)Enum.Parse(typeof(DesignerEdges), constructionArguments["SourceConnectionEdge"] as string); int sourceIndex = Convert.ToInt32(constructionArguments["SourceConnectionIndex"] as string, System.Globalization.CultureInfo.InvariantCulture); if (sourceDesigner != null && sourceEdge != DesignerEdges.None && sourceIndex >= 0) sourceConnection = new ConnectionPoint(sourceDesigner, sourceEdge, sourceIndex); } if (constructionArguments.ContainsKey("TargetActivity") && constructionArguments.ContainsKey("TargetConnectionIndex") && constructionArguments.ContainsKey("TargetConnectionEdge")) { ActivityDesigner targetDesigner = ActivityDesigner.GetDesigner(referenceService.GetReference(constructionArguments["TargetActivity"] as string) as Activity); DesignerEdges targetEdge = (DesignerEdges)Enum.Parse(typeof(DesignerEdges), constructionArguments["TargetConnectionEdge"] as string); int targetIndex = Convert.ToInt32(constructionArguments["TargetConnectionIndex"] as string, System.Globalization.CultureInfo.InvariantCulture); if (targetDesigner != null && targetEdge != DesignerEdges.None && targetIndex >= 0) targetConnection = new ConnectionPoint(targetDesigner, targetEdge, targetIndex); } } catch { } if (sourceConnection != null && targetConnection != null) connector = freeformDesigner.AddConnector(sourceConnection, targetConnection); } return connector; }
internal static void GetMappingsFromXmlNamespace(WorkflowMarkupSerializationManager serializationManager, string xmlNamespace, out IList <WorkflowMarkupSerializerMapping> matchingMappings, out IList <WorkflowMarkupSerializerMapping> collectedMappings) { matchingMappings = new List <WorkflowMarkupSerializerMapping>(); collectedMappings = new List <WorkflowMarkupSerializerMapping>(); XmlReader reader = serializationManager.WorkflowMarkupStack[typeof(XmlReader)] as XmlReader; if (reader != null) { if (xmlNamespace.StartsWith("clr-namespace:", StringComparison.OrdinalIgnoreCase)) { bool flag = false; string clrNamespace = xmlNamespace.Substring("clr-namespace:".Length).Trim(); string assemblyName = string.Empty; int index = clrNamespace.IndexOf(';'); if (index != -1) { assemblyName = ((index + 1) < clrNamespace.Length) ? clrNamespace.Substring(index + 1).Trim() : string.Empty; clrNamespace = clrNamespace.Substring(0, index).Trim(); if (!assemblyName.StartsWith("Assembly=", StringComparison.OrdinalIgnoreCase)) { flag = true; } assemblyName = assemblyName.Substring("Assembly=".Length); } if (!flag) { if (clrNamespace.Equals("{Global}", StringComparison.OrdinalIgnoreCase)) { clrNamespace = string.Empty; } matchingMappings.Add(new WorkflowMarkupSerializerMapping(reader.Prefix, xmlNamespace, clrNamespace, assemblyName)); } } else { List <Assembly> list = new List <Assembly>(); if (serializationManager.LocalAssembly != null) { list.Add(serializationManager.LocalAssembly); } ITypeProvider service = serializationManager.GetService(typeof(ITypeProvider)) as ITypeProvider; if (service != null) { list.AddRange(service.ReferencedAssemblies); } foreach (Assembly assembly in list) { object[] customAttributes = assembly.GetCustomAttributes(typeof(XmlnsDefinitionAttribute), true); if (customAttributes != null) { foreach (XmlnsDefinitionAttribute attribute in customAttributes) { string fullName = string.Empty; if (serializationManager.LocalAssembly != assembly) { if ((attribute.AssemblyName != null) && (attribute.AssemblyName.Trim().Length > 0)) { fullName = attribute.AssemblyName; } else { fullName = assembly.FullName; } } if (attribute.XmlNamespace.Equals(xmlNamespace, StringComparison.Ordinal)) { matchingMappings.Add(new WorkflowMarkupSerializerMapping(reader.Prefix, xmlNamespace, attribute.ClrNamespace, fullName)); } else { collectedMappings.Add(new WorkflowMarkupSerializerMapping(reader.Prefix, xmlNamespace, attribute.ClrNamespace, fullName)); } } } } } } }
protected internal virtual PropertyInfo[] GetProperties(WorkflowMarkupSerializationManager serializationManager, object obj) { if (obj == null) throw new ArgumentNullException("obj"); if (serializationManager == null) throw new ArgumentNullException("serializationManager"); List<PropertyInfo> properties = new List<PropertyInfo>(); object[] attributes = obj.GetType().GetCustomAttributes(typeof(RuntimeNamePropertyAttribute), true); string name = null; if (attributes.Length > 0) name = (attributes[0] as RuntimeNamePropertyAttribute).Name; foreach (PropertyInfo property in obj.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.FlattenHierarchy)) { DesignerSerializationVisibility visibility = Helpers.GetSerializationVisibility(property); if (visibility == DesignerSerializationVisibility.Hidden) continue; if (visibility != DesignerSerializationVisibility.Content && (!property.CanWrite || property.GetSetMethod() == null)) { // work around for CodeObject which are ICollection needs to be serialized. if (!(obj is CodeObject) || !typeof(ICollection).IsAssignableFrom(property.PropertyType)) continue; } TypeProvider typeProvider = serializationManager.GetService(typeof(ITypeProvider)) as TypeProvider; if (typeProvider != null) { if (!typeProvider.IsSupportedProperty(property, obj)) { continue; } } if (name == null || !name.Equals(property.Name)) properties.Add(property); else properties.Add(new ExtendedPropertyInfo(property, OnGetRuntimeNameValue, OnSetRuntimeNameValue, OnGetRuntimeQualifiedName)); } return properties.ToArray(); }
protected override object CreateInstance(WorkflowMarkupSerializationManager serializationManager, Type type) { if (serializationManager == null) throw new ArgumentNullException("serializationManager"); if (type == null) throw new ArgumentNullException("type"); StateDesignerConnector connector = null; IReferenceService referenceService = serializationManager.GetService(typeof(IReferenceService)) as IReferenceService; FreeformActivityDesigner freeformDesigner = serializationManager.Context[typeof(FreeformActivityDesigner)] as FreeformActivityDesigner; if (freeformDesigner != null && referenceService != null) { StateDesigner.DesignerLayoutConnectionPoint sourceConnection = null; ConnectionPoint targetConnection = null; StateDesigner.TransitionInfo transitionInfo = null; StateDesigner rootStateDesigner = null; try { Dictionary<string, string> constructionArguments = GetConnectorConstructionArguments(serializationManager, type); if (constructionArguments.ContainsKey("EventHandlerName") && constructionArguments.ContainsKey("SetStateName") && constructionArguments.ContainsKey("TargetStateName")) { CompositeActivity eventHandler = (CompositeActivity)referenceService.GetReference(constructionArguments["EventHandlerName"] as string); SetStateActivity setState = (SetStateActivity)referenceService.GetReference(constructionArguments["SetStateName"] as string); StateActivity targetState = (StateActivity)referenceService.GetReference(constructionArguments["TargetStateName"] as string); transitionInfo = new StateDesigner.TransitionInfo(setState, eventHandler); transitionInfo.TargetState = targetState; } if (constructionArguments.ContainsKey("SourceActivity") && constructionArguments.ContainsKey("SourceConnectionIndex") && constructionArguments.ContainsKey("SourceConnectionEdge") && constructionArguments.ContainsKey("EventHandlerName")) { StateDesigner sourceDesigner = (StateDesigner)StateDesigner.GetDesigner(referenceService.GetReference(constructionArguments["SourceActivity"] as string) as Activity); CompositeActivity eventHandler = (CompositeActivity)referenceService.GetReference(constructionArguments["EventHandlerName"] as string); rootStateDesigner = sourceDesigner.RootStateDesigner; DesignerEdges sourceEdge = (DesignerEdges)Enum.Parse(typeof(DesignerEdges), constructionArguments["SourceConnectionEdge"] as string); int sourceIndex = Convert.ToInt32(constructionArguments["SourceConnectionIndex"] as string, System.Globalization.CultureInfo.InvariantCulture); if (sourceDesigner != null && eventHandler != null && sourceEdge != DesignerEdges.None && sourceIndex >= 0) sourceConnection = new StateDesigner.DesignerLayoutConnectionPoint(sourceDesigner, sourceIndex, eventHandler, sourceEdge); } if (constructionArguments.ContainsKey("TargetActivity") && constructionArguments.ContainsKey("TargetConnectionIndex") && constructionArguments.ContainsKey("TargetConnectionEdge")) { ActivityDesigner targetDesigner = StateDesigner.GetDesigner(referenceService.GetReference(constructionArguments["TargetActivity"] as string) as Activity); DesignerEdges targetEdge = (DesignerEdges)Enum.Parse(typeof(DesignerEdges), constructionArguments["TargetConnectionEdge"] as string); int targetIndex = Convert.ToInt32(constructionArguments["TargetConnectionIndex"] as string, System.Globalization.CultureInfo.InvariantCulture); if (targetDesigner != null && targetEdge != DesignerEdges.None && targetIndex >= 0) targetConnection = new ConnectionPoint(targetDesigner, targetEdge, targetIndex); } } catch { } if (transitionInfo != null && sourceConnection != null && targetConnection != null) { connector = rootStateDesigner.FindConnector(transitionInfo); if (connector == null) { rootStateDesigner.AddingSetState = false; try { connector = freeformDesigner.AddConnector(sourceConnection, targetConnection) as StateDesignerConnector; } finally { rootStateDesigner.AddingSetState = true; } } else { connector.Source = sourceConnection; connector.Target = targetConnection; connector.ClearConnectorSegments(); } } } return connector; }