public void Start(Duration duration, IntervalType intervalType) { this.duration = duration; this.intervalType = intervalType; remainingTime = duration; systemTimer.Start(); eventHub.Publish(new TimerStarted(intervalType, duration, remainingTime)); }
public void TestSubscribingDuringPublishing() { IEventHub hub = EventHub; Box <int> box = new Box <int>(0); Assert.IsTrue(hub.Subscribe <EventHubTests, IEventHub>(this, SubInsideThisMethod)); Assert.DoesNotThrow(() => hub.Publish(hub)); hub.Publish(box); hub.Unsubscribe <EventHubTests, IEventHub>(this); hub.Unsubscribe <EventHubTests, Box <int> >(this); Assert.AreEqual(1, box.Value); }
public void TestPubNoSub() { IEventHub hub = EventHub; Assert.DoesNotThrow(() => hub.Publish(42)); Assert.Pass(); }
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 StartupEvents(IEventHub eventHub) { Task.Run(() => { if (Flags.IsOn(FirstRunFlag, true)) { Flags.TurnOff(FirstRunFlag); eventHub.Publish(new FirstRun()); } if (Flags.IsOn(AppUpdatedFlag, false)) { Flags.TurnOff(AppUpdatedFlag); eventHub.Publish(new AppUpdated()); } }); }
private async Task CompileAndLoad(Workspace[] workspaces) { var myWorksSpace = await FindOrCreate(workspaces); try { var result = await _sqlCqrsGenerator.Generate(0); if (result.Any()) { if (_dynamicPool.All(x => x.SourceUnits.SrcHash != result.SrcHash)) { _logger.Info("New metadata model loaded from database with {hash} hash.", result.SrcHash); DynamicAssembly assembly = new DynamicAssembly(_eventHub); assembly.AddDefaultReferences(); assembly.AppendSourceUnits(result); assembly.Compile(); _dynamicPool.AddOrReplace(assembly); _metadataProvider.Clear(); _metadataProvider.Discover(assembly.Assembly); // TODO: Refactor this and from Load await _eventHub.Publish(new AssemblyLoadedEvent() { Assembly = assembly.Assembly, Purpose = assembly.Purpose }); var c = await _repo.Query <Model.Compilation>() .FirstAsync(x => x.Hash == assembly.SrcHash); c.Workspace = myWorksSpace; myWorksSpace.Status = WorkspaceStatus.Running; c.LoadedAt = DateTimeOffset.Now; await _repo.CommitChanges(); } } } catch (Exception ex) { myWorksSpace.Status = WorkspaceStatus.Error; myWorksSpace.Error = ex.Message; await _repo.CommitChanges(); } }
public void TestPubSub() { IEventHub hub = EventHub; Assert.IsTrue(hub.Subscribe <EventHubTests, int>(this, i => { Assert.Greater(i, 0); })); hub.Publish(42); }
public void DoMyThang() { // 1. do some business MyBusinessData data = SomeBusinessFunction(); // 2. publish complete event AnalysisSubject subject = new AnalysisSubject() { Data = data, }; _events.Publish(subject); }
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 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 Discover(Predicate <HandlerInfo> filter, params Assembly[] assemblies) { if (filter == null) { filter = x => true; } foreach (var handlerType in assemblies.SelectMany(x => x.GetTypes()) .Where(x => !x.IsAbstract && x.IsClass && !x.IsInterface)) { var collection = handlerType.GetInterfaces() .Where(x => x.IsGenericType) .Where(x => x.Namespace == "Monkey.Cqrs") .Where(x => validaHandlers.Any(y => x.Name.StartsWith(y))) .Select(interfaceType => _handlerFactory.Create(interfaceType, handlerType)) .Where(x => x != null) .Where(x => filter(x)); foreach (var handler in collection) { string serviceName = _provider.EvaluateHandler(handler); if (!_services.TryGetValue(serviceName, out ServiceInfo service)) { service = new ServiceInfo(_handlerFactory); service.WithName(serviceName); _services.Add(serviceName, service); } service.AddHandler(handler); } } _hub.Publish(new ServiceMadatadaChangedEvent()); }
private void PomodoroCompleted(Duration duration) { IncreasePomodoroCount(); eventHub.Publish(new PomodoroCompleted(duration)); }
public Task Publish(object viewEvent) { return(_eventHub?.Publish(viewEvent)); }