internal void AddAsyncCallBack(AsyncCalls asyncalls, long id) { if (CallBackDiy == null) { CallBackDiy = new ConcurrentDictionary <long, AsyncCalls>(); } CallBackDiy.AddOrUpdate(id, asyncalls, (a, b) => asyncalls); }
public void Close() { IsClose = true; AsyncWaitTimeOut.Clear(); ClientManager.Close(); Module.ModuleDiy.Clear(); AsyncRunDiy.Clear(); CallBackDiy.Clear(); AsyncCallDiy.Clear(); SyncWaitDic.Clear(); FodyDir.Clear(); Container.Dispose(); }
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"); } }
internal void Disconnect(string message) { if (AsyncCallDiy != null) { AsyncCallDiy.Clear(); } if (CallBackDiy != null) { CallBackDiy.Clear(); } if (UserDisconnect != null) { UserDisconnect(this, message); } }
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); } } }
internal void AddAsyncCallBack(AsyncCalls asyncalls, long id) { CallBackDiy.AddOrUpdate(id, asyncalls, (a, b) => asyncalls); }
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; } } }