Exemplo n.º 1
0
        protected AppletChannel(Guid appletId, IAppInfo appInfo)
        {
            _appInfo = appInfo ?? throw new ArgumentNullException(nameof(appInfo));
            if (false == appInfo.IsAppletId(appletId))
            {
                throw new ArgumentException($"Invalid applet ID. Application: {appInfo.ApplicationName}, Applet ID: {appletId}");
            }
            AppletId = appletId;
            Instance = Guid.NewGuid();

            var disposing = _cancellationSource.Token.ToObservable();

            _privateResponses = Observable
                                .Defer(CreatePrivateResponsesObservable)
                                .TakeUntil(disposing)
                                .ObserveOn(_privateEventLoopScheduler)
                                .Do(InspectPrivateResponse)
                                .Do(args => Pulse())
                                .Where(IsValidResponse)
                                .Publish();

            _privateResponses
            .SubscribeOn(_privateEventLoopScheduler)
            .Where(response => _privateResponseObserversByCorrelationId.ContainsKey(response.CorrelationId))
            .Subscribe(
                OnPrivateResponse,
                OnPrivateResponsesError,
                OnPrivateResponsesCompleted);

            Observable
            .Interval(_appInfo.HeartbeatInterval)
            .TakeUntil(disposing)
            .SkipUntil(_pulse)
            .Select(CreateHeartbeatDto)
            .Select(ToDispatchArgs)
            .Subscribe(args =>
            {
                args.IntentId = AppInfo.HeartbeatIntent;
                SendAsync(args);
            });
        }
Exemplo n.º 2
0
        static void Bootstrapper_PipelineRefreshed(object sender, PipelineRefreshEventArgs e)
        {
            Console.WriteLine("{0}tarting pipeline", Subscription == null ? "S" : "Re");

            Subscription?.Dispose();

            try
            {
                IConnectableObservable <Message> observable = Bootstrapper.PipelineRoot.Pipeline.Publish();
                observable.Connect();

                Subscription = observable.SubscribeOn(TaskPoolScheduler.Default).Subscribe <Message>(
                    msg => RegisterMessage(msg),
                    ex => LogError(ex),
                    () => Console.WriteLine("Pipeline completed")
                    );
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Exemplo n.º 3
0
        static void Bootstrapper_PipelineRefreshed(object sender, PipelineRefreshEventArgs e)
        {
            Console.WriteLine("Starting pipeline");

            stoppingTokenSource?.Cancel();
            stoppingTokenSource = new CancellationTokenSource();

            try
            {
                IConnectableObservable <Message> observable = Bootstrapper.PipelineRoot.Pipeline.Publish();
                observable.Connect();

                observable.SubscribeOn(TaskPoolScheduler.Default).Subscribe <Message>(
                    msg => EOLMessage(msg),
                    ex => LogError(ex),
                    () => Console.WriteLine("Pipeline completed"),
                    stoppingTokenSource.Token
                    );
            }
            catch (Exception ex)
            {
                logger.Error(ex, "{0} thrown when running pipeline: {1}", ex.GetType().Name, ex.Message);
            }
        }