예제 #1
0
 public static EventEnvelope ToEnvelope(this IClientEvent @event)
 {
     if (@event == null)
     {
         throw new ArgumentNullException(nameof(@event));
     }
     return(new EventEnvelope(@event, @event.GetType().Name));
 }
예제 #2
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."));
            }
        }