Exemplo n.º 1
0
 protected virtual void OnDataReceive(DataFrame data)
 {
     if (DataReceive != null)
     {
         WSReceiveArgs e = new WSReceiveArgs();
         e.Client = this;
         e.Frame  = data;
         DataReceive(this, e);
     }
     else
     {
         lock (mLockReceive)
         {
             if (mReceiveCompletionSource != null)
             {
                 var result = mReceiveCompletionSource;
                 mReceiveCompletionSource = null;
                 Task.Run(() => result.Success(data));
             }
             else
             {
                 mDataFrames.Enqueue(data);
             }
         }
     }
 }
Exemplo n.º 2
0
 protected virtual void OnDataReceive(WSReceiveArgs e)
 {
     try
     {
         DataReceive?.Invoke(this, e);
     }
     catch (Exception e_)
     {
         try
         {
             e.Error = new BXException($"ws client receive error {e_.Message}", e_);
             DataReceive?.Invoke(this, e);
         }
         catch { }
     }
 }
Exemplo n.º 3
0
        private void OnClientError(IClient c, ClientErrorArgs e)
        {
            if (OnWSConnected)
            {
                if (e.Error is BXException)
                {
                    OnWSConnected = false;
                }
                lock (mLockReceive)
                {
                    if (mReceiveCompletionSource != null)
                    {
                        var completed = mReceiveCompletionSource;
                        mReceiveCompletionSource = null;
                        Task.Run(() =>
                        {
                            completed.Error(e.Error);
                        });
                        return;
                    }
                }

                if (DataReceive != null)
                {
                    try
                    {
                        WSReceiveArgs wse = new WSReceiveArgs();
                        wse.Client = this;
                        wse.Error  = e.Error;
                        DataReceive?.Invoke(this, wse);
                    }
                    catch { }
                }
            }
            else
            {
                OnConnectResponse(e.Error, null);
            }
        }