コード例 #1
0
        public void ProcessDuplicateEvent()
        {
            var testEvent = new GameCreatedEvent();
            var mockIdempotencyChecker = new Mock<IIdempotencyChecker>();
            var mockQueryDataStore = new Mock<IQueryDataStore>();

            mockIdempotencyChecker.Setup(x => x.CheckIdempotency(testEvent.EventId)).Returns(true);

            var sut = new EventHandlerFactory(mockQueryDataStore.Object, mockIdempotencyChecker.Object, null);

            sut.HandleEvent(testEvent);

            mockQueryDataStore.Verify(x => x.Insert(It.IsAny<GetGameCountByDateDto>()), Times.Never());
        }
コード例 #2
0
        public void ProcessNewEvent()
        {
            var testEvent = new GameCreatedEvent();
            var mockIdempotencyChecker = new Mock<IIdempotencyChecker>();
            var mockQueryDataStore = new Mock<IQueryDataStore>();
            var mockDatabaseLayer = new Mock<IDatabaseLayer>();

            mockDatabaseLayer.Setup(x => x.ExecuteInTransaction(It.IsAny<Action>())).Callback<Action>(x => x());

            mockIdempotencyChecker.Setup(x => x.CheckIdempotency(testEvent.EventId)).Returns(false);

            var sut = new EventHandlerFactory(mockQueryDataStore.Object, mockIdempotencyChecker.Object, mockDatabaseLayer.Object);

            sut.HandleEvent(testEvent);

            mockQueryDataStore.Verify(x => x.Insert(It.IsAny<GetGameCountByDateDto>()));
        }
コード例 #3
0
        private void HandleEvents(IEnumerable<IEvent> events, IQueryDataStore queryDataStore)
        {
            var mockIdempotencyChecker = new Mock<IIdempotencyChecker>();
            var mockDatabaseLayer = new Mock<IDatabaseLayer>();

            mockDatabaseLayer.Setup(x => x.ExecuteInTransaction(It.IsAny<Action>())).Callback<Action>(x => x());

            var eventHandler = new EventHandlerFactory(queryDataStore, mockIdempotencyChecker.Object, mockDatabaseLayer.Object);

            foreach (IEvent e in events)
            {
                eventHandler.HandleEvent(e);
            }
        }
コード例 #4
0
ファイル: EventsVerifier.cs プロジェクト: nbstrat/aout1
        private MethodInfo registerLocallyForEvent(EventInfo eventInfo, object target)
        {
            EventHandlerFactory factory = new EventHandlerFactory("testing");

            object handler = factory.GetEventHandler(eventInfo);

            // Create a delegate, which points to the custom event handler
            Delegate customEventDelegate = Delegate.CreateDelegate(eventInfo.EventHandlerType, handler, "CustomEventHandler");
            // Link event handler to event
            eventInfo.AddEventHandler(target, customEventDelegate);

            // Map our own event handler to the common event
            EventInfo commonEventInfo = handler.GetType().GetEvent("CommonEvent");
            Delegate commonDelegate = Delegate.CreateDelegate(commonEventInfo.EventHandlerType, this, "MyEventCallback");
            commonEventInfo.AddEventHandler(handler, commonDelegate);

            return null;
        }
コード例 #5
0
 private IObservable <String> observableFromFileEvent(String eventName)
 {
     return(EventHandlerFactory
            .GetEventObservable(watcher, eventName)
            .Select(o => ((FileSystemEventArgs)o.EventArgs).FullPath));
 }
コード例 #6
0
        public void Run()
        {
            EventHandlerFactory.AddEventHandler(typeof(PostHandler).GetTypeInfo().Assembly);
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddOptions();
            serviceCollection.Configure <EntityMutexFactoryOptions>(options => {
                options.ConnectionString = _configurationRoot.GetSection("Lock")["ConnectionString"];
                options.Name             = _configurationRoot.GetSection("Lock")["Name"];
            });
            serviceCollection.Configure <JobHandlerOptions>(options => {
                options.ConnectionString   = _configurationRoot.GetSection("JobHandler")["ConnectionString"];
                options.JobTableName       = _configurationRoot.GetSection("JobHandler")["JobTableName"];
                options.CommandTableName   = _configurationRoot.GetSection("JobHandler")["CommandTableName"];
                options.EventTableName     = _configurationRoot.GetSection("JobHandler")["EventTableName"];
                options.ArchiveStorageName = _configurationRoot.GetSection("JobHandler")["ArchiveStorageName"];
                options.ArchiveTableName   = _configurationRoot.GetSection("JobHandler")["ArchiveTableName"];
            });
            serviceCollection.Configure <EventQueueOptions>(options => {
                options.FileShareConnectionString =
                    _configurationRoot.GetSection("EventQueue")["FileShareConnectionString"];
                options.FileShareName         = _configurationRoot.GetSection("EventQueue")["FileShareName"];
                options.QueueConnectionString = _configurationRoot.GetSection("EventQueue")["QueueConnectionString"];
                options.QueueName             = _configurationRoot.GetSection("EventQueue")["QueueName"];
            });
            serviceCollection.Configure <CommandStoreOptions>(options => {
                options.ConnectionString = _configurationRoot.GetSection("CommandStore")["ConnectionString"];
                options.Name             = _configurationRoot.GetSection("CommandStore")["Name"];
            });
            serviceCollection.Configure <CommandQueueOptions>(options => {
                options.FileShareConnectionString =
                    _configurationRoot.GetSection("CommandQueue")["FileShareConnectionString"];
                options.FileShareName         = _configurationRoot.GetSection("CommandQueue")["FileShareName"];
                options.QueueConnectionString = _configurationRoot.GetSection("CommandQueue")["QueueConnectionString"];
                options.QueueName             = _configurationRoot.GetSection("CommandQueue")["QueueName"];
            });
            serviceCollection.Configure <SecurityServiceOptions>(options => {
                options.Encryption = bool.Parse(_configurationRoot.GetSection("Security")["Encryption"]);
                options.Key        = _configurationRoot.GetSection("Security")["Key"];
            });
            serviceCollection.AddScoped <ICommandQueue, CommandQueue>();
            serviceCollection.AddScoped <IEntityMutexFactory, EntityMutexFactory>();
            serviceCollection.AddScoped <IMutexGarbageCollector, MutexGarbageCollector>();
            serviceCollection.AddScoped <IJsonConverter, NewtonsoftJsonConverter>();
            serviceCollection.AddScoped <IJobHandler, JobHandler>();
            serviceCollection.AddScoped <PostHandler>();
            serviceCollection.AddScoped <ICommandStore, CommandStore>();
            serviceCollection.AddScoped <IActionDispatcher, ActionDispatcher>();
            serviceCollection.AddScoped <EventProcessor>();
            serviceCollection.AddScoped <EventHandlerFactory>();
            serviceCollection.AddScoped <IEventQueue, EventQueue>();
            serviceCollection.AddScoped <ISecurityService, SecurityService>();

            var serviceProvider = serviceCollection.BuildServiceProvider();
            var eventQueue      = serviceProvider.GetService <IEventQueue>();

            Console.WriteLine("Start listening...");
            eventQueue.RegisterMessageHandler(async(wrapper, token) => {
                using (var scopedServiceProvider = serviceProvider.CreateScope()) {
                    var eventProcessor = scopedServiceProvider.ServiceProvider.GetService <EventProcessor>();
                    var eventType      = wrapper.GetType().GetTypeInfo().GetGenericArguments()[0];
                    await(Task) eventProcessor.GetType()
                    .GetMethod("Process")
                    .MakeGenericMethod(eventType)
                    .Invoke(eventProcessor, new object[] { wrapper });
                    scopedServiceProvider.ServiceProvider.GetService <IMutexGarbageCollector>().Collect();
                }
            });
        }
コード例 #7
0
 public async Task EnqueueAsync <T>(string queueName, T message)
 {
     var queueMessage = QueueMessage.CreateQueueMessage(queueName, message);
     var job          = EventHandlerFactory.GetEventHandlerInstance(queueName, queueMessage);
     //await _jobs.SendAsync(job);
 }
コード例 #8
0
ファイル: Environment.cs プロジェクト: adz21c/Periturf
 private Environment()
 {
     _eventHandlerFactory = new EventHandlerFactory(this);
 }