Ejemplo n.º 1
0
 /// <summary>
 /// Removes the saga data instance from the index file
 /// </summary>
 public async Task Delete(ISagaData sagaData)
 {
     using (new FileSystemExclusiveLock(_lockFile, _log))
     {
         var index = new FileSystemSagaIndex(_basePath);
         var id    = sagaData.Id;
         if (!index.Contains(id))
         {
             throw new ConcurrencyException("Saga data with ID {0} no longer exists and cannot be deleted", id);
         }
         index.Remove(id);
     }
 }
Ejemplo n.º 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 {id} already exists!");
         }
         index.Insert(sagaData, correlationProperties);
     }
 }
Ejemplo n.º 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 {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);
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Looks up an existing saga data instance from the index file
        /// </summary>
        public async Task <ISagaData> Find(Type sagaDataType, string propertyName, object propertyValue)
        {
            using (new FileSystemExclusiveLock(_lockFile, _log))
            {
                var index = new FileSystemSagaIndex(_basePath);
                if (propertyName == IdPropertyName)
                {
                    var sagaData = index.FindById((Guid)propertyValue);

                    if (!sagaDataType.IsInstanceOfType(sagaData))
                    {
                        return(null);
                    }

                    return(sagaData);
                }
                return(index.Find(sagaDataType, propertyName, propertyValue));
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Looks up an existing saga data instance from the index file
        /// </summary>
        public async Task<ISagaData> Find(Type sagaDataType, string propertyName, object propertyValue)
        {
            using (new FileSystemExclusiveLock(_lockFile, _log))
            {
                var index = new FileSystemSagaIndex(_basePath);
                if (propertyName == IdPropertyName)
                {
                    var sagaData = index.FindById((Guid) propertyValue);

                    if (!sagaDataType.IsInstanceOfType(sagaData))
                    {
                        return null;
                    }

                    return sagaData;
                }
                return index.Find(sagaDataType, propertyName, propertyValue);
            }
        }
Ejemplo n.º 6
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);

            }
        }
Ejemplo n.º 7
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);
     }
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Removes the saga data instance from the index file
 /// </summary>
 public async Task Delete(ISagaData sagaData)
 {
     using (new FileSystemExclusiveLock(_lockFile, _log))
     {
         var index = new FileSystemSagaIndex(_basePath);
         var id = sagaData.Id;
         if (!index.Contains(id))
         {
             throw new ConcurrencyException("Saga data with ID {0} no longer exists and cannot be deleted", id);
         }
         index.Remove(id);
     }
 }