/// <summary> /// Inserts the given saga data instance into the index file /// </summary> public async Task Insert(ISagaData sagaData, IEnumerable <ISagaCorrelationProperty> correlationProperties) { using (new FileSystemExclusiveLock(_lockFile, _log)) { var index = new FileSystemSagaIndex(_basePath); var id = GetId(sagaData); if (sagaData.Revision != 0) { throw new InvalidOperationException($"Attempted to insert saga data with ID {id} and revision {sagaData.Revision}, but revision must be 0 on first insert!"); } var existingSaga = index.FindById(id); if (existingSaga != null) { throw new ConcurrencyException($"Saga data with ID {id} already exists!"); } index.Insert(sagaData, correlationProperties); } }
/// <summary> /// Updates the given saga data instance in the index file /// </summary> public async Task Update(ISagaData sagaData, IEnumerable <ISagaCorrelationProperty> correlationProperties) { using (new FileSystemExclusiveLock(_lockFile, _log)) { var index = new FileSystemSagaIndex(_basePath); var id = GetId(sagaData); var existingCopy = index.FindById(id); if (existingCopy == null) { throw new ConcurrencyException($"Saga data with ID {id} does not exist!"); } if (existingCopy.Revision != sagaData.Revision) { throw new ConcurrencyException($"Attempted to update saga data with ID {id} with revision {sagaData.Revision}, but the existing data was updated to revision {existingCopy.Revision}"); } sagaData.Revision++; index.Insert(sagaData, correlationProperties); } }
/// <summary> /// Inserts the given saga data instance into the index file /// </summary> public async Task Insert(ISagaData sagaData, IEnumerable<ISagaCorrelationProperty> correlationProperties) { using (new FileSystemExclusiveLock(_lockFile, _log)) { var index = new FileSystemSagaIndex(_basePath); var id = GetId(sagaData); if (sagaData.Revision != 0) { throw new InvalidOperationException($"Attempted to insert saga data with ID {id} and revision {sagaData.Revision}, but revision must be 0 on first insert!"); } var existingSaga = index.FindById(id); if (existingSaga != null) { throw new ConcurrencyException("Saga data with ID {0} already exists!", id); } index.Insert(sagaData, correlationProperties); } }
/// <summary> /// Updates the given saga data instance in the index file /// </summary> public async Task Update(ISagaData sagaData, IEnumerable<ISagaCorrelationProperty> correlationProperties) { using (new FileSystemExclusiveLock(_lockFile, _log)) { var index = new FileSystemSagaIndex(_basePath); var id = GetId(sagaData); var existingCopy = index.FindById(id); if (existingCopy == null) { throw new ConcurrencyException("Saga data with ID {0} does not exist!", id); } if (existingCopy.Revision != sagaData.Revision) { throw new ConcurrencyException("Attempted to update saga data with ID {0} with revision {1}, but the existing data was updated to revision {2}", id, sagaData.Revision, existingCopy.Revision); } sagaData.Revision++; index.Insert(sagaData, correlationProperties); } }