public void TestDispatchNoArgs() { confirmationValue = INIT_VALUE; dispatcher.UpdateListener(true, SomeEnum.ONE, noArgumentsMethod); dispatcher.Dispatch(SomeEnum.ONE); Assert.AreEqual(INIT_VALUE + INCREMENT, confirmationValue); }
public void OrderTest() { void Listener01() { _counter++; Assert.AreEqual(1, _counter); } void Listener02() { _counter++; Assert.AreEqual(2, _counter); } void Listener03() { _counter++; Assert.AreEqual(3, _counter); } _dispatcher.AddListener(TestEvent.Event00, Listener01); _dispatcher.AddListener(TestEvent.Event00, Listener02); _dispatcher.AddListener(TestEvent.Event00, Listener03); _dispatcher.Dispatch(TestEvent.Event00); Assert.AreEqual(3, _counter); }
/// <summary> /// Even though all of the events are fired in one method, as the payment flow becomes /// more complicated (adding sanctions screening, non-trivial validation, eventual consistency etc) it /// would be 'simple' to refactor the service, audit the payment and add further events. /// </summary> public async Task <Response> Create(CreateRequest request) { var payment = await Get(request.Id); if (payment != null) { return(new Response($"A payment with Id '{request.Id}' already exists")); } await _eventDispatcher.Dispatch(new CreatePaymentEvent(request.Id, DateTime.UtcNow, request.Amount, request.Currency, request.CardNumber)); await _eventDispatcher.Dispatch(new SentToAcquiringBankEvent(request.Id, DateTime.UtcNow)); var response = await _acquiringBankApiClient.Post <Guid>("/payment", new { request.Amount, request.CardNumber, request.Currency, request.ExpiryMonth, request.ExpiryYear, request.SecurityCode }); if (response.IsSuccessful) { await _eventDispatcher.Dispatch(new PaymentSuccessEvent(request.Id, DateTime.UtcNow, response.Value)); } else { await _eventDispatcher.Dispatch(new PaymentFailureEvent(request.Id, DateTime.UtcNow, response.ToString())); } return(response); }
public void RemoveListenerOnceTest00() { void Listener() => _counter++; _dispatcher.AddListenerOnce(TestEvent.Event00, Listener); _dispatcher.RemoveListener(TestEvent.Event00, Listener); _dispatcher.Dispatch(TestEvent.Event00); Assert.AreEqual(0, _counter); }
public void ListenerUniquenessTest00() { void Listener() => _counter++; _dispatcher.AddListener(TestEvent.Event00, Listener); _dispatcher.AddListener(TestEvent.Event00, Listener); _dispatcher.Dispatch(TestEvent.Event00); Assert.AreEqual(1, _counter); }
public void Dispatch(IEventDispatcher dispatcher) { if (Argument == null) { dispatcher.Dispatch(RequestEvent); } else { dispatcher.Dispatch(RequestEvent, Argument); } }
public static void DispatchStrangeEvent(object eventType) { if (strangeDispatcher != null) { strangeDispatcher.Dispatch(eventType); } else { Debug.LogWarning("strangeDispatcher Not Ready"); } }
public void SingleTest() { var count = 0; Command00.OnExecute += () => { count++; }; _binder.Bind(CommandTestEvent.Event00).To <Command00>(); _dispatcher.Dispatch(CommandTestEvent.Event00); Assert.AreEqual(1, count); }
public void SendResetPasswordEmail(string email, bool canBeReset, string hash = null) { var resetPasswordMessage = new ResetPasswordMessage { To = email, CanBeResetInternally = canBeReset, Subject = "Password reset", Link = $"{_passwordResetOptions.Url}/{hash}" }; _emailDispatcher.Dispatch(resetPasswordMessage); }
public void Execute() { switch ((LanguageRequestEvent.Type)evt.type) { case LanguageRequestEvent.Type.REQUEST_CONTENT: dispatcher.Dispatch(new LanguageResponseEvent(LanguageResponseEvent.Type.ON_REQUEST_CONTENT, model.GetText(evt.Key))); break; case LanguageRequestEvent.Type.REQUEST_CURRENT_LANGUAGE: dispatcher.Dispatch(new LanguageResponseEvent(LanguageResponseEvent.Type.ON_REQUEST_CURRENT_LANGUAGE, model.CurrentLanguage)); break; } }
private void Select() { var signal = new HeroSelectedSignal(_hero); _eventDispatcher.Dispatch(signal); _heroGuiController.HighlightSelectableCircle(); }
public async Task <bool> SaveChangesAndDispatchDomainEventsAsync(CancellationToken cancellationToken = default) { var changedEntities = this.GetChangedEntities(); await _eventDispatcher.Dispatch(changedEntities); return(await this.SaveChangesWithRetriesAsync(cancellationToken)); }
private static InMemoryUser UserFound(User dbUser, string userTimezoneOffset) { int?userTimezoneOffsetInt = null; int tmp; if (Int32.TryParse(userTimezoneOffset, out tmp)) { userTimezoneOffsetInt = tmp; } var profiles = UserProfileManager.FindUserProfiles(dbUser); var inMemoryUser = new InMemoryUser(dbUser, profiles, userTimezoneOffsetInt); if (_users.ContainsKey(inMemoryUser.Login)) { _users.Remove(inMemoryUser.Login); } try { _users.Add(inMemoryUser.Login, inMemoryUser); } catch { Log.Warn("Duplicate user should not happen here " + inMemoryUser.Login); } LogicalThreadContext.SetData("user", dbUser.UserName); _eventDispatcher.Dispatch(new UserLoginEvent(inMemoryUser)); if (Log.IsDebugEnabled) { Log.Debug(String.Format("user:{0} logged in with roles {1}; profiles {2}; locations {3}", inMemoryUser.Login, string.Join(",", inMemoryUser.Roles), string.Join(",", inMemoryUser.Profiles), string.Join(",", inMemoryUser.PersonGroups) )); } return(inMemoryUser); }
public CloseEventCommandResult Handle(CloseEventCommand command) { Validate(command); var handledEvents = new List <Domain.Event>(); foreach (var @event in command.Events) { @event.Progress = command.Progress; @event.EndDate = command.EndDate; @event.UpdatedAt = command.UpdateTime; @event.LastUpdateBy = command.Username; handledEvents.Add(@event); } _eventDispatcher.Dispatch(new ClosedEvent(command.CorrelationId) { Events = handledEvents }); return(new CloseEventCommandResult() { Events = handledEvents }); }
protected async Task Dispatch(ResolvedEvent resolvedEvent) { if (resolvedEvent.Event != null && !IsSystemEvent(resolvedEvent)) { await dispatcher.Dispatch(resolvedEvent); } }
/// <summary> /// Processes an event queue by dispatching the events /// </summary> /// <param name="preTransaction">True, if pre-transaction handlers required</param> /// <param name="queue">The event queue to process</param> private void ProcessEventQueue ( IEventQueue queue, bool preTransaction = false ) { while (false == queue.IsEmpty()) { var nextItem = queue.GetNext(); _eventDispatcher.Dispatch ( nextItem.Event, preTransaction ); // We don't want to log pre-transaction events if (false == preTransaction) { _eventLogger.LogEvent ( nextItem.AggregateKey, nextItem.AggregateType, nextItem.Event ); } } }
////////////////////////////////////////////////////////////////////////// /// <summary> /// Sends event synchronously /// </summary> public void SendEvent(IEventDispatcher dispatcher) { using (dispatcher) { dispatcher.Dispatch(); } }
////////////////////////////////////////////////////////////////////////// /// <summary> /// Sends event synchronously /// </summary> public void SendEvent(IEventDispatcher dispatcher) { using (dispatcher) { dispatcher.Dispatch(); } }
public async Task Publish(UncommittedEvents events) { foreach (var @event in events.GetStream()) { Stamp(@event); await CheckSequence(@event); await SaveAndDispatch(@event); } async Task CheckSequence(IDomainEvent @event) { if (await _eventStore.GetLastSequence(@event.AggregateId) >= @event.Sequence) { throw new ConcurrencyException(); } } async Task SaveAndDispatch(IDomainEvent @event) { await _eventStore.Save(@event); await _eventDispatcher.Dispatch(@event); } void Stamp(IDomainEvent @event) => ((IEventMetaData)@event).SetCreationInfos(_connectedUserService.GetCurrentUserName(), DateTimeOffset.Now); }
public RepositoryEntityState PreSaveChanges(RepositoryEntityState entityState, object entity) { if (entity is IDomianEventProvider domianEventProvider) { var entityEvents = domianEventProvider.GetDomainEvents(); var completedEventCount = 0; if (entityEvents == null || entityEvents.Count == 0) { return(entityState); } foreach (var @event in entityEvents) { try { _eventDispatcher.Dispatch(@event); completedEventCount++; } catch { } } if (completedEventCount != entityEvents.Count) { //count is not equal. prove the existence of failed events } } return(entityState); }
public void SetHighscore(int highscore) { if (highscore > Highscore) { Highscore = highscore; dispatcher.Dispatch(new HighscoreEvent(HighscoreEvent.Type.HIGHSCORE_UPDATED, highscore)); } }
/*============================================================================*/ /* Public Functions */ /*============================================================================*/ public void Execute() { eventCommandMap .Map(EventType.CASCADING_EVENT) .ToCommand <NullCommand>().Once(); dispatcher.Dispatch(new Event(EventType.CASCADING_EVENT)); }
public void InvokeUnregisteredListener() { void Listener() => _counter++; _dispatcher.RemoveListener(TestEvent.Event00, Listener); _dispatcher.Dispatch(TestEvent.Event00); Assert.AreEqual(0, _counter); }
public void Dispatch(ICommit commit) { if (commit.Headers.ContainsKey(PreventCommitDispatchHeader.Key)) { return; } commit.Events.Select(m => m.Body).ForEach(e => innerDispatcher.Dispatch(e)); }
public void Allows_Communication_From_Child_To_Parent() { parentConnector.OnDefaultChannel() .ReceiveEvent(SupportEvent.Type.TYPE1); childAConnector.OnDefaultChannel() .RelayEvent(SupportEvent.Type.TYPE1); bool wasCalled = false; parentDispatcher.AddEventListener(SupportEvent.Type.TYPE1, delegate(IEvent evt) { wasCalled = true; }); childADispatcher.Dispatch(new SupportEvent(SupportEvent.Type.TYPE1)); Assert.That(wasCalled, Is.True); }
public void SingleTest() { var count = 0; var param01Received = 0; Command01.OnExecute += param01 => { count++; param01Received = param01; }; _binder.Bind(CommandTestEvent.Event01).To <Command01>(); _dispatcher.Dispatch(CommandTestEvent.Event01, 10); Assert.AreEqual(1, count); Assert.AreEqual(10, param01Received); }
protected void DispatchEvents(EntityAbstract entity) { foreach (var domainEvent in entity.DomainEvents.ToList()) { _eventDispatcher.Dispatch(domainEvent); entity.RemoveDomainEvent(domainEvent); } }
public override async Task HandleAsync(LogReceivedEvent evnt) { if (evnt == null) { throw new ArgumentNullException(nameof(evnt)); } await _eventDispatcher.Dispatch(evnt); }
public void Execute(int personId) { var person = _repository.Get(personId); person.Deactivate(); _eventDispatcher.Dispatch(person.Events.ToArray()); //Send Email //Send Sms }
public void Execute() { var readOnlyToDo = model.ToDoList; List <Item> toDo = new List <Item>(); toDo.AddRange(readOnlyToDo); dispatcher.Dispatch(new GetToDoItemsEvent(GetToDoItemsEvent.Type.Got, toDo)); }
public void SetCurrentLanguage(string language) { if (_currentLanguage == language) { return; } _currentLanguage = language; dispatcher.Dispatch(new LanguageEvent(LanguageEvent.Type.CHANGED_LANGUAGE, language)); }