Esempio n. 1
0
        public void Start(Duration duration, IntervalType intervalType)
        {
            this.duration     = duration;
            this.intervalType = intervalType;

            remainingTime = duration;

            systemTimer.Start();

            eventHub.Publish(new TimerStarted(intervalType, duration, remainingTime));
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        public void TestPubNoSub()
        {
            IEventHub hub = EventHub;

            Assert.DoesNotThrow(() => hub.Publish(42));
            Assert.Pass();
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
        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());
                }
            });
        }
Esempio n. 6
0
        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();
            }
        }
Esempio n. 7
0
        public void TestPubSub()
        {
            IEventHub hub = EventHub;

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

            hub.Publish(42);
        }
Esempio n. 8
0
    public void DoMyThang()
    {
        // 1. do some business
        MyBusinessData data = SomeBusinessFunction();
        // 2. publish complete event
        AnalysisSubject subject = new AnalysisSubject()
        {
            Data = data,
        };

        _events.Publish(subject);
    }
Esempio n. 9
0
        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);
        }
Esempio n. 10
0
        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);
        }
Esempio n. 11
0
        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());
        }
Esempio n. 12
0
 private void PomodoroCompleted(Duration duration)
 {
     IncreasePomodoroCount();
     eventHub.Publish(new PomodoroCompleted(duration));
 }
 public Task Publish(object viewEvent)
 {
     return(_eventHub?.Publish(viewEvent));
 }