Пример #1
0
        private ReturnResult SendDataAsWait(long Id, byte[] Data)
        {
            using (ReturnEventWaitHandle wait = new ReturnEventWaitHandle(MillisecondsTimeout, false, EventResetMode.AutoReset))
            {
                if (!SyncWaitDic.TryAdd(Id, wait))
                {
                    LogAction.Log(LogType.Err, "Insert Wait Dic fail");
                    return(null);
                }

                Client.Send(Data);

                wait.WaitOne();
                var value = wait.Result;
                wait.Dispose();

                if (value != null)
                {
                    if (value.Arguments == null)
                    {
                        return(null);
                    }
                    else
                    {
                        return(value);
                    }
                }
                else
                {
                    return(null);
                }
            }
        }
Пример #2
0
 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
        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);
                }
            }
        }
Пример #5
0
        private Result SendDataAsWait(long Id, byte[] Data)
        {
            using (ReturnEventWaitHandle wait = new ReturnEventWaitHandle(this.LoggerFactory, MillisecondsTimeout, false, EventResetMode.AutoReset))
            {
                if (!SyncWaitDic.TryAdd(Id, wait))
                {
                    Log.Error("Insert Wait Dic fail");
                }

                ClientManager.SendData(Data);

                if (!wait.WaitOne())
                {
                    throw new TimeoutException("Call Time Out");
                }

                var value = wait.Result;


                if (value != null)
                {
                    if (value.Arguments == null && !value.IsError)
                    {
                        return(null);
                    }
                    else
                    {
                        return(value);
                    }
                }
                else
                {
                    return(null);
                }
            }
        }