Example #1
0
        public void write( object obj, IProtocolFormatter writer )
        {
            int refId = -1;
            ReferenceCache referenceCache = null;

            if( isReferenceable )
            {
                referenceCache = writer.GetReferenceCache();
                refId = referenceCache.GetStringId( obj );
            }

            if( refId != -1 )
            {
                writer.WriteStringReference( refId );
            }
            else
            {
                if( isReferenceable )
                    referenceCache.AddString( obj );

                //formatter.getContextWriter().write( obj, formatter );
                if( obj is string )
                    writer.WriteString( (string) obj );
                else if( obj is StringBuilder )
                    writer.WriteString( ((StringBuilder) obj).ToString() );
                else if( obj is Char )
                    writer.WriteString( obj.ToString() );
                else if( obj is char[] )
                    writer.WriteString( new String( (char[]) obj ) );
            }
        }
Example #2
0
        public override void write(object obj, IProtocolFormatter writer)
        {
            Array array = (Array)obj;

            int[] coord = new int[array.Rank];
            serialize(coord, 0, array, writer);
        }
Example #3
0
        public override void write(object obj, IProtocolFormatter writer)
        {
            //If obj is float Convert.ToDouble( obj ) adds extra numbers
            double d = obj is float?double.Parse(obj.ToString()) : Convert.ToDouble(obj);

            writer.WriteDouble(d);
        }
Example #4
0
        public override void write(object obj, IProtocolFormatter writer)
        {
            Enum enumeration = (Enum)obj;
            Type undertype   = Enum.GetUnderlyingType(enumeration.GetType());

            MessageWriter.writeObject(Enum.GetName(obj.GetType(), Convert.ChangeType(enumeration, undertype, CultureInfo.InvariantCulture)), writer);;
        }
Example #5
0
        public void WriteObject(string className, IDictionary objectFields, IProtocolFormatter writer)
        {
            if (objectFields.Contains("serializeAsArrayMap"))
            {
                objectFields.Remove("serializeAsArrayMap");
                WriteObjectMap(objectFields, writer);
                return;
            }

            if (className != null)
            {
                writer.BeginWriteNamedObject(className, objectFields.Count);
            }
            else
            {
                //writer.BeginWriteObjectMap( objectFields.Count );
                writer.BeginWriteObject(objectFields.Count);
            }

            IEnumerator en = objectFields.Keys.GetEnumerator();

            while (en.MoveNext())
            {
                object fieldName = en.Current;

                if (Log.isLogging(LoggingConstants.SERIALIZATION))
                {
                    Log.log(LoggingConstants.SERIALIZATION, "serializing property/field : " + fieldName);
                }

                writer.WriteFieldName(fieldName.ToString());
                writer.BeginWriteFieldValue();

                try
                {
                    MessageWriter.writeObject(objectFields[fieldName], writer);
                }
                catch (Exception exception)
                {
                    if (Log.isLogging(LoggingConstants.ERROR))
                    {
                        Log.log(LoggingConstants.ERROR, "unable to serialize object's field " + fieldName, exception);
                    }
                }
                finally
                {
                    writer.EndWriteFieldValue();
                }
            }

            if (className != null)
            {
                writer.EndWriteNamedObject();
            }
            else
            {
                //writer.EndWriteObjectMap();
                writer.EndWriteObject();
            }
        }
Example #6
0
        public override void write( object obj, IProtocolFormatter writer )
		{
			Header header = (Header) obj;
            writer.DirectWriteString( header.headerName );
            writer.DirectWriteBoolean( header.mustUnderstand );
            writer.DirectWriteInt( -1 );
			MessageWriter.writeObject( header.headerValue, writer );
		}
Example #7
0
    public override void write( object obj, IProtocolFormatter writer )
    {
      BackendlessUser user = (BackendlessUser) obj;

      Dictionary<string, object> props = user.Properties;
      props.Add( "___class", "Users" );
      MessageWriter.writeObject( props, writer );
    }
Example #8
0
        public override void write(object obj, IProtocolFormatter writer)
        {
            Header header = (Header)obj;

            writer.DirectWriteString(header.headerName);
            writer.DirectWriteBoolean(header.mustUnderstand);
            writer.DirectWriteInt(-1);
            MessageWriter.writeObject(header.headerValue, writer);
        }
Example #9
0
    public override void write( object obj, IProtocolFormatter formatter )
      {
#if FULL_BUILD
      // write object and try to cache output if applicable
      Cache.WriteAndSave( ( (BodyHolder)obj ).body, formatter );
#else
      MessageWriter.writeObject( ((BodyHolder) obj).body, formatter );
#endif
      }
        public override void write( object obj, IProtocolFormatter writer )
		{
            //IDictionary propertyBag = (IDictionary) obj;
            IDictionary props = (IDictionary) obj;
            string clientClass = GetClientClass(props);
#if FULL_BUILD
            props = new SortedList(props);
#endif
            writer.GetObjectSerializer().WriteObject( clientClass, props, writer );
		}
Example #11
0
        public override void write(object obj, IProtocolFormatter writer)
        {
            Enum   enumeration     = (Enum)obj;
            Type   undertype       = Enum.GetUnderlyingType(enumeration.GetType());
            Type   enumType        = obj.GetType();
            Object convertedToType = Convert.ChangeType(enumeration, undertype, CultureInfo.InvariantCulture);
            String enumName        = Enum.GetName(enumType, convertedToType);

            MessageWriter.writeObject(enumName, writer);
        }
 public override void write( object obj, IProtocolFormatter formatter )
 {
     ServiceException exception = (ServiceException)obj;
     Dictionary<String, Object> objectFields = new Dictionary<String, Object>();
     objectFields[ "description" ] = exception.description;
     objectFields[ "details" ] = exception.details;
     objectFields[ "type" ] = exception.type;
     objectFields[ "code" ] = exception.code;
     String className = exception.exceptionName;
     formatter.GetObjectSerializer().WriteObject( className, objectFields, formatter );
 }
        public override void write(object obj, IProtocolFormatter writer)
        {
            //IDictionary propertyBag = (IDictionary) obj;
            IDictionary props       = (IDictionary)obj;
            string      clientClass = GetClientClass(props);

#if FULL_BUILD
            props = new SortedList(props);
#endif
            writer.GetObjectSerializer().WriteObject(clientClass, props, writer);
        }
Example #14
0
        public override void write(object obj, IProtocolFormatter formatter)
        {
            ServiceException            exception    = (ServiceException)obj;
            Dictionary <String, Object> objectFields = new Dictionary <String, Object>();

            objectFields["description"] = exception.description;
            objectFields["details"]     = exception.details;
            objectFields["type"]        = exception.type;
            objectFields["code"]        = exception.code;
            String className = exception.exceptionName;

            formatter.GetObjectSerializer().WriteObject(className, objectFields, formatter);
        }
        public override void write( object obj, IProtocolFormatter writer )
        {
            IWebORBArrayCollection collection = (IWebORBArrayCollection) obj;
            List<Object> array = new List<Object>();
            IEnumerator en = collection.GetEnumerator();

            while( en.MoveNext() )
                array.Add( en.Current );

            Dictionary<String, object> fields = new Dictionary<String, object>();
            fields[ "source" ] = array.ToArray();
            writer.GetObjectSerializer().WriteObject( "flex.messaging.io.ArrayCollection", fields, writer );
        }
Example #16
0
        public void write(object obj, IProtocolFormatter formatter)
        {
            ReferenceCache referenceCache = formatter.GetReferenceCache();
            int            refId          = referenceCache.GetObjectId(obj);

            if (refId != -1)
            {
#if FULL_BUILD
                if (VectorUtils.IsVector(obj) && formatter is AmfV3Formatter)
                {
                    Type           collectionType = obj.GetType();
                    AmfV3Formatter amfV3Formatter = (AmfV3Formatter)formatter;

                    if (VectorUtils.isIntType(collectionType))
                    {
                        amfV3Formatter.WriteVarIntWithoutMarker(Datatypes.INT_VECTOR_V3);
                    }
                    else if (VectorUtils.isUIntType(collectionType))
                    {
                        amfV3Formatter.WriteVarIntWithoutMarker(Datatypes.UINT_VECTOR_V3);
                    }
                    else if (VectorUtils.isNumberType(collectionType))
                    {
                        amfV3Formatter.WriteVarIntWithoutMarker(Datatypes.DOUBLE_VECTOR_V3);
                    }
                    else
                    {
                        amfV3Formatter.WriteVarIntWithoutMarker(Datatypes.OBJECT_VECTOR_V3);
                    }

                    amfV3Formatter.WriteVarIntWithoutMarker(refId << 1);
                }
                else
#endif
                if (obj is IWebORBArrayCollection || obj is IDictionary)
                {
                    formatter.WriteObjectReference(refId);
                }
                else if (obj is ICollection || obj is Array || obj is IWebORBArray)
                {
                    formatter.WriteArrayReference(refId);
                }
            }
            else
            {
                referenceCache.AddObject(obj);
                formatter.getContextWriter().write(obj, formatter);
            }
        }
        public void write( object obj, IProtocolFormatter formatter )
        {
            ReferenceCache referenceCache = formatter.GetReferenceCache();
            int refId = referenceCache.GetObjectId( obj );

            if( refId != -1 )
            {
                formatter.WriteObjectReference( refId );
            }
            else
            {
                referenceCache.AddObject( obj );
                formatter.getContextWriter().write( obj, formatter );
            }
        }
Example #18
0
        public void write(object obj, IProtocolFormatter formatter)
        {
            ReferenceCache referenceCache = formatter.GetReferenceCache();
            int            refId          = referenceCache.GetStringId(obj);

            if (refId != -1)
            {
                formatter.WriteStringReference(refId);
            }
            else
            {
                referenceCache.AddString(obj);
                formatter.getContextWriter().write(obj, formatter);
            }
        }
Example #19
0
        public override void write( object obj, IProtocolFormatter writer )
		{
			IDictionary propertyBag = ((AnonymousObject) obj).Properties;
			writer.BeginWriteObject( propertyBag.Count );

			foreach( object key in propertyBag.Keys )
			{
                writer.WriteFieldName( key.ToString() );
                writer.BeginWriteFieldValue();
				MessageWriter.writeObject( propertyBag[ key ], writer );
                writer.EndWriteFieldValue();
			}

            writer.EndWriteObject();
		}
Example #20
0
		public void WriteObject( string className, IDictionary objectFields, IProtocolFormatter writer )
		{
    if ( objectFields.Contains( "serializeAsArrayMap" ) )
      {
      objectFields.Remove( "serializeAsArrayMap" );
      WriteObjectMap( objectFields, writer );
      return;
      }

		  if( className != null )
				writer.BeginWriteNamedObject( className, objectFields.Count );
			else
				//writer.BeginWriteObjectMap( objectFields.Count );
                writer.BeginWriteObject( objectFields.Count );

			IEnumerator en = objectFields.Keys.GetEnumerator();

			while( en.MoveNext() )
			{
				object fieldName = en.Current;

				if( Log.isLogging( LoggingConstants.SERIALIZATION ) )
                    Log.log( LoggingConstants.SERIALIZATION, "serializing property/field : " + fieldName );

				writer.WriteFieldName( fieldName.ToString() );
				writer.BeginWriteFieldValue();

				try
				{
					MessageWriter.writeObject( objectFields[ fieldName ], writer );
				}
				catch( Exception exception )
				{
					if( Log.isLogging( LoggingConstants.ERROR ) )
						Log.log( LoggingConstants.ERROR, "unable to serialize object's field " + fieldName, exception );
				}
				finally
				{
					writer.EndWriteFieldValue();
				}
			}
            
			if( className != null )
				writer.EndWriteNamedObject();
			else
				//writer.EndWriteObjectMap();
                writer.EndWriteObject();
		}
Example #21
0
        private void WriteObjectMap(IDictionary objectFields, IProtocolFormatter writer)
        {
            int maxInt = -1;

            for (int i = 0; i < objectFields.Count; i++)
            {
                if (!objectFields.Contains(i))
                {
                    break;
                }

                maxInt = i;
            }

            writer.BeginWriteObjectMap(maxInt + 1);

            IEnumerator en = objectFields.Keys.GetEnumerator();

            while (en.MoveNext())
            {
                object fieldName = en.Current;

                if (fieldName.Equals("length"))
                {
                    continue;
                }

                if (Log.isLogging(LoggingConstants.SERIALIZATION))
                {
                    Log.log(LoggingConstants.SERIALIZATION, "serializing property/field : " + fieldName);
                }

                writer.WriteFieldName(fieldName.ToString());
                writer.BeginWriteFieldValue();

                MessageWriter.writeObject(objectFields[fieldName], writer);

                writer.EndWriteFieldValue();
            }

            if (maxInt >= 0)
            {
                writer.WriteFieldName("length");
                MessageWriter.writeObject(maxInt + 1, writer);
            }

            writer.EndWriteObjectMap();
        }
Example #22
0
        public override void write(object obj, IProtocolFormatter writer)
        {
            IDictionary propertyBag = ((AnonymousObject)obj).Properties;

            writer.BeginWriteObject(propertyBag.Count);

            foreach (object key in propertyBag.Keys)
            {
                writer.WriteFieldName(key.ToString());
                writer.BeginWriteFieldValue();
                MessageWriter.writeObject(propertyBag[key], writer);
                writer.EndWriteFieldValue();
            }

            writer.EndWriteObject();
        }
        public virtual void write( object obj, IProtocolFormatter formatter )
        {
            ReferenceCache referenceCache = formatter.GetReferenceCache();
            DateTime date = (DateTime) obj;
            int refId = referenceCache.GetObjectId( date.ToUniversalTime() );

            if( refId != -1 )
            {
                formatter.WriteDateReference( refId );
            }
            else
            {
                referenceCache.AddObject( date.ToUniversalTime() );
                formatter.getContextWriter().write( obj, formatter );
            }
        }
        public override void write(object obj, IProtocolFormatter writer)
        {
            IWebORBArrayCollection collection = (IWebORBArrayCollection)obj;
            List <Object>          array      = new List <Object>();
            IEnumerator            en         = collection.GetEnumerator();

            while (en.MoveNext())
            {
                array.Add(en.Current);
            }

            Dictionary <String, object> fields = new Dictionary <String, object>();

            fields["source"] = array.ToArray();
            writer.GetObjectSerializer().WriteObject("flex.messaging.io.ArrayCollection", fields, writer);
        }
Example #25
0
        public virtual void write(object obj, IProtocolFormatter formatter)
        {
            ReferenceCache referenceCache = formatter.GetReferenceCache();
            DateTime       date           = (DateTime)obj;
            int            refId          = referenceCache.GetObjectId(date.ToUniversalTime());

            if (refId != -1)
            {
                formatter.WriteDateReference(refId);
            }
            else
            {
                referenceCache.AddObject(date.ToUniversalTime());
                formatter.getContextWriter().write(obj, formatter);
            }
        }
		private void serialize( int[] coord, int dim, Array array, IProtocolFormatter writer )
		{
			int dimLength = array.GetLength( dim );
            writer.BeginWriteArray( dimLength );

			for( int i = 0; i < dimLength; i++ )
			{
				coord[ dim ] = i;

				if( dim == (array.Rank - 1) )
					MessageWriter.writeObject( array.GetValue( coord ), writer );					
				else
					serialize( coord, dim + 1, array, writer );
			}			

            writer.EndWriteArray();
		}
Example #27
0
        public override void write(object obj, IProtocolFormatter writer)
        {
            Request message = (Request)obj;

            writer.BeginWriteMessage(message);
            writer.WriteMessageVersion((int)message.getVersion());

            Header[] headers = message.getResponseHeaders();
            Body[]   bodies  = message.getResponseBodies();

            writer.DirectWriteShort(headers.Length);

            if (Log.isLogging(LoggingConstants.DEBUG))
            {
                Log.log(LoggingConstants.DEBUG, "got headers " + headers.Length);
                Log.log(LoggingConstants.DEBUG, "got bodies " + bodies.Length);
                Log.log(LoggingConstants.DEBUG, "AMFMessageWriter.write - message version: " + message.getVersion() + " header length: " + headers.Length);
            }

            for (int i = 0; i < headers.Length; i++)
            {
                MessageWriter.writeObject(headers[i], writer);
            }

            writer.DirectWriteShort(bodies.Length);

#if FULL_BUILD
            bool isAMF3 = ThreadContext.currentHttpContext() != null && ThreadContext.currentHttpContext().Items.Contains("v3_request");
#endif

            for (int i = 0; i < bodies.Length; i++)
            {
                // if message is amf0 then body of the message is invocation result and if should be
                // processed via cache managment
#if FULL_BUILD
                if (!isAMF3)
                {
                    Cache.WriteAndSave(bodies[i], writer);
                }
                else
#endif
                MessageWriter.writeObject(bodies[i], writer);
            }

            writer.EndWriteMessage();
        }
Example #28
0
    protected override void onWriteObject( object obj, string className, IDictionary objectFields, IProtocolFormatter writer )
    {
      IDictionary<string, object> underflowData = UnderflowStore.GetObjectUnderflow( obj );

      if( underflowData != null )
      {
        int lastIndex = className.LastIndexOf( '.' );

        if( lastIndex > -1 )
          className = className.Substring( lastIndex + 1 );

        foreach( string key in underflowData.Keys )
          if( !objectFields.Contains( key ) && underflowData[ key ] != null )
            objectFields[ key ] = underflowData[ key ];
      }

      writer.GetObjectSerializer().WriteObject( className, objectFields, writer );
    }
Example #29
0
		public override void write( object obj, IProtocolFormatter writer )
		{
			//Log.log( ORBConstants.INFO, "AMFBodyWriter.write.begin: " + writer.BaseStream.Length );
			Body body = (Body) obj;

			if( Log.isLogging( LoggingConstants.DEBUG ) )
				Log.log( LoggingConstants.DEBUG, "AMFBodyWriter:write body.responseURI: " + body.responseURI + " body.serviceURI: " + body.serviceURI );

            writer.DirectWriteString( body.ResponseUri == null ? "null" : body.ResponseUri );
            writer.DirectWriteString( body.ServiceUri == null ? "null" : body.ServiceUri );
            writer.DirectWriteInt( -1 );
			//((FlashorbBinaryWriter)writer).WriteInt( i );
			//Log.log( ORBConstants.INFO, "AMFBodyWriter.write.before writing response object: " + writer.BaseStream.Length );
			writer.ResetReferenceCache();
			writer.BeginWriteBodyContent();
			MessageWriter.writeObject( body.responseDataObject, writer );
			writer.EndWriteBodyContent();
			//Log.log( ORBConstants.INFO, "AMFBodyWriter.write.end: " + writer.BaseStream.Length );
		}
Example #30
0
        public override void write( object obj, IProtocolFormatter formatter )
        {
            if( obj is IDictionary )
            {
                ITypeWriter typeWriter = MessageWriter.getWriter( typeof( IDictionary ), formatter, false );
                typeWriter.write( obj, formatter );
                return;
            }

            IEnumerator en = (IEnumerator)obj;
            List<Object> arrayList = new List<Object>();

            while( en.MoveNext() )
                arrayList.Add( en.Current );
            
          object[] array = arrayList.ToArray();
          ITypeWriter writer = MessageWriter.getWriter( array.GetType(), formatter, false );
          writer.write( array, formatter );
        }
Example #31
0
    public override void write( object obj, IProtocolFormatter writer )
      {
      Request message = (Request)obj;
      writer.BeginWriteMessage( message );
      writer.WriteMessageVersion( (int)message.getVersion() );

      Header[] headers = message.getResponseHeaders();
      Body[] bodies = message.getResponseBodies();

      writer.DirectWriteShort( headers.Length );

      if ( Log.isLogging( LoggingConstants.DEBUG ) )
        {
        Log.log( LoggingConstants.DEBUG, "got headers " + headers.Length );
        Log.log( LoggingConstants.DEBUG, "got bodies " + bodies.Length );
        Log.log( LoggingConstants.DEBUG, "AMFMessageWriter.write - message version: " + message.getVersion() + " header length: " + headers.Length );
        }

      for ( int i = 0; i < headers.Length; i++ )
        MessageWriter.writeObject( headers[ i ], writer );

      writer.DirectWriteShort( bodies.Length );

#if FULL_BUILD
      bool isAMF3 = ThreadContext.currentHttpContext() != null && ThreadContext.currentHttpContext().Items.Contains( "v3_request" );
#endif

      for ( int i = 0; i < bodies.Length; i++ )
        {
        // if message is amf0 then body of the message is invocation result and if should be 
        // processed via cache managment
#if FULL_BUILD
        if ( !isAMF3 )
          Cache.WriteAndSave( bodies[ i ], writer );
        else
#endif
          MessageWriter.writeObject( bodies[ i ], writer );
        }

      writer.EndWriteMessage();
      }
Example #32
0
    private void WriteObjectMap( IDictionary objectFields, IProtocolFormatter writer )
      {
      int maxInt = -1;
      for ( int i = 0; i < objectFields.Count; i++ )
        {
        if ( !objectFields.Contains( i ) )
            break;          

        maxInt = i;
        }

      writer.BeginWriteObjectMap( maxInt + 1 );        

      IEnumerator en = objectFields.Keys.GetEnumerator();

      while ( en.MoveNext() )
        {
        object fieldName = en.Current;

        if ( fieldName.Equals( "length" ) )
          continue;

        if ( Log.isLogging( LoggingConstants.SERIALIZATION ) )
          Log.log( LoggingConstants.SERIALIZATION, "serializing property/field : " + fieldName );

          writer.WriteFieldName( fieldName.ToString() );
          writer.BeginWriteFieldValue();

          MessageWriter.writeObject( objectFields[ fieldName ], writer );

          writer.EndWriteFieldValue();          
        }

        if ( maxInt >= 0 )
          {
          writer.WriteFieldName( "length" );
          MessageWriter.writeObject( maxInt + 1, writer );
          }

        writer.EndWriteObjectMap();        
      }
Example #33
0
        public void write(object obj, IProtocolFormatter writer)
        {
            int            refId          = -1;
            ReferenceCache referenceCache = null;

            if (isReferenceable)
            {
                referenceCache = writer.GetReferenceCache();
                refId          = referenceCache.GetStringId(obj);
            }

            if (refId != -1)
            {
                writer.WriteStringReference(refId);
            }
            else
            {
                if (isReferenceable)
                {
                    referenceCache.AddString(obj);
                }

                //formatter.getContextWriter().write( obj, formatter );
                if (obj is string)
                {
                    writer.WriteString((string)obj);
                }
                else if (obj is StringBuilder)
                {
                    writer.WriteString(((StringBuilder)obj).ToString());
                }
                else if (obj is Char)
                {
                    writer.WriteString(obj.ToString());
                }
                else if (obj is char[])
                {
                    writer.WriteString(new String((char[])obj));
                }
            }
        }
    public void write( object obj, IProtocolFormatter formatter )
    {
      ReferenceCache referenceCache = formatter.GetReferenceCache();
      int refId = referenceCache.GetObjectId( obj );

      if( refId != -1 )
      {
#if FULL_BUILD
        if( VectorUtils.IsVector( obj ) && formatter is AmfV3Formatter )
        {
          Type collectionType = obj.GetType();
          AmfV3Formatter amfV3Formatter = (AmfV3Formatter) formatter;

          if( VectorUtils.isIntType( collectionType ) )
            amfV3Formatter.WriteVarIntWithoutMarker( Datatypes.INT_VECTOR_V3 );
          else if( VectorUtils.isUIntType( collectionType ) )
            amfV3Formatter.WriteVarIntWithoutMarker( Datatypes.UINT_VECTOR_V3 );
          else if( VectorUtils.isNumberType( collectionType ) )
            amfV3Formatter.WriteVarIntWithoutMarker( Datatypes.DOUBLE_VECTOR_V3 );
          else
            amfV3Formatter.WriteVarIntWithoutMarker( Datatypes.OBJECT_VECTOR_V3 );

          amfV3Formatter.WriteVarIntWithoutMarker( refId << 1 );
        }
        else 
#endif
        if( obj is IWebORBArrayCollection || obj is IDictionary )
        {
          formatter.WriteObjectReference( refId );
        }
        else if( obj is ICollection || obj is Array || obj is IWebORBArray )
        {
          formatter.WriteArrayReference( refId );
        }
      }
      else
      {
        referenceCache.AddObject( obj );
        formatter.getContextWriter().write( obj, formatter );
      }
    }
Example #35
0
        public override void write(object obj, IProtocolFormatter writer)
        {
            //Log.log( ORBConstants.INFO, "AMFBodyWriter.write.begin: " + writer.BaseStream.Length );
            Body body = (Body)obj;

            if (Log.isLogging(LoggingConstants.DEBUG))
            {
                Log.log(LoggingConstants.DEBUG, "AMFBodyWriter:write body.responseURI: " + body.responseURI + " body.serviceURI: " + body.serviceURI);
            }

            writer.DirectWriteString(body.ResponseUri == null ? "null" : body.ResponseUri);
            writer.DirectWriteString(body.ServiceUri == null ? "null" : body.ServiceUri);
            writer.DirectWriteInt(-1);
            //((FlashorbBinaryWriter)writer).WriteInt( i );
            //Log.log( ORBConstants.INFO, "AMFBodyWriter.write.before writing response object: " + writer.BaseStream.Length );
            writer.ResetReferenceCache();
            writer.BeginWriteBodyContent();
            MessageWriter.writeObject(body.responseDataObject, writer);
            writer.EndWriteBodyContent();
            //Log.log( ORBConstants.INFO, "AMFBodyWriter.write.end: " + writer.BaseStream.Length );
        }
Example #36
0
        private void serialize(int[] coord, int dim, Array array, IProtocolFormatter writer)
        {
            int dimLength = array.GetLength(dim);

            writer.BeginWriteArray(dimLength);

            for (int i = 0; i < dimLength; i++)
            {
                coord[dim] = i;

                if (dim == (array.Rank - 1))
                {
                    MessageWriter.writeObject(array.GetValue(coord), writer);
                }
                else
                {
                    serialize(coord, dim + 1, array, writer);
                }
            }

            writer.EndWriteArray();
        }
Example #37
0
        public override void write(object obj, IProtocolFormatter formatter)
        {
            if (obj is IDictionary)
            {
                ITypeWriter typeWriter = MessageWriter.getWriter(typeof(IDictionary), formatter, false);
                typeWriter.write(obj, formatter);
                return;
            }

            IEnumerator   en        = (IEnumerator)obj;
            List <Object> arrayList = new List <Object>();

            while (en.MoveNext())
            {
                arrayList.Add(en.Current);
            }

            object[]    array  = arrayList.ToArray();
            ITypeWriter writer = MessageWriter.getWriter(array.GetType(), formatter, false);

            writer.write(array, formatter);
        }
Example #38
0
    protected override void onWriteObject( object obj, string className, IDictionary objectFields, IProtocolFormatter writer )
    {
      IDictionary<string, object> underflowData = UnderflowStore.GetObjectUnderflow( obj );

      if( underflowData != null )
      {
        int lastIndex = className.LastIndexOf( '.' );

        if( lastIndex > -1 )
          className = className.Substring( lastIndex + 1 );

        foreach( string key in underflowData.Keys )
          if( !objectFields.Contains( key ) && underflowData[ key ] != null )
            objectFields[ key ] = underflowData[ key ];
      }

      if( !className.StartsWith( "flex.messaging.messages" ) && !className.StartsWith( "com.backendless" ) )
      {
        if( objectFields.Contains( "___class" ) )
          className = (String) objectFields[ "___class" ];
        else
        {
          int dotIndex = className.LastIndexOf( '+' );

          if( dotIndex == -1 )
            dotIndex = className.LastIndexOf( '.' );

          if( dotIndex > -1 )
            className = className.Substring( dotIndex + 1 );

          objectFields.Add( "___class", className );
        }

        className = null;
      }

      writer.GetObjectSerializer().WriteObject( className, objectFields, writer );
    }
Example #39
0
        public override void write( object obj, IProtocolFormatter formatter )
		{
			TypedObject typedObject = (TypedObject) obj;
			formatter.GetObjectSerializer().WriteObject( typedObject.typeName, typedObject.objectData, formatter );
		}
Example #40
0
 public abstract void write(object obj, IProtocolFormatter writer);
    public void WriteObject( string className, IDictionary objectFields, IProtocolFormatter writer )
    {
      IEnumerator en = objectFields.Keys.GetEnumerator();
      V3ReferenceCache cache = (V3ReferenceCache) writer.GetReferenceCache();
      String traitsClassId = className;

      if( traitsClassId == null )
      {
        StringBuilder sb = new StringBuilder();

        while( en.MoveNext() )
        {
          sb.Append( en.Current.ToString() );
          sb.Append( "-" );
        }

        traitsClassId = sb.ToString();
        en.Reset();
      }

      if( cache.HasTraits( traitsClassId ) )
      {
        writer.DirectWriteBytes( new byte[] { (byte) Datatypes.OBJECT_DATATYPE_V3 } );
        int traitId = (int) cache.GetTraitsId( traitsClassId );
        byte[] bytes = FlashorbBinaryWriter.GetVarIntBytes( 0x1 | traitId << 2 );
        writer.DirectWriteBytes( bytes );
      }
      else
      {
        writer.BeginWriteNamedObject( className, objectFields.Count );

        if( className == null )
          cache.AddToTraitsCache( traitsClassId );

        while( en.MoveNext() )
        {
          string fieldName = en.Current.ToString();

          if( Log.isLogging( LoggingConstants.DEBUG ) )
            Log.log( LoggingConstants.DEBUG, "serializing property/field : " + fieldName );

          writer.WriteFieldName( fieldName );
        }

        en.Reset();
      }

      while( en.MoveNext() )
      {
        Object fieldName = en.Current;

        if( Log.isLogging( LoggingConstants.DEBUG ) )
          Log.log( LoggingConstants.DEBUG, "serializing property/field : " + fieldName );

        //writer.BeginWriteFieldValue();

        //try
        //{
        //MessageWriter.writeObject( objectFields[ fieldName ], writer );
        //Log.log( "REFCACHE", "WRITING FIELD " + fieldName );
        object obj = objectFields[ fieldName ];
        ITypeWriter typeWriter = MessageWriter.getWriter( obj, writer );
        typeWriter.write( obj, writer );
        //Log.log( "REFCACHE", "DONE WRITING FIELD " + fieldName );
        //}
        //catch( Exception exception )
        //{
        //	if( Log.isLogging( LoggingConstants.ERROR ) )
        //		Log.log( LoggingConstants.ERROR, "unable to serialize object's field " + fieldName, exception );
        //}
        //finally
        //{
        //	writer.EndWriteFieldValue();
        //}
      }

      writer.EndWriteNamedObject();
    }
Example #42
0
        public override void write( object obj, IProtocolFormatter writer )
		{
            writer.WriteNull();
		}
Example #43
0
 public override void write( object obj, IProtocolFormatter formatter )
 {
     TimeSpan ts = (TimeSpan) obj;
     MessageWriter.writeObject( ts.TotalMilliseconds, formatter );
 }
Example #44
0
        public override void write(object obj, IProtocolFormatter writer)
        {
            //Log.log( ORBConstants.INFO, "ObjectWriter.write.begin: " + writer.BaseStream.Length );
#if (FULL_BUILD)
            if (obj is IRemote)
            {
                remoteReferenceWriter.write(RemoteReferenceObject.createReference(obj), writer);
                return;
            }

            SerializationConfigHandler serializationConfig = (SerializationConfigHandler)ORBConfig.GetInstance().GetConfig("weborb/serialization");

            if (!configured)
            {
                //serializePrivate = ThreadContext.getORBConfig().serializePrivateFields;

                if (serializationConfig != null)
                {
                    serializePrivate = serializationConfig.SerializePrivateFields;
                }

                configured = true;
            }
#endif
            Type objectClass = obj.GetType();

            /*
             * if( obj is IAutoUpdate )
             * {
             *  //if( Weborb.Util.License.LicenseManager.GetInstance().IsStandardLicense() && !NetUtils.RequestIsLocal( ThreadContext.currentRequest() ) )
             *  //    throw new Exception( "auto-update is disabled, this feature is available in WebORB Professional Edition" );
             *
             *  string id = Guid.NewGuid().ToString();
             *  objectFields[ "_orbid_" ] = id;
             *  ThreadContext.currentHttpContext().Cache.Insert( id, new AutoUpdateObjectWrapper( ((IAutoUpdate) obj).GetUpdateHandler(), obj ) );
             * }
             */

            ClassDefinition classDef;

            cachedClassDefs.TryGetValue(objectClass, out classDef);
            Dictionary <String, Object> objectFields = new Dictionary <String, Object>();

            if (classDef == null)
            {
                string className = objectClass.IsGenericType && objectClass.FullName != null
                             ? objectClass.FullName.Substring(0, objectClass.FullName.IndexOf("`"))
                             : objectClass.FullName;

                string clientSideMapping = GetClientClass(className);

                if (clientSideMapping != null)
                {
                    // if( Log.isLogging( LoggingConstants.DEBUG ) )
                    //    Log.log( LoggingConstants.DEBUG, "serializing a named object with client side mapping " + clientSideMapping );

                    className = clientSideMapping;
                }
                // Commented out this code in 4.0.0.4. This code does not make sense anymore
                // For one these mappings exist between ServiceNames (or Destination names) and
                // classes. A service class should not be serialized back to the client.
                // If it is serialized, user should use class mapping for that.
                //else
                //{
                //    className = ServiceRegistry.GetReverseMapping( className );

                //    if( Log.isLogging( LoggingConstants.DEBUG ) )
                //        Log.log( LoggingConstants.DEBUG, "serializing object " + className );
                //}

                classDef = getClassDefinition(className, obj);
                lock (_sync)
                {
                    cachedClassDefs[objectClass] = classDef;
                }

                // TODO: remove this try/catch
                //try
                //{
                //cachedClassDefs[ objectClass ] = classDef;
                // }
                //catch ( Exception e )
                // {
                //if ( Log.isLogging( LoggingConstants.ERROR ) )
                //  Log.log( LoggingConstants.ERROR, e );
                //System.Diagnostics.Debugger.Launch();
                //}
            }
            else
            {
                if (Log.isLogging(LoggingConstants.DEBUG))
                {
                    Log.log(LoggingConstants.DEBUG, "serializing using cached Class Def " + classDef.ClassName);
                }
            }

            Dictionary <string, MemberInfo> members = classDef.Members;

            foreach (KeyValuePair <string, MemberInfo> member in members)
            {
                Object val = null;

                if (member.Value is PropertyInfo)
                {
                    try
                    {
                        val = ((PropertyInfo)member.Value).GetValue(obj, null);
                    }
                    catch (Exception exception)
                    {
                        if (Log.isLogging(LoggingConstants.ERROR))
                        {
                            Log.log(LoggingConstants.ERROR, "Unable to retrieve property/field value from an instance of " + classDef.ClassName + ". Value will be set to null. Property name is " + member.Value.Name);
                        }

                        if (Log.isLogging(LoggingConstants.EXCEPTION))
                        {
                            Log.log(LoggingConstants.EXCEPTION, exception);
                        }
                    }
                }
                else
                {
                    val = ((FieldInfo)member.Value).GetValue(obj);
                }

                String memberName = member.Key;

#if (FULL_BUILD)
                if (serializationConfig != null && serializationConfig.Keywords.Contains(memberName))
                {
                    memberName = serializationConfig.PrefixForKeywords + memberName;
                }
#endif

                objectFields[memberName] = val;
            }

            onWriteObject(obj, classDef.ClassName, objectFields, writer);
        }
Example #45
0
 public override void write( object obj, IProtocolFormatter writer )
 {
   //If obj is float Convert.ToDouble( obj ) adds extra numbers
   double d = obj is float ? double.Parse( obj.ToString() ) : Convert.ToDouble( obj );
   writer.WriteDouble(d);
 }
Example #46
0
    internal static ITypeWriter getWriter( object obj, IProtocolFormatter formatter )
      {
      if ( obj == null || obj is DBNull )
        return nullWriter;

      Type objectType = obj.GetType();
      ITypeWriter writer = formatter.getCachedWriter( objectType );

      if ( writer == null )
        {
        // none of the interfaces matched a writer.
        // perform a lookup for the object class hierarchy
        writer = getWriter( objectType, formatter, true );

        if ( writer == null )
          {
          if ( typeof( IEnumerable ).IsInstanceOfType( obj ) )
            {
            writer = enumerableWriter;
            }
          else
            {
            if ( logSer )
              Log.log( LoggingConstants.SERIALIZATION, "cannot find a writer for the object, will use default writer - " + defaultWriter );

            writer = defaultWriter;
            }
          }

        formatter.addCachedWriter( objectType, writer );
        }

      ITypeWriter referenceWriter = writer.getReferenceWriter();

      if ( referenceWriter != null )
        {
        // if the return object implements IHTTPSessionObject
        // keep it in the http session. The same object will be retrieved
        // on the subsequent invocations
#if (FULL_BUILD)
        if ( obj is IHttpSessionObject )
          {
          IHttpSessionObject httpSessionObject = (IHttpSessionObject)obj;
          string id = httpSessionObject.getID();
          object objectInSession = httpSessionObject.getObject();

          if ( Log.isLogging( LoggingConstants.DEBUG ) )
            Log.log( LoggingConstants.DEBUG, "placing object into HTTP session. ID - " + id + " object " + obj );

          //TODO: check for acuracy of Add method here
          HttpSessionState session = (HttpSessionState)ThreadContext.currentSession();

          if ( session != null )
            session.Add( id, objectInSession );
          }
#endif

        formatter.setContextWriter( writer );
        writer = referenceWriter;
        }

      // if a writer is found, use it, otherwise use the default writer
      return writer;
      }
Example #47
0
    /*
    public static Object writeObject( object obj )
    {
        ITypeWriter writer = getWriter( obj );
        return writer.write( obj );
    }
     */

    public static void writeObject( object obj, IProtocolFormatter formatter )
      {
      ITypeWriter typeWriter = getWriter( obj, formatter );
      typeWriter.write( obj, formatter );
      }
Example #48
0
        internal static ITypeWriter getWriter(object obj, IProtocolFormatter formatter)
        {
            if (obj == null || obj is DBNull)
            {
                return(nullWriter);
            }

            Type        objectType = obj.GetType();
            ITypeWriter writer     = formatter.getCachedWriter(objectType);

            if (writer == null)
            {
                // none of the interfaces matched a writer.
                // perform a lookup for the object class hierarchy
                writer = getWriter(objectType, formatter, true);

                if (writer == null)
                {
                    if (typeof(IEnumerable).IsInstanceOfType(obj))
                    {
                        writer = enumerableWriter;
                    }
                    else
                    {
                        if (logSer)
                        {
                            Log.log(LoggingConstants.SERIALIZATION, "cannot find a writer for the object, will use default writer - " + defaultWriter);
                        }

                        writer = defaultWriter;
                    }
                }

                formatter.addCachedWriter(objectType, writer);
            }

            ITypeWriter referenceWriter = writer.getReferenceWriter();

            if (referenceWriter != null)
            {
                // if the return object implements IHTTPSessionObject
                // keep it in the http session. The same object will be retrieved
                // on the subsequent invocations
#if (FULL_BUILD)
                if (obj is IHttpSessionObject)
                {
                    IHttpSessionObject httpSessionObject = (IHttpSessionObject)obj;
                    string             id = httpSessionObject.getID();
                    object             objectInSession = httpSessionObject.getObject();

                    if (Log.isLogging(LoggingConstants.DEBUG))
                    {
                        Log.log(LoggingConstants.DEBUG, "placing object into HTTP session. ID - " + id + " object " + obj);
                    }

                    //TODO: check for acuracy of Add method here
                    HttpSessionState session = (HttpSessionState)ThreadContext.currentSession();

                    if (session != null)
                    {
                        session.Add(id, objectInSession);
                    }
                }
#endif

                formatter.setContextWriter(writer);
                writer = referenceWriter;
            }

            // if a writer is found, use it, otherwise use the default writer
            return(writer);
        }
Example #49
0
    internal static ITypeWriter getWriter( Type type, IProtocolFormatter formatter, bool checkInterfaces )
      {
      // class can be null only when we traverse class hierarchy.
      // when we get to the ver root of it, the superclass is null.
      // return null here, so the outer code can use a default writer
      if ( type == null )
        return null;

      // perform the lookup. Let protocol formatter do the check for any
      // protocol specific type bindings
      ITypeWriter writer = null;

      if ( formatter != null )
        writer = formatter.getWriter( type );

      // check against the additional lookup table (this will override main table)
      if ( writer == null )
        additionalWriters.TryGetValue( type, out writer );

      // check against the main lookup table
      if ( writer == null )
        writers.TryGetValue( type, out writer );

      // if we have a writer - use it
      if ( writer != null )
        return writer;

      if ( type.IsArray )
        {
        if ( logSer )
          Log.log( LoggingConstants.SERIALIZATION, "object is an array returning ArrayWriter" );

        return arrayWriter;
        }
      else if ( typeof( Enum ).IsAssignableFrom( type ) )
        {
        if ( logSer )
          Log.log( LoggingConstants.SERIALIZATION, "object is an enumeration type" );

        return enumWriter;
        }

      if ( checkInterfaces )
        writer = matchInterfaces( type.GetInterfaces() );

      if ( writer != null )
        {
        if ( logSer )
          Log.log( LoggingConstants.SERIALIZATION, "found a writer for an interface - " + writer );

        return writer;
        }

      // go to the super class as the last resort
      return getWriter( type.BaseType, formatter, true );
      }
Example #50
0
    public void write( object obj, IProtocolFormatter writer )
    {
      ITypeWriter typeWriter;

      if ( obj is IDictionary )
      {
        typeWriter = MessageWriter.getWriter( typeof( IDictionary ), writer, false );
        typeWriter.write( obj, writer );
        return;
      }

      /*
if( obj is Array )
{
  base.write( obj, writer );
  return;
}*/

      object[] array = null;

#if( FULL_BUILD)
      

      if ( VectorUtils.IsVector( obj ) )
      {
        Type objectType = obj.GetType();
        Type elementType = objectType.GetGenericArguments()[0];
        Type vectorType = typeof( V3VectorWriter<> ).MakeGenericType( elementType );
        typeWriter = (ITypeWriter)vectorType.GetConstructor( new Type[0] ).Invoke( new object[0] );
        typeWriter.write( obj, writer );
        return;
      }

      if ( obj is ICollection )
      {
        ICollection coll = (ICollection) obj;
        SerializationConfigHandler serializationConfig = (SerializationConfigHandler) ORBConfig.GetInstance().GetConfig( "weborb/serialization" );
        
        if ( !serializationConfig.LegacyCollectionSerialization && !(obj is IWebORBArray ) )
        {
          typeWriter = MessageWriter.getWriter( typeof( IWebORBArrayCollection ), writer, false );
          typeWriter.write( new WebORBArrayCollection( coll ), writer );
          return;
        }
        else
        {
          array = new object[ coll.Count ];
          coll.CopyTo( array, 0 );
        }
      }
      else
      {
#endif
        IEnumerable collection = (IEnumerable) obj;
        IEnumerator enumerator = collection.GetEnumerator();
        List<Object> arrayList = new List<Object>();

        while ( enumerator.MoveNext() )
          arrayList.Add( enumerator.Current );

        array = arrayList.ToArray();
#if( FULL_BUILD)
      }
#endif

      typeWriter = MessageWriter.getWriter( array.GetType(), writer, false );
      typeWriter.write( array, writer );
      //base.write( array, writer );
    }
Example #51
0
 public override void write(object obj, IProtocolFormatter writer)
 {
     writer.WriteNull();
 }
Example #52
0
        public override void write(object obj, IProtocolFormatter formatter)
        {
            TimeSpan ts = (TimeSpan)obj;

            MessageWriter.writeObject(ts.TotalMilliseconds, formatter);
        }
Example #53
0
 public override void write(object obj, IProtocolFormatter writer)
 {
     writer.WriteDouble((double)((NumberObject)obj).adapt(typeof(double)));
 }
 public abstract void write( object obj, IProtocolFormatter writer );
Example #55
0
 public override void write(object obj, IProtocolFormatter formatter)
 {
     MessageWriter.writeObject(((Guid)obj).ToString(), formatter);
 }
Example #56
0
        public void write(object obj, IProtocolFormatter writer)
        {
            ITypeWriter typeWriter;

            if (obj is IDictionary)
            {
                typeWriter = MessageWriter.getWriter(typeof(IDictionary), writer, false);
                typeWriter.write(obj, writer);
                return;
            }

            /*
             * if( obj is Array )
             * {
             * base.write( obj, writer );
             * return;
             * }*/

            object[] array = null;

#if (FULL_BUILD)
            if (VectorUtils.IsVector(obj))
            {
                Type objectType  = obj.GetType();
                Type elementType = objectType.GetGenericArguments()[0];
                Type vectorType  = typeof(V3VectorWriter <>).MakeGenericType(elementType);
                typeWriter = (ITypeWriter)vectorType.GetConstructor(new Type[0]).Invoke(new object[0]);
                typeWriter.write(obj, writer);
                return;
            }

            if (obj is ICollection)
            {
                ICollection coll = (ICollection)obj;
                SerializationConfigHandler serializationConfig = (SerializationConfigHandler)ORBConfig.GetInstance().GetConfig("weborb/serialization");

                if (!serializationConfig.LegacyCollectionSerialization && !(obj is IWebORBArray))
                {
                    typeWriter = MessageWriter.getWriter(typeof(IWebORBArrayCollection), writer, false);
                    typeWriter.write(new WebORBArrayCollection(coll), writer);
                    return;
                }
                else
                {
                    array = new object[coll.Count];
                    coll.CopyTo(array, 0);
                }
            }
            else
            {
#endif
            IEnumerable collection  = (IEnumerable)obj;
            IEnumerator enumerator  = collection.GetEnumerator();
            List <Object> arrayList = new List <Object>();

            while (enumerator.MoveNext())
            {
                arrayList.Add(enumerator.Current);
            }

            array = arrayList.ToArray();
#if (FULL_BUILD)
        }
#endif

            typeWriter = MessageWriter.getWriter(array.GetType(), writer, false);
            typeWriter.write(array, writer);
            //base.write( array, writer );
        }
Example #57
0
 public override void write( object obj, IProtocolFormatter formatter )
 {
     Type type = (Type) obj;
     MessageWriter.writeObject( type.FullName, formatter );
 }
Example #58
0
        /*
         * public static Object writeObject( object obj )
         * {
         *  ITypeWriter writer = getWriter( obj );
         *  return writer.write( obj );
         * }
         */

        public static void writeObject(object obj, IProtocolFormatter formatter)
        {
            ITypeWriter typeWriter = getWriter(obj, formatter);

            typeWriter.write(obj, formatter);
        }
Example #59
0
        internal static ITypeWriter getWriter(Type type, IProtocolFormatter formatter, bool checkInterfaces)
        {
            // class can be null only when we traverse class hierarchy.
            // when we get to the ver root of it, the superclass is null.
            // return null here, so the outer code can use a default writer
            if (type == null)
            {
                return(null);
            }

            // perform the lookup. Let protocol formatter do the check for any
            // protocol specific type bindings
            ITypeWriter writer = null;

            if (formatter != null)
            {
                writer = formatter.getWriter(type);
            }

            // check against the additional lookup table (this will override main table)
            if (writer == null)
            {
                additionalWriters.TryGetValue(type, out writer);
            }

            // check against the main lookup table
            if (writer == null)
            {
                writers.TryGetValue(type, out writer);
            }

            // if we have a writer - use it
            if (writer != null)
            {
                return(writer);
            }

            if (type.IsArray)
            {
                if (logSer)
                {
                    Log.log(LoggingConstants.SERIALIZATION, "object is an array returning ArrayWriter");
                }

                return(arrayWriter);
            }
            else if (typeof(Enum).IsAssignableFrom(type))
            {
                if (logSer)
                {
                    Log.log(LoggingConstants.SERIALIZATION, "object is an enumeration type");
                }

                return(enumWriter);
            }

            if (checkInterfaces)
            {
                writer = matchInterfaces(type.GetInterfaces());
            }

            if (writer != null)
            {
                if (logSer)
                {
                    Log.log(LoggingConstants.SERIALIZATION, "found a writer for an interface - " + writer);
                }

                return(writer);
            }

            // go to the super class as the last resort
            return(getWriter(type.BaseType, formatter, true));
        }
Example #60
0
        public override void write(object obj, IProtocolFormatter formatter)
        {
            TypedObject typedObject = (TypedObject)obj;

            formatter.GetObjectSerializer().WriteObject(typedObject.typeName, typedObject.objectData, formatter);
        }