Пример #1
0
 /// <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);
     }
 }
Пример #2
0
        /// <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);

            }
        }
Пример #3
0
 /// <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);
     }
 }
Пример #4
0
 /// <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);
     }
 }