protected internal override object DeserializeFromString(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");
            }

            // Work around For Bind based properties whose base type is an
            // ICollection<string> or its derivative, special case! (A synchronization
            // handle cannot begin with a * because it won't be a language independent
            // identifier :) )
            if (IsValidCompactAttributeFormat(value))
            {
                return(DeserializeFromCompactFormat(serializationManager, serializationManager.WorkflowMarkupStack[typeof(XmlReader)] as XmlReader, value));
            }
            else
            {
                return(SynchronizationHandlesTypeConverter.UnStringify(value));
            }
        }
コード例 #2
0
        protected internal override object DeserializeFromString(WorkflowMarkupSerializationManager serializationManager, Type propertyType, string value)
        {
            CodeTypeReference reference;

            if (!propertyType.IsAssignableFrom(typeof(CodeTypeReference)))
            {
                return(null);
            }
            if (string.IsNullOrEmpty(value) || base.IsValidCompactAttributeFormat(value))
            {
                return(null);
            }
            try
            {
                Type type = serializationManager.GetType(value);
                if (type != null)
                {
                    reference = new CodeTypeReference(type);
                    reference.UserData["QualifiedName"] = type.AssemblyQualifiedName;
                    return(reference);
                }
            }
            catch (Exception)
            {
            }
            reference = new CodeTypeReference(value);
            reference.UserData["QualifiedName"] = value;
            return(reference);
        }
コード例 #3
0
        protected internal override object DeserializeFromString(WorkflowMarkupSerializationManager serializationManager, Type propertyType, string value)
        {
            if (!propertyType.IsAssignableFrom(typeof(CodeTypeReference)))
                return null;

            // if the string is empty or markup extension,
            // then the object is null
            if (string.IsNullOrEmpty(value) || IsValidCompactAttributeFormat(value))
                return null;

            // value is the fully qualified name of the type
            // however, it may refer to non-existant assemblies, so we may get an error
            CodeTypeReference result;
            try
            {
                Type type = serializationManager.GetType(value);
                if (type != null)
                {
                    result = new CodeTypeReference(type);
                    result.UserData[QualifiedName] = type.AssemblyQualifiedName;
                    return result;
                }
            }
            catch (Exception)
            {
                // something went wrong getting the type, so simply pass in the string and
                // let CodeTypeReference figure it out. Note that CodeTypeReference has a method
                // RipOffAssemblyInformationFromTypeName, so assembly names are ignored.
            }
            result = new CodeTypeReference(value);
            result.UserData[QualifiedName] = value;
            return result;
        }
 protected internal override object DeserializeFromString(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");
     }
     if (string.Equals(value, "*null", StringComparison.Ordinal))
     {
         return null;
     }
     ITypeDescriptorContext context = null;
     TypeConverter converter = this.GetTypeConversionInfoForPropertySegment(serializationManager, propertyType, out context);
     if ((converter != null) && converter.CanConvertFrom(context, typeof(string)))
     {
         return converter.ConvertFromString(context, value);
     }
     if (this.containedSerializer != null)
     {
         return this.containedSerializer.DeserializeFromString(serializationManager, propertyType, value);
     }
     return base.DeserializeFromString(serializationManager, propertyType, value);
 }
コード例 #5
0
 protected internal override void AddChild(WorkflowMarkupSerializationManager serializationManager, object obj, object childObj)
 {
     if (this.containedSerializer != null)
     {
         this.containedSerializer.AddChild(serializationManager, obj, childObj);
     }
 }
コード例 #6
0
 protected override object CreateInstance(WorkflowMarkupSerializationManager serializationManager, Type type)
 {
     if (typeof(PropertySegment) == type)
         return Activator.CreateInstance(type, new object[] { serializationManager as IServiceProvider, serializationManager.Context.Current });
     else
         return base.CreateInstance(serializationManager, type);
 }
コード例 #7
0
        protected internal override bool CanSerializeToString(WorkflowMarkupSerializationManager serializationManager, object value)
        {
            bool canSerializeToString = false;
            if (value != null)
            {
                ITypeDescriptorContext context = null;
                TypeConverter converter = GetTypeConversionInfoForPropertySegment(serializationManager, value.GetType(), out context);
                if (converter != null)
                    canSerializeToString = converter.CanConvertTo(context, typeof(string));

                if (!canSerializeToString)
                {
                    if (this.containedSerializer != null)
                        canSerializeToString = this.containedSerializer.CanSerializeToString(serializationManager, value);
                    else
                        canSerializeToString = base.CanSerializeToString(serializationManager, value);
                }
            }
            else
            {
                canSerializeToString = true;
            }

            return canSerializeToString;
        }
コード例 #8
0
        private static string GetPrefix(WorkflowMarkupSerializationManager manager, Assembly assembly, string xmlNamespace)
        {
            string prefix = String.Empty;

            object[] xmlnsPrefixes = assembly.GetCustomAttributes(typeof(XmlnsPrefixAttribute), true);
            if (xmlnsPrefixes != null)
            {
                foreach (XmlnsPrefixAttribute xmlnsPrefix in xmlnsPrefixes)
                {
                    if (xmlnsPrefix.XmlNamespace.Equals(xmlNamespace, StringComparison.Ordinal))
                    {
                        prefix = xmlnsPrefix.Prefix;
                        break;
                    }
                }
            }

            if (String.IsNullOrEmpty(prefix) || !IsNamespacePrefixUnique(prefix, manager.PrefixBasedMappings.Keys))
            {
                string basePrefix = (String.IsNullOrEmpty(prefix)) ? "ns" : prefix;

                int index = 0;
                prefix = basePrefix + string.Format(CultureInfo.InvariantCulture, "{0}", index++);
                while (!IsNamespacePrefixUnique(prefix, manager.PrefixBasedMappings.Keys))
                {
                    prefix = basePrefix + string.Format(CultureInfo.InvariantCulture, "{0}", index++);
                }
            }

            return(prefix);
        }
        internal override void OnBeforeSerializeContents(WorkflowMarkupSerializationManager serializationManager, object obj)
        {
            base.OnBeforeSerializeContents(serializationManager, obj);

            serializationManager.ExtendedPropertiesProviders.Add(this);
            this.keylookupDictionary = new Hashtable();
        }
コード例 #10
0
        internal override void OnBeforeSerializeContents(WorkflowMarkupSerializationManager serializationManager, object obj)
        {
            base.OnBeforeSerializeContents(serializationManager, obj);

            //For root activity we will go through all the nested activities and put the namespaces at the top level
            CompositeActivity compositeActivity = obj as CompositeActivity;
            XmlWriter writer = serializationManager.WorkflowMarkupStack[typeof(XmlWriter)] as XmlWriter;
            if (compositeActivity.Parent == null && writer != null)
            {
                Dictionary<string, Activity> writtenMappings = new Dictionary<string, Activity>();

                string prefix = String.Empty;
                XmlQualifiedName xmlQualifiedName = serializationManager.GetXmlQualifiedName(compositeActivity.GetType(), out prefix);
                writtenMappings.Add(xmlQualifiedName.Namespace, compositeActivity);

                foreach (Activity containedActivity in Helpers.GetNestedActivities(compositeActivity))
                {
                    prefix = String.Empty;
                    xmlQualifiedName = serializationManager.GetXmlQualifiedName(containedActivity.GetType(), out prefix);
                    if (!writtenMappings.ContainsKey(xmlQualifiedName.Namespace))
                    {
                        writer.WriteAttributeString("xmlns", prefix, null, xmlQualifiedName.Namespace);
                        writtenMappings.Add(xmlQualifiedName.Namespace, containedActivity);
                    }
                }
            }
        }
コード例 #11
0
        private TypeConverter GetTypeConversionInfoForPropertySegment(WorkflowMarkupSerializationManager serializationManager, Type propertyType, out ITypeDescriptorContext context)
        {
            TypeConverter converter = null;

            context = null;
            PropertySegmentPropertyInfo propertyInfo = serializationManager.Context[typeof(PropertySegmentPropertyInfo)] as PropertySegmentPropertyInfo;

            if (propertyInfo.PropertySegment != null)
            {
                if (propertyInfo.PropertySegment.PropertyDescriptor != null)
                {
                    context   = new TypeDescriptorContext(propertyInfo.PropertySegment.ServiceProvider, propertyInfo.PropertySegment.PropertyDescriptor, propertyInfo.PropertySegment.Object);
                    converter = propertyInfo.PropertySegment.PropertyDescriptor.Converter;
                }
                else if (propertyInfo.PropertySegment.Object != null)
                {
                    PropertyDescriptor propertyDescriptor = TypeDescriptor.GetProperties(propertyInfo.PropertySegment.Object)[propertyInfo.Name];
                    if (propertyDescriptor != null)
                    {
                        context   = new TypeDescriptorContext(propertyInfo.PropertySegment.ServiceProvider, propertyDescriptor, propertyInfo.PropertySegment.Object);
                        converter = propertyDescriptor.Converter;
                    }
                }
            }

            if (propertyType != null && converter == null)
            {
                converter = TypeDescriptor.GetConverter(propertyType);
            }

            return(converter);
        }
 protected internal override void AddChild(WorkflowMarkupSerializationManager serializationManager, object obj, object childObj)
 {
     if (this.containedSerializer != null)
     {
         this.containedSerializer.AddChild(serializationManager, obj, childObj);
     }
 }
コード例 #13
0
        protected override void OnAfterSerialize(WorkflowMarkupSerializationManager serializationManager, object obj)
        {
            base.OnAfterSerialize(serializationManager, obj);

            serializationManager.ExtendedPropertiesProviders.Remove(this);
            this.keylookupDictionary = null;
        }
コード例 #14
0
        protected internal override bool CanSerializeToString(WorkflowMarkupSerializationManager serializationManager, object value)
        {
            bool canSerializeToString = false;

            if (value != null)
            {
                ITypeDescriptorContext context   = null;
                TypeConverter          converter = GetTypeConversionInfoForPropertySegment(serializationManager, value.GetType(), out context);
                if (converter != null)
                {
                    canSerializeToString = converter.CanConvertTo(context, typeof(string));
                }

                if (!canSerializeToString)
                {
                    if (this.containedSerializer != null)
                    {
                        canSerializeToString = this.containedSerializer.CanSerializeToString(serializationManager, value);
                    }
                    else
                    {
                        canSerializeToString = base.CanSerializeToString(serializationManager, value);
                    }
                }
            }
            else
            {
                canSerializeToString = true;
            }

            return(canSerializeToString);
        }
 protected internal override void ClearChildren(WorkflowMarkupSerializationManager serializationManager, object obj)
 {
     if (this.containedSerializer != null)
     {
         this.containedSerializer.ClearChildren(serializationManager, obj);
     }
 }
コード例 #16
0
        protected internal override string SerializeToString(WorkflowMarkupSerializationManager serializationManager, object value)
        {
            String stringValue = String.Empty;

            if (value == null)
            {
                stringValue = "*null";
            }
            else
            {
                ITypeDescriptorContext context   = null;
                TypeConverter          converter = GetTypeConversionInfoForPropertySegment(serializationManager, value.GetType(), out context);
                if (converter != null && converter.CanConvertTo(context, typeof(string)))
                {
                    stringValue = converter.ConvertToString(context, value);
                }
                else if (this.containedSerializer != null)
                {
                    stringValue = this.containedSerializer.SerializeToString(serializationManager, value);
                }
                else
                {
                    stringValue = base.SerializeToString(serializationManager, value);
                }
            }

            return(stringValue);
        }
 protected internal override PropertyInfo[] GetProperties(WorkflowMarkupSerializationManager serializationManager, object obj)
 {
     if (serializationManager == null)
     {
         throw new ArgumentNullException("serializationManager");
     }
     if (obj == null)
     {
         throw new ArgumentNullException("obj");
     }
     XmlWriter writer = serializationManager.WorkflowMarkupStack[typeof(XmlWriter)] as XmlWriter;
     PropertyInfo[] properties = base.GetProperties(serializationManager, obj);
     FreeformActivityDesigner designer = obj as FreeformActivityDesigner;
     if (designer == null)
     {
         return properties;
     }
     List<PropertyInfo> list = new List<PropertyInfo>();
     foreach (PropertyInfo info in properties)
     {
         if (((writer == null) || !info.Name.Equals("AutoSizeMargin", StringComparison.Ordinal)) || (designer.AutoSizeMargin != FreeformActivityDesigner.DefaultAutoSizeMargin))
         {
             list.Add(info);
         }
     }
     list.Add(typeof(FreeformActivityDesigner).GetProperty("DesignerConnectors", BindingFlags.NonPublic | BindingFlags.Instance));
     return list.ToArray();
 }
        protected internal override void AddChild(WorkflowMarkupSerializationManager serializationManager, object obj, object childObj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }
            if (childObj == null)
            {
                throw new ArgumentNullException("childObj");
            }
            ActivityCollection activitys = obj as ActivityCollection;

            if (activitys == null)
            {
                throw new ArgumentException(SR.GetString("Error_SerializerTypeMismatch", new object[] { typeof(ActivityCollection).FullName }), "obj");
            }
            if (!(childObj is Activity))
            {
                throw new InvalidOperationException(SR.GetString("Error_ActivityCollectionSerializer", new object[] { childObj.GetType().FullName }));
            }
            CompositeActivity owner = activitys.Owner as CompositeActivity;

            if (owner != null)
            {
                if (Helpers.IsCustomActivity(owner))
                {
                    throw new InvalidOperationException(SR.GetString("Error_CanNotAddActivityInBlackBoxActivity"));
                }
                base.AddChild(serializationManager, obj, childObj);
            }
        }
コード例 #19
0
        protected internal override void AddChild(WorkflowMarkupSerializationManager serializationManager, object parentObj, object childObj)
        {
            if (parentObj == null)
            {
                throw new ArgumentNullException("parentObj");
            }
            if (childObj == null)
            {
                throw new ArgumentNullException("childObj");
            }
            IDictionary dictionary = parentObj as IDictionary;

            if (dictionary == null)
            {
                throw new InvalidOperationException(SR.GetString("Error_DictionarySerializerNonDictionaryObject"));
            }
            object key = null;

            foreach (DictionaryEntry entry in this.keylookupDictionary)
            {
                if ((!entry.Value.GetType().IsValueType&& (entry.Value == childObj)) || (entry.Value.GetType().IsValueType&& entry.Value.Equals(childObj)))
                {
                    key = entry.Key;
                    break;
                }
            }
            if (key == null)
            {
                throw new InvalidOperationException(SR.GetString("Error_DictionarySerializerKeyNotFound", new object[] { childObj.GetType().FullName }));
            }
            dictionary.Add(key, childObj);
            this.keylookupDictionary.Remove(key);
        }
 protected internal override object DeserializeFromString(WorkflowMarkupSerializationManager serializationManager, Type propertyType, string value)
 {
     CodeTypeReference reference;
     if (!propertyType.IsAssignableFrom(typeof(CodeTypeReference)))
     {
         return null;
     }
     if (string.IsNullOrEmpty(value) || base.IsValidCompactAttributeFormat(value))
     {
         return null;
     }
     try
     {
         Type type = serializationManager.GetType(value);
         if (type != null)
         {
             reference = new CodeTypeReference(type);
             reference.UserData["QualifiedName"] = type.AssemblyQualifiedName;
             return reference;
         }
     }
     catch (Exception)
     {
     }
     reference = new CodeTypeReference(value);
     reference.UserData["QualifiedName"] = value;
     return reference;
 }
コード例 #21
0
 protected internal override void ClearChildren(WorkflowMarkupSerializationManager serializationManager, object obj)
 {
     if (this.containedSerializer != null)
     {
         this.containedSerializer.ClearChildren(serializationManager, obj);
     }
 }
        protected internal override IList GetChildren(WorkflowMarkupSerializationManager serializationManager, object obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }

            ActivityCollection activityCollection = obj as ActivityCollection;

            if (activityCollection == null)
            {
                throw new ArgumentException(SR.GetString(SR.Error_SerializerTypeMismatch, typeof(ActivityCollection).FullName), "obj");
            }

            CompositeActivity compositeActivity = activityCollection.Owner as CompositeActivity;

            if (compositeActivity != null && Helpers.IsCustomActivity(compositeActivity))
            {
                return(null);
            }
            else
            {
                return(base.GetChildren(serializationManager, obj));
            }
        }
コード例 #23
0
        protected internal override object DeserializeFromString(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");
            }
            if (string.Equals(value, "*null", StringComparison.Ordinal))
            {
                return(null);
            }
            ITypeDescriptorContext context   = null;
            TypeConverter          converter = this.GetTypeConversionInfoForPropertySegment(serializationManager, propertyType, out context);

            if ((converter != null) && converter.CanConvertFrom(context, typeof(string)))
            {
                return(converter.ConvertFromString(context, value));
            }
            if (this.containedSerializer != null)
            {
                return(this.containedSerializer.DeserializeFromString(serializationManager, propertyType, value));
            }
            return(base.DeserializeFromString(serializationManager, propertyType, value));
        }
        private static string GetPrefix(WorkflowMarkupSerializationManager manager, Assembly assembly, string xmlNamespace)
        {
            string prefix = string.Empty;

            object[] customAttributes = assembly.GetCustomAttributes(typeof(XmlnsPrefixAttribute), true);
            if (customAttributes != null)
            {
                foreach (XmlnsPrefixAttribute attribute in customAttributes)
                {
                    if (attribute.XmlNamespace.Equals(xmlNamespace, StringComparison.Ordinal))
                    {
                        prefix = attribute.Prefix;
                        break;
                    }
                }
            }
            if (string.IsNullOrEmpty(prefix) || !IsNamespacePrefixUnique(prefix, manager.PrefixBasedMappings.Keys))
            {
                string str2 = string.IsNullOrEmpty(prefix) ? "ns" : prefix;
                int    num  = 0;
                prefix = str2 + string.Format(CultureInfo.InvariantCulture, "{0}", new object[] { num++ });
                while (!IsNamespacePrefixUnique(prefix, manager.PrefixBasedMappings.Keys))
                {
                    prefix = str2 + string.Format(CultureInfo.InvariantCulture, "{0}", new object[] { num++ });
                }
            }
            return(prefix);
        }
 protected internal override void AddChild(WorkflowMarkupSerializationManager serializationManager, object parentObj, object childObj)
 {
     if (parentObj == null)
     {
         throw new ArgumentNullException("parentObj");
     }
     if (childObj == null)
     {
         throw new ArgumentNullException("childObj");
     }
     IDictionary dictionary = parentObj as IDictionary;
     if (dictionary == null)
     {
         throw new InvalidOperationException(SR.GetString("Error_DictionarySerializerNonDictionaryObject"));
     }
     object key = null;
     foreach (DictionaryEntry entry in this.keylookupDictionary)
     {
         if ((!entry.Value.GetType().IsValueType && (entry.Value == childObj)) || (entry.Value.GetType().IsValueType && entry.Value.Equals(childObj)))
         {
             key = entry.Key;
             break;
         }
     }
     if (key == null)
     {
         throw new InvalidOperationException(SR.GetString("Error_DictionarySerializerKeyNotFound", new object[] { childObj.GetType().FullName }));
     }
     dictionary.Add(key, childObj);
     this.keylookupDictionary.Remove(key);
 }
コード例 #26
0
        internal override void OnBeforeSerializeContents(WorkflowMarkupSerializationManager serializationManager, object obj)
        {
            base.OnBeforeSerializeContents(serializationManager, obj);

            //For root activity we will go through all the nested activities and put the namespaces at the top level
            CompositeActivity compositeActivity = obj as CompositeActivity;
            XmlWriter         writer            = serializationManager.WorkflowMarkupStack[typeof(XmlWriter)] as XmlWriter;

            if (compositeActivity.Parent == null && writer != null)
            {
                Dictionary <string, Activity> writtenMappings = new Dictionary <string, Activity>();

                string           prefix           = String.Empty;
                XmlQualifiedName xmlQualifiedName = serializationManager.GetXmlQualifiedName(compositeActivity.GetType(), out prefix);
                writtenMappings.Add(xmlQualifiedName.Namespace, compositeActivity);

                foreach (Activity containedActivity in Helpers.GetNestedActivities(compositeActivity))
                {
                    prefix           = String.Empty;
                    xmlQualifiedName = serializationManager.GetXmlQualifiedName(containedActivity.GetType(), out prefix);
                    if (!writtenMappings.ContainsKey(xmlQualifiedName.Namespace))
                    {
                        writer.WriteAttributeString("xmlns", prefix, null, xmlQualifiedName.Namespace);
                        writtenMappings.Add(xmlQualifiedName.Namespace, containedActivity);
                    }
                }
            }
        }
コード例 #27
0
        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);
        }
コード例 #28
0
 protected internal override IList GetChildren(WorkflowMarkupSerializationManager serializationManager, object obj)
 {
     if (this.containedSerializer != null)
     {
         return(this.containedSerializer.GetChildren(serializationManager, obj));
     }
     return(null);
 }
コード例 #29
0
 protected override InstanceDescriptor GetInstanceDescriptor(WorkflowMarkupSerializationManager serializationManager, object value)
 {
     ActivityBind activityBind = value as ActivityBind;
     if (activityBind == null)
         throw new ArgumentException(SR.GetString(SR.Error_UnexpectedArgumentType, typeof(ActivityBind).FullName), "value");
     return new InstanceDescriptor(typeof(ActivityBind).GetConstructor(new Type[] { typeof(string) }),
         new object[] { activityBind.Name });
 }
コード例 #30
0
 protected override object CreateInstance(WorkflowMarkupSerializationManager serializationManager, Type type)
 {
     if (typeof(PropertySegment) == type)
     {
         return(Activator.CreateInstance(type, new object[] { serializationManager, serializationManager.Context.Current }));
     }
     return(base.CreateInstance(serializationManager, type));
 }
コード例 #31
0
        protected override void OnBeforeSerialize(WorkflowMarkupSerializationManager serializationManager, object obj)
        {
            if (serializationManager == null)
                throw new ArgumentNullException("serializationManager");
            if (obj == null)
                throw new ArgumentNullException("obj");

            Activity activity = obj as Activity;
            if (activity == null)
                throw new ArgumentException(SR.GetString(SR.Error_UnexpectedArgumentType, typeof(Activity).FullName), "obj");

            XmlWriter writer = serializationManager.WorkflowMarkupStack[typeof(XmlWriter)] as XmlWriter;
            if (writer == null)
            {
                //We should not throw an exception here as both of the above properties are internal and
                //our serializer makes sure that they are always set. Note that OnBeforeSerialize can be 
                //only called by WorkflowMarkupSerializer.
                Debug.Assert(false);
                return;
            }

            StringWriter stringWriter = serializationManager.WorkflowMarkupStack[typeof(StringWriter)] as StringWriter;
            if (stringWriter != null)
            {
                // we capture the start and end line of the activity getting serialized to xoml
                writer.Flush();
                string currentXoml = stringWriter.ToString();
                int startLine = 0;
                int currentIndex = 0;
                string newLine = stringWriter.NewLine;
                int newLineLength = newLine.Length;

                // Get to the starting line of this activity.
                while (true)
                {
                    int nextNewLineIndex = currentXoml.IndexOf(newLine, currentIndex, StringComparison.Ordinal);
                    if (nextNewLineIndex == -1)
                        break;

                    currentIndex = nextNewLineIndex + newLineLength;
                    startLine++;
                }

                // We always serialize an element start tag onto exactly 1 line.
                activity.SetValue(ActivityMarkupSerializer.StartLineProperty, startLine);
                activity.SetValue(ActivityMarkupSerializer.EndLineProperty, startLine);

                // Cache the index of the beginning of the line.
                activity.SetValue(ActivityMarkupSerializer.EndColumnProperty, currentIndex);
                activity.SetValue(ActivityMarkupSerializer.StartColumnProperty, (currentXoml.IndexOf('<', currentIndex) - currentIndex + 1));
            }

            // write x:Class attribute
            string className = activity.GetValue(WorkflowMarkupSerializer.XClassProperty) as string;
            if (className != null)
                writer.WriteAttributeString(StandardXomlKeys.Definitions_XmlNs_Prefix, StandardXomlKeys.Definitions_Class_LocalName, StandardXomlKeys.Definitions_XmlNs, className);

        }
 public XmlQualifiedName GetXmlQualifiedName(WorkflowMarkupSerializationManager manager, out string prefix)
 {
     prefix = string.Empty;
     if (this.OnGetXmlQualifiedName != null)
     {
         return this.OnGetXmlQualifiedName(this, manager, out prefix);
     }
     return null;
 }
コード例 #33
0
        protected internal override bool CanSerializeToString(WorkflowMarkupSerializationManager serializationManager, object value)
        {
            if (serializationManager == null)
                throw new ArgumentNullException("serializationManager");
            if (value == null)
                throw new ArgumentNullException("value");

            return (value is ICollection<String>);
        }
コード例 #34
0
 public XmlQualifiedName GetXmlQualifiedName(WorkflowMarkupSerializationManager manager, out string prefix)
 {
     prefix = string.Empty;
     if (this.OnGetXmlQualifiedName != null)
     {
         return(this.OnGetXmlQualifiedName(this, manager, out prefix));
     }
     return(null);
 }
 protected internal override string SerializeToString(WorkflowMarkupSerializationManager serializationManager, object value)
 {
     TypeConverter converter = TypeDescriptor.GetConverter(value);
     if ((converter != null) && converter.CanConvertTo(typeof(string)))
     {
         return (converter.ConvertTo(value, typeof(string)) as string);
     }
     return base.SerializeToString(serializationManager, value);
 }
コード例 #36
0
        protected internal override string SerializeToString(WorkflowMarkupSerializationManager serializationManager, object value)
        {
            if (serializationManager == null)
                throw new ArgumentNullException("serializationManager");
            if (value == null)
                throw new ArgumentNullException("value");

            return SynchronizationHandlesTypeConverter.Stringify(value as ICollection<String>);
        }
 protected virtual InstanceDescriptor GetInstanceDescriptor(WorkflowMarkupSerializationManager serializationManager, object value)
 {
     MarkupExtension extension = value as MarkupExtension;
     if (extension == null)
     {
         throw new ArgumentException(SR.GetString("Error_UnexpectedArgumentType", new object[] { typeof(MarkupExtension).FullName }), "value");
     }
     return new InstanceDescriptor(extension.GetType().GetConstructor(new Type[0]), null);
 }
コード例 #38
0
        protected internal override bool ShouldSerializeValue(WorkflowMarkupSerializationManager serializationManager, object value)
        {
            if (value == null)
                return false;

            if (!(value is IDictionary))
                throw new InvalidOperationException(SR.GetString(SR.Error_DictionarySerializerNonDictionaryObject));

            return (((IDictionary)value).Count > 0);
        }
コード例 #39
0
        protected virtual InstanceDescriptor GetInstanceDescriptor(WorkflowMarkupSerializationManager serializationManager, object value)
        {
            MarkupExtension markupExtension = value as MarkupExtension;

            if (markupExtension == null)
            {
                throw new ArgumentException(SR.GetString(SR.Error_UnexpectedArgumentType, typeof(MarkupExtension).FullName), "value");
            }
            return(new InstanceDescriptor(markupExtension.GetType().GetConstructor(new Type[0]), null));
        }
 protected internal override PropertyInfo[] GetProperties(WorkflowMarkupSerializationManager serializationManager, object obj)
 {
     List<PropertyInfo> list = new List<PropertyInfo>();
     if (obj is Size)
     {
         list.Add(typeof(Size).GetProperty("Width"));
         list.Add(typeof(Size).GetProperty("Height"));
     }
     return list.ToArray();
 }
コード例 #41
0
        protected override InstanceDescriptor GetInstanceDescriptor(WorkflowMarkupSerializationManager serializationManager, object value)
        {
            ActivityBind bind = value as ActivityBind;

            if (bind == null)
            {
                throw new ArgumentException(SR.GetString("Error_UnexpectedArgumentType", new object[] { typeof(ActivityBind).FullName }), "value");
            }
            return(new InstanceDescriptor(typeof(ActivityBind).GetConstructor(new Type[] { typeof(string) }), new object[] { bind.Name }));
        }
コード例 #42
0
        protected internal override PropertyInfo[] GetProperties(WorkflowMarkupSerializationManager serializationManager, object obj)
        {
            if (this.containedSerializer != null)
                return this.containedSerializer.GetProperties(serializationManager, obj);

            if (obj != null && obj.GetType() == typeof(PropertySegment))
                return (obj as PropertySegment).GetProperties(serializationManager);
            else
                return base.GetProperties(serializationManager, obj);
        }
コード例 #43
0
        protected internal override void AddChild(WorkflowMarkupSerializationManager serializationManager, object parentObj, object childObj)
        {
            if (parentObj == null)
                throw new ArgumentNullException("parentObj");

            if (!IsValidCollectionType(parentObj.GetType()))
                throw new Exception(SR.GetString(SR.Error_SerializerTypeRequirement, parentObj.GetType().FullName, typeof(ICollection).FullName, typeof(ICollection<>).FullName));

            parentObj.GetType().InvokeMember("Add", BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance, null, parentObj, new object[] { childObj }, CultureInfo.InvariantCulture);
        }
コード例 #44
0
        protected override object CreateInstance(WorkflowMarkupSerializationManager serializationManager, Type type)
        {
            XmlReader reader = serializationManager.WorkflowMarkupStack[typeof(XmlReader)] as XmlReader;

            if (reader == null)
            {
                return(null);
            }
            object obj2 = base.CreateInstance(serializationManager, type);

            if (((obj2 is Activity) && (serializationManager.Context[typeof(Activity)] == null)) && (serializationManager.Context[typeof(WorkflowCompilerParameters)] != null))
            {
                (obj2 as Activity).UserData[UserDataKeys.CustomActivity] = false;
            }
            WorkflowMarkupSourceAttribute[] customAttributes = (WorkflowMarkupSourceAttribute[])type.GetCustomAttributes(typeof(WorkflowMarkupSourceAttribute), false);
            if (((obj2 is CompositeActivity) && (customAttributes.Length > 0)) && (type.Assembly == serializationManager.LocalAssembly))
            {
                object obj3 = null;
                using (XmlReader reader2 = XmlReader.Create(customAttributes[0].FileName))
                {
                    obj3 = base.Deserialize(serializationManager, reader2);
                }
                ReplaceChildActivities(obj2 as CompositeActivity, obj3 as CompositeActivity);
            }
            if (obj2 is Activity)
            {
                int  num6;
                int  num  = (reader is IXmlLineInfo) ? ((IXmlLineInfo)reader).LineNumber : 1;
                int  num2 = (reader is IXmlLineInfo) ? ((IXmlLineInfo)reader).LinePosition : 1;
                int  num3 = num - 1;
                int  num4 = num2 - 1;
                bool flag = false;
                while (reader.MoveToNextAttribute())
                {
                    flag = true;
                }
                int num5 = num - 1;
                if (flag)
                {
                    reader.ReadAttributeValue();
                    num6 = num2 + reader.Value.Length;
                }
                else
                {
                    num6 = (num2 + reader.Name.Length) - 1;
                }
                reader.MoveToElement();
                Activity activity = (Activity)obj2;
                activity.SetValue(StartLineProperty, num3);
                activity.SetValue(StartColumnProperty, num4);
                activity.SetValue(EndLineProperty, num5);
                activity.SetValue(EndColumnProperty, num6);
            }
            return(obj2);
        }
コード例 #45
0
 protected override InstanceDescriptor GetInstanceDescriptor(WorkflowMarkupSerializationManager serializationManager, object value)
 {
     TypeExtension typeExtension = value as TypeExtension;
     if (typeExtension == null)
         throw new ArgumentException(SR.GetString(SR.Error_UnexpectedArgumentType, typeof(TypeExtension).FullName), "value");
     if (typeExtension.Type != null)
         return new InstanceDescriptor(typeof(TypeExtension).GetConstructor(new Type[] { typeof(System.Type) }),
             new object[] { typeExtension.Type });
     return new InstanceDescriptor(typeof(TypeExtension).GetConstructor(new Type[] { typeof(string) }),
         new object[] { typeExtension.TypeName });
 }
コード例 #46
0
        protected internal override void ClearChildren(WorkflowMarkupSerializationManager serializationManager, object deserializedObject)
        {
            if (deserializedObject == null)
                throw new ArgumentNullException("deserializedObject");

            IDictionary dictionary = deserializedObject as IDictionary;
            if (dictionary == null)
                throw new InvalidOperationException(SR.GetString(SR.Error_DictionarySerializerNonDictionaryObject));

            dictionary.Clear();
        }
コード例 #47
0
 protected internal override bool ShouldSerializeValue(WorkflowMarkupSerializationManager serializationManager, object value)
 {
     if (value == null)
     {
         return(false);
     }
     if (!(value is IDictionary))
     {
         throw new InvalidOperationException(SR.GetString("Error_DictionarySerializerNonDictionaryObject"));
     }
     return(((IDictionary)value).Count > 0);
 }
コード例 #48
0
 protected internal override PropertyInfo[] GetProperties(WorkflowMarkupSerializationManager serializationManager, object obj)
 {
     if (this.containedSerializer != null)
     {
         return(this.containedSerializer.GetProperties(serializationManager, obj));
     }
     if ((obj != null) && (obj.GetType() == typeof(PropertySegment)))
     {
         return((obj as PropertySegment).GetProperties(serializationManager));
     }
     return(base.GetProperties(serializationManager, obj));
 }
コード例 #49
0
ファイル: QueueSerializer.cs プロジェクト: ssickles/archive
        protected override IList GetChildren(WorkflowMarkupSerializationManager serializationManager, object obj)
        {
            if (obj == null)
                throw new ArgumentNullException("obj");

            Queue queue = obj as Queue;
            if (queue == null)
                throw new Exception(string.Format("The type of obj is not {0}", typeof(Queue).FullName));

            ArrayList arrayList = new ArrayList(queue.ToArray());
            return arrayList;
        }
コード例 #50
0
 protected override object CreateInstance(WorkflowMarkupSerializationManager serializationManager, Type type)
 {
     if (typeof(PropertySegment) == type)
     {
         // This is a "safe" Activiator.CreateInstance because we know we are creating an instance of PropertySegment, which is an internal sealed class.
         return(Activator.CreateInstance(type, new object[] { serializationManager as IServiceProvider, serializationManager.Context.Current }));
     }
     else
     {
         return(base.CreateInstance(serializationManager, type));
     }
 }
コード例 #51
0
        internal static Type ResolveWellKnownTypes(WorkflowMarkupSerializationManager manager, string xmlns, string typeName)
        {
            Type resolvedType = null;

            List <WorkflowMarkupSerializerMapping> knownMappings = new List <WorkflowMarkupSerializerMapping>();

            if (xmlns.Equals(StandardXomlKeys.WorkflowXmlNs, StringComparison.Ordinal))
            {
                if (!WorkflowMarkupSerializerMapping.wellKnownTypes.TryGetValue(typeName, out resolvedType))
                {
                    if (typeName.EndsWith("Activity", StringComparison.OrdinalIgnoreCase))
                    {
                        knownMappings.Add(WorkflowMarkupSerializerMapping.Activities);
                        knownMappings.Add(WorkflowMarkupSerializerMapping.ComponentModel);
                    }
                    if (typeName.EndsWith("Designer", StringComparison.OrdinalIgnoreCase))
                    {
                        knownMappings.Add(WorkflowMarkupSerializerMapping.Activities);
                        knownMappings.Add(WorkflowMarkupSerializerMapping.ComponentModel);
                        knownMappings.Add(WorkflowMarkupSerializerMapping.ComponentModelDesign);
                    }
                    else if (typeName.EndsWith("Theme", StringComparison.OrdinalIgnoreCase))
                    {
                        knownMappings.Add(WorkflowMarkupSerializerMapping.ComponentModelDesign);
                        knownMappings.Add(WorkflowMarkupSerializerMapping.Activities);
                    }
                    else if (typeName.StartsWith("Rule", StringComparison.OrdinalIgnoreCase) ||
                             typeName.EndsWith("Action", StringComparison.OrdinalIgnoreCase))
                    {
                        knownMappings.Add(WorkflowMarkupSerializerMapping.Rules);
                    }
                }
            }
            else if (xmlns.Equals(StandardXomlKeys.Definitions_XmlNs, StringComparison.Ordinal))
            {
                knownMappings.Add(WorkflowMarkupSerializerMapping.Serialization);
            }

            if (resolvedType == null)
            {
                foreach (WorkflowMarkupSerializerMapping mapping in knownMappings)
                {
                    string fullyQualifiedTypeName = mapping.ClrNamespace + "." + typeName + ", " + mapping.AssemblyName;
                    resolvedType = manager.GetType(fullyQualifiedTypeName);
                    if (resolvedType != null)
                    {
                        break;
                    }
                }
            }

            return(resolvedType);
        }
コード例 #52
0
        protected internal override void ClearChildren(WorkflowMarkupSerializationManager serializationManager, object obj)
        {
            if (obj == null)
                throw new ArgumentNullException("obj");

            if (!IsValidCollectionType(obj.GetType()))
                throw new Exception(SR.GetString(SR.Error_SerializerTypeRequirement, obj.GetType().FullName, typeof(ICollection).FullName, typeof(ICollection<>).FullName));

            ICollection collection = obj as ICollection;
            if (collection == null)
                obj.GetType().InvokeMember("Clear", BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance, null, obj, new object[] { }, CultureInfo.InvariantCulture);
        }
コード例 #53
0
 protected internal override bool CanSerializeToString(WorkflowMarkupSerializationManager serializationManager, object value)
 {
     if (serializationManager == null)
     {
         throw new ArgumentNullException("serializationManager");
     }
     if (value == null)
     {
         throw new ArgumentNullException("value");
     }
     return(value is ICollection <string>);
 }
コード例 #54
0
 protected internal override string SerializeToString(WorkflowMarkupSerializationManager serializationManager, object value)
 {
     if (serializationManager == null)
     {
         throw new ArgumentNullException("serializationManager");
     }
     if (value == null)
     {
         throw new ArgumentNullException("value");
     }
     return(SynchronizationHandlesTypeConverter.Stringify(value as ICollection <string>));
 }
 protected internal override PropertyInfo[] GetProperties(WorkflowMarkupSerializationManager serializationManager, object obj)
 {
     List<PropertyInfo> list = new List<PropertyInfo>(base.GetProperties(serializationManager, obj));
     foreach (PropertyInfo info in obj.GetType().GetProperties(BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Instance))
     {
         if (((Helpers.GetSerializationVisibility(info) != DesignerSerializationVisibility.Hidden) && (info.GetSetMethod() == null)) && (info.GetSetMethod(true) != null))
         {
             list.Add(info);
         }
     }
     return list.ToArray();
 }
コード例 #56
0
 protected internal override void AddChild(WorkflowMarkupSerializationManager serializationManager, object parentObj, object childObj)
 {
     if (parentObj == null)
     {
         throw new ArgumentNullException("parentObj");
     }
     if (!IsValidCollectionType(parentObj.GetType()))
     {
         throw new Exception(SR.GetString("Error_SerializerTypeRequirement", new object[] { parentObj.GetType().FullName, typeof(ICollection).FullName, typeof(ICollection <>).FullName }));
     }
     parentObj.GetType().InvokeMember("Add", BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Instance, null, parentObj, new object[] { childObj }, CultureInfo.InvariantCulture);
 }
 protected override object CreateInstance(WorkflowMarkupSerializationManager serializationManager, Type type)
 {
     XmlReader reader = serializationManager.WorkflowMarkupStack[typeof(XmlReader)] as XmlReader;
     if (reader == null)
     {
         return null;
     }
     object obj2 = base.CreateInstance(serializationManager, type);
     if (((obj2 is Activity) && (serializationManager.Context[typeof(Activity)] == null)) && (serializationManager.Context[typeof(WorkflowCompilerParameters)] != null))
     {
         (obj2 as Activity).UserData[UserDataKeys.CustomActivity] = false;
     }
     WorkflowMarkupSourceAttribute[] customAttributes = (WorkflowMarkupSourceAttribute[]) type.GetCustomAttributes(typeof(WorkflowMarkupSourceAttribute), false);
     if (((obj2 is CompositeActivity) && (customAttributes.Length > 0)) && (type.Assembly == serializationManager.LocalAssembly))
     {
         object obj3 = null;
         using (XmlReader reader2 = XmlReader.Create(customAttributes[0].FileName))
         {
             obj3 = base.Deserialize(serializationManager, reader2);
         }
         ReplaceChildActivities(obj2 as CompositeActivity, obj3 as CompositeActivity);
     }
     if (obj2 is Activity)
     {
         int num6;
         int num = (reader is IXmlLineInfo) ? ((IXmlLineInfo) reader).LineNumber : 1;
         int num2 = (reader is IXmlLineInfo) ? ((IXmlLineInfo) reader).LinePosition : 1;
         int num3 = num - 1;
         int num4 = num2 - 1;
         bool flag = false;
         while (reader.MoveToNextAttribute())
         {
             flag = true;
         }
         int num5 = num - 1;
         if (flag)
         {
             reader.ReadAttributeValue();
             num6 = num2 + reader.Value.Length;
         }
         else
         {
             num6 = (num2 + reader.Name.Length) - 1;
         }
         reader.MoveToElement();
         Activity activity = (Activity) obj2;
         activity.SetValue(StartLineProperty, num3);
         activity.SetValue(StartColumnProperty, num4);
         activity.SetValue(EndLineProperty, num5);
         activity.SetValue(EndColumnProperty, num6);
     }
     return obj2;
 }
コード例 #58
0
        protected override IList GetChildren(WorkflowMarkupSerializationManager serializationManager, object obj)
        {
            if (obj == null)
                throw new ArgumentNullException("obj");

            Stack stack = obj as Stack;
            if (stack == null)
                throw new Exception(string.Format("The type of obj is not {0}", typeof(Stack).FullName));

            ArrayList arrayList = new ArrayList(stack.ToArray());
            arrayList.Reverse();
            return arrayList;
        }
コード例 #59
0
        protected internal override IList GetChildren(WorkflowMarkupSerializationManager serializationManager, object obj)
        {
            IDictionary dictionary = obj as IDictionary;
            if (dictionary == null)
                throw new InvalidOperationException(SR.GetString(SR.Error_DictionarySerializerNonDictionaryObject));

            List<object> childEntries = new List<object>();
            foreach (DictionaryEntry dictionaryEntry in dictionary)
            {
                childEntries.Add(dictionaryEntry);
            }
            return childEntries;
        }
 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;
 }