Пример #1
0
        private void Handle(IClientEvent @event)
        {
            EnsureIsNotDisposed();
            if (@event == null)
            {
                _context.Logger.Error("[Bot:{BotId}:{UserId}] Received null event.", _context.BotId, _context.UserId);
                return;
            }
            if (_state == BotState.Stopped)
            {
                throw new InvalidOperationException("Bot is stopped.");
            }
            _received.Increment();
            _queueSize.Write();
            _context.Logger.Debug("[Bot:{BotId}:{UserId}]: Received {EventType} {@Event}",
                                  _context.BotId,
                                  _context.UserId,
                                  @event.GetType().Name,
                                  @event);
            if (_cancellationToken.IsCancellationRequested)
            {
                _context.Logger.Warning("[Bot:{BotId}:{UserId}] Bot execution cancelled.");
                Stop(new TaskCanceledException("Bot execution was cancelled."));
                return;
            }
            var posted = _processor.Post(@event);

            if (!posted)
            {
                _context.Logger.Warning("[Bot:{BotId}:{UserId}] Failed to accept {EventType}. Queue length exceeded.",
                                        _context.BotId,
                                        _context.UserId,
                                        @event.GetType().Name);
                Stop(new InvalidOperationException("Bot queue is too large."));
            }
        }