public SoapFormatter()
 {
     this.m_assemblyFormat = FormatterAssemblyStyle.Full;
     this.m_securityLevel = TypeFilterLevel.Full;
     this.m_surrogates = null;
     this.m_context = new StreamingContext(StreamingContextStates.All);
 }
 public SoapFormatter(ISurrogateSelector selector, StreamingContext context)
 {
     this.m_assemblyFormat = FormatterAssemblyStyle.Full;
     this.m_securityLevel = TypeFilterLevel.Full;
     this.m_surrogates = selector;
     this.m_context = context;
 }
	// Constructor.
	public BinaryFormatter()
			{
				this.context = new StreamingContext(StreamingContextStates.All);
				this.assemblyFormat = FormatterAssemblyStyle.Full;
				this.typeFormat = FormatterTypeStyle.TypesAlways;
				this.filterLevel = TypeFilterLevel.Full;
				this.converter = new FormatterConverter();
			}
Esempio n. 4
0
 public NetDataContractSerializer(StreamingContext context,
     int maxItemsInObjectGraph,
     bool ignoreExtensionDataObject,
     FormatterAssemblyStyle assemblyFormat,
     ISurrogateSelector surrogateSelector)
 {
     Initialize(context, maxItemsInObjectGraph, ignoreExtensionDataObject, assemblyFormat, surrogateSelector);
 }
 internal XmlObjectSerializerReadContextComplex(NetDataContractSerializer serializer) : base(serializer)
 {
     this.mode = SerializationMode.SharedType;
     this.preserveObjectReferences = true;
     this.binder = serializer.Binder;
     this.surrogateSelector = serializer.SurrogateSelector;
     this.assemblyFormat = serializer.AssemblyFormat;
 }
Esempio n. 6
0
 public NetDataContractSerializer(XmlDictionaryString rootName, XmlDictionaryString rootNamespace,
     StreamingContext context,
     int maxItemsInObjectGraph,
     bool ignoreExtensionDataObject,
     FormatterAssemblyStyle assemblyFormat,
     ISurrogateSelector surrogateSelector)
 {
     Initialize(rootName, rootNamespace, context, maxItemsInObjectGraph, ignoreExtensionDataObject, assemblyFormat, surrogateSelector);
 }
Esempio n. 7
0
 public NetDataContractSerializer(string rootName, string rootNamespace,
     StreamingContext context,
     int maxItemsInObjectGraph,
     bool ignoreExtensionDataObject,
     FormatterAssemblyStyle assemblyFormat,
     ISurrogateSelector surrogateSelector)
 {
     XmlDictionary dictionary = new XmlDictionary(2);
     Initialize(dictionary.Add(rootName), dictionary.Add(DataContract.GetNamespace(rootNamespace)), context, maxItemsInObjectGraph, ignoreExtensionDataObject, assemblyFormat, surrogateSelector);
 }
	public BinaryFormatter(ISurrogateSelector selector,
						   StreamingContext context)
			{
				this.surrogateSelector = selector;
				this.context = context;
				this.assemblyFormat = FormatterAssemblyStyle.Full;
				this.typeFormat = FormatterTypeStyle.TypesAlways;
				this.filterLevel = TypeFilterLevel.Full;
				this.converter = new FormatterConverter();
			}
Esempio n. 9
0
		/// <summary>
		/// Initializes a new instance of the <see cref="XmlFormatter"/> class.
		/// </summary>
		public XmlFormatter()
		{
			this.context = new StreamingContext(StreamingContextStates.File);

			this.enableEventSerialization = true;
			this.assemblyFormat = FormatterAssemblyStyle.Full;

			this.initializeSystemSurrogateSelector(this.context, this.enableEventSerialization);

			this.registeredReferenceObjects = new ListDictionary(new ReferenceComparer());
		}
Esempio n. 10
0
        public static string GetTypeName(Type t, FormatterAssemblyStyle assemblyFormat)
        {
            switch (assemblyFormat)
            {
            case FormatterAssemblyStyle.Simple:
                return(GetSimpleTypeName(t));

            case FormatterAssemblyStyle.Full:
                return(t.AssemblyQualifiedName);

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Esempio n. 11
0
 void Initialize(StreamingContext context,
     int maxItemsInObjectGraph,
     bool ignoreExtensionDataObject,
     FormatterAssemblyStyle assemblyFormat,
     ISurrogateSelector surrogateSelector)
 {
     this.context = context;
     if (maxItemsInObjectGraph < 0)
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("maxItemsInObjectGraph", SR.GetString(SR.ValueMustBeNonNegative)));
     this.maxItemsInObjectGraph = maxItemsInObjectGraph;
     this.ignoreExtensionDataObject = ignoreExtensionDataObject;
     this.surrogateSelector = surrogateSelector;
     this.AssemblyFormat = assemblyFormat;
 }
Esempio n. 12
0
        public static string GetTypeName(Type t, FormatterAssemblyStyle assemblyFormat, SerializationBinder binder)
        {
            string assemblyQualifiedName = t.AssemblyQualifiedName;

            if (assemblyFormat == FormatterAssemblyStyle.Simple)
            {
                return(ReflectionUtils.RemoveAssemblyDetails(assemblyQualifiedName));
            }
            if (assemblyFormat != FormatterAssemblyStyle.Full)
            {
                throw new ArgumentOutOfRangeException();
            }
            return(assemblyQualifiedName);
        }
        private static byte[] ToByteArray(object obj,
                                          FormatterAssemblyStyle assemblyStyle = FormatterAssemblyStyle.Simple)
        {
            var binaryFormatter = new BinaryFormatter
            {
                AssemblyFormat = assemblyStyle
            };

            using (MemoryStream ms = new MemoryStream())
            {
                binaryFormatter.Serialize(ms, obj);
                return(ms.ToArray());
            }
        }
Esempio n. 14
0
        public void ValidateNonSerializableTypes(object obj, FormatterAssemblyStyle assemblyFormat, TypeFilterLevel filterLevel, FormatterTypeStyle typeFormat)
        {
            var f = new BinaryFormatter()
            {
                AssemblyFormat = assemblyFormat,
                FilterLevel    = filterLevel,
                TypeFormat     = typeFormat
            };

            using (var s = new MemoryStream())
            {
                Assert.Throws <SerializationException>(() => f.Serialize(s, obj));
            }
        }
Esempio n. 15
0
        /// <summary>
        /// Tests the FormatterAssemblyStyle property in a JSON serializer settings object.
        /// </summary>
        /// <param name="typeNameAssemblyFormat">Expected FormatterAssemblyStyle.</param>
        /// <returns>The same JSON serializer settings test builder.</returns>
        public IAndJsonSerializerSettingsTestBuilder WithTypeNameAssemblyFormat(FormatterAssemblyStyle typeNameAssemblyFormat)
        {
            this.jsonSerializerSettings.TypeNameAssemblyFormat = typeNameAssemblyFormat;
            this.validations.Add((expected, actual) =>
            {
                if (!CommonValidator.CheckEquality(expected.TypeNameAssemblyFormat, actual.TypeNameAssemblyFormat))
                {
                    this.ThrowNewJsonResultAssertionException(
                        string.Format("{0} type name assembly format", expected.TypeNameAssemblyFormat),
                        string.Format("in fact found {0}", actual.TypeNameAssemblyFormat));
                }
            });

            return(this);
        }
Esempio n. 16
0
        private static byte[] ToByteArray(object obj,
                                          FormatterAssemblyStyle assemblyStyle = FormatterAssemblyStyle.Simple)
        {
            var binaryFormatter = new BinaryFormatter
            {
                AssemblyFormat = assemblyStyle
            };

            using (MemoryStream ms = new MemoryStream())
            {
#pragma warning disable CS0618 // Type or member is obsolete
                binaryFormatter.Serialize(ms, obj);
#pragma warning restore CS0618 // Type or member is obsolete
                return(ms.ToArray());
            }
        }
Esempio n. 17
0
        public static string GetTypeName(Type t, FormatterAssemblyStyle assemblyFormat, SerializationBinder binder)
        {
            string assemblyQualifiedName = t.AssemblyQualifiedName;

            switch (assemblyFormat)
            {
            case FormatterAssemblyStyle.Simple:
                return(RemoveAssemblyDetails(assemblyQualifiedName));

            case FormatterAssemblyStyle.Full:
                return(t.AssemblyQualifiedName);

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
 void Initialize(StreamingContext context,
                 int maxItemsInObjectGraph,
                 bool ignoreExtensionDataObject,
                 FormatterAssemblyStyle assemblyFormat,
                 ISurrogateSelector surrogateSelector)
 {
     this.context = context;
     if (maxItemsInObjectGraph < 0)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("maxItemsInObjectGraph", SR.GetString(SR.ValueMustBeNonNegative)));
     }
     this.maxItemsInObjectGraph     = maxItemsInObjectGraph;
     this.ignoreExtensionDataObject = ignoreExtensionDataObject;
     this.surrogateSelector         = surrogateSelector;
     this.AssemblyFormat            = assemblyFormat;
 }
Esempio n. 19
0
        private static object FromByteArray(byte[] raw,
                                            FormatterAssemblyStyle assemblyStyle = FormatterAssemblyStyle.Simple)
        {
            var binaryFormatter = new BinaryFormatter
            {
                AssemblyFormat = assemblyStyle
            };

            using (var serializedStream = new MemoryStream(raw))
            {
#pragma warning disable CS0618 // Type or member is obsolete
                return(binaryFormatter.Deserialize(serializedStream));

#pragma warning restore CS0618 // Type or member is obsolete
            }
        }
Esempio n. 20
0
        /// <summary>
        /// handle the $type field of the json data
        /// </summary>
        /// <param name="config">
        /// The bootstrapper config
        /// </param>
        /// <param name="typeNameHandling">
        /// TypeNameHandling
        /// </param>
        /// <param name="formatterAssemblyStyle">
        /// FormatterAssemblyStyle
        /// </param>
        /// <returns>
        /// The <see cref="IBootstrapperConfig"/>.
        /// </returns>
        public static IBootstrapperConfig EnableJsonTypeNameHandling(
            this IBootstrapperConfig config,
            TypeNameHandling typeNameHandling             = TypeNameHandling.All,
            FormatterAssemblyStyle formatterAssemblyStyle = FormatterAssemblyStyle.Simple)
        {
            /*
             * GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.TypeNameHandling = typeNameHandling;
             * GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.TypeNameAssemblyFormat = formatterAssemblyStyle;
             *
             * GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.Error = HandleJsonSerializationErrors;*/
            config.Configuration.Formatters.JsonFormatter.SerializerSettings.TypeNameHandling       = typeNameHandling;
            config.Configuration.Formatters.JsonFormatter.SerializerSettings.TypeNameAssemblyFormat = formatterAssemblyStyle;

            config.Configuration.Formatters.JsonFormatter.SerializerSettings.Error = HandleJsonSerializationErrors;

            return(config);
        }
Esempio n. 21
0
        public static string GetTypeName(Type t, FormatterAssemblyStyle assemblyFormat, ISerializationBinder binder)
        {
//      string fullyQualifiedTypeName;
//#if !(NET20 || NET35)
//      if (binder != null)
//      {
//        string assemblyName, typeName;
//        binder.BindToName(t, out assemblyName, out typeName);
//        fullyQualifiedTypeName = typeName + (assemblyName == null ? "" : ", " + assemblyName);
//      }
//      else
//      {
//        fullyQualifiedTypeName = t.AssemblyQualifiedName;
//      }
//#else
//      fullyQualifiedTypeName = t.AssemblyQualifiedName;
//#endif

            string fullyQualifiedTypeName;

            if (binder != null)
            {
                string assemblyName, typeName;
                binder.BindToName(t, out assemblyName, out typeName);
                fullyQualifiedTypeName = typeName + (assemblyName == null ? "" : ", " + assemblyName);
            }
            else
            {
                fullyQualifiedTypeName = t.AssemblyQualifiedName;
            }

            switch (assemblyFormat)
            {
            case FormatterAssemblyStyle.Simple:
                return(RemoveAssemblyDetails(fullyQualifiedTypeName));

            case FormatterAssemblyStyle.Full:
                return(fullyQualifiedTypeName);

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Esempio n. 22
0
 // Constructor used by SoapWriter
 public SoapTypeMapper(
     XmlTextWriter xmlWriter,
     FormatterAssemblyStyle assemblyFormat,
     FormatterTypeStyle typeFormat)
 {
     _xmlWriter      = xmlWriter;
     _assemblyFormat = assemblyFormat;
     _prefixNumber   = 1;
     //Type elementType = typeof(string);
     if (typeFormat == FormatterTypeStyle.XsdString)
     {
         elementString = new Element("xsd", "string", XmlSchema.Namespace);
     }
     else
     {
         elementString = new Element(SoapEncodingPrefix, "string", SoapEncodingNamespace);
     }
     //			typeToXmlNodeTable.Add(elementType.AssemblyQualifiedName, element);
 }
Esempio n. 23
0
        private /*static*/ string getAssemblyName(Assembly assembly, FormatterAssemblyStyle assemblyStyle)
        {
            System.Diagnostics.Debug.Assert(null != assembly, "The 'assembly' argument cannot be null.");

            AssemblyInfo assemblyInfo = new AssemblyInfo(assembly);

            if (assemblyInfo.Name == "mscorlib" || assemblyInfo.Name == "System")
            {
                return(null);
            }

            string assemblyName = assemblyInfo.ToString();

            if (FormatterAssemblyStyle.Simple == assemblyStyle)
            {
                assemblyName = assemblyInfo.Name;
            }
            return(assemblyName);
        }
        public void OptionalField_Missing_Success(FormatterAssemblyStyle style)
        {
            var f = new BinaryFormatter();
            var s = new MemoryStream();

            f.Serialize(s, new Version1ClassWithoutField());
            s.Position = 0;

            f = new BinaryFormatter()
            {
                AssemblyFormat = style
            };
            f.Binder = new DelegateBinder {
                BindToTypeDelegate = (_, __) => typeof(Version2ClassWithOptionalField)
            };
            var result = (Version2ClassWithOptionalField)f.Deserialize(s);

            Assert.NotNull(result);
            Assert.Equal(null, result.Value);
        }
Esempio n. 25
0
        /// <summary>
        /// Get a serializer suited for two-way serialization of .NET types.
        /// </summary>
        /// <returns></returns>
        public static JsonSerializer Serializer(
            TypeNameHandling typeNameHandling           = TypeNameHandling.Arrays,
            FormatterAssemblyStyle assemblyNameType     = FormatterAssemblyStyle.Simple,
            NullValueHandling nullValueHandling         = NullValueHandling.Ignore,
            DefaultValueHandling defaultValueHandling   = DefaultValueHandling.Ignore,
            MissingMemberHandling missingMemberHandling = MissingMemberHandling.Ignore,
            ReferenceLoopHandling loopHandling          = ReferenceLoopHandling.Ignore)
        {
            var result = new JsonSerializer
            {
                MissingMemberHandling  = missingMemberHandling,
                NullValueHandling      = nullValueHandling,
                ReferenceLoopHandling  = loopHandling,
                DefaultValueHandling   = defaultValueHandling,
                TypeNameHandling       = typeNameHandling,
                TypeNameAssemblyFormat = assemblyNameType
            };

            result.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter());
            return(result);
        }
Esempio n. 26
0
            public static void SerializeTest()
            {
                //     FileStream fs = File.Create("D:\\dirInfo\\serial.dat");
                FileStream             fs  = new FileStream("D:\\dirInfo\\serial.dat", FileMode.OpenOrCreate);
                BinaryFormatter        bf  = new BinaryFormatter();
                FormatterAssemblyStyle fas = bf.AssemblyFormat;

                Console.WriteLine(fas.ToString());

                bf.Serialize(fs, person);
                fs.Seek(0, SeekOrigin.Begin);
                ToSerialize ts = (ToSerialize)bf.Deserialize(fs);

                Console.WriteLine(ts.age);



                SoapFormatter sf = new SoapFormatter();

                sf.Serialize(fs, ts);
                fs.Close();
            }
Esempio n. 27
0
        public static string GetTypeName(Type t, FormatterAssemblyStyle assemblyFormat, SerializationBinder binder)
        {
            string assemblyQualifiedName;

            if (binder != null)
            {
                binder.BindToName(t, out string str, out string str2);
                assemblyQualifiedName = str2 + ((str == null) ? "" : (", " + str));
            }
            else
            {
                assemblyQualifiedName = t.AssemblyQualifiedName;
            }
            if (assemblyFormat != FormatterAssemblyStyle.Simple)
            {
                if (assemblyFormat != FormatterAssemblyStyle.Full)
                {
                    throw new ArgumentOutOfRangeException();
                }
                return(assemblyQualifiedName);
            }
            return(RemoveAssemblyDetails(assemblyQualifiedName));
        }
 public NetDataContractSerializer(
     XmlDictionaryString rootName,
     XmlDictionaryString rootNamespace,
     StreamingContext context,
     int maxItemsInObjectGraph,
     bool ignoreExtensibleDataObject,
     FormatterAssemblyStyle assemblyFormat,
     ISurrogateSelector surrogateSelector)
     : this(context, maxItemsInObjectGraph,
            ignoreExtensibleDataObject, assemblyFormat,
            surrogateSelector)
 {
     if (rootName == null)
     {
         throw new ArgumentNullException("rootName");
     }
     if (rootNamespace == null)
     {
         throw new ArgumentNullException("rootNamespace");
     }
     root_name = rootName;
     root_ns   = rootNamespace;
 }
Esempio n. 29
0
		private /*static*/ void writeType(XmlWriter xmlWriter, Type type, FormatterAssemblyStyle assemblyStyle)
		{
			System.Diagnostics.Debug.Assert(null != xmlWriter, "The 'xmlWriter' argument cannot be null.");
			System.Diagnostics.Debug.Assert(null != type, "The 'type' argument cannot be null.");
			System.Diagnostics.Debug.Assert(!type.IsArray, "The Type type cannot be an Array.");

			string typeName = this.getQualifiedTypeName(type, assemblyStyle);
			xmlWriter.WriteStartAttribute("type");
			xmlWriter.WriteString(typeName);
			xmlWriter.WriteEndAttribute();
		}
        public NetDataContractSerializer(string rootName, string rootNamespace, StreamingContext context, int maxItemsInObjectGraph, bool ignoreExtensionDataObject, FormatterAssemblyStyle assemblyFormat, ISurrogateSelector surrogateSelector)
        {
            XmlDictionary dictionary = new XmlDictionary(2);

            this.Initialize(dictionary.Add(rootName), dictionary.Add(DataContract.GetNamespace(rootNamespace)), context, maxItemsInObjectGraph, ignoreExtensionDataObject, assemblyFormat, surrogateSelector);
        }
 private void Initialize(XmlDictionaryString rootName, XmlDictionaryString rootNamespace, StreamingContext context, int maxItemsInObjectGraph, bool ignoreExtensionDataObject, FormatterAssemblyStyle assemblyFormat, ISurrogateSelector surrogateSelector)
 {
     this.Initialize(context, maxItemsInObjectGraph, ignoreExtensionDataObject, assemblyFormat, surrogateSelector);
     this.rootName      = rootName;
     this.rootNamespace = rootNamespace;
 }
		public ObjectWriter (BinaryFormatter formatter)
		{
			_surrogateSelector = formatter.SurrogateSelector;
			_context = formatter.Context;
			_assemblyFormat = formatter.AssemblyFormat;
			_typeFormat = formatter.TypeFormat;
			_manager = new SerializationObjectManager (formatter.Context);
#if NET_4_0
			_binder = formatter.Binder;
#endif
		}
Esempio n. 33
0
        internal void Serialize(object objGraph, Header[] headers, FormatterTypeStyle typeFormat, FormatterAssemblyStyle assemblyFormat)
        {
            CultureInfo savedCi = CultureInfo.CurrentCulture;

            try {
                Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
                Serialize_inner(objGraph, headers, typeFormat, assemblyFormat);
            } finally {
                Thread.CurrentThread.CurrentCulture = savedCi;
            }

#if NET_2_0 && !TARGET_JVM
            _manager.RaiseOnSerializedEvent();
#endif
        }
Esempio n. 34
0
		private /*static*/ string getQualifiedTypeName(Array array, FormatterAssemblyStyle assemblyStyle)
		{
			System.Diagnostics.Debug.Assert(null != array, "The 'array' argument cannot be null.");

			int rank = array.Rank;
			string dimensionLenghts = string.Empty;
			for (int i = 0; i < rank; i++) {
				dimensionLenghts += (array.GetUpperBound(i) + 1);
				if (i < rank - 1)
					dimensionLenghts += ",";
			}

			Type elementType = array.GetType().GetElementType();

			string qualifiedTypeName = this.getTypeName(elementType, assemblyStyle); // Return value
			qualifiedTypeName += string.Format("[{0}]", dimensionLenghts);
			string assemblyName = this.getAssemblyName(elementType.Assembly, assemblyStyle);
			if (!string.IsNullOrEmpty(assemblyName))
				qualifiedTypeName += string.Format(", {0}", assemblyName);
			return qualifiedTypeName;
		}
Esempio n. 35
0
		private /*static*/ string getTypeName(Type type, FormatterAssemblyStyle assemblyStyle)
		{
			System.Diagnostics.Debug.Assert(null != type, "The 'type' argument cannot be null.");

			string typeName = type.FullName;
			if (type.IsGenericType) {
				typeName = type.GetGenericTypeDefinition().FullName;
				if (!type.IsGenericTypeDefinition) {
					typeName += "[";
					Type[] genericArguments = type.GetGenericArguments();
					for (int i = 0; i < genericArguments.Length; i++) {
						string genericArgumentTypeName = this.getQualifiedTypeName(genericArguments[i], assemblyStyle);
						typeName += string.Format("[{0}]", genericArgumentTypeName);
						if (i < genericArguments.Length - 1)
							typeName += ",";
					}
					typeName += "]";
				}
			}
			return typeName;
		}
Esempio n. 36
0
		public static void WriteMethodResponse (BinaryWriter writer, object obj, Header[] headers, ISurrogateSelector surrogateSelector, StreamingContext context, FormatterAssemblyStyle assemblyFormat, FormatterTypeStyle typeFormat)
		{
			IMethodReturnMessage resp = (IMethodReturnMessage)obj;
			writer.Write ((byte) BinaryElement.MethodResponse);

			string[] internalProperties = MethodReturnDictionary.InternalReturnKeys;

			int infoArrayLength = 0;
			object info = null;
			object[] extraProperties = null;

			// Type of return value

			ReturnTypeTag returnTypeTag;
			MethodFlags contextFlag = MethodFlags.ExcludeLogicalCallContext;

			if (resp.Exception != null) {
				returnTypeTag = ReturnTypeTag.Exception | ReturnTypeTag.Null;
				internalProperties = MethodReturnDictionary.InternalExceptionKeys;
				infoArrayLength = 1;
			}
			else if (resp.ReturnValue == null) {
				returnTypeTag = ReturnTypeTag.Null;
			}
			else if (IsMethodPrimitive(resp.ReturnValue.GetType())) {
				returnTypeTag = ReturnTypeTag.PrimitiveType;
			}
			else {
				returnTypeTag = ReturnTypeTag.ObjectType;
				infoArrayLength++;
			}

			// Message flags

			MethodFlags formatFlag;

			if ((resp.LogicalCallContext != null) && resp.LogicalCallContext.HasInfo) 
			{
				contextFlag = MethodFlags.IncludesLogicalCallContext;
				infoArrayLength++;
			}

			if (resp.Properties.Count > internalProperties.Length && ((returnTypeTag & ReturnTypeTag.Exception) == 0))
			{
				extraProperties = GetExtraProperties (resp.Properties, internalProperties);
				infoArrayLength++;
			}

			if (resp.OutArgCount == 0)
				formatFlag = MethodFlags.NoArguments;
			else 
			{
				if (AllTypesArePrimitive (resp.Args)) 
					formatFlag = MethodFlags.PrimitiveArguments;
				else 
				{
					if (infoArrayLength == 0)
						formatFlag = MethodFlags.ArgumentsInSimpleArray; 
					else {
						formatFlag = MethodFlags.ArgumentsInMultiArray;
						infoArrayLength++;
					}
				}
			}

			writer.Write ((byte) (contextFlag | formatFlag));
			writer.Write ((byte) returnTypeTag);

			// FIXME: what are the following 2 bytes for?
			writer.Write ((byte) 0);
			writer.Write ((byte) 0);

			// Arguments

			if (returnTypeTag == ReturnTypeTag.PrimitiveType)
			{
				writer.Write (BinaryCommon.GetTypeCode (resp.ReturnValue.GetType()));
				ObjectWriter.WritePrimitiveValue (writer, resp.ReturnValue);
			}

			if (formatFlag == MethodFlags.PrimitiveArguments)
			{
				writer.Write ((uint)resp.ArgCount);
				for (int n=0; n<resp.ArgCount; n++)
				{
					object val = resp.GetArg(n);
					if (val != null) {
						writer.Write (BinaryCommon.GetTypeCode (val.GetType()));
						ObjectWriter.WritePrimitiveValue (writer, val);
					}
					else
						writer.Write ((byte)BinaryTypeCode.Null);
				}
			}

			if (infoArrayLength > 0)
			{
				object[] infoArray = new object[infoArrayLength];
				int n = 0;

				if ((returnTypeTag & ReturnTypeTag.Exception) != 0)
					infoArray[n++] = resp.Exception;
				
				if (formatFlag == MethodFlags.ArgumentsInMultiArray)
					infoArray[n++] = resp.Args;

				if (returnTypeTag == ReturnTypeTag.ObjectType)
					infoArray[n++] = resp.ReturnValue;

				if (contextFlag == MethodFlags.IncludesLogicalCallContext)
					infoArray[n++] = resp.LogicalCallContext;

				if (extraProperties != null)
					infoArray[n++] = extraProperties;

				info = infoArray;
			}
			else if ((formatFlag & MethodFlags.ArgumentsInSimpleArray) > 0)
				info = resp.Args;

			if (info != null)
			{
				ObjectWriter objectWriter = new ObjectWriter (surrogateSelector, context, assemblyFormat, typeFormat);
				objectWriter.WriteObjectGraph (writer, info, headers);
			}
			else
				writer.Write ((byte) BinaryElement.End);
		}
Esempio n. 37
0
        public ObjectWriter(ISurrogateSelector surrogateSelector, StreamingContext context, FormatterAssemblyStyle assemblyFormat, FormatterTypeStyle typeFormat)
        {
            _surrogateSelector = surrogateSelector;
            _context           = context;
            _assemblyFormat    = assemblyFormat;
            _typeFormat        = typeFormat;
#if NET_2_0
            _manager = new SerializationObjectManager(context);
#endif
        }
Esempio n. 38
0
		public static void WriteMethodCall (BinaryWriter writer, object obj, Header[] headers, ISurrogateSelector surrogateSelector, StreamingContext context, FormatterAssemblyStyle assemblyFormat, FormatterTypeStyle typeFormat)
		{
			IMethodCallMessage call = (IMethodCallMessage)obj;
			writer.Write ((byte) BinaryElement.MethodCall);

			MethodFlags methodFlags;
			int infoArraySize = 0;
			object info = null;
			object[] extraProperties = null;

			if (call.LogicalCallContext != null && call.LogicalCallContext.HasInfo)
			{
				methodFlags = MethodFlags.IncludesLogicalCallContext;
				infoArraySize++;
			}
			else
				methodFlags = MethodFlags.ExcludeLogicalCallContext;

			if (RemotingServices.IsMethodOverloaded (call))
			{
				infoArraySize++;
				methodFlags |= MethodFlags.IncludesSignature;
			}

			if (call.Properties.Count > MethodCallDictionary.InternalKeys.Length)
			{
				extraProperties = GetExtraProperties (call.Properties, MethodCallDictionary.InternalKeys);
				infoArraySize++;
			}

#if NET_2_0
			if (call.MethodBase.IsGenericMethod) {
				infoArraySize++;
				methodFlags |= MethodFlags.GenericArguments;
			}
#endif
			if (call.ArgCount == 0)
				methodFlags |= MethodFlags.NoArguments;
			else {
				if (AllTypesArePrimitive (call.Args)) 
					methodFlags |= MethodFlags.PrimitiveArguments;
				else {
					if (infoArraySize == 0)
						methodFlags |= MethodFlags.ArgumentsInSimpleArray;
					else {
						methodFlags |= MethodFlags.ArgumentsInMultiArray;
						infoArraySize++;
					}
				}
			}

			writer.Write ((int) methodFlags);

			// Method name
			writer.Write ((byte) BinaryTypeCode.String);
			writer.Write (call.MethodName);

			// Class name
			writer.Write ((byte) BinaryTypeCode.String);
			writer.Write (call.TypeName);

			// Arguments

			if ((methodFlags & MethodFlags.PrimitiveArguments) > 0)
			{
				writer.Write ((uint)call.Args.Length);
				for (int n=0; n<call.ArgCount; n++)
				{
					object arg = call.GetArg(n);
					if (arg != null) {
						writer.Write (BinaryCommon.GetTypeCode (arg.GetType()));
						ObjectWriter.WritePrimitiveValue (writer, arg);
					}
					else
						writer.Write ((byte)BinaryTypeCode.Null);
				}
			}

			if ( infoArraySize > 0)
			{
				object[] ainfo = new object[infoArraySize];
				int n=0;
				if ((methodFlags & MethodFlags.ArgumentsInMultiArray) > 0) ainfo[n++] = call.Args;

#if NET_2_0
				if ((methodFlags & MethodFlags.GenericArguments) > 0) ainfo[n++] = call.MethodBase.GetGenericArguments ();
#endif

				if ((methodFlags & MethodFlags.IncludesSignature) > 0) ainfo[n++] = call.MethodSignature;
				if ((methodFlags & MethodFlags.IncludesLogicalCallContext) > 0) ainfo[n++] = call.LogicalCallContext;
				if (extraProperties != null) ainfo[n++] = extraProperties;
				info = ainfo;
			}
			else if ((methodFlags & MethodFlags.ArgumentsInSimpleArray) > 0)
				info = call.Args;

			if (info != null)
			{
				ObjectWriter objectWriter = new ObjectWriter (surrogateSelector, context, assemblyFormat, typeFormat);
				objectWriter.WriteObjectGraph (writer, info, headers);
			}
			else
				writer.Write ((byte) BinaryElement.End);
		}
Esempio n. 39
0
 public static object DeserializeBlobToObject(string base64Str, FormatterAssemblyStyle assemblyStyle)
 {
     byte[] raw = Convert.FromBase64String(base64Str);
     return(DeserializeRawToObject(raw, assemblyStyle));
 }
Esempio n. 40
0
		public NetDataContractSerializer (
			XmlDictionaryString rootName,
			XmlDictionaryString rootNamespace,
			StreamingContext context,
			int maxItemsInObjectGraph,
			bool ignoreExtensibleDataObject,
			FormatterAssemblyStyle assemblyFormat,
			ISurrogateSelector surrogateSelector)
			: this (context, maxItemsInObjectGraph,
				ignoreExtensibleDataObject, assemblyFormat,
				surrogateSelector)
		{
			if (rootName == null)
				throw new ArgumentNullException ("rootName");
			if (rootNamespace == null)
				throw new ArgumentNullException ("rootNamespace");
			root_name = rootName;
			root_ns = rootNamespace;
		}
Esempio n. 41
0
		public NetDataContractSerializer (
			string rootName, string rootNamespace,
			StreamingContext context, 
			int maxItemsInObjectGraph,
			bool ignoreExtensibleDataObject,
			FormatterAssemblyStyle assemblyFormat,
			ISurrogateSelector surrogateSelector)
			: this (context, maxItemsInObjectGraph,
				ignoreExtensibleDataObject, assemblyFormat,
				surrogateSelector)
		{
			FillDictionaryString (rootName, rootNamespace);
		}
Esempio n. 42
0
		void Serialize_inner (object objGraph, Header[] headers, FormatterTypeStyle typeFormat, FormatterAssemblyStyle assemblyFormat)
		{
			_typeFormat = typeFormat;
			_assemblyFormat = assemblyFormat;
			// Create the XmlDocument with the 
			// Envelope and Body elements
			_mapper = new SoapTypeMapper(_xmlWriter, assemblyFormat, typeFormat);

			// The root element
			_xmlWriter.WriteStartElement(
				SoapTypeMapper.SoapEnvelopePrefix, 
				"Envelope",
				SoapTypeMapper.SoapEnvelopeNamespace);

			// adding namespaces
			_xmlWriter.WriteAttributeString(
				"xmlns",
				"xsi",
				"http://www.w3.org/2000/xmlns/",
				"http://www.w3.org/2001/XMLSchema-instance");

			_xmlWriter.WriteAttributeString(
				"xmlns",
				"xsd",
				"http://www.w3.org/2000/xmlns/",
				XmlSchema.Namespace);

			_xmlWriter.WriteAttributeString(
				"xmlns",
				SoapTypeMapper.SoapEncodingPrefix,
				"http://www.w3.org/2000/xmlns/",
				SoapTypeMapper.SoapEncodingNamespace);

			_xmlWriter.WriteAttributeString(
				"xmlns",
				SoapTypeMapper.SoapEnvelopePrefix,
				"http://www.w3.org/2000/xmlns/",
				SoapTypeMapper.SoapEnvelopeNamespace);

			_xmlWriter.WriteAttributeString(
				"xmlns",
				"clr",
				"http://www.w3.org/2000/xmlns/",
				SoapServices.XmlNsForClrType);

			_xmlWriter.WriteAttributeString(
				SoapTypeMapper.SoapEnvelopePrefix,
				"encodingStyle",
				SoapTypeMapper.SoapEnvelopeNamespace,
				"http://schemas.xmlsoap.org/soap/encoding/");
						
			ISoapMessage msg = objGraph as ISoapMessage;
			if (msg != null)
				headers = msg.Headers;
			
			if (headers != null && headers.Length > 0)
			{
				_xmlWriter.WriteStartElement (SoapTypeMapper.SoapEnvelopePrefix, "Header", SoapTypeMapper.SoapEnvelopeNamespace);
				foreach (Header h in headers)
					SerializeHeader (h);
					
				WriteObjectQueue ();
				_xmlWriter.WriteEndElement ();
			}
				
			// The body element
			_xmlWriter.WriteStartElement(
				SoapTypeMapper.SoapEnvelopePrefix,
				"Body",
				SoapTypeMapper.SoapEnvelopeNamespace);


			bool firstTime = false;

			if (msg != null)
				SerializeMessage(msg);
			else
				_objectQueue.Enqueue(new EnqueuedObject( objGraph, idGen.GetId(objGraph, out firstTime)));

			WriteObjectQueue ();

			_xmlWriter.WriteFullEndElement(); // the body element
			_xmlWriter.WriteFullEndElement(); // the envelope element
			_xmlWriter.Flush();
		}
Esempio n. 43
0
		private /*static*/ string getAssemblyName(Assembly assembly, FormatterAssemblyStyle assemblyStyle)
		{
			System.Diagnostics.Debug.Assert(null != assembly, "The 'assembly' argument cannot be null.");

			AssemblyInfo assemblyInfo = new AssemblyInfo(assembly);
			if (assemblyInfo.Name == "mscorlib" || assemblyInfo.Name == "System")
				return null;

			string assemblyName = assemblyInfo.ToString();
			if (FormatterAssemblyStyle.Simple == assemblyStyle)
				assemblyName = assemblyInfo.Name;
			return assemblyName;
		}
Esempio n. 44
0
		internal void Serialize (object objGraph, Header[] headers, FormatterTypeStyle typeFormat, FormatterAssemblyStyle assemblyFormat)
		{
			CultureInfo savedCi = CultureInfo.CurrentCulture;
			try {
				Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
				Serialize_inner (objGraph, headers, typeFormat, assemblyFormat);
			} finally {
				Thread.CurrentThread.CurrentCulture = savedCi;
			}

#if NET_2_0 && !TARGET_JVM
			_manager.RaiseOnSerializedEvent ();
#endif
		}
Esempio n. 45
0
		private /*static*/ string getQualifiedTypeName(Type type, FormatterAssemblyStyle assemblyStyle)
		{
			System.Diagnostics.Debug.Assert(null != type, "The 'type' argument cannot be null.");

			string qualifiedTypeName = this.getTypeName(type, assemblyStyle);
			string assemblyName = this.getAssemblyName(type.Assembly, assemblyStyle);
			if (!string.IsNullOrEmpty(assemblyName))
				qualifiedTypeName += string.Format(", {0}", assemblyName);
			return qualifiedTypeName;
		}
Esempio n. 46
0
		public BinaryMessageFormatter (FormatterAssemblyStyle topObjectFormat, FormatterTypeStyle typeFormat)
		{
			_formatter = new BinaryFormatter ();
			_formatter.AssemblyFormat = topObjectFormat;
			_formatter.TypeFormat = typeFormat;
		}
Esempio n. 47
0
 void Initialize(XmlDictionaryString rootName, XmlDictionaryString rootNamespace,
     StreamingContext context,
     int maxItemsInObjectGraph,
     bool ignoreExtensionDataObject,
     FormatterAssemblyStyle assemblyFormat,
     ISurrogateSelector surrogateSelector)
 {
     Initialize(context, maxItemsInObjectGraph, ignoreExtensionDataObject, assemblyFormat, surrogateSelector);
     this.rootName = rootName;
     this.rootNamespace = rootNamespace;
 }
Esempio n. 48
0
		// Constructor used by SoapWriter
		public SoapTypeMapper(
			XmlTextWriter xmlWriter, 
			FormatterAssemblyStyle assemblyFormat,
			FormatterTypeStyle typeFormat) 
		{
			_xmlWriter = xmlWriter;
			_assemblyFormat = assemblyFormat;
			_prefixNumber = 1;
			//Type elementType = typeof(string);
			if(typeFormat == FormatterTypeStyle.XsdString)
			{
				elementString = new Element("xsd", "string", XmlSchema.Namespace);
			}
			else
			{
				elementString = new Element(SoapEncodingPrefix, "string", SoapEncodingNamespace);
			}
//			typeToXmlNodeTable.Add(elementType.AssemblyQualifiedName, element);
		}
Esempio n. 49
0
        void Serialize_inner(object objGraph, Header[] headers, FormatterTypeStyle typeFormat, FormatterAssemblyStyle assemblyFormat)
        {
            _typeFormat     = typeFormat;
            _assemblyFormat = assemblyFormat;
            // Create the XmlDocument with the
            // Envelope and Body elements
            _mapper = new SoapTypeMapper(_xmlWriter, assemblyFormat, typeFormat);

            // The root element
            _xmlWriter.WriteStartElement(
                SoapTypeMapper.SoapEnvelopePrefix,
                "Envelope",
                SoapTypeMapper.SoapEnvelopeNamespace);

            // adding namespaces
            _xmlWriter.WriteAttributeString(
                "xmlns",
                "xsi",
                "http://www.w3.org/2000/xmlns/",
                "http://www.w3.org/2001/XMLSchema-instance");

            _xmlWriter.WriteAttributeString(
                "xmlns",
                "xsd",
                "http://www.w3.org/2000/xmlns/",
                XmlSchema.Namespace);

            _xmlWriter.WriteAttributeString(
                "xmlns",
                SoapTypeMapper.SoapEncodingPrefix,
                "http://www.w3.org/2000/xmlns/",
                SoapTypeMapper.SoapEncodingNamespace);

            _xmlWriter.WriteAttributeString(
                "xmlns",
                SoapTypeMapper.SoapEnvelopePrefix,
                "http://www.w3.org/2000/xmlns/",
                SoapTypeMapper.SoapEnvelopeNamespace);

            _xmlWriter.WriteAttributeString(
                "xmlns",
                "clr",
                "http://www.w3.org/2000/xmlns/",
                SoapServices.XmlNsForClrType);

            _xmlWriter.WriteAttributeString(
                SoapTypeMapper.SoapEnvelopePrefix,
                "encodingStyle",
                SoapTypeMapper.SoapEnvelopeNamespace,
                "http://schemas.xmlsoap.org/soap/encoding/");

            ISoapMessage msg = objGraph as ISoapMessage;

            if (msg != null)
            {
                headers = msg.Headers;
            }

            if (headers != null && headers.Length > 0)
            {
                _xmlWriter.WriteStartElement(SoapTypeMapper.SoapEnvelopePrefix, "Header", SoapTypeMapper.SoapEnvelopeNamespace);
                foreach (Header h in headers)
                {
                    SerializeHeader(h);
                }

                WriteObjectQueue();
                _xmlWriter.WriteEndElement();
            }

            // The body element
            _xmlWriter.WriteStartElement(
                SoapTypeMapper.SoapEnvelopePrefix,
                "Body",
                SoapTypeMapper.SoapEnvelopeNamespace);


            bool firstTime = false;

            if (msg != null)
            {
                SerializeMessage(msg);
            }
            else
            {
                _objectQueue.Enqueue(new EnqueuedObject(objGraph, idGen.GetId(objGraph, out firstTime)));
            }

            WriteObjectQueue();

            _xmlWriter.WriteFullEndElement();             // the body element
            _xmlWriter.WriteFullEndElement();             // the envelope element
            _xmlWriter.Flush();
        }
Esempio n. 50
0
 public static string ToBase64String(object @object,
                                     FormatterAssemblyStyle assemblyStyle = FormatterAssemblyStyle.Simple)
 {
     byte[] raw = ToByteArray(@object, assemblyStyle);
     return(Convert.ToBase64String(raw));
 }
Esempio n. 51
0
#pragma warning disable 436
        public static string GetTypeName(Type t, FormatterAssemblyStyle assemblyFormat)
        {
            return(GetTypeName(t, assemblyFormat, null));
        }
Esempio n. 52
0
 private static object FromBase64String(string base64String,
                                        FormatterAssemblyStyle assemblyStyle = FormatterAssemblyStyle.Simple)
 {
     byte[] raw = Convert.FromBase64String(base64String);
     return(FromByteArray(raw, assemblyStyle));
 }
 public NetDataContractSerializer(StreamingContext context, int maxItemsInObjectGraph, bool ignoreExtensionDataObject, FormatterAssemblyStyle assemblyFormat, ISurrogateSelector surrogateSelector)
 {
     this.Initialize(context, maxItemsInObjectGraph, ignoreExtensionDataObject, assemblyFormat, surrogateSelector);
 }
Esempio n. 54
0
		public ObjectWriter (ISurrogateSelector surrogateSelector, StreamingContext context, FormatterAssemblyStyle assemblyFormat, FormatterTypeStyle typeFormat)
		{
			_surrogateSelector = surrogateSelector;
			_context = context;
			_assemblyFormat = assemblyFormat;
			_typeFormat = typeFormat;
#if NET_2_0
			_manager = new SerializationObjectManager (context);
#endif
		}
 public NetDataContractSerializer(XmlDictionaryString rootName, XmlDictionaryString rootNamespace, StreamingContext context, int maxItemsInObjectGraph, bool ignoreExtensionDataObject, FormatterAssemblyStyle assemblyFormat, ISurrogateSelector surrogateSelector)
 {
     this.Initialize(rootName, rootNamespace, context, maxItemsInObjectGraph, ignoreExtensionDataObject, assemblyFormat, surrogateSelector);
 }
 public IBinaryConfiguration WithFormat(FormatterAssemblyStyle format)
 {
     _binaryFormatter.AssemblyFormat = format;
     return this;
 }
Esempio n. 57
0
 public BinaryMessageFormatter(FormatterAssemblyStyle topObjectFormat, FormatterTypeStyle typeFormat)
 {
     _formatter = new BinaryFormatter();
     _formatter.AssemblyFormat = topObjectFormat;
     _formatter.TypeFormat     = typeFormat;
 }
Esempio n. 58
0
		public NetDataContractSerializer (StreamingContext context, 
			int maxItemsInObjectGraph,
			bool ignoreExtensibleDataObject,
			FormatterAssemblyStyle assemblyFormat,
			ISurrogateSelector surrogateSelector)
		{
			this.context = context;
			max_items = maxItemsInObjectGraph;
			ignore_extensions = ignoreExtensibleDataObject;
			ass_style = assemblyFormat;
			selector = surrogateSelector;
		}