/// <summary> /// Save the specified aggregate /// </summary> /// <param name="aggregate">aggregate to save</param> /// <param name="commitId">the commit id</param> /// <param name="updateHeaders">update headers</param> public void Save(SimpleAggregate aggregate, Guid commitId, Action <IDictionary <string, object> > updateHeaders) { if (aggregate == null) { throw new ArgumentNullException("aggregate"); } if (aggregate.Id == Guid.Empty) { throw new InvalidOperationException("Guid.Empty is not a valid id for an aggregate"); } LazyInit(ref _storeEvents, _lockObject); _repository.Save(aggregate, commitId, updateHeaders); }
public void Snapshot(SimpleAggregate aggregate) { var memento = aggregate.prepareMemento(); _storeEvents.Advanced.AddSnapshot(new Snapshot(aggregate.Id.ToString(), memento.Version, memento)); }
static void Main(string[] args) { var repoType = eRepositoryType.AzureBlob; if (args.Length > 0) { if (args[0].Equals("sql", StringComparison.OrdinalIgnoreCase)) { repoType = eRepositoryType.Sql; } } var eventsPerAggregate = 30; var aggregatesToMake = 5; if (args.Length > 1) { aggregatesToMake = Convert.ToInt32(args[1]); } var history = new ConcurrentBag <Tuple <Guid, ConcurrentBag <int> > >(); var startTime = DateTime.UtcNow; var options = new ParallelOptions() { MaxDegreeOfParallelism = Math.Min(15, aggregatesToMake / 5 + 5) }; Parallel.For(0, aggregatesToMake, options, (i) => { var aggregateId = Guid.NewGuid(); var values = new ConcurrentBag <int>(); Stopwatch sw = new Stopwatch(); sw.Start(); var repo = new TestRepository(repoType); Stopwatch creationTimer = new Stopwatch(); creationTimer.Start(); values.Add(42); Thread.Sleep(new Random().Next(0, 1000)); var aggy = SimpleAggregate.CreateNew(DateTime.Now, aggregateId, 42); repo.Save(aggy, Guid.NewGuid(), null); creationTimer.Stop(); _log.Trace("Create aggy in [{0}]", creationTimer.Elapsed); Random random = new Random(); var commitOptions = new ParallelOptions() { MaxDegreeOfParallelism = 10 }; Parallel.For(0, eventsPerAggregate, options, (j) => { values.Add(j); try { RetryWhileConcurrent(repoType, aggy.Id, j); } catch (Exception ex) { _log.Error("error iteration {0}-{1}, {2}", i, j, ex.ToString()); } }); history.Add(new Tuple <Guid, ConcurrentBag <int> >(aggregateId, values)); _log.Trace(string.Format("Iteration [{0}] took me [{1}] ms", i, sw.ElapsedMilliseconds)); }); var totalTime = DateTime.UtcNow.Subtract(startTime); _log.Info("checking aggregates for errors"); Parallel.ForEach(history, (historyItem) => { var repository = new TestRepository(repoType); CheckAggregate(repository, historyItem.Item1, historyItem.Item2); }); _log.Info("Took [{0}] to source all aggregates", totalTime); }
public void Snapshot(SimpleAggregate aggregate) { var memento = aggregate.prepareMemento(); _storeEvents.Advanced.AddSnapshotAsync(new Snapshot(aggregate.Id.ToString(), memento.Version, memento), CancellationToken.None).GetAwaiter().GetResult(); }