コード例 #1
0
ファイル: UserHandler.cs プロジェクト: reharik/EventSpike
        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);
        }
コード例 #2
0
ファイル: UserHandler.cs プロジェクト: reharik/EventSpike
        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);
        }
コード例 #3
0
ファイル: UserHandler.cs プロジェクト: reharik/EventSpike
 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;
 } 
コード例 #4
0
 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);
 }
コード例 #5
0
ファイル: DispatcherBase.cs プロジェクト: reharik/EventSpike
 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);
 }
コード例 #6
0
ファイル: HandlerBase.cs プロジェクト: reharik/EventSpike
 // 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);
 }
コード例 #7
0
ファイル: HandlerBase.cs プロジェクト: reharik/EventSpike
        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);
        }
コード例 #8
0
ファイル: UserHandler.cs プロジェクト: reharik/EventSpike
 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);
 }
コード例 #9
0
ファイル: HandlerBase.cs プロジェクト: reharik/EventSpike
        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);
        }
コード例 #10
0
ファイル: HandlerBase.cs プロジェクト: reharik/EventSpike
        // 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);
        }
コード例 #11
0
 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);
 }
コード例 #12
0
        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);
        }
コード例 #13
0
ファイル: UserHandler.cs プロジェクト: reharik/EventSpike
        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);
        }
コード例 #14
0
ファイル: UserHandler.cs プロジェクト: reharik/EventSpike
 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;
 }
コード例 #15
0
ファイル: UserHandler.cs プロジェクト: reharik/EventSpike
 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;
 }
コード例 #16
0
 public bool HandlesEvent(IGESEvent @event)
 {
     return @event.EventType == "RegisterUser";
 }
コード例 #17
0
ファイル: HandlerBase.cs プロジェクト: reharik/EventSpike
 // this is used by all handlers
 protected bool ExpectEventPositionIsGreaterThanLastRecorded(IGESEvent x)
 {
     return(x.OriginalPosition == null || _lastProcessedPosition.CommitPosition >= x.OriginalPosition.Value.CommitPosition);
 }
コード例 #18
0
 public bool HandlesEvent(IGESEvent @event)
 {
     return @event.EventType == "LoginUser";
 }
コード例 #19
0
ファイル: HandlerBase.cs プロジェクト: reharik/EventSpike
 // this is used by all handlers
 protected bool ExpectEventPositionIsGreaterThanLastRecorded(IGESEvent x)
 {
     return x.OriginalPosition == null || _lastProcessedPosition.CommitPosition >= x.OriginalPosition.Value.CommitPosition;
 }
コード例 #20
0
 public bool HandlesEvent(IGESEvent @event)
 {
     return(@event.EventType == "RegisterUser");
 }
コード例 #21
0
 public bool HandlesEvent(IGESEvent @event)
 {
     return(@event.EventType == "LoginUser");
 }
コード例 #22
0
ファイル: UserHandler.cs プロジェクト: reharik/EventSpike
 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;
 }