예제 #1
0
        protected void InitializePersistentState()
        {
            _hostShutdownToken = _context.HostShutdownToken();

            Completed = new TaskCompletionSource <object>();

            // Create a token that represents the end of this connection's life
            _connectionEndTokenSource = new CancellationTokenSource();
            _connectionEndToken       = _connectionEndTokenSource.Token;

            // Handle the shutdown token's callback so we can end our token if it trips
            _hostRegistration = _hostShutdownToken.Register(state =>
            {
                try
                {
                    ((CancellationTokenSource)state).Cancel();
                }
                catch (ObjectDisposedException)
                {
                    // We've already disposed the token and we don't need to do any clean up
                    // or triggering so just swallow the exception
                }
            },
                                                            _connectionEndTokenSource,
                                                            useSynchronizationContext: false);
        }
예제 #2
0
 public TransportDisconnectBase(HostContext context, IJsonSerializer jsonSerializer, ITransportHeartBeat heartBeat)
 {
     _context = context;
     _jsonSerializer = jsonSerializer;
     _heartBeat = heartBeat;
     _timeoutTokenSource = new CancellationTokenSource();
     _hostShutdownToken = context.HostShutdownToken();
 }
예제 #3
0
 public TransportDisconnectBase(HostContext context, IJsonSerializer jsonSerializer, ITransportHeartBeat heartBeat)
 {
     _context            = context;
     _jsonSerializer     = jsonSerializer;
     _heartBeat          = heartBeat;
     _timeoutTokenSource = new CancellationTokenSource();
     _hostShutdownToken  = context.HostShutdownToken();
 }
        protected void InitializePersistentState()
        {
            _hostShutdownToken = _context.HostShutdownToken();

            Completed = new TaskCompletionSource <object>();

            // Create a token that represents the end of this connection's life
            _connectionEndTokenSource = CancellationTokenSource.CreateLinkedTokenSource(_hostShutdownToken);
            _connectionEndToken       = _connectionEndTokenSource.Token;
        }
예제 #5
0
        public TransportDisconnectBase(HostContext context, IJsonSerializer jsonSerializer, ITransportHeartBeat heartBeat)
        {
            _context = context;
            _jsonSerializer = jsonSerializer;
            _heartBeat = heartBeat;
            _timeoutTokenSource = new CancellationTokenSource();
            _hostShutdownToken = context.HostShutdownToken();

            // Create a token that represents the end of this connection's life
            _connectionEndToken = CancellationTokenSource.CreateLinkedTokenSource(_timeoutTokenSource.Token, _hostShutdownToken);
        }
예제 #6
0
        public TransportDisconnectBase(HostContext context, IJsonSerializer jsonSerializer, ITransportHeartBeat heartBeat)
        {
            _context            = context;
            _jsonSerializer     = jsonSerializer;
            _heartBeat          = heartBeat;
            _timeoutTokenSource = new CancellationTokenSource();
            _endTokenSource     = new CancellationTokenSource();
            _hostShutdownToken  = context.HostShutdownToken();

            // Create a token that represents the end of this connection's life
            _connectionEndToken = CancellationTokenSource.CreateLinkedTokenSource(_timeoutTokenSource.Token, _endTokenSource.Token, _hostShutdownToken);
        }
예제 #7
0
        public TransportDisconnectBase(HostContext context, IJsonSerializer jsonSerializer, ITransportHeartBeat heartBeat, IPerformanceCounterManager performanceCounterManager)
        {
            _context = context;
            _jsonSerializer = jsonSerializer;
            _heartBeat = heartBeat;
            _timeoutTokenSource = new CancellationTokenSource();
            _endTokenSource = new CancellationTokenSource();
            _disconnectedToken = new CancellationTokenSource();
            _hostShutdownToken = context.HostShutdownToken();
            _counters = performanceCounterManager;

            Completed = new TaskCompletionSource<object>();

            // Create a token that represents the end of this connection's life
            _connectionEndToken = CancellationTokenSource.CreateLinkedTokenSource(_timeoutTokenSource.Token, _endTokenSource.Token, _disconnectedToken.Token, _hostShutdownToken);
        }
예제 #8
0
        public TransportDisconnectBase(HostContext context, IJsonSerializer jsonSerializer, ITransportHeartBeat heartBeat, IPerformanceCounterManager performanceCounterManager)
        {
            _context            = context;
            _jsonSerializer     = jsonSerializer;
            _heartBeat          = heartBeat;
            _timeoutTokenSource = new CancellationTokenSource();
            _endTokenSource     = new CancellationTokenSource();
            _disconnectedToken  = new CancellationTokenSource();
            _hostShutdownToken  = context.HostShutdownToken();
            _counters           = performanceCounterManager;

            Completed = new TaskCompletionSource <object>();

            // Create a token that represents the end of this connection's life
            _connectionEndToken = CancellationTokenSource.CreateLinkedTokenSource(_timeoutTokenSource.Token, _endTokenSource.Token, _disconnectedToken.Token, _hostShutdownToken);
        }
        protected void InitializePersistentState()
        {
            _hostShutdownToken = _context.HostShutdownToken();

            Completed = new TaskCompletionSource <object>();

            // Create a token that represents the end of this connection's life
            _connectionEndTokenSource = new SafeCancellationTokenSource();
            _connectionEndToken       = _connectionEndTokenSource.Token;

            // Handle the shutdown token's callback so we can end our token if it trips
            _hostRegistration = _hostShutdownToken.SafeRegister(state =>
            {
                state.Cancel();
            },
                                                                _connectionEndTokenSource);
        }
        public void ExtensionMethodsMapToDictionaryEntries()
        {
            // Arrange
            var request = new Mock<IRequest>();
            var response = new Mock<IResponse>();
            var context = new HostContext(request.Object, response.Object);

            // Act
            context.Items[HostConstants.DebugMode] = true;
            context.Items[HostConstants.InstanceName] = "Instance name";
            context.Items[HostConstants.ShutdownToken] = CancellationToken.None;
            context.Items[HostConstants.SupportsWebSockets] = false;
            context.Items[HostConstants.WebSocketServerUrl] = "ws://123";

            // Assert
            Assert.True(context.IsDebuggingEnabled());
            Assert.Equal("Instance name", context.InstanceName());
            Assert.Equal(CancellationToken.None, context.HostShutdownToken());
            Assert.False(context.SupportsWebSockets());
            Assert.Equal("ws://123", context.WebSocketServerUrl());
        }
예제 #11
0
        public void ExtensionMethodsMapToDictionaryEntries()
        {
            // Arrange
            var request  = new Mock <IRequest>();
            var response = new Mock <IResponse>();
            var context  = new HostContext(request.Object, response.Object);

            // Act
            context.Items[HostConstants.DebugMode]          = true;
            context.Items[HostConstants.InstanceName]       = "Instance name";
            context.Items[HostConstants.ShutdownToken]      = CancellationToken.None;
            context.Items[HostConstants.SupportsWebSockets] = false;
            context.Items[HostConstants.WebSocketServerUrl] = "ws://123";

            // Assert
            Assert.True(context.IsDebuggingEnabled());
            Assert.Equal("Instance name", context.InstanceName());
            Assert.Equal(CancellationToken.None, context.HostShutdownToken());
            Assert.False(context.SupportsWebSockets());
            Assert.Equal("ws://123", context.WebSocketServerUrl());
        }
예제 #12
0
        protected virtual void InitializePersistentState()
        {
            _hostShutdownToken = _context.HostShutdownToken();

            _requestLifeTime = new HttpRequestLifeTime(WriteQueue, Trace, ConnectionId);

            // Create a token that represents the end of this connection's life
            _connectionEndTokenSource = new SafeCancellationTokenSource();
            _connectionEndToken       = _connectionEndTokenSource.Token;

            // Handle the shutdown token's callback so we can end our token if it trips
            _hostRegistration = _hostShutdownToken.SafeRegister(state =>
            {
                ((SafeCancellationTokenSource)state).Cancel();
            },
                                                                _connectionEndTokenSource);

            // When the connection ends release the request
            _connectionEndRegistration = CancellationToken.SafeRegister(state =>
            {
                ((HttpRequestLifeTime)state).Complete();
            },
                                                                        _requestLifeTime);
        }