Example #1
0
        public HubConnection(IConnection connection, IHubProtocol protocol, ILoggerFactory loggerFactory)
        {
            if (connection == null)
            {
                throw new ArgumentNullException(nameof(connection));
            }

            if (protocol == null)
            {
                throw new ArgumentNullException(nameof(protocol));
            }

            _connection    = connection;
            _binder        = new HubBinder(this);
            _protocol      = protocol;
            _loggerFactory = loggerFactory ?? NullLoggerFactory.Instance;
            _logger        = _loggerFactory.CreateLogger <HubConnection>();
            _connection.OnReceived((data, state) => ((HubConnection)state).OnDataReceivedAsync(data), this);
            Closed = _connection.Closed.ContinueWith(task =>
            {
                Shutdown(task.Exception);
                return(task);
            }).Unwrap();

            // Create the timer for timeout, but disabled by default (we enable it when started).
            _timeoutTimer = new Timer(state => ((HubConnection)state).TimeoutElapsed(), this, Timeout.Infinite, Timeout.Infinite);
        }
Example #2
0
        public HubConnection(IConnection connection, IHubProtocol protocol, ILoggerFactory loggerFactory)
        {
            if (connection == null)
            {
                throw new ArgumentNullException(nameof(connection));
            }

            if (protocol == null)
            {
                throw new ArgumentNullException(nameof(protocol));
            }

            _connection           = connection;
            _binder               = new HubBinder(this);
            _protocol             = protocol;
            _loggerFactory        = loggerFactory ?? NullLoggerFactory.Instance;
            _logger               = _loggerFactory.CreateLogger <HubConnection>();
            _connection.Received += OnDataReceivedAsync;
            _connection.Closed   += Shutdown;
        }
Example #3
0
        public HubConnection(IConnection connection, IHubProtocol protocol, ILoggerFactory loggerFactory)
        {
            if (connection == null)
            {
                throw new ArgumentNullException(nameof(connection));
            }

            if (protocol == null)
            {
                throw new ArgumentNullException(nameof(protocol));
            }

            _connection    = connection;
            _binder        = new HubBinder(this);
            _protocol      = protocol;
            _loggerFactory = loggerFactory ?? NullLoggerFactory.Instance;
            _logger        = _loggerFactory.CreateLogger <HubConnection>();
            _connection.OnReceived((data, state) => ((HubConnection)state).OnDataReceivedAsync(data), this);
            Closed = _connection.Closed.ContinueWith(task =>
            {
                Shutdown(task.Exception);
                return(task);
            }).Unwrap();
        }