IPipeContextAgent <TContext> IPipeContextFactory <TContext> .CreateContext(ISupervisor supervisor) { IAsyncPipeContextAgent <TContext> asyncContext = supervisor.AddAsyncContext <TContext>(); Task <TContext> context = CreateJoinContext(asyncContext, supervisor.Stopped); context.ContinueWith(task => { try { if (task.IsCanceled) { asyncContext.CreateCanceled(); } else if (task.IsFaulted) { asyncContext.CreateFaulted(task.Exception); } } catch { } }); return(asyncContext); }
IPipeContextAgent <ProcessorContext> IPipeContextFactory <ProcessorContext> .CreateContext(ISupervisor supervisor) { IAsyncPipeContextAgent <ProcessorContext> asyncContext = supervisor.AddAsyncContext <ProcessorContext>(); CreateProcessor(asyncContext, supervisor.Stopped); return(asyncContext); }
public IPipeContextAgent <SendEndpointContext> CreateContext(ISupervisor supervisor) { IAsyncPipeContextAgent <SendEndpointContext> asyncContext = supervisor.AddAsyncContext <SendEndpointContext>(); CreateSendEndpointContext(asyncContext, supervisor.Stopped); return(asyncContext); }
IPipeContextAgent <ClientContext> IPipeContextFactory <ClientContext> .CreateContext(ISupervisor supervisor) { IAsyncPipeContextAgent <ClientContext> asyncContext = supervisor.AddAsyncContext <ClientContext>(); CreateModel(asyncContext, supervisor.Stopped); return(asyncContext); }
public IPipeContextAgent <ProducerContext <TKey, TValue> > CreateContext(ISupervisor supervisor) { IAsyncPipeContextAgent <ProducerContext <TKey, TValue> > asyncContext = supervisor.AddAsyncContext <ProducerContext <TKey, TValue> >(); CreateProducer(asyncContext, supervisor.Stopped); return(asyncContext); }
IPipeContextAgent <ConnectionContext> IPipeContextFactory <ConnectionContext> .CreateContext(ISupervisor supervisor) { IAsyncPipeContextAgent <ConnectionContext> asyncContext = supervisor.AddAsyncContext <ConnectionContext>(); Task.Run(() => CreateConnection(asyncContext, supervisor), supervisor.Stopping); return(asyncContext); }
public IPipeContextAgent<ClientContext> CreateContext(ISupervisor supervisor) { IAsyncPipeContextAgent<ClientContext> asyncContext = supervisor.AddAsyncContext<ClientContext>(); CreateClientContext(asyncContext, supervisor.Stopped); return asyncContext; }
IPipeContextAgent <TContext> IPipeContextFactory <TContext> .CreateContext(ISupervisor supervisor) { IAsyncPipeContextAgent <TContext> asyncContext = supervisor.AddAsyncContext <TContext>(); Task <TContext> context = CreateJoinContext(asyncContext, supervisor.Stopped); return(asyncContext); }
IPipeContextAgent <ConnectionContext> IPipeContextFactory <ConnectionContext> .CreateContext(ISupervisor supervisor) { IAsyncPipeContextAgent <ConnectionContext> asyncContext = supervisor.AddAsyncContext <ConnectionContext>(); var context = Task.Factory.StartNew(() => CreateConnection(asyncContext, supervisor), supervisor.Stopping, TaskCreationOptions.None, TaskScheduler.Default) .Unwrap(); return(asyncContext); }
IPipeContextAgent <ConnectionContext> IPipeContextFactory <ConnectionContext> .CreateContext(ISupervisor supervisor) { IAsyncPipeContextAgent <ConnectionContext> asyncContext = supervisor.AddAsyncContext <ConnectionContext>(); var context = Task.Factory.StartNew(() => CreateConnection(asyncContext, supervisor), supervisor.Stopping, TaskCreationOptions.None, TaskScheduler.Default).Unwrap(); void HandleConnectionException(Exception exception) { asyncContext.Stop($"Connection Exception: {exception}"); } context.ContinueWith(task => { task.Result.Connection.ExceptionListener += HandleConnectionException; asyncContext.Completed.ContinueWith(_ => task.Result.Connection.ExceptionListener -= HandleConnectionException); }, TaskContinuationOptions.OnlyOnRanToCompletion); return(asyncContext); }
IPipeContextAgent <ModelContext> IPipeContextFactory <ModelContext> .CreateContext(ISupervisor supervisor) { IAsyncPipeContextAgent <ModelContext> asyncContext = supervisor.AddAsyncContext <ModelContext>(); var context = CreateModel(asyncContext, supervisor.Stopped); void HandleShutdown(object sender, ShutdownEventArgs args) { if (args.Initiator != ShutdownInitiator.Application) { asyncContext.Stop(args.ReplyText); } } context.ContinueWith(task => { task.Result.Model.ModelShutdown += HandleShutdown; asyncContext.Completed.ContinueWith(_ => task.Result.Model.ModelShutdown -= HandleShutdown); }, TaskContinuationOptions.OnlyOnRanToCompletion); return(asyncContext); }