Example #1
0
 public UserFail()
 {
     Factory = (events, observer) =>
     {
         var state = new UserAggregateState(events);
         return(new UserAggregate(state, observer));
     };
 }
Example #2
0
 public UserAggregate()
 {
     _userState = new UserAggregateState
     {
         Picture = string.Empty,
         Subject = string.Empty,
         State   = UserStates.NotCreated
     };
 }
Example #3
0
        public Applied Load(ICollection <ICommand <IIdentity> > commands)
        {
            var id      = commands.First().Id;
            var stream  = _factory.GetOrCreateStream(IdentityConvert.ToStream(id));
            var records = stream.ReadRecords(0, int.MaxValue).ToList();
            var events  = records
                          .SelectMany(r => _streamer.ReadAsEnvelopeData(r.Data).Items.Select(m => (IEvent <IIdentity>)m.Content))
                          .ToArray();

            var then = new Applied();

            if (records.Count > 0)
            {
                then.Version = records.Last().Version;
            }

            var user = id as UserId;

            if (user != null)
            {
                var state = new UserAggregateState(events);
                var agg   = new UserAggregate(state, then.Events.Add);
                ExecuteSafely(agg, commands);
                return(then);
            }

            var security = id as SecurityId;

            if (security != null)
            {
                var state = new SecurityAggregateState(events);
                var agg   = new SecurityAggregate(state, then.Events.Add, new PasswordGenerator(), _generator);
                ExecuteSafely(agg, commands);
                return(then);
            }

            throw new NotSupportedException("identity not supported " + id);
        }