コード例 #1
0
        public IPipeContextAgent <ClientContext> CreateContext(ISupervisor supervisor)
        {
            var           client        = new HttpClient();
            ClientContext clientContext = new HttpClientContext(client, _receivePipe, supervisor.Stopped);

            return(supervisor.AddContext(clientContext));
        }
コード例 #2
0
        IPipeContextAgent <ConnectionContext> IPipeContextFactory <ConnectionContext> .CreateContext(ISupervisor supervisor)
        {
            Task <ConnectionContext> context = Task.FromResult(CreateConnectionContext(supervisor));

            IPipeContextAgent <ConnectionContext> contextHandle = supervisor.AddContext(context);

            return(contextHandle);
        }
コード例 #3
0
        IPipeContextAgent <ConnectionContext> IPipeContextFactory <ConnectionContext> .CreateContext(ISupervisor supervisor)
        {
            var context = Task.Run(() => CreateConnection(supervisor), supervisor.Stopping);

            IPipeContextAgent <ConnectionContext> contextHandle = supervisor.AddContext(context);

            return(contextHandle);
        }
コード例 #4
0
        IPipeContextAgent <MessagingFactoryContext> IPipeContextFactory <MessagingFactoryContext> .CreateContext(ISupervisor supervisor)
        {
            var context = Task.Factory.StartNew(() => CreateConnection(supervisor), supervisor.Stopping, TaskCreationOptions.None, TaskScheduler.Default)
                          .Unwrap();

            IPipeContextAgent <MessagingFactoryContext> contextHandle = supervisor.AddContext(context);

            return(contextHandle);
        }
コード例 #5
0
        IPipeContextAgent <HttpHostContext> IPipeContextFactory <HttpHostContext> .CreateContext(ISupervisor supervisor)
        {
            HttpHostContext hostContext = new KestrelHttpHostContext(_configuration, supervisor.Stopped);

            hostContext.GetOrAddPayload(() => _configuration);

            IPipeContextAgent <HttpHostContext> contextHandle = supervisor.AddContext(hostContext);

            return(contextHandle);
        }
コード例 #6
0
            public IPipeContextAgent <SimpleContext> CreateContext(ISupervisor supervisor)
            {
                var context = new SimpleContextImpl()
                {
                    Value = Interlocked.Increment(ref _id).ToString()
                };

                IPipeContextAgent <SimpleContext> contextHandle = supervisor.AddContext <SimpleContext>(context);

                void SimpleContextOnInvalid(object sender, EventArgs args) => contextHandle.DisposeAsync();

                context.OnInvalid += SimpleContextOnInvalid;

                return(contextHandle);
            }
コード例 #7
0
        IPipeContextAgent <HttpHostContext> IPipeContextFactory <HttpHostContext> .CreateContext(ISupervisor supervisor)
        {
            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Created: {0}", _configuration.HostAddress);
            }

            HttpHostContext hostContext = new KestrelHttpHostContext(_configuration, supervisor.Stopped);

            hostContext.GetOrAddPayload(() => _configuration);

            IPipeContextAgent <HttpHostContext> contextHandle = supervisor.AddContext(hostContext);

            return(contextHandle);
        }
コード例 #8
0
        IPipeContextAgent <ConnectionContext> IPipeContextFactory <ConnectionContext> .CreateContext(ISupervisor supervisor)
        {
            var context = Task.Run(() => CreateConnection(supervisor), supervisor.Stopping);

            IPipeContextAgent <ConnectionContext> contextHandle = supervisor.AddContext(context);

            void HandleConnectionException(Exception exception)
            {
                contextHandle.Stop($"Connection Exception: {exception}");
            }

            context.ContinueWith(task =>
            {
                task.Result.Connection.ExceptionListener += HandleConnectionException;

                contextHandle.Completed.ContinueWith(_ => task.Result.Connection.ExceptionListener -= HandleConnectionException);
            }, TaskContinuationOptions.OnlyOnRanToCompletion);

            return(contextHandle);
        }
コード例 #9
0
        IPipeContextAgent <HttpHostContext> IPipeContextFactory <HttpHostContext> .CreateContext(ISupervisor supervisor)
        {
            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Connecting: {0}", _settings.Description);
            }

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

            HttpHostContext hostContext = new KestrelHttpHostContext(_settings, supervisor.Stopped);

            hostContext.GetOrAddPayload(() => _settings);

            IPipeContextAgent <HttpHostContext> contextHandle = supervisor.AddContext(hostContext);

            return(contextHandle);
        }
コード例 #10
0
        IPipeContextAgent <ConnectionContext> IPipeContextFactory <ConnectionContext> .CreateContext(ISupervisor supervisor)
        {
            Task <ConnectionContext> context = Task.Run(() => CreateConnection(supervisor), supervisor.Stopped);

            IPipeContextAgent <ConnectionContext> contextHandle = supervisor.AddContext(context);

            void HandleShutdown(object sender, ShutdownEventArgs args)
            {
                if (args.Initiator != ShutdownInitiator.Application)
                {
                    contextHandle.Stop(args.ReplyText);
                }
            }

            context.ContinueWith(task =>
            {
                task.Result.Connection.ConnectionShutdown += HandleShutdown;

                contextHandle.Completed.ContinueWith(_ => task.Result.Connection.ConnectionShutdown -= HandleShutdown);
            }, TaskContinuationOptions.OnlyOnRanToCompletion);

            return(contextHandle);
        }