Inheritance: IFormatterConverter
        public void GetObjectData()
        {
            Type type = typeof(HsqlDataSourceException);
            FormatterConverter converter = new FormatterConverter();
            SerializationInfo info = new SerializationInfo(type, converter);
            StreamingContext context = new StreamingContext();

            HsqlDataSourceException testSubject = new HsqlDataSourceException("foo", -1, "42001");

            testSubject.GetObjectData(info, context);

            Console.WriteLine("Member Count: {0}", info.MemberCount);

            foreach(SerializationEntry item in info)
            {
                Console.WriteLine("Name: {0},  Type: {1},  Value: {2}", item.Name, item.ObjectType, item.Value);

                if (item.Name == "m_code")
                {
                    Assert.AreEqual(-1, item.Value);
                }
                else if (item.Name == "m_state")
                {
                    Assert.AreEqual("42001", item.Value);
                }
                else if (item.Name == "Message")
                {
                    Assert.AreEqual("foo", item.Value);
                }
            }

            //Assert.Fail("TODO");
        }
	// 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();
			}
	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();
			}
Example #4
0
        public CrySerializer()
        {
            Converter = new FormatterConverter();
            ObjectReferences = new Dictionary<int, ObjectReference>();

            #if !UNIT_TESTING
            var debugCVar = CVar.Get("mono_realtimeScriptingDebug");
            if (debugCVar != null)
                IsDebugModeEnabled = (debugCVar.IVal != 0);
            #endif
        }
        public virtual void GetObjectData()
        {
            int[] expected = new int[] { 1, 1, 2, 1 };
            Type type = typeof(HsqlBatchUpdateException);
            FormatterConverter converter = new FormatterConverter();
            SerializationInfo info = new SerializationInfo(type, converter);
            StreamingContext context = new StreamingContext();
            HsqlBatchUpdateException exception = new HsqlBatchUpdateException(expected);

            exception.GetObjectData(info, context);

            int[] actual = (int[]) info.GetValue("UpdateCounts", typeof(int[]));

            Assert.AreEqual(expected.Length, actual.Length);

            for (int i = 0; i < actual.Length; i++)
            {
                Assert.AreEqual(expected[i], actual[i]);
            }
        }
        private void HQueue()
        {
            var item = Q.Dequeue();
            IFormatterConverter converter = new FormatterConverter();
               var method = FindMethodForDataService(item);
            while (locked){}

            if (method.RequiresLock)
                locked = true;
            item.Compile().Invoke();
            locked = false;
        }
 /// <summary>
 /// Uses the <see cref="T:PropertyInfo" /> setter to set the value of of the context object's member data.
 /// </summary>
 /// <param name="pi">The field to set the value in.</param>
 /// <param name="value">The value that will be set.</param>
 /// <exception cref="T:Ikarii.Lib.Data.Alpaca.MappingException">This exception is thrown if 
 /// <see cref="T:System.Runtime.Serialization.FormatterConverter"/> is unable to set 
 /// <paramref name="pi"/> with <paramref name="value"/>.</exception>
 internal void SetMappedValue( PropertyInfo pi, object value )
 {
     if( value != null )
                                         {
                                                         try
                                                         {
                                                                         if( value.GetType() == pi.PropertyType || value.GetType().BaseType == pi.PropertyType )
                                                                         {
                                                                                         pi.SetValue( this.Instance, value, null );
                                                                         }
                                                                         else if( pi.PropertyType == typeof( System.Guid ) )
                                                                         {
                                                                                         pi.SetValue( this.Instance, new Guid( value.ToString() ), null );
                                                                         }
                                                                         else if( pi.PropertyType.IsGenericType && ( pi.PropertyType.GetGenericTypeDefinition().Equals( typeof( Nullable<> ) ) ||
                 pi.PropertyType.GetGenericTypeDefinition().Equals( typeof( Trackable<> ) ) ) )
                                                                         {
                                                                                         Type generic = pi.PropertyType.GetGenericArguments()[ 0 ];
                                                                                         pi.SetValue( this.Instance, Convert.ChangeType( value, generic ), null );
                                                                         }
                                                                         else if( Utility.ImplementsInterface( pi.PropertyType, typeof( System.Collections.ICollection ) ) )
                                                                         {
                                                                                         pi.SetValue( this.Instance, value, null );
                                                                         }
                                                                         else
                                                                         {
                                                                                         try
                                                                                         {
                                                                                                         FormatterConverter fc = new FormatterConverter();
                                                                                                         Type valuetype = pi.PropertyType;
                                                                                                         object v = fc.Convert( value, valuetype );
                                                                                                         pi.SetValue( this.Instance, v, null );
                                                                                         }
                                                                                         catch( Exception e )
                                                                                         {
                                                                                                         throw new MappingException(
                                                                                                             String.Format( System.Globalization.CultureInfo.InvariantCulture,
                                                                                                                 @"There was difficulty setting the field named {0} in {1}.
                         The field's return type is {2} and the value's type was {3}. {2} cannot be converted to {3}. ",
                                                                                                                 pi.Name, pi.DeclaringType, pi.PropertyType, value.GetType() ), e );
                                                                                         }
                                                                         }
                                                         }
                                                         catch( Exception e )
                                                         {
                                                                         throw new MappingException(
                                                                                         String.Format( System.Globalization.CultureInfo.InvariantCulture,
                                                                                                         @"Unable to set member {0} with value {1} in {2}.",
                                                                                                         pi.Name, value.ToString(), pi.DeclaringType.Name ), e );
                                                         }
                                         }
 }
 public void Default(object defaultValue)
 {
     var formatterConverter = new FormatterConverter();
     mapping.@default = defaultValue == null ? "null" : formatterConverter.ToString(defaultValue);
 }
	public TypeInfo(DeserializationContext context, String name, String[] fieldNames,
	                BinaryTypeTag[] tt, TypeSpecification[] ts, Assembly assembly) 
	{
        mConverter = context.Formatter.converter;
		mFieldNames = fieldNames;
		mTypeTag = tt;
		mTypeSpec = ts;

		// lookup our type in the right assembly
		if(assembly == null) 
		{
			mObjectType = Type.GetType(name, true);
		} 
		else 
		{
			mObjectType = assembly.GetType(name, true);
		}

		if(typeof(ISerializable).IsAssignableFrom(mObjectType))
        {
            mIsIserializable = true;
        }
        else
        {
            mIsIserializable = false;

		    // lookup all members once
	    	mMembers = new MemberInfo[NumMembers];
    		for(int i = 0; i < NumMembers; i++) 
		    {
	    		// ms and mono have their values for boxed primitive types called 'm_value', we need a fix for that
    			if(mObjectType.IsPrimitive && (mFieldNames[i] == "m_value")) 
			    {
		    		mFieldNames[i] = "value_";
	    		}
    			else if (mObjectType == typeof(DateTime) && 
			    			(mFieldNames[i] == "ticks")) 
		    	{
	    			// this is for DateTime
    				mFieldNames[i] = "value_";
			    } 
		    	else if (mObjectType == typeof(TimeSpan) && 
	    					(mFieldNames[i] == "_ticks")) 
    			{
		    		// this is for TimeSpan
	    			mFieldNames[i] = "value_";
    			} 
			    else if (mObjectType == typeof(Decimal)) 
		    	{
	    			switch(mFieldNames[i]) 
    				{
				    	case "hi":
			    		{
		    				mFieldNames[i] = "high";
	    				}
    					break;
					    case "lo":
				    	{
			    			mFieldNames[i] = "low";
		    			}
	    				break;
    					case "mid":
					    {
				    		mFieldNames[i] = "middle";
			    		}
		    			break;
	    			}
    			}

		    	Type memberType;
	    		String memberName;
    			int classSeparator = mFieldNames[i].IndexOf('+');
			    if(classSeparator != -1) 
		    	{
	    			/*
    				*  TODO: check if there are constraints in which assembly 
				    *  the Type may be looked up! for now just look it up 
			    	*  generally
		    		*/
	    			String baseName = mFieldNames[i].Substring(0, classSeparator);
    				memberName = mFieldNames[i].Substring(classSeparator+1, mFieldNames[i].Length-classSeparator-1);
    				memberType = mObjectType;

	    			// MS does NOT store the FullQualifiedTypename if there 
    				// is no collision but only the Typename :-(
				    while(!memberType.FullName.EndsWith(baseName)) 
			    	{
		    			// check if we reached System.Object
	    				if(memberType == memberType.BaseType || memberType == null) 
    					{
						    // TODO : I18n
					    	throw new SerializationException("Can't find member "+mFieldNames[i]);
				    	}
			    		memberType = memberType.BaseType;
		    		}
	    		} 
    			else 
			    {
		    		memberType = mObjectType;
	    			memberName = mFieldNames[i];
    			}

	    		// get member from object
    			MemberInfo[] members = memberType.GetMember(memberName, 
				    							MemberTypes.Field | 
			    								MemberTypes.Property, 
		    									BindingFlags.Instance | 
	    										BindingFlags.Public | 
    											BindingFlags.NonPublic);

		    	if((members == null) || (members.Length < 1)) 
	    		{
    				// TODO: I18n
			    	throw new SerializationException("Can't find member "+mFieldNames[i]);
		    	} 
	    		else 
    			{
			    	mMembers[i] = members[0];
		    	}
	    	}
    	}
	}
Example #10
0
		public MainWindow() {
			int		X;
			int		Y;
			CursorInfo	ci;

			ClientSize = new System.Drawing.Size (max_labels_row * size_of_label, (((num_of_cursors + (max_labels_row - (num_of_cursors % max_labels_row))) * size_of_label) / (max_labels_row * size_of_label)) * size_of_label);
			Text = "SWF Cursor Test App";

			labels = new Label[num_of_cursors];

			ci = new CursorInfo();
			for (int i = 0; i < num_of_cursors; i++) {
				GetCursor(i, out ci);

				labels[i] = new Label();
				labels[i].Location = new Point((i * size_of_label) % (max_labels_row * size_of_label), ((i * size_of_label) / (max_labels_row * size_of_label)) * size_of_label);
				labels[i].Size = new Size(size_of_label, size_of_label);
				labels[i].Text = ci.name;
				labels[i].BackColor = Color.FromArgb(i * 9, i * 9, i * 9);
				labels[i].ForeColor = Color.Red;
				labels[i].Cursor = ci.cursor;
				labels[i].Paint += new PaintEventHandler(MainWindow_Paint);
				this.Controls.Add(labels[i]);

			}

			// Get the GetDataObject method
			SerializationInfo	si;
			FormatterConverter	fc;

			fc = new FormatterConverter();
			si = new SerializationInfo(typeof(Cursor), fc);
			((ISerializable)ci.cursor).GetObjectData(si, new StreamingContext(StreamingContextStates.All));

			Console.WriteLine("Member count: {0}", si.MemberCount);

			Console.WriteLine("Members: {0}", si.MemberCount);
			SerializationInfoEnumerator e;
			e = si.GetEnumerator();
			while (e.MoveNext()) {
				Console.WriteLine("Member {0}", e.Name);
			}

			byte [] data = (byte [])si.GetValue ("CursorData", typeof (byte []));
			Console.WriteLine("CursorData:");
			for (int i = 0; i < data.Length; i++) {
				Console.Write("{0:X2}, ", data[i]);
			}
			Console.WriteLine("");

			Console.WriteLine("Result: {0}", si.ToString());
				
			//ci.cursor.I

			KeyDown += new KeyEventHandler(MainWindow_KeyDown);
		}		
Example #11
0
		/// <summary>
		/// Serializes an object, or graph of objects with the given root to the provided stream.
		/// </summary>
		/// <param name="serializationStream">
		/// The stream where the formatter puts the serialized data. This stream can reference a variety
		/// of backing stores (such as files, network, memory, and so on).
		/// </param>
		/// <param name="graph">
		/// The object, or root of the object graph, to serialize. All child objects of this root object
		/// are automatically serialized.
		/// </param>
		/// <exception cref="T:System.ArgumentNullException">The <para>serializationStream</para> cannot be null.</exception>
		/// <exception cref="T:System.ArgumentNullException">The <para>graph</para> cannot be null.</exception>
		public void Serialize(Stream serializationStream, object graph)
		{
			if (null == serializationStream)
				throw new ArgumentNullException("serializationStream", "Stream serializationStream cannot be null.");

			if (null == graph)
				throw new ArgumentNullException("graph", "Object graph cannot be null.");

			XmlWriter xmlWriter = null; 
			try {
				xmlWriter = XmlWriter.Create(serializationStream, this.createXmlWriterSettings());
				
				this.registeredReferenceObjects.Clear();
				this.idGenerator = new ObjectIDGenerator();

                IFormatterConverter converter = new FormatterConverter();
                SerializationEntry graphEntry = this.createSerializationEntry(this.getName(graph.GetType()), graph, converter);
                this.serializeEntry(xmlWriter, graphEntry, converter);
				xmlWriter.WriteWhitespace(Environment.NewLine);
			}
			finally {
				if (null != xmlWriter)
					xmlWriter.Flush();
			}
		}
Example #12
0
		/// <summary>
		/// Deserializes the data on the provided stream and reconstitutes the graph of objects.
		/// </summary>
		/// <param name="serializationStream">The stream that contains the data to deserialize.</param>
		/// <returns>The top object of the deserialized graph.</returns>
		/// <exception cref="T:System.ArgumentNullException">The <para>serializationStream</para> cannot be null.</exception>
		public object Deserialize(Stream serializationStream)
		{
			if (null == serializationStream)
				throw new ArgumentNullException("serializationStream", "The Stream serializationStream cannot be null.");

			long initialStreamPosition = serializationStream.Position;
			XmlReader xmlReader = null;
			try {
				xmlReader = XmlReader.Create(serializationStream, this.createXmlReaderSettings());

				if (!xmlReader.IsStartElement())
					throw new SerializationException("Root element is missing.");

				this.registeredReferenceObjects.Clear();

				IFormatterConverter converter = new FormatterConverter();
				SerializationEntry graphEntry = this.deserialize(xmlReader, converter);

				return graphEntry.Value;
			}
			finally {
				if (null != xmlReader) {
					serializationStream.Position = this.getStreamPosition(xmlReader, serializationStream, initialStreamPosition);
					xmlReader.Close();
				}
			}
		}
Example #13
0
        /// <summary>
        /// Creates an object instance based on the specified object definition.
        /// </summary>
        /// <param name="objectDefinition">The definition of the object to create.</param>
        /// <returns>An instance based on the specified object definition.</returns>
        private static object GetObject(ObjectDefinition objectDefinition)
        {
            object instance = null;
            FormatterConverter formatterConverter = new FormatterConverter();

            if (objectDefinition.ConstructorParameters.Count > 0)
            {
                ConstructorInfo[] constructors = objectDefinition.Type.GetConstructors(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
                foreach (ConstructorInfo constructorInfo in constructors)
                {
                    ParameterInfo[] constructorParameters = constructorInfo.GetParameters();
                    if (constructorParameters.Length == objectDefinition.ConstructorParameters.Count)
                    {
                        bool match = true;
                        for (int i = 0; i < constructorParameters.Length; i++)
                        {
                            if (objectDefinition.ConstructorParameters[i] is ObjectDefinition)
                            {
                                ObjectDefinition constructorParameterDefinition = (ObjectDefinition) objectDefinition.ConstructorParameters[i];
                                if (constructorParameters[i].ParameterType != constructorParameterDefinition.Type)
                                {
                                    match = false;
                                    break;
                                }
                            }
                            else if (constructorParameters[i].ParameterType != objectDefinition.ConstructorParameters[i].GetType())
                            {
                                match = false;
                                break;
                            }
                        }

                        if (match)
                        {
                            List<object> parameters = new List<object>();
                            for (int i = 0; i < objectDefinition.ConstructorParameters.Count; i++)
                            {
                                object parameter = objectDefinition.ConstructorParameters[i];
                                if (parameter is ObjectDefinition)
                                {
                                    ObjectDefinition parameterDefinition = (ObjectDefinition) parameter;
                                    parameters.Add(GetObject(parameterDefinition));
                                }
                                else
                                {
                                    parameter = formatterConverter.Convert(parameter, constructorParameters[i].ParameterType);
                                    parameters.Add(parameter);
                                }
                            }

                            instance = constructorInfo.Invoke(parameters.ToArray());
                            break;
                        }
                    }
                }
            }
            else
            {
                instance = Activator.CreateInstance(objectDefinition.Type);
            }

            if (instance == null)
            {
                throw new ArgumentException("A match could not be found for the specified ObjectDefinition [" + objectDefinition.Id + "].  Please verify the class definition and the configured constructor information.");
            }
            else
            {
                if (objectDefinition.Properties.Count > 0)
                {
                    foreach (PropertyInfo propertyInfo in objectDefinition.Type.GetProperties())
                    {
                        object propertyValue = objectDefinition.Properties[propertyInfo.Name];
                        if (propertyValue != null)
                        {
                            if (propertyValue is ObjectDefinition)
                            {
                                propertyValue = GetObject(propertyValue as ObjectDefinition);
                            }
                            propertyInfo.SetValue(instance, formatterConverter.Convert(propertyValue, propertyInfo.PropertyType), null);
                        }
                    }
                }

                return instance;
            }
        }