Esempio 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 {id} no longer exists and cannot be deleted");
         }
         index.Remove(id);
         sagaData.Revision++;
     }
 }
Esempio 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);
     }
 }
Esempio 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);
     }
 }
Esempio 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));
        }
    }