Esempio n. 1
0
 public AggregateCommit(IAggregateRootId aggregateId, int revision, List<IEvent> events)
 {
     AggregateRootId = aggregateId.RawId;
     BoundedContext = aggregateId.GetType().GetBoundedContext().BoundedContextName;
     Revision = revision;
     InternalEvents = events.Cast<object>().ToList();
     Timestamp = DateTime.UtcNow.ToFileTimeUtc();
 }
 public EventStream Load(IAggregateRootId aggregateId)
 {
     using (SqlConnection connection = new SqlConnection(connectionString))
     {
         connection.Open();
         string boundedContext = aggregateId.GetType().GetBoundedContext().BoundedContextName;
         string query = String.Format(LoadAggregateStateQueryTemplate, tableNameStrategy.GetEventsTableName(boundedContext, aggregateId));
         SqlCommand command = new SqlCommand(query, connection);
         command.Parameters.AddWithValue("@aggregateId", Convert.ToBase64String(aggregateId.RawId));
         List<AggregateCommit> aggregateCommits = new List<AggregateCommit>();
         using (var reader = command.ExecuteReader())
         {
             while (reader.Read())
             {
                 var buffer = reader[0] as byte[];
                 using (var stream = new MemoryStream(buffer))
                 {
                     aggregateCommits.Add((AggregateCommit)serializer.Deserialize(stream));
                 }
             }
         }
         return new EventStream(aggregateCommits);
     }
 }