Пример #1
0
        public GameHub(
            ILogger logger,
            OrleansClient client,
            GameHubCountersCollection counters,
            ClientHandlerFactory clientHandlerFactory)
        {
            _logger               = logger ?? throw new ArgumentNullException(nameof(logger));
            _client               = client ?? throw new ArgumentNullException(nameof(client));
            _countersCollection   = counters ?? throw new ArgumentNullException(nameof(counters));
            _clientHandlerFactory = clientHandlerFactory ??
                                    throw new ArgumentNullException(nameof(clientHandlerFactory));

            _errorSerializer = JsonSerializer.Create(new JsonSerializerSettings
            {
                TypeNameHandling = TypeNameHandling.Objects,
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            });
            _connectionsGauge = _logger.GaugeOperation("Hub.Connections", "connection(s)", () => Connections.Count);
        }
Пример #2
0
        public async Task Run(CancellationToken?cancellationToken = null)
        {
            EnsureIsNotDisposed();
            _cancellationToken = cancellationToken ?? CancellationToken.None;
            var processorOptions = new ExecutionDataflowBlockOptions
            {
                BoundedCapacity = MaxQueueSize
            };

            _processor = new ActionBlock <IClientEvent>(Process, processorOptions);
            _subject?.Dispose();
            _subject   = new Subject <IBotEvent>();
            _queueSize = _context.Logger.GaugeOperation(QueueSizeGaugeName, "items", () => _processor.InputCount);
            _received.Reset();
            Events = _subject.AsObservable();
            Notify(new BotStarted());
            _state = BotState.Started;
            await _processor.Completion;

            if (_exception != null)
            {
                throw _exception;
            }
        }