예제 #1
0
        internal void AddAsyncCallBack(AsyncCalls asyncalls, long id)
        {
            if (CallBackDiy == null)
            {
                CallBackDiy = new ConcurrentDictionary <long, AsyncCalls>();
            }

            CallBackDiy.AddOrUpdate(id, asyncalls, (a, b) => asyncalls);
        }
예제 #2
0
파일: CloudClient.cs 프로젝트: kk3959/ZYNet
 public void Close()
 {
     IsClose = true;
     AsyncWaitTimeOut.Clear();
     ClientManager.Close();
     Module.ModuleDiy.Clear();
     AsyncRunDiy.Clear();
     CallBackDiy.Clear();
     AsyncCallDiy.Clear();
     SyncWaitDic.Clear();
     FodyDir.Clear();
     Container.Dispose();
 }
예제 #3
0
        private void SetReturnValue(ReturnResult result)
        {
            long idx = result.Id;

            if (CallBackDiy.ContainsKey(idx))
            {
                AsyncCalls call;

                if (CallBackDiy.TryRemove(result.Id, out call))
                {
                    try
                    {
                        call.SetRet(result);
                    }
                    catch (Exception er)
                    {
                        LogAction.Log(LogType.Err, "CMD:" + call.Cmd + " ERROR:\r\n" + er.Message);
                    }
                }
            }
            else if (AsyncRunDiy.ContainsKey(idx))
            {
                AsyncRun call;

                if (AsyncRunDiy.TryRemove(result.Id, out call))
                {
                    try
                    {
                        call.SetRet(result);
                    }
                    catch (Exception er)
                    {
                        LogAction.Log(LogType.Err, "AsynRun ID:" + result.Id + " ERROR:\r\n" + er.Message);
                    }
                }
            }
            else if (SyncWaitDic.ContainsKey(idx))
            {
                ReturnEventWaitHandle wait;

                if (SyncWaitDic.TryRemove(result.Id, out wait))
                {
                    wait.Set(result);
                }
            }
            else
            {
                throw new InvalidOperationException("not call the Id");
            }
        }
예제 #4
0
        internal void Disconnect(string message)
        {
            if (AsyncCallDiy != null)
            {
                AsyncCallDiy.Clear();
            }
            if (CallBackDiy != null)
            {
                CallBackDiy.Clear();
            }

            if (UserDisconnect != null)
            {
                UserDisconnect(this, message);
            }
        }
예제 #5
0
파일: CloudClient.cs 프로젝트: kk3959/ZYNet
        private void SetReturnValue(Result result)
        {
            long idx = result.Id;

            if (CallBackDiy.ContainsKey(idx))
            {
                if (CallBackDiy.TryRemove(result.Id, out AsyncCalls call))
                {
                    try
                    {
                        call.SetRes(result);
                    }
                    catch (Exception er)
                    {
                        if (PushException(new SetResultException(er.Message, (int)ErrorTag.SetErr, er)))
                        {
                            Log.Error($"CMD:{call.Cmd} ERROR:\r\n{er.Message}");
                        }
                    }
                }
            }
            else if (AsyncRunDiy.ContainsKey(idx))
            {
                if (AsyncRunDiy.TryRemove(result.Id, out AsyncRun call))
                {
                    try
                    {
                        call.SetRet(result);
                    }
                    catch (Exception er)
                    {
                        if (PushException(new SetResultException(er.Message, (int)ErrorTag.SetErr, er)))
                        {
                            Log.Error($"AsynRun ID:{result.Id} ERROR:\r\n{er.Message}");
                        }
                    }
                }
            }
            else if (SyncWaitDic.ContainsKey(idx))
            {
                if (SyncWaitDic.TryRemove(result.Id, out ReturnEventWaitHandle wait))
                {
                    wait.Set(result);
                }
            }
        }
예제 #6
0
파일: CloudClient.cs 프로젝트: kk3959/ZYNet
 internal void AddAsyncCallBack(AsyncCalls asyncalls, long id)
 {
     CallBackDiy.AddOrUpdate(id, asyncalls, (a, b) => asyncalls);
 }
예제 #7
0
        public void DataOn(byte[] data)
        {
            ReadBytes read = null;

            if (CurrentServer.DecodeingHandler != null)
            {
                read = new ReadBytes(data, 4, -1, CurrentServer.DecodeingHandler);
            }
            else
            {
                read = new ReadBytes(data);
            }

            int cmd;
            int length;

            if (read.ReadInt32(out length) && read.ReadInt32(out cmd) && read.Length == length)
            {
                switch (cmd)
                {
                case CmdDef.CallCmd:
                {
                    CallPack tmp;

                    if (read.ReadObject <CallPack>(out tmp))
                    {
                        try
                        {
                            CallPackRun(tmp);
                        }
                        catch (Exception er)
                        {
                            LogAction.Log(LogType.Err, "CMD:" + tmp.CmdTag + "\r\n" + er.ToString());
                        }
                    }
                }
                break;

                case CmdDef.ReturnResult:
                {
                    ReturnResult result;

                    if (read.ReadObject <ReturnResult>(out result))
                    {
                        if (CallBackDiy.ContainsKey(result.Id))
                        {
                            AsyncCalls call;

                            if (CallBackDiy.TryRemove(result.Id, out call))
                            {
                                try
                                {
                                    call.SetRet(result);
                                }
                                catch (Exception er)
                                {
                                    LogAction.Log(LogType.Err, "Cmd:" + call.Cmd + " Error:\r\n" + er.ToString());
                                }
                            }
                        }
                    }
                }
                break;
                }
            }
        }