Exemplo n.º 1
0
 private void ConvertSFSObject(IAWArray fieldList, object csObj, Type objType)
 {
     for (int i = 0; i < fieldList.Size(); i++)
     {
         IAWObject     sFSObject = fieldList.GetAWObject(i);
         string        utfString = sFSObject.GetUtfString(DefaultAWDataSerializer.FIELD_NAME_KEY);
         AWDataWrapper data      = sFSObject.GetData(DefaultAWDataSerializer.FIELD_VALUE_KEY);
         object        value     = this.UnwrapField(data);
         FieldInfo     field     = objType.GetField(utfString, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
         if (field != null)
         {
             field.SetValue(csObj, value);
         }
     }
 }
Exemplo n.º 2
0
        public void HandleHandShake(BaseEvent evt)
        {
            IAWObject iAWObject = evt.Params["message"] as IAWObject;

            if (iAWObject.IsNull(BaseRequest.KEY_ERROR_CODE))
            {
                this.sessionToken = iAWObject.GetUtfString(HandshakeRequest.KEY_SESSION_TOKEN);
                this.bitSwarm.CompressionThreshold = iAWObject.GetInt(HandshakeRequest.KEY_COMPRESSION_THRESHOLD);
                this.bitSwarm.MaxMessageSize       = iAWObject.GetInt(HandshakeRequest.KEY_MAX_MESSAGE_SIZE);
                if (this.debug)
                {
                    this.log.Debug(new string[]
                    {
                        string.Format("Handshake response: tk => {0}, ct => {1}", this.sessionToken, this.bitSwarm.CompressionThreshold)
                    });
                }
                if (this.bitSwarm.IsReconnecting)
                {
                    this.bitSwarm.IsReconnecting = false;
                    this.DispatchEvent(new AWEvent(AWEvent.CONNECTION_RESUME));
                }
                else
                {
                    this.isConnecting = false;
                    Hashtable hashtable = new Hashtable();
                    hashtable["success"] = true;
                    this.DispatchEvent(new AWEvent(AWEvent.CONNECTION, hashtable));
                }
            }
            else
            {
                short     @short       = iAWObject.GetShort(BaseRequest.KEY_ERROR_CODE);
                string    errorMessage = AWErrorCodes.GetErrorMessage((int)@short, this.log, iAWObject.GetUtfStringArray(BaseRequest.KEY_ERROR_PARAMS));
                Hashtable hashtable2   = new Hashtable();
                hashtable2["success"]      = false;
                hashtable2["errorMessage"] = errorMessage;
                hashtable2["errorCode"]    = @short;
                this.DispatchEvent(new AWEvent(AWEvent.CONNECTION, hashtable2));
            }
        }
Exemplo n.º 3
0
        public object Sfs2Cs(IAWObject sfsObj)
        {
            if (!sfsObj.ContainsKey(DefaultAWDataSerializer.CLASS_MARKER_KEY) || !sfsObj.ContainsKey(DefaultAWDataSerializer.CLASS_FIELDS_KEY))
            {
                throw new AWCodecError("The AWObject passed does not represent any serialized class.");
            }
            string utfString = sfsObj.GetUtfString(DefaultAWDataSerializer.CLASS_MARKER_KEY);
            Type   type;

            if (DefaultAWDataSerializer.runningAssembly == null)
            {
                type = Type.GetType(utfString);
            }
            else
            {
                type = DefaultAWDataSerializer.runningAssembly.GetType(utfString);
            }
            if (type == null)
            {
                throw new AWCodecError("Cannot find type: " + utfString);
            }
            object obj = Activator.CreateInstance(type);

            if (!(obj is SerializableAWType))
            {
                throw new AWCodecError(string.Concat(new object[]
                {
                    "Cannot deserialize object: ",
                    obj,
                    ", type: ",
                    utfString,
                    " -- It doesn't implement the SerializableAWType interface"
                }));
            }
            this.ConvertSFSObject(sfsObj.GetSFSArray(DefaultAWDataSerializer.CLASS_FIELDS_KEY), obj, type);
            return(obj);
        }