Ejemplo n.º 1
0
        private async Task ProccessMessage()
        {
            TcpMessage requestMessage = await MessageTransport.ReadAsync(this._connectionInfo);

            if (requestMessage == null)
            {
                throw new Exception("Сообщение имеет некорректный формат");
            }

            Command = requestMessage.Header.Command;

            bool      isNeedExeLog = ServerCommands.IsNeedExeLog(Command);
            Stopwatch stopwatch    = null;

            if (isNeedExeLog)
            {
                stopwatch = new Stopwatch();
                stopwatch.Start();
            }

            using (CommandContext commandContext = new CommandContext(this, requestMessage, _bufferManager))
            {
                this._commandContext = commandContext;
                await CommandDispatcher.Instance.ExecuteAsync(commandContext);

                this._commandContext = null;
            }

            if (isNeedExeLog)
            {
                stopwatch.Stop();
                ServerLog.AddFBLog(ExecuteFolder,
                                   string.Format("| {0,8} | {1,8} | {2}", Command, stopwatch.ElapsedMilliseconds, ClientAddress));
            }
        }
Ejemplo n.º 2
0
 private void LogProcessError(Exception ex)
 {
     if (Glvar.RunAsServise)
     {
         ServerLog.AddFBLog(CommunicationErrorFolder, string.Format("| {0,8} | {1}\r\n{2}", this.Command, this.ClientAddress, ex));
     }
     else
     {
         Console.WriteLine(ex.ToString());
         Logger.ErrorException("ProccessMessage error", ex);
     }
 }
Ejemplo n.º 3
0
        public async Task Start()
        {
            this._clientSocket.ReceiveBufferSize = this._listener.Configuration.ClientSocketReceiveBufferSize;
            this._clientSocket.SendBufferSize    = this._listener.Configuration.ClientSocketSendBufferSize;
            this._listener.AddConnection(this);

            try
            {
                await ProccessMessage();
            }
            catch (IOException ex)
            {
                SocketException socketException = ex.InnerException as SocketException;
                if (socketException != null)
                {
                    string errText = string.Format("SocketException. {0}, {1}", socketException.SocketErrorCode, socketException);
                    if (Glvar.RunAsServise)
                    {
                        ServerLog.AddFBLog(SocketErrorFolder, string.Format("| {0,8} | {1}\r\n{2}", this.Command, this.ClientAddress, errText));
                    }
                    else
                    {
                        Console.WriteLine(errText);
                        Logger.ErrorException("ProccessMessage io error", ex);
                    }
                }
                else
                {
                    this.LogProcessError(ex);
                }
            }
            catch (Exception ex)
            {
                this.LogProcessError(ex);
            }
            finally
            {
                this._listener.RemoveConnection(this);
                Dispose();
            }
        }