Ejemplo n.º 1
0
        private void SetError(Exception e, string errorMessage)
        {
            // Wait until making a new request, retrying or disposing is in progress
            lock (_syncObject)
            {
                try
                {
                    Logger.Debug(errorMessage + Environment.NewLine + e + Environment.NewLine + "Closing socket due to error.");
                    CloseSocket();

                    // no specific asyncResult, notify all pending requests about the error
                    foreach (ulong key in _asyncResults.GetKeys())
                    {
                        TcpKsiServiceAsyncResult asyncResult = _asyncResults.GetValue(key);
                        // If an error already exists then do not overwrite.
                        if (asyncResult.Error != null)
                        {
                            continue;
                        }
                        asyncResult.Error = new KsiServiceProtocolException(errorMessage, e);
                        asyncResult.SetComplete();
                    }

                    Logger.Debug("Clearing asyncResults.");
                    _asyncResults.Clear();
                }
                catch (Exception ex)
                {
                    Logger.Debug("SetError failed.", ex);
                    throw;
                }
            }
        }
Ejemplo n.º 2
0
 private void SetError(TcpKsiServiceAsyncResult asyncResult, Exception e, string errorMessage)
 {
     try
     {
         // If an error already exists then do not overwrite.
         if (asyncResult.Error != null)
         {
             return;
         }
         asyncResult.Error = new KsiServiceProtocolException(errorMessage, e);
         asyncResult.SetComplete();
         _asyncResults.Remove(asyncResult);
     }
     catch (Exception ex)
     {
         Logger.Debug("SetError with asyncResult failed.", ex);
         throw;
     }
 }
Ejemplo n.º 3
0
        private void EndBeginRequestCallback(object state, bool timedOut)
        {
            try
            {
                TcpKsiServiceAsyncResult asyncResult = (TcpKsiServiceAsyncResult)state;
                _asyncResults.Remove(asyncResult);

                if (timedOut)
                {
                    asyncResult.Error = new KsiServiceProtocolException("Request timed out.");
                }

                asyncResult.SetComplete();
            }
            catch (Exception ex)
            {
                Logger.Debug("EndBeginRequestCallback failed.", ex);
                throw;
            }
        }