public Decision(IEventStream stream) { foreach (var domainEvent in stream.GetEvents()) { if (domainEvent is UserDeleted userDeleted) { Apply(userDeleted); } } }
private void Restore(IEventStream stream) { foreach (var domainEvent in stream.GetEvents()) { if (domainEvent is RadioCreated radioCreated) { Name = radioCreated.Name; Url = radioCreated.Url; } } }
public Decision(IEventStream stream) { _stream = stream; foreach (var domainEvent in _stream.GetEvents()) { if (domainEvent is RadioDeleted radioDeleted) { Apply(radioDeleted); } } }
public async Task Start(CancellationToken cancellationToken) { var handlers = _allHandlersResolver(); var types = handlers.Select(h => h.GetType().GenericTypeArguments.Single()); await _eventStream.Start(types); while (cancellationToken.IsCancellationRequested == false) { var eventWrappers = await _eventStream.GetEvents(); foreach (var eventWrapper in eventWrappers) { if (_processEventDelegateCache.ContainsKey(eventWrapper.Event.GetType()) == false) { _processEventDelegateCache.Add(eventWrapper.Event.GetType(), GetProcessEventDelegate(eventWrapper.Event.GetType())); } await _processEventDelegateCache[eventWrapper.Event.GetType()](eventWrapper); } } }
private void Restore(IEventStream stream) { foreach (var domainEvent in stream.GetEvents()) { if (domainEvent is UserCreated userCreated) { Identity = userCreated.Identity; } else if (domainEvent is PlaylistAdded playlistAdded) { Playlist = new Playlist(playlistAdded.PlaylistId, playlistAdded.Name); } else if (domainEvent is SongAdded songAdded) { Playlist.AddSong(new Song(songAdded.SongId, songAdded.Title, songAdded.Artist)); } else if (domainEvent is PlaylistDeleted) { Playlist = Playlist.Empty; } } }
public bool RadioSongExists(string name, RadioSong radioSong) { return(_stream.GetEvents().OfType <RadioSongParsed>() .Any(x => x == new RadioSongParsed(name, radioSong.Title, radioSong.Artist))); }