Ejemplo n.º 1
0
        private RequestDelegate CreateStack(CancellationToken cancellationToken)
        {
            var stackBuilder = new StackBuilder(_services);

            if (_sqlOptions.ConnectionString != null)
            {
                stackBuilder.Use <SqlServerMiddleware>();
            }
            else
            {
                _logger.LogWarning("No ConnectionString found, disabling SqlServer injection");
            }

            return(stackBuilder
                   .Use(next =>
            {
                return async(packet) =>
                {
                    if (!await _chatHub.TryWriteChatAsync(packet.Raw, cancellationToken))
                    {
                        _logger.LogWarning("Unable to write {RawCount} bytes to chat client", packet.Raw.Length);
                    }
                    await next(packet);
                };
            })
                   .Build());
        }
Ejemplo n.º 2
0
        public DeviceServer(ProtocolFactory protocolFactory, IServiceProvider services, FanoutHub fanoutHub, IOptions <ProxyOptions> options, IOptions <SqlServerOptions> sqlOptions, ILogger <DeviceServer> logger)
        {
            _fanoutHub = fanoutHub;
            _options   = options.Value;
            _logger    = logger;

            var stackBuilder = new StackBuilder(services);

            if (sqlOptions.Value.ConnectionString != null)
            {
                stackBuilder.Use <SqlServerMiddleware>();
            }

            var stack = stackBuilder.Build();

            _protocol = protocolFactory.Create(_options.ProtocolName, stack);
        }