protected void CompleteSaga <T>(Guid sagaId) where T : IContainSagaData
        {
            var saga = _sagaPersister.Get <T>(sagaId);

            Assert.NotNull(saga);
            _sagaPersister.Complete(saga);
        }
        public override async Task <IContainSagaData> Find(IServiceProvider builder, SagaFinderDefinition finderDefinition, SynchronizedStorageSession storageSession, ContextBag context, object message, IReadOnlyDictionary <string, string> messageHeaders, CancellationToken cancellationToken)
        {
            var headerName = (string)finderDefinition.Properties["message-header-name"];

            if (!messageHeaders.TryGetValue(headerName, out var messageHeaderValue))
            {
                var saga           = context.Get <ActiveSagaInstance>();
                var sagaEntityName = saga.Metadata.Name;
                var messageName    = finderDefinition.MessageTypeName;

                throw new Exception($"Message {messageName} mapped to saga {sagaEntityName} is missing a header used for correlation: {headerName}.");
            }

            var correlationPropertyName = (string)finderDefinition.Properties["saga-property-name"];
            var correlationPropertyType = (Type)finderDefinition.Properties["saga-property-type"];

            object convertedHeaderValue;

            try
            {
                convertedHeaderValue = TypeDescriptor.GetConverter(correlationPropertyType).ConvertFromInvariantString(messageHeaderValue);
            }
            catch (Exception exception)
            {
                var saga           = context.Get <ActiveSagaInstance>();
                var sagaEntityName = saga.Metadata.Name;
                var messageName    = finderDefinition.MessageTypeName;

                throw new Exception($"Message {messageName} mapped to saga {sagaEntityName} contains correlation header {headerName} value that cannot be cast to correlation property type {correlationPropertyType}: {messageHeaderValue}", exception);
            }

            var lookupValues = context.GetOrCreate <SagaLookupValues>();

            lookupValues.Add <TSagaData>(correlationPropertyName, convertedHeaderValue);

            if (convertedHeaderValue == null)
            {
                var saga           = context.Get <ActiveSagaInstance>();
                var sagaEntityName = saga.Metadata.Name;
                var messageName    = finderDefinition.MessageTypeName;

                throw new Exception($"Message {messageName} mapped to saga {sagaEntityName} has attempted to assign null to the correlation property {correlationPropertyName}. Correlation properties cannot be assigned null.");
            }

            if (correlationPropertyName.ToLower() == "id")
            {
                return(await persister.Get <TSagaData>((Guid)convertedHeaderValue, storageSession, context, cancellationToken).ConfigureAwait(false));
            }

            return(await persister.Get <TSagaData>(correlationPropertyName, convertedHeaderValue, storageSession, context, cancellationToken).ConfigureAwait(false));
        }
Beispiel #3
0
        internal override IContainSagaData Find(IBuilder builder, SagaFinderDefinition finderDefinition, LogicalMessage message)
        {
            var propertyAccessor = (Func <object, object>)finderDefinition.Properties["property-accessor"];
            var propertyValue    = propertyAccessor(message.Instance);

            var sagaPropertyName = (string)finderDefinition.Properties["saga-property-name"];

            if (sagaPropertyName.ToLower() == "id")
            {
                return(sagaPersister.Get <TSagaData>((Guid)propertyValue));
            }

            return(sagaPersister.Get <TSagaData>(sagaPropertyName, propertyValue));
        }
Beispiel #4
0
 public async Task <IContainSagaData> Load(ISagaPersister persister, string sagaId, SynchronizedStorageSession storageSession, ContextBag context)
 {
     return(await persister.Get <T>(Guid.Parse(sagaId), storageSession, context).ConfigureAwait(false));
 }
 protected T LoadSaga <T>(Guid id) where T : IContainSagaData
 {
     return(_sagaPersister.Get <T>(id));
 }
 protected Task <T> LoadSaga <T>(Guid id) where T : class, IContainSagaData
 {
     return(_sagaPersister.Get <T>(id, null, null));
 }
 public IContainSagaData Load(ISagaPersister persister, string sagaId)
 {
     return(persister.Get <T>(Guid.Parse(sagaId)));
 }