Exemplo n.º 1
0
        Task SendUsingNewConnection(IPipe<OwinHostContext> connectionPipe, OwinHostScope scope, CancellationToken stoppingToken)
        {
            try
            {
                if (_cacheTaskScope.StoppingToken.IsCancellationRequested)
                    throw new TaskCanceledException($"The connection is being disconnected: {_settings.ToDebugString()}");

                if (_log.IsDebugEnabled)
                    _log.DebugFormat("Connecting: {0}", _settings.ToDebugString());
                
                if (_log.IsDebugEnabled)
                {
                    _log.DebugFormat("Connected: {0} (address: {1}, local: {2}", _settings.ToDebugString(),
                        _settings.Host, _settings.Port);
                }

                var hostContext = new HttpOwinHostContext(_settings, _cacheTaskScope);

                hostContext.GetOrAddPayload(() => _settings);

                scope.Connected(hostContext);
            }
            catch (Exception ex)
            {
                Interlocked.CompareExchange(ref _scope, null, scope);

                scope.ConnectFaulted(ex);

                throw new HttpConnectionException("Connect failed: " + _settings.ToDebugString(), ex);
            }

            return SendUsingExistingConnection(connectionPipe, scope, stoppingToken);
        }
Exemplo n.º 2
0
        public Task Send(IPipe<OwinHostContext> connectionPipe, CancellationToken stoppingToken)
        {
            OwinHostScope newScope = null;
            OwinHostScope existingScope;

            lock (_scopeLock)
            {
                existingScope = _scope;
                if (existingScope == null)
                {
                    newScope = new OwinHostScope(_cacheTaskScope, _settings);
                    _scope = newScope;
                }
            }
            if (existingScope != null)
                return SendUsingExistingConnection(connectionPipe, existingScope, stoppingToken);

            return SendUsingNewConnection(connectionPipe, newScope, stoppingToken);
        }
Exemplo n.º 3
0
        public Task Send(IPipe <OwinHostContext> connectionPipe, CancellationToken stoppingToken)
        {
            OwinHostScope newScope = null;
            OwinHostScope existingScope;

            lock (_scopeLock)
            {
                existingScope = _scope;
                if (existingScope == null)
                {
                    newScope = new OwinHostScope(_cacheTaskScope, _settings);
                    _scope   = newScope;
                }
            }
            if (existingScope != null)
            {
                return(SendUsingExistingConnection(connectionPipe, existingScope, stoppingToken));
            }

            return(SendUsingNewConnection(connectionPipe, newScope, stoppingToken));
        }
Exemplo n.º 4
0
        Task SendUsingNewConnection(IPipe <OwinHostContext> connectionPipe, OwinHostScope scope, CancellationToken stoppingToken)
        {
            try
            {
                if (_cacheTaskScope.StoppingToken.IsCancellationRequested)
                {
                    throw new TaskCanceledException($"The connection is being disconnected: {_settings.ToDebugString()}");
                }

                if (_log.IsDebugEnabled)
                {
                    _log.DebugFormat("Connecting: {0}", _settings.ToDebugString());
                }

                if (_log.IsDebugEnabled)
                {
                    _log.DebugFormat("Connected: {0} (address: {1}, local: {2}", _settings.ToDebugString(),
                                     _settings.Host, _settings.Port);
                }

                var hostContext = new HttpOwinHostContext(_settings, _cacheTaskScope);

                hostContext.GetOrAddPayload(() => _settings);

                scope.Connected(hostContext);
            }
            catch (Exception ex)
            {
                Interlocked.CompareExchange(ref _scope, null, scope);

                scope.ConnectFaulted(ex);

                throw new HttpConnectionException("Connect failed: " + _settings.ToDebugString(), ex);
            }

            return(SendUsingExistingConnection(connectionPipe, scope, stoppingToken));
        }
Exemplo n.º 5
0
        async Task SendUsingExistingConnection(IPipe <OwinHostContext> connectionPipe, OwinHostScope scope, CancellationToken cancellationToken)
        {
            try
            {
                using (var context = await scope.Attach(cancellationToken).ConfigureAwait(false))
                {
                    if (_log.IsDebugEnabled)
                    {
                        _log.DebugFormat("Using host: {0}", context.HostSettings.ToDebugString());
                    }

                    await connectionPipe.Send(context).ConfigureAwait(false);
                }
            }
            catch (Exception ex)
            {
                if (_log.IsDebugEnabled)
                {
                    _log.Debug("The host usage threw an exception", ex);
                }

                Interlocked.CompareExchange(ref _scope, null, scope);

                scope.ConnectFaulted(ex);

                throw;
            }
        }
Exemplo n.º 6
0
        async Task SendUsingExistingConnection(IPipe<OwinHostContext> connectionPipe, OwinHostScope scope, CancellationToken cancellationToken)
        {
            try
            {
                using (var context = await scope.Attach(cancellationToken).ConfigureAwait(false))
                {
                    if (_log.IsDebugEnabled)
                        _log.DebugFormat("Using host: {0}", context.HostSettings.ToDebugString());

                    await connectionPipe.Send(context).ConfigureAwait(false);
                }
            }
            catch (Exception ex)
            {
                if (_log.IsDebugEnabled)
                    _log.Debug("The host usage threw an exception", ex);

                Interlocked.CompareExchange(ref _scope, null, scope);

                scope.ConnectFaulted(ex);

                throw;
            }
        }