public async Task Complete(IContainSagaData sagaData, SynchronizedStorageSession session, ContextBag context) { var storageSession = (StorageSession)session; var entry = GetEntry(context, sagaData.Id); var sagaInfo = sagaInfoCache.GetInfo(sagaData.GetType()); var sagas = await storageSession.Sagas(sagaInfo.SagaAttribute.CollectionName).ConfigureAwait(false); await storageSession.Add(async tx => { var conditionalValue = await sagas.TryRemoveAsync(tx, sagaData.Id).ConfigureAwait(false); if (conditionalValue.HasValue && conditionalValue.Value.Data != entry.Data) { throw new Exception("Saga can't be completed as it was updated by another process."); } }) .ConfigureAwait(false); }
public Guid Generate(SagaIdGeneratorContext context) { if (context.CorrelationProperty == SagaCorrelationProperty.None) { return(Guid.NewGuid()); } var sagaInfo = sagaInfoCache.GetInfo(context.SagaMetadata.SagaEntityType); return(Generate(sagaInfo, context.CorrelationProperty.Name, context.CorrelationProperty.Value)); }