コード例 #1
0
        public async Task <TSagaData> Get <TSagaData>(string propertyName, object propertyValue, ISynchronizedStorageSession session, ContextBag context, CancellationToken cancellationToken = default)
            where TSagaData : class, IContainSagaData
        {
            var storageSession = (StorageSession)session;

            // Saga ID needs to be calculated the same way as in SagaIdGenerator does
            var sagaId = CosmosSagaIdGenerator.Generate(typeof(TSagaData), propertyName, propertyValue);

            // reads need to go directly
            var container    = storageSession.ContainerHolder.Container;
            var partitionKey = GetPartitionKey(context, sagaId);

            TSagaData sagaData;

            if (!pessimisticLockingEnabled)
            {
                (_, sagaData) = await ReadSagaData <TSagaData>(sagaId, context, container, partitionKey, cancellationToken).ConfigureAwait(false);

                return(sagaData);
            }

            (_, sagaData) = await AcquireLease <TSagaData>(sagaId, context, container, partitionKey, cancellationToken).ConfigureAwait(false);

            storageSession.AddOperation(new SagaReleaseLock(sagaData, partitionKey, serializer, context));
            return(sagaData);
        }
コード例 #2
0
        public Guid Generate(SagaIdGeneratorContext context)
        {
            if (context.CorrelationProperty == SagaCorrelationProperty.None)
            {
                throw new Exception("The CosmosDB saga persister doesn't support custom saga finders.");
            }

            return(CosmosSagaIdGenerator.Generate(context.SagaMetadata.SagaEntityType, context.CorrelationProperty.Name, context.CorrelationProperty.Value));
        }