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); }); }
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); }
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); }
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); }
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); }
public void TestSubUnsubUsingMethods() { IEventHub hub = EventHub; Assert.IsTrue(hub.Subscribe <EventHubTests, Box <int> >(this, IncrementBox)); Assert.IsTrue(hub.Unsubscribe <EventHubTests, Box <int> >(this)); }
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); }
Subscribe <T>(this IEventHub sub, Action eventHandler) { return(sub.Subscribe <T>(topic => { eventHandler(); return Task.CompletedTask; })); }
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); }
public static IDisposable Subscribe <T>(this IEventHub sub, Action <T> eventHandler) { return(sub.Subscribe <T>(topic => { eventHandler(topic); return Task.CompletedTask; })); }
public PomodoroEngine(ITimer timer, IUserPreferences userPreferences, IEventHub eventHub) { this.timer = timer; this.userPreferences = userPreferences; this.eventHub = eventHub; eventHub.Subscribe <TimerStopped>(OnTimerStopped); }
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)); }
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); }
public void TestPubSub() { IEventHub hub = EventHub; Assert.IsTrue(hub.Subscribe <EventHubTests, int>(this, i => { Assert.Greater(i, 0); })); hub.Publish(42); }
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); }
public ExportTagsCommand( IEventHub eventHub, TagSourceService tagSourceService, ActivityReaderMessageClient activityReaderMessageClient, IViewTimelineCache viewTimelineCache) { _tagSourceService = tagSourceService; _activityReaderMessageClient = activityReaderMessageClient; _viewTimelineCache = viewTimelineCache; eventHub.Subscribe <TagSourceCacheUpdatedEvent>(OnTagSourceCacheUpdated); InvokeOnUiThread(SetCanExecute); }
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]); } } }
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); }
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); } }
public void Subscribe(Action <T> action) { _hub.Subscribe(action); }
public SoundNotificationPlayer(IUserPreferences userPreferences, IEventHub eventHub) { this.userPreferences = userPreferences; eventHub.Subscribe <TimerStopped>(OnTimerStopped); }
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); }); }
public AsyncFiberConsumer(IEventHub hub, AutoResetEvent reset) { _reset = reset; hub.Subscribe(Fiber, this); }
private void SubInsideThisMethod(IEventHub hub) { hub.Subscribe <EventHubTests, IEventHub>(this, hub => { }); hub.Subscribe <EventHubTests, Box <int> >(this, IncrementBox); }
public void Register <T>(Func <T, Task> topicHandler) { _disposables.Add(_eventHub.Subscribe(topicHandler)); }
public NotificationsPresenter(IPomodoroEngine pomodoroEngine, IEventHub eventHub) { this.pomodoroEngine = pomodoroEngine; eventHub.Subscribe <TimerStopped>(OnTimerStopped); }
public SolutionProvider(IEventHub eventHub) { eventHub.Subscribe <EventSubject <PropertyChangedEventArgs> >(this, (x) => { return(x.Sender is ISolution); }); }