示例#1
0
        protected virtual void HandlePackage(byte[] buffer)
        {
            MemoryStream      ms = new MemoryStream(buffer);
            CytarStreamReader cr = new CytarStreamReader(ms);
            var    cid           = cr.ReadInt32();
            string apiName       = cr.ReadString();

            if (apiName == APIReturnHandlerAPI)
            {
                var returnID = cr.ReadInt32();
                OnAPIReturn(returnID, ms);
                return;
            }
            else if (apiName == ErrorHandlerAPI)
            {
                OnErrorCallback(cid, cr.ReadObject <RemoteException>());
                return;
            }

            try
            {
                var(result, isVoid) = CallAPI(apiName, ms);
                CallRemoteAPI(APIReturnHandlerAPI, cid, result);
            }
            catch (Exception ex)
            {
                CallRemoteAPI(ErrorHandlerAPI, new RemoteException(ex.Message));
            }
        }
示例#2
0
 public static object Deserialize(Type type, byte[] data)
 {
     using (MemoryStream ms = new MemoryStream(data))
         using (CytarStreamReader cr = new CytarStreamReader(ms))
         {
             return(cr.ReadObject(type));
         }
 }
示例#3
0
        public virtual void OnAPIReturn(int cid, Stream returnStream)
        {
            if (!RemoteCallingRecode.ContainsKey(cid))
            {
                return;
            }
            CytarStreamReader cr = new CytarStreamReader(returnStream);

            if (RemoteCallingRecode[cid].ReturnType == typeof(void))
            {
                RemoteCallingRecode[cid].Return(null);
            }
            else
            {
                RemoteCallingRecode[cid].Return(cr.ReadObject(RemoteCallingRecode[cid].ReturnType));
            }
            RemoteCallingRecode.Remove(cid);
        }
示例#4
0
        public virtual (object, bool) CallAPI(string apiName, Stream stream)
        {
            var api              = GetAPI(apiName);
            var paramsList       = new List <object>();
            CytarStreamReader cr = new CytarStreamReader(stream);

            foreach (var paramType in api.Parameters)
            {
                if (paramType.IsSubclassOf(typeof(Session)))
                {
                    paramsList.Add(this);
                }
                else
                {
                    paramsList.Add(cr.ReadObject(paramType));
                }
            }
            return(api.Method.Invoke(api.APIContext, paramsList.ToArray()), api.Method.ReturnType == typeof(void));
        }