Пример #1
0
		public IAdaptingType read( FlashorbBinaryReader reader, ParseContext parseContext )
		{
			int refId = reader.ReadVarInteger();

			if( (refId & 0x1) == 0 )
				return (DateType) parseContext.getReference( refId >> 1 );

			double dateTime = reader.ReadDouble();

            DateTime sent = new DateTime( 1970, 1, 1, 0, 0, 0, DateTimeKind.Utc );

            try
            {
                sent = sent.AddMilliseconds(dateTime).ToLocalTime();
            }
            catch(Exception e)
            {
                if (Log.isLogging(LoggingConstants.EXCEPTION))
                    Log.log(LoggingConstants.EXCEPTION, e);

                sent = DateTime.MinValue;
            }

			DateType dateType = new DateType( sent );
			parseContext.addReference( dateType );
			return dateType;
		}
Пример #2
0
		public IAdaptingType read( FlashorbBinaryReader reader, ParseContext parseContext )
		{
            double dateTime = reader.ReadDouble();
            // ignore the stupid timezone
            reader.ReadUnsignedShort();

            DateTime sent = new DateTime( 1970, 1, 1 );

#if (FULL_BUILD || PURE_CLIENT_LIB )
            // get the offset of the time zone the server is in
            double localTimezoneOffset = TimeZone.CurrentTimeZone.GetUtcOffset( sent ).TotalMilliseconds;
            // convert 1/1/1970 12AM to UTC
            sent = TimeZone.CurrentTimeZone.ToUniversalTime( sent );
#else
            double localTimezoneOffset = TimeZoneInfo.Local.GetUtcOffset( sent ).TotalMilliseconds;
            sent = TimeZoneInfo.ConvertTime( sent, TimeZoneInfo.Utc );
#endif
            
            // bring it back to 12AM
            sent = sent.AddMilliseconds( localTimezoneOffset );

            // now that the sent object is in UTC and it represents 1/1/1970 12AM
            // convert it to the time sent by the client. The result of the operation
            // is going to be client's datetime object in UTC
            sent = sent.AddMilliseconds( dateTime );

            return new DateType( sent );
		}	
Пример #3
0
        public int ReadInt16(FlashorbBinaryReader reader)
        {
            int byte1 = this.BaseStream.ReadByte();
            int byte2 = this.BaseStream.ReadByte();

            return((byte2 << 8) + byte2);
        }
Пример #4
0
        public static object FromBytes( byte[] bytes, int type, bool doNotAdapt )
        {
#if( !SILVERLIGHT && !PURE_CLIENT_LIB && !WINDOWS_PHONE8)
            if( type == AMF0 || type == AMF3 )
            {
#endif
            using ( MemoryStream stream = new MemoryStream( bytes ) )
                {
                    using( FlashorbBinaryReader reader = new FlashorbBinaryReader( stream ) )
                    {
                        IAdaptingType adpatingType = Weborb.Protocols.Amf.RequestParser.readData( reader, type == AMF0 ? 0 : 3 );

                        if( doNotAdapt )
                            return adpatingType;
                        else
                            return adpatingType.defaultAdapt();
                    }
                }
#if( !SILVERLIGHT && !PURE_CLIENT_LIB && !WINDOWS_PHONE8)
           }
            else
            {
                using( MemoryStream stream = new MemoryStream( bytes ) )
                {
                    Weborb.Protocols.Wolf.RequestParser parser = Weborb.Protocols.Wolf.RequestParser.GetInstance();
                    Request requestObj = parser.Parse( stream );
                    return requestObj.getRequestBodyData();
                }
            }
#endif
        }
Пример #5
0
        public static object FromBytes(byte[] bytes, int type, bool doNotAdapt)
        {
            switch (type)
            {
            case AMF0:
            case AMF3:
                using (MemoryStream stream = new MemoryStream(bytes))
                {
                    using (FlashorbBinaryReader reader = new FlashorbBinaryReader(stream))
                    {
                        IAdaptingType adpatingType = Weborb.Protocols.Amf.RequestParser.readData(reader, type == AMF0 ? 0 : 3);

                        if (doNotAdapt)
                        {
                            return(adpatingType);
                        }
                        else
                        {
                            return(adpatingType.defaultAdapt());
                        }
                    }
                }

            case JSON:
                using (MemoryStream stream = new MemoryStream(bytes))
                {
                    StreamReader streamReader = new StreamReader(stream, Encoding.UTF8);

                    using (JsonTextReader jsonReader = new JsonTextReader(streamReader))
                    {
                        jsonReader.Read();
                        IAdaptingType jsonType = Weborb.Protocols.JsonRPC.RequestParser.Read(jsonReader);

                        if (doNotAdapt)
                        {
                            return(jsonType);
                        }
                        else
                        {
                            return(jsonType.defaultAdapt());
                        }
                    }
                }

#if (!UNIVERSALW8 && !SILVERLIGHT && !PURE_CLIENT_LIB && !WINDOWS_PHONE8)
            case WOLF:

                using (MemoryStream stream = new MemoryStream(bytes))
                {
                    Weborb.Protocols.Wolf.RequestParser parser = Weborb.Protocols.Wolf.RequestParser.GetInstance();
                    Request requestObj = parser.Parse(stream);
                    return(requestObj.getRequestBodyData());
                }
                break;
#endif
            default:
                throw new Exception("Unknown formatting type");
            }
        }
Пример #6
0
 public object readExternal( FlashorbBinaryReader reader, ParseContext context )
 {
   ArrayType arrayType = (ArrayType) RequestParser.readData( reader, context );
   object array = arrayType.defaultAdapt();
   Object[] arrayCopy = new Object[ ((ICollection) array).Count ];
   ((ICollection) array).CopyTo( arrayCopy, 0 );
   return new ArrayCollectionType( arrayCopy, arrayType );
   //return new WebORBArrayCollection( (ICollection) array );
 }
Пример #7
0
		public IAdaptingType read( FlashorbBinaryReader reader, ParseContext parseContext )
		{
			int length = reader.ReadInteger();
			IAdaptingType[] array = new IAdaptingType[ length ];
			ArrayType arrayType = new ArrayType( array );
			parseContext.addReference( arrayType );

			for( int i = 0; i < length; i++ )
				array[ i ] = RequestParser.readData( reader, parseContext );

			return arrayType;
		}
Пример #8
0
		public IAdaptingType read( FlashorbBinaryReader reader, ParseContext parseContext )
		{
			int refId = reader.ReadVarInteger();

			if( (refId & 0x1) == 0 )
				return parseContext.getReference( refId >> 1 );

			int arraySize = refId >> 1;
			IAdaptingType adaptingType = null;
			object container = null;

			while( true )
			{
				string str = ReaderUtils.readString( reader, parseContext );

				if( str == null || str.Length == 0 )
					break;

				if( container == null )
				{
					container = new Dictionary<object, object>();
					adaptingType = new AnonymousObject( (IDictionary) container );
					parseContext.addReference( adaptingType );
				}

				object obj = RequestParser.readData( reader, parseContext );
				((IDictionary) container)[ str ] = obj;
			}

			if( adaptingType == null )
			{
				container = new object[ arraySize ];
				adaptingType = new ArrayType( (object[]) container );
				parseContext.addReference( adaptingType );

				for( int i = 0; i < arraySize; i++ )
					((object[]) container)[ i ] = RequestParser.readData( reader, parseContext );
			}
			else
			{
				for( int i = 0; i < arraySize; i++ )
				{
					object obj = RequestParser.readData( reader, parseContext );
					((IDictionary) container)[ i.ToString() ] = obj;
				}
			}

			return adaptingType;
		}
Пример #9
0
		public static string readString( FlashorbBinaryReader reader, ParseContext parseContext )
		{
			int len = reader.ReadVarInteger();

			if( (len & 0x1) == 0 )
				return (string) parseContext.getStringReference( len >> 1 );

			string str = reader.ReadUTF( len >> 1 );

			if( str.Length == 0 )
				return str;

			parseContext.addStringReference( str );
			return str;
		}
Пример #10
0
		public IAdaptingType read( FlashorbBinaryReader reader, ParseContext parseContext )
		{
			int refId = reader.ReadVarInteger();

			if( (refId & 0x1) == 0 )
				return (ArrayType) parseContext.getReference( refId >> 1 );

			byte[] bytes = reader.ReadBytes( refId >> 1 );
            IAdaptingType[] objArray = new IAdaptingType[bytes.Length];

            for (int i = 0; i < bytes.Length; i++)
                objArray[i] = new NumberObject( bytes[i] );

			ArrayType arrayType = new ArrayType( objArray );
			parseContext.addReference( arrayType );
			return arrayType;
		}
Пример #11
0
		public IAdaptingType read( FlashorbBinaryReader reader, ParseContext parseContext )
		{
			//int capacity = reader.ReadInt32();
            int capacity = reader.ReadInteger();
            Dictionary<String, Object> properties = new Dictionary<String, Object>( capacity );
			AnonymousObject anonymousObject = new AnonymousObject( properties );
			parseContext.addReference( anonymousObject );

			while( true )
			{
				String propName = reader.ReadUTF();
				object obj =  RequestParser.readData( reader, parseContext );

				if( obj == null )
					break;

				properties[ propName ] = obj;
			}

			return anonymousObject;
		}
Пример #12
0
        public static object DeserializeFromBytes(byte[] bytes, bool doNotAdapt, int serializationType)
        {
            MemoryStream ms = new MemoryStream(bytes);
            FlashorbBinaryReader reader = new FlashorbBinaryReader(ms);

            try
            {
                IAdaptingType type;
                
                switch(serializationType)
                {
#if (!SILVERLIGHT && !PURE_CLIENT_LIB && !WINDOWS_PHONE8)
                    case WOLF:
                        type = (IAdaptingType)Weborb.Protocols.Wolf.RequestParser.GetInstance().Parse(ms).getRequestBodyData();
                        break;
#endif
                    case AMF3:
                    case AMF0:
                    default:
                        type = Weborb.Protocols.Amf.RequestParser.readData(reader, 3);
                        break;
                }


                if (type != null)
                {
                    if (!doNotAdapt)
                        return type.defaultAdapt();
                    else
                        return type;
                }
                else
                    return null;
            }
            catch
            {
                return null;
            }
        }
Пример #13
0
        public static object FromBytes(byte[] bytes, int type, bool doNotAdapt)
        {
#if (!UNIVERSALW8 && !SILVERLIGHT && !PURE_CLIENT_LIB && !WINDOWS_PHONE8)
            if (type == AMF0 || type == AMF3)
            {
#endif
            using (MemoryStream stream = new MemoryStream(bytes))
            {
                using (FlashorbBinaryReader reader = new FlashorbBinaryReader(stream))
                {
                    IAdaptingType adpatingType = Weborb.Protocols.Amf.RequestParser.readData(reader, type == AMF0 ? 0 : 3);

                    if (doNotAdapt)
                    {
                        return(adpatingType);
                    }
                    else
                    {
                        return(adpatingType.defaultAdapt());
                    }
                }
            }
#if (!UNIVERSALW8 && !SILVERLIGHT && !PURE_CLIENT_LIB && !WINDOWS_PHONE8)
        }

        else
        {
            using (MemoryStream stream = new MemoryStream(bytes))
            {
                Weborb.Protocols.Wolf.RequestParser parser = Weborb.Protocols.Wolf.RequestParser.GetInstance();
                Request requestObj = parser.Parse(stream);
                return(requestObj.getRequestBodyData());
            }
        }
#endif
        }
Пример #14
0
		public IAdaptingType read( FlashorbBinaryReader reader, ParseContext parseContext )
		{
			return RequestParser.readData( reader, parseContext.getVersion() == 3 ? parseContext : parseContext.getCachedContext( 3 ) );
		}
Пример #15
0
		private ClassInfo getClassInfo( int refId, FlashorbBinaryReader reader, ParseContext parseContext )
		{
			if( (refId & 0x3) == 1 )
				return (ClassInfo) parseContext.getClassInfoReference( refId >> 2 );

			ClassInfo classInfo = new ClassInfo();
            classInfo.externalizable = (refId & 0x4) == 4; 
			classInfo.looseProps = (refId & 0x8) == 8;			
			classInfo.className = ReaderUtils.readString( reader, parseContext );
			int propsCount = refId >> 4;

			for( int i = 0; i < propsCount; i++ )
				classInfo.addProperty( ReaderUtils.readString( reader, parseContext ) );

			parseContext.addClassInfoReference( classInfo );
			return classInfo;
		}
Пример #16
0
		public IAdaptingType read( FlashorbBinaryReader reader, ParseContext parseContext )
		{
			int refId = reader.ReadVarInteger();

			if( (refId & 0x1) == 0 )
				return (IAdaptingType) parseContext.getReference( refId >> 1 );

			ClassInfo classInfo = getClassInfo( refId, reader, parseContext );

		  Type mappedType = null;
      if ( !string.IsNullOrEmpty( classInfo.className ) ) 
        mappedType = Types.Types.getServerTypeForClientClass( classInfo.className );

      if ( classInfo.externalizable || typeof( IExternalizable ).IsAssignableFrom( mappedType ) )
            {
                Type type = Types.Types.getServerTypeForClientClass( classInfo.className );
                object extobj = null;

                if( type != null )
                    extobj = ObjectFactories.CreateServiceObject( type );
                else
                    extobj = ObjectFactories.CreateServiceObject( classInfo.className );

                if( !(extobj is IExternalizable) )
                {
                    throw new Exception( "object must implement IExternalizable" );
                }
                else
                {
                    CacheableAdaptingTypeWrapper wrapper = new CacheableAdaptingTypeWrapper();
                    parseContext.addReference( wrapper );

                    IAdaptingType returnValue = null;
                    extobj = ((IExternalizable)extobj).readExternal( reader, parseContext );

                    if( extobj is IAdaptingType )
                        returnValue = (IAdaptingType) extobj;
                    else
                        returnValue = new ConcreteObject( extobj );

                    wrapper.setType( returnValue );
                    return returnValue;
                }
            }
            else 
            {
                Dictionary<String, IAdaptingType> props = new Dictionary<String, IAdaptingType>();
                AnonymousObject anonObj = new AnonymousObject();
                IAdaptingType returnValue = anonObj;

                if( classInfo.className != null && classInfo.className.Length > 0 )
                    returnValue = new NamedObject( classInfo.className, anonObj );

                parseContext.addReference( returnValue );
                int propCount = classInfo.getPropertyCount();

                for( int i = 0; i < propCount; i++ )
                {
                    if( Log.isLogging( LoggingConstants.DEBUG ) )
                        Log.log( LoggingConstants.DEBUG, "reading object property " + classInfo.getProperty( i ) );

                    props[ classInfo.getProperty( i ) ] = RequestParser.readData( reader, parseContext );
                }

                if( classInfo.looseProps )
                    while( true )
                    {
                        string propName = ReaderUtils.readString( reader, parseContext );

                        if( propName == null || propName.Length == 0 )
                            break;

                        props[ propName ] = RequestParser.readData( reader, parseContext );
                    }

                anonObj.Properties = props;
                return returnValue;
            }
		}
Пример #17
0
    private Header readHeader(FlashorbBinaryReader reader)
    {
      int nameLength = reader.ReadUnsignedShort();
      byte[] bytes = reader.ReadBytes(nameLength);
#if (FULL_BUILD)
      string headerName = encoding.GetString(bytes);
#else 
            string headerName = BitConverter.ToString( bytes );
#endif
      bool mustUnderstand = reader.ReadBoolean();
      //int length = reader.ReadInt32();
      int length = reader.ReadInteger();

      if (Log.isLogging(LoggingConstants.DEBUG))
        Log.log(LoggingConstants.DEBUG, "MessageReader::readHeader: name - " + headerName + " mustUnderstand - " + mustUnderstand + " length - " + length);

      return new Header(headerName, mustUnderstand, length, readData(reader));
    }
Пример #18
0
 public static IAdaptingType readData(int dataType, FlashorbBinaryReader reader, ParseContext parseContext)
 {
   return readData(dataType, reader, parseContext, READERS[parseContext.getVersion()]);
 }
Пример #19
0
 public static IAdaptingType readData(FlashorbBinaryReader reader, ParseContext parseContext, ITypeReader[] readers)
 {
   int type = reader.ReadByte();
   return readers[type].read(reader, parseContext);
 }
Пример #20
0
		public IAdaptingType read( FlashorbBinaryReader reader, ParseContext parseContext )
		{
			return new BooleanType( initialized ? val : reader.ReadBoolean() );
		}
Пример #21
0
 public static IAdaptingType readData(int dataType, FlashorbBinaryReader reader, ParseContext parseContext, ITypeReader[] readers)
 {
   return readers[dataType].read(reader, parseContext);
 }
Пример #22
0
		public Weborb.Types.IAdaptingType read( FlashorbBinaryReader reader, ParseContext parseContext )
		{
			return new NumberObject( (reader.ReadVarInteger() << 3) >> 3 );
		}
Пример #23
0
		public IAdaptingType read( FlashorbBinaryReader reader, ParseContext parseContext )
		{
			return undefinedType;
		}
Пример #24
0
 public static IAdaptingType readData(FlashorbBinaryReader reader)
 {
   return readData(reader, new ParseContext(0), V1READERS);
 }
Пример #25
0
    public Request readMessage(Stream input)
    {
      FlashorbBinaryReader reader = new FlashorbBinaryReader(input);

      try
      {
        if (Log.isLogging(LoggingConstants.DEBUG))
          Log.log(LoggingConstants.DEBUG, "MessageReader:: parsing stream");

        int version = reader.ReadUnsignedShort();
        int totalHeaders = reader.ReadUnsignedShort();

        if (Log.isLogging(LoggingConstants.DEBUG))
          Log.log(LoggingConstants.DEBUG, "MessageReader:: parsing message - version: " + version + " totalHeaders: " + totalHeaders);

        Header[] headers = new Header[totalHeaders];

        for (int i = 0; i < totalHeaders; i++)
          headers[i] = readHeader(reader);

        int totalBodyParts = reader.ReadUnsignedShort();

        if (Log.isLogging(LoggingConstants.DEBUG))
          Log.log(LoggingConstants.DEBUG, "MessageReader:: Total body parts: " + totalBodyParts);

        Body[] bodies = new Body[totalBodyParts];

        for (int i = 0; i < totalBodyParts; i++)
          bodies[i] = readBodyPart(reader);

        if (Log.isLogging(LoggingConstants.DEBUG))
          Log.log(LoggingConstants.DEBUG, "MessageReader:: returning AMFMessage");

        Request request = new Request(version, headers, bodies);
        request.SetFormatter(version == 3 ? (IProtocolFormatter)new AmfV3Formatter() : (IProtocolFormatter)new AmfFormatter());
        return request;
      }
      catch (Exception exception)
      {
        if (Log.isLogging(LoggingConstants.EXCEPTION))
          Log.log(LoggingConstants.EXCEPTION, "Exception: " + exception.Message + " StackTrace: " + exception.StackTrace);
        return null;
      }
    }
Пример #26
0
		public int ReadInt16( FlashorbBinaryReader reader )
		{
			int byte1 = this.BaseStream.ReadByte();
			int byte2 = this.BaseStream.ReadByte();
			return ((byte2 << 8) + byte2);
		}
Пример #27
0
    private Body readBodyPart(FlashorbBinaryReader reader)
    {
      int serviceURILength = reader.ReadUnsignedShort();
#if (FULL_BUILD)
      string serviceURI = encoding.GetString(reader.ReadBytes(serviceURILength));
#else
            string serviceURI = BitConverter.ToString( reader.ReadBytes( serviceURILength ) );
#endif
      int responseURILength = reader.ReadUnsignedShort();
#if (FULL_BUILD)
      string responseURI = encoding.GetString(reader.ReadBytes(responseURILength));
#else
            string responseURI = BitConverter.ToString( reader.ReadBytes( responseURILength ) );
#endif
      int length = reader.ReadInteger();

      if (Log.isLogging(LoggingConstants.DEBUG))
        Log.log(LoggingConstants.DEBUG, "MessageReader::readBodyPart: serviceURI - " + serviceURI + " responseURI - " + responseURI + " length: " + length);

      return new Body(serviceURI, responseURI, length, readData(reader));
    }
Пример #28
0
		public Weborb.Types.IAdaptingType read(FlashorbBinaryReader reader, ParseContext parseContext)
		{
			return new NullType();
		}
Пример #29
0
 public static IAdaptingType readData(FlashorbBinaryReader reader, int version)
 {
   return readData(reader, new ParseContext(version), READERS[version]);
 }
Пример #30
0
		public IAdaptingType read( FlashorbBinaryReader reader, ParseContext parseContext )
		{
			return null;
		}
Пример #31
0
 public IAdaptingType read( FlashorbBinaryReader reader, ParseContext parseContext )
 {
   int dataLength = reader.ReadInteger();
   byte[] buffer = reader.ReadBytes( dataLength );
   return new StringType( Encoding.UTF8.GetString( buffer, 0, buffer.Length ) );
 }
Пример #32
0
		public IAdaptingType read( FlashorbBinaryReader reader, ParseContext parseContext )
		{
			int pointer = reader.ReadUnsignedShort();
			return parseContext.getReference( pointer );
		}
Пример #33
0
		public IAdaptingType read( FlashorbBinaryReader reader, ParseContext parseContext )
		{
			double d = reader.ReadDouble();
			return new NumberObject( d );
		}