Exemplo n.º 1
0
        public UserState Calculate(IEnumerable <BaseEvent> baseEvents, DateTime currentTime)
        {
            // Posortuj eventy w kolejności wystąpienia

            var eventQueue = baseEvents.OrderBy(x => x.Date);

            BaseEvent lastOperation = null;
            UserState currentState  = null;

            foreach (var @event in eventQueue)
            {
                var handler = _handlers[@event.GetType()];
                @event.State  = handler(@event, UserState.Copy(lastOperation?.State ?? new UserState()));
                lastOperation = @event;

                if (@event.Date <= currentTime)
                {
                    currentState = @event.State;
                }
            }

            return(currentState);
        }