/// <summary> /// /// </summary> /// <param name="bucketId"></param> /// <param name="aggregate"></param> /// <param name="commitId"></param> /// <param name="updateHeaders"></param> /// <returns></returns> public Int32 Save(string bucketId, IAggregateEx aggregate, Guid commitId, Action <IDictionary <string, object> > updateHeaders) { if (_disposed) { throw new ObjectDisposedException("This instance of repository was already disposed"); } Dictionary <string, object> headers = PrepareHeaders(aggregate, updateHeaders); Int32 uncommittedEvents = aggregate.GetUncommittedEvents().Count; while (true) { IEventStream stream = this.PrepareStream(bucketId, aggregate, headers); int commitEventCount = stream.CommittedEvents.Count; try { stream.CommitChanges(commitId); aggregate.ClearUncommittedEvents(); return(uncommittedEvents); } catch (DuplicateCommitException dex) { stream.ClearChanges(); _logger.Debug(String.Format("Duplicate commit exception bucket {0} - id {1} - commitid {2}. \n{3}", bucketId, aggregate.Id, commitId, dex)); return(0); //no events commited } catch (ConcurrencyException e) { _logger.Warn(String.Format("Concurrency Exception bucket {0} - id {1} - commitid {2}. \n{3}", bucketId, aggregate.Id, commitId, e)); if (this.ThrowOnConflict(stream, commitEventCount)) { //@@FIX -> aggiungere prima del lancio dell'eccezione stream.ClearChanges(); throw new ConflictingCommandException(e.Message, e); } stream.ClearChanges(); } catch (StorageException e) { throw new PersistenceException(e.Message, e); } finally { ReleaseAggregateId(aggregate.Id); } } }
public void Save(string bucketId, IAggregateEx aggregate, Guid commitId, Action <IDictionary <string, object> > updateHeaders) { Dictionary <string, object> headers = PrepareHeaders(aggregate, updateHeaders); while (true) { IEventStream stream = this.PrepareStream(bucketId, aggregate, headers); int commitEventCount = stream.CommittedEvents.Count; try { stream.CommitChanges(commitId); aggregate.ClearUncommittedEvents(); return; } catch (DuplicateCommitException) { stream.ClearChanges(); return; } catch (ConcurrencyException e) { if (this.ThrowOnConflict(stream, commitEventCount)) { //@@FIX -> aggiungere prima del lancio dell'eccezione stream.ClearChanges(); throw new ConflictingCommandException(e.Message, e); } stream.ClearChanges(); } catch (StorageException e) { throw new PersistenceException(e.Message, e); } finally { ReleaseAggregateId(aggregate.Id); } } }
protected static void ClearUncommittedEvents() { IAggregateEx agg = Aggregate; agg.ClearUncommittedEvents(); }