private IReadModel userLoggedIn(IGESEvent x) { var userLoggedIn = (UserLoggedIn)x; var userLogins = new UserLogins { UserName = userLoggedIn.UserName, Id = userLoggedIn.Id, Token = userLoggedIn.Token, Date = userLoggedIn.Now }; var input = JsonConvert.SerializeObject(userLoggedIn); var output = JsonConvert.SerializeObject(userLogins); // noise Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("input: "); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(input); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("output: "); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(output); // noise return(userLogins); }
private IReadModel userRegistered(IGESEvent x) { Thread.Sleep(1000); var userRegistered = (UserRegistered)x; var user = _mongoRepository.Get <User>(u => u.Id == userRegistered.Id); user.UserName = userRegistered.UserName; user.FirstName = userRegistered.FirstName; user.LastName = userRegistered.LastName; user.Email = userRegistered.EmailAddress; var input = JsonConvert.SerializeObject(userRegistered); var output = JsonConvert.SerializeObject(user); // noise Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("input: "); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(input); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("output: "); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(output); // noise return(user); }
public bool HandlesEvent(IGESEvent @event) { if (@event.EventType == "UserCreated") { return true; } if (@event.EventType == "UserRegistered") { return true; } if (@event.EventType == "UserLoggedIn") { return true; } return false; }
public void HandleEvent(IGESEvent _event) { // noise Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("Handing Event to broadcast block: "); Console.ForegroundColor = ConsoleColor.White; Console.Write(_event.EventType); Console.Write(Environment.NewLine); // noise _broadcastBlock.Post(_event); }
// this is only used by readmodeleventhandler not commandmodel //TODO figure out how to abstract this so it can be use by both. //TODO problem is event is saved to mongo and command is saved to GES protected void HandleEvent(IGESEvent @event, Func<IGESEvent, IReadModel> handleBy) { if (ExpectEventPositionIsGreaterThanLastRecorded(@event)) { return; }; var view = handleBy(@event); _mongoRepository.Save(view); // noise Console.ForegroundColor = ConsoleColor.Cyan; Console.Write("ReadModel Saved: "); Console.ForegroundColor = ConsoleColor.White; Console.Write(JsonConvert.SerializeObject(view)); // noise SetEventAsRecorded(@event); }
protected void SetEventAsRecorded(IGESEvent @event) { // can probably find way to check if we have already got it // and then just update and save rather than retreive for every event if ([email protected]) throw new ArgumentException("ResolvedEvent didn't come off a subscription to all (has no position)."); var lastProcessedPosition = _mongoRepository.Get<LastProcessedPosition>(x => x.HandlerType == _handlerType) ?? new LastProcessedPosition { HandlerType = _handlerType, CommitPosition = 0, PreparePosition = 0 }; lastProcessedPosition.CommitPosition = @event.OriginalPosition.Value.CommitPosition; lastProcessedPosition.PreparePosition = @event.OriginalPosition.Value.PreparePosition; _mongoRepository.Save(lastProcessedPosition); }
public bool HandlesEvent(IGESEvent @event) { if (@event.EventType == "UserCreated") { return(true); } if (@event.EventType == "UserRegistered") { return(true); } if (@event.EventType == "UserLoggedIn") { return(true); } return(false); }
protected void SetEventAsRecorded(IGESEvent @event) { // can probably find way to check if we have already got it // and then just update and save rather than retreive for every event if ([email protected]) { throw new ArgumentException("ResolvedEvent didn't come off a subscription to all (has no position)."); } var lastProcessedPosition = _mongoRepository.Get <LastProcessedPosition>(x => x.HandlerType == _handlerType) ?? new LastProcessedPosition { HandlerType = _handlerType, CommitPosition = 0, PreparePosition = 0 }; lastProcessedPosition.CommitPosition = @event.OriginalPosition.Value.CommitPosition; lastProcessedPosition.PreparePosition = @event.OriginalPosition.Value.PreparePosition; _mongoRepository.Save(lastProcessedPosition); }
// this is only used by readmodeleventhandler not commandmodel //TODO figure out how to abstract this so it can be use by both. //TODO problem is event is saved to mongo and command is saved to GES protected void HandleEvent(IGESEvent @event, Func <IGESEvent, IReadModel> handleBy) { if (ExpectEventPositionIsGreaterThanLastRecorded(@event)) { return; } ; var view = handleBy(@event); _mongoRepository.Save(view); // noise Console.ForegroundColor = ConsoleColor.Cyan; Console.Write("ReadModel Saved: "); Console.ForegroundColor = ConsoleColor.White; Console.Write(JsonConvert.SerializeObject(view)); // noise SetEventAsRecorded(@event); }
protected async void PostEvent(IGESEvent @event, Guid commitId, Dictionary<string, object> updateHeaders = null) { // standard data for metadata portion of persisted event var commitHeaders = new Dictionary<string, object> { // handy tracking id {CommitIdHeader, commitId}, {CommandClrTypeHeader, @event.GetType().AssemblyQualifiedName} }; // add extra data to metadata portion of presisted event commitHeaders = (updateHeaders ?? new Dictionary<string, object>()) .Concat(commitHeaders) .GroupBy(d => d.Key) .ToDictionary(d => d.Key, d => d.First().Value); // process command so they fit the expectations of GES var commandToSave = new[] {ToEventData(Guid.NewGuid(), @event, commitHeaders)}; // post to command stream await _eventStoreConnection.AppendToStreamAsync(EventStreamName, ExpectedVersion.Any, commandToSave); }
protected async void PostEvent(IGESEvent @event, Guid commitId, Dictionary <string, object> updateHeaders = null) { // standard data for metadata portion of persisted event var commitHeaders = new Dictionary <string, object> { // handy tracking id { CommitIdHeader, commitId }, { CommandClrTypeHeader, @event.GetType().AssemblyQualifiedName } }; // add extra data to metadata portion of presisted event commitHeaders = (updateHeaders ?? new Dictionary <string, object>()) .Concat(commitHeaders) .GroupBy(d => d.Key) .ToDictionary(d => d.Key, d => d.First().Value); // process command so they fit the expectations of GES var commandToSave = new[] { ToEventData(Guid.NewGuid(), @event, commitHeaders) }; // post to command stream await _eventStoreConnection.AppendToStreamAsync(EventStreamName, ExpectedVersion.Any, commandToSave); }
private IReadModel userCreated(IGESEvent x) { var userCreated = (UserCreated)x; var user = new User { Id = userCreated.Id }; var input = JsonConvert.SerializeObject(userCreated); var output = JsonConvert.SerializeObject(user); // noise Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("input: "); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(input); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("output: "); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(output); // noise return(user); }
private IReadModel userRegistered(IGESEvent x) { Thread.Sleep(1000); var userRegistered = (UserRegistered)x; var user = _mongoRepository.Get<User>(u => u.Id == userRegistered.Id); user.UserName = userRegistered.UserName; user.FirstName = userRegistered.FirstName; user.LastName = userRegistered.LastName; user.Email = userRegistered.EmailAddress; var input = JsonConvert.SerializeObject(userRegistered); var output = JsonConvert.SerializeObject(user); // noise Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("input: "); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(input); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("output: "); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(output); // noise return user; }
private IReadModel userLoggedIn(IGESEvent x) { var userLoggedIn = (UserLoggedIn) x; var userLogins = new UserLogins { UserName = userLoggedIn.UserName, Id = userLoggedIn.Id, Token = userLoggedIn.Token, Date = userLoggedIn.Now }; var input = JsonConvert.SerializeObject(userLoggedIn); var output = JsonConvert.SerializeObject(userLogins); // noise Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("input: "); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(input); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("output: "); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(output); // noise return userLogins; }
public bool HandlesEvent(IGESEvent @event) { return @event.EventType == "RegisterUser"; }
// this is used by all handlers protected bool ExpectEventPositionIsGreaterThanLastRecorded(IGESEvent x) { return(x.OriginalPosition == null || _lastProcessedPosition.CommitPosition >= x.OriginalPosition.Value.CommitPosition); }
public bool HandlesEvent(IGESEvent @event) { return @event.EventType == "LoginUser"; }
// this is used by all handlers protected bool ExpectEventPositionIsGreaterThanLastRecorded(IGESEvent x) { return x.OriginalPosition == null || _lastProcessedPosition.CommitPosition >= x.OriginalPosition.Value.CommitPosition; }
public bool HandlesEvent(IGESEvent @event) { return(@event.EventType == "RegisterUser"); }
public bool HandlesEvent(IGESEvent @event) { return(@event.EventType == "LoginUser"); }
private IReadModel userCreated(IGESEvent x) { var userCreated = (UserCreated)x; var user = new User {Id = userCreated.Id}; var input = JsonConvert.SerializeObject(userCreated); var output = JsonConvert.SerializeObject(user); // noise Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("input: "); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(input); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("output: "); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(output); // noise return user; }