コード例 #1
0
        public TrayMenuController(ITrayMenu menu, ApplicationContext app, IPomodoroEngine pomodoroEngine, IEventHub eventHub)
        {
            this.menu           = menu;
            this.app            = app;
            this.pomodoroEngine = pomodoroEngine;

            menu.OnStartPomodoroClick(OnStartPomodoroClick);
            menu.OnStartLongBreakClick(OnStartLongBreakClick);
            menu.OnStartShortBreakClick(OnStartShortBreakClick);
            menu.OnStopTimerClick(OnStopTimerClick);
            menu.OnResetPomodoroCountClick(OnResetPomodoroCountClick);
            menu.OnExitClick(OnExitClick);

            eventHub.Subscribe <TimerStarted>(OnTimerStarted);
            eventHub.Subscribe <TimerStopped>(OnTimerStopped);
            eventHub.Subscribe <TimeElapsed>(OnTimeElasped);
            eventHub.Subscribe <PomodoroCountChanged>(OnPomodoroCountChanged);

            menu.Update(mutator =>
            {
                mutator.UpdateRemainingTime(Duration.Zero.ToTimeString());
                mutator.UpdatePomodoroCount(0);
                mutator.EnableStopTimerItem(false);
            });
        }
コード例 #2
0
 public NotificationsPresenter(IPomodoroEngine pomodoroEngine, IUserPreferences userPreferences, IEventHub eventHub)
 {
     this.pomodoroEngine  = pomodoroEngine;
     this.userPreferences = userPreferences;
     eventHub.Subscribe <TimerStopped>(OnTimerStopped);
     eventHub.Subscribe <AppUpdated>(OnAppUpdated);
     eventHub.Subscribe <FirstRun>(OnFirstRun);
 }
コード例 #3
0
        public TrayIconController(NotifyIcon notifyIcon, TimerWindowPresenter timerWindowPresenter, IEventHub eventHub)
        {
            this.notifyIcon           = notifyIcon;
            this.timerWindowPresenter = timerWindowPresenter;

            notifyIcon.Click += OnNotifyIconClick;

            eventHub.Subscribe <TimerStarted>(OnTimerStarted);
            eventHub.Subscribe <TimerStopped>(OnTimerStopped);
        }
コード例 #4
0
ファイル: EventHubTests.cs プロジェクト: jamcar23/PubSub.NET
        public void TestPubMultiSubUsingMethods()
        {
            IEventHub hub = EventHub;
            Box <int> box = new Box <int>(0);

            Assert.IsTrue(hub.Subscribe <EventHubTests, Box <int> >(this, IncrementBox));
            Assert.IsTrue(hub.Subscribe <EventHubTests, Box <int> >(this, IncrementBox2));

            hub.Publish(box);
            hub.Unsubscribe <EventHubTests, Box <int> >(this);

            Assert.AreEqual(2, box.Value);
        }
コード例 #5
0
ファイル: EventHubTests.cs プロジェクト: jamcar23/PubSub.NET
        public void TestPubMultiSubUsingLambdas()
        {
            IEventHub hub = EventHub;
            Box <int> box = new Box <int>(0);

            Assert.IsTrue(hub.Subscribe <EventHubTests, Box <int> >(this, b => b.Value++));
            Assert.IsTrue(hub.Subscribe <EventHubTests, Box <int> >(this, b => b.Value++));

            hub.Publish(box);
            hub.Unsubscribe <EventHubTests, Box <int> >(this);

            Assert.AreEqual(2, box.Value);
        }
コード例 #6
0
ファイル: EventHubTests.cs プロジェクト: jamcar23/PubSub.NET
        public void TestSubUnsubUsingMethods()
        {
            IEventHub hub = EventHub;

            Assert.IsTrue(hub.Subscribe <EventHubTests, Box <int> >(this, IncrementBox));
            Assert.IsTrue(hub.Unsubscribe <EventHubTests, Box <int> >(this));
        }
コード例 #7
0
ファイル: EventHubTests.cs プロジェクト: jamcar23/PubSub.NET
        public void TestUnsubscribingDuringPublishing()
        {
            IEventHub hub = EventHub;
            Box <int> box = new Box <int>(-1);

            hub.Subscribe <EventHubTests, Box <int> >(this, IncrementBox);

            Assert.IsTrue(hub.Subscribe <EventHubTests, IEventHub>(this, UnsubInsideThisMethod));
            Assert.DoesNotThrow(() => hub.Publish(hub));

            hub.Publish(box);
            hub.Unsubscribe <EventHubTests, IEventHub>(this);
            hub.Unsubscribe <EventHubTests, Box <int> >(this);

            Assert.AreEqual(-1, box.Value);
        }
コード例 #8
0
 Subscribe <T>(this IEventHub sub, Action eventHandler)
 {
     return(sub.Subscribe <T>(topic => {
         eventHandler();
         return Task.CompletedTask;
     }));
 }
コード例 #9
0
        public int Execute(string commandLine, IEnumerable <string> optionalInputs)
        {
            commandLine = commandLine.Trim();
            if (commandLine == string.Empty)
            {
                return(0);
            }
            string commandParameters = commandLine;
            var    command           = _handlers.Select(x => x.Execute(ref commandParameters)).Where(x => x != null).FirstOrDefault();

            if (command == null)
            {
                var sp = commandLine.IndexOf(" ");

                _formatter.Render(new Error("The term '{0}' is not a recognized command or alias. Check the spelling or enter 'get-help' to get a list of available commands.",
                                            sp != -1 ? commandLine.Substring(0, sp) : commandLine));
                return(-10);
            }
            int returnCode        = 0;
            var commandLineRunner = new CommandLineRunner {
                OptionalInputs = optionalInputs
            };

            using (_eventHub.Subscribe <ICommandOutput>(_formatter.Render))
                foreach (var output in commandLineRunner.Run(command, commandParameters))
                {
                    _eventHub.Publish(output);
                    if (output.Type == CommandResultType.Error)
                    {
                        returnCode = -50;
                    }
                }
            return(returnCode);
        }
コード例 #10
0
 public static IDisposable Subscribe <T>(this IEventHub sub,
                                         Action <T> eventHandler)
 {
     return(sub.Subscribe <T>(topic => {
         eventHandler(topic);
         return Task.CompletedTask;
     }));
 }
コード例 #11
0
        public PomodoroEngine(ITimer timer, IUserPreferences userPreferences, IEventHub eventHub)
        {
            this.timer           = timer;
            this.userPreferences = userPreferences;
            this.eventHub        = eventHub;

            eventHub.Subscribe <TimerStopped>(OnTimerStopped);
        }
コード例 #12
0
ファイル: EventHubTests.cs プロジェクト: jamcar23/PubSub.NET
        public void TestSubUnsubUsingLambdas()
        {
            IEventHub hub = EventHub;
            Box <int> box = new Box <int>(0);

            Assert.IsTrue(hub.Subscribe <EventHubTests, Box <int> >(this, b => b.Value++));
            Assert.IsTrue(hub.Unsubscribe <EventHubTests, Box <int> >(this));
        }
コード例 #13
0
        public TimerWindowPresenter(IPomodoroEngine pomodoroEngine, ICountdownClock countdownClock, IEventHub eventHub)
        {
            this.countdownClock = countdownClock;

            idleState                = new IdleState(pomodoroEngine);
            pomodoroState            = new PomodoroState(pomodoroEngine);
            shortBreakState          = new ShortBreakState(pomodoroEngine);
            longBreakState           = new LongBreakState(pomodoroEngine);
            pomodoroCompletedState   = new PomodoroCompletedState(pomodoroEngine);
            breakFinishedState       = new BreakFinishedState(pomodoroEngine);
            pomodoroInterruptedState = new TimerInterruptedState("Pomodoro Interrupted", pomodoroEngine);
            breakInterruptedState    = new TimerInterruptedState("Break Interrupted", pomodoroEngine);

            currentState = idleState;

            eventHub.Subscribe <TimerStarted>(OnTimerStarted);
            eventHub.Subscribe <TimeElapsed>(OnTimeElapsed);
            eventHub.Subscribe <TimerStopped>(OnTimerStopped);
        }
コード例 #14
0
ファイル: EventHubTests.cs プロジェクト: jamcar23/PubSub.NET
        public void TestPubSub()
        {
            IEventHub hub = EventHub;

            Assert.IsTrue(hub.Subscribe <EventHubTests, int>(this, i =>
            {
                Assert.Greater(i, 0);
            }));

            hub.Publish(42);
        }
コード例 #15
0
        public Task StartAsync(CancellationToken cancellationToken)
        {
            if (_diagnostic != null && _diagnostic.IsEnabled() && _diagnostic.IsEnabled(DiagnosticOperations.ServiceStart))
            {
                _diagnostic.Write(DiagnosticOperations.ServiceStart, _config);
            }

            _subscription = _eventHub.Subscribe(_config.Namespace, async m => await ProcessMessage(m, cancellationToken));

            return(Task.CompletedTask);
        }
 public ExportTagsCommand(
     IEventHub eventHub,
     TagSourceService tagSourceService,
     ITimelineRepository timelineRepository,
     IActivityRepository activityRepository)
 {
     _tagSourceService   = tagSourceService;
     _timelineRepository = timelineRepository;
     _activityRepository = activityRepository;
     eventHub.Subscribe <TagSourceCacheUpdatedEvent>(OnTagSourceCacheUpdated);
     InvokeOnUiThread(SetCanExecute);
 }
コード例 #17
0
 public ExportTagsCommand(
     IEventHub eventHub,
     TagSourceService tagSourceService,
     ActivityReaderMessageClient activityReaderMessageClient,
     IViewTimelineCache viewTimelineCache)
 {
     _tagSourceService            = tagSourceService;
     _activityReaderMessageClient = activityReaderMessageClient;
     _viewTimelineCache           = viewTimelineCache;
     eventHub.Subscribe <TagSourceCacheUpdatedEvent>(OnTagSourceCacheUpdated);
     InvokeOnUiThread(SetCanExecute);
 }
コード例 #18
0
        public static void WireEvents(this IEventHub hub, params Assembly[] assemblies)
        {
            var registrations = assemblies.SelectMany(x => x.GetExportedTypes())
                                .Where(x => x.IsClass && !x.IsAbstract)
                                .Where(x => typeof(IEventSubscriber).IsAssignableFrom(x))
                                .Select(x => new
            {
                ServiceType = x, Interfaces = x.GetInterfaces()
                                              .Where(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IEventSubscriber <>)).ToArray()
            })
                                .Where(x => x.Interfaces.Any())
                                .ToArray();

            foreach (var r in registrations)
            {
                foreach (var s in r.Interfaces)
                {
                    hub.Subscribe(r.ServiceType, s.GetGenericArguments()[0]);
                }
            }
        }
コード例 #19
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            _logger.LogInformation("Worker started. (at: {time})", DateTimeOffset.UtcNow);

            if (!stoppingToken.IsCancellationRequested)
            {
                var subscription =
                    _eventHub.Subscribe(_config.Namespace, async m => await HandleEvent(m, stoppingToken));

                _logger.LogInformation("Worker started listening on EventHub¡£ (at: {time})", DateTimeOffset.UtcNow);

                while (!stoppingToken.IsCancellationRequested)
                {
                    await Task.Delay(TimeSpan.FromSeconds(PollInterval), stoppingToken);

                    _logger.LogInformation("Worker is still alive. (at: {time})", DateTimeOffset.UtcNow);
                }

                subscription.Unsubscribe();
            }

            _logger.LogInformation("Worker stopped. (at: {time})", DateTimeOffset.UtcNow);
        }
コード例 #20
0
ファイル: Cache.cs プロジェクト: Synnduit/Synnduit
 public Cache(
     IGateway <TEntity> gateway,
     ICompositeHomogenizer <TEntity> compositeHomogenizer,
     IServiceProvider <TEntity> serviceProvider,
     IEventDispatcher <TEntity> eventDispatcher,
     IEventHub <TEntity> eventHub,
     IInitializer initializer)
 {
     this.gateway = gateway;
     this.compositeHomogenizer = compositeHomogenizer;
     this.serviceProvider      = serviceProvider;
     this.eventDispatcher      = eventDispatcher;
     this.isCacheInitialized   = false;
     this.entities             = new List <TEntity>();
     this.indices     = new List <IIndexer>();
     this.entityLists = new Dictionary <EntityIdentifier, List <List <TEntity> > >();
     if (gateway.IsCacheFeedAvailable)
     {
         eventHub.Subscribe(new EventReceiver(this));
         initializer.Register(
             new Initializer(this),
             suppressEvents: true);
     }
 }
コード例 #21
0
 public void Subscribe(Action <T> action)
 {
     _hub.Subscribe(action);
 }
コード例 #22
0
 public SoundNotificationPlayer(IUserPreferences userPreferences, IEventHub eventHub)
 {
     this.userPreferences = userPreferences;
     eventHub.Subscribe <TimerStopped>(OnTimerStopped);
 }
コード例 #23
0
 public ProjectProvider(IEventHub eventHub)
 {
     // We're only interested in property changed events coming from IProject.
     eventHub.Subscribe <EventSubject <PropertyChangedEventArgs> >(this, (x) => { return(x.Sender is IProject); });
 }
コード例 #24
0
 public AsyncFiberConsumer(IEventHub hub, AutoResetEvent reset)
 {
     _reset = reset;
     hub.Subscribe(Fiber, this);
 }
コード例 #25
0
ファイル: EventHubTests.cs プロジェクト: jamcar23/PubSub.NET
 private void SubInsideThisMethod(IEventHub hub)
 {
     hub.Subscribe <EventHubTests, IEventHub>(this, hub => { });
     hub.Subscribe <EventHubTests, Box <int> >(this, IncrementBox);
 }
コード例 #26
0
 public void Register <T>(Func <T, Task> topicHandler)
 {
     _disposables.Add(_eventHub.Subscribe(topicHandler));
 }
コード例 #27
0
 public NotificationsPresenter(IPomodoroEngine pomodoroEngine, IEventHub eventHub)
 {
     this.pomodoroEngine = pomodoroEngine;
     eventHub.Subscribe <TimerStopped>(OnTimerStopped);
 }
コード例 #28
0
 public SolutionProvider(IEventHub eventHub)
 {
     eventHub.Subscribe <EventSubject <PropertyChangedEventArgs> >(this, (x) => { return(x.Sender is ISolution); });
 }