public override async Task <IContainSagaData> Find(IServiceProvider builder, SagaFinderDefinition finderDefinition, SynchronizedStorageSession storageSession, ContextBag context, object message, IReadOnlyDictionary <string, string> messageHeaders, CancellationToken cancellationToken = default) { var propertyAccessor = (Func <object, object>)finderDefinition.Properties["property-accessor"]; var propertyValue = propertyAccessor(message); var sagaPropertyName = (string)finderDefinition.Properties["saga-property-name"]; var lookupValues = context.GetOrCreate <SagaLookupValues>(); lookupValues.Add <TSagaData>(sagaPropertyName, propertyValue); if (propertyValue == 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 {sagaPropertyName}. Correlation properties cannot be assigned null."); } if (sagaPropertyName.ToLower() == "id") { return(await sagaPersister.Get <TSagaData>((Guid)propertyValue, storageSession, context, cancellationToken).ConfigureAwait(false)); } return(await sagaPersister.Get <TSagaData>(sagaPropertyName, propertyValue, storageSession, context, cancellationToken).ConfigureAwait(false)); }
public override async Task <IContainSagaData> Find(IBuilder builder, SagaFinderDefinition finderDefinition, SynchronizedStorageSession storageSession, ContextBag context, object message) { var customFinderType = (Type)finderDefinition.Properties["custom-finder-clr-type"]; var finder = (IFindSagas <TSagaData> .Using <TMessage>)builder.Build(customFinderType); return(await finder .FindBy((TMessage)message, storageSession, context) .ThrowIfNull() .ConfigureAwait(false)); }
public override async Task <IContainSagaData> Find(IServiceProvider builder, SagaFinderDefinition finderDefinition, SynchronizedStorageSession storageSession, ContextBag context, object message, IReadOnlyDictionary <string, string> messageHeaders, CancellationToken cancellationToken) { var customFinderType = (Type)finderDefinition.Properties["custom-finder-clr-type"]; var finder = (IFindSagas <TSagaData> .Using <TMessage>)builder.GetRequiredService(customFinderType); return(await finder .FindBy((TMessage)message, storageSession, context, cancellationToken) .ThrowIfNull() .ConfigureAwait(false)); }
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)); }
public override async Task <IContainSagaData> Find(IBuilder builder, SagaFinderDefinition finderDefinition, SynchronizedStorageSession storageSession, ContextBag context, object message) { var propertyAccessor = (Func <object, object>)finderDefinition.Properties["property-accessor"]; var propertyValue = propertyAccessor(message); var sagaPropertyName = (string)finderDefinition.Properties["saga-property-name"]; if (sagaPropertyName.ToLower() == "id") { return(await sagaPersister.Get <TSagaData>((Guid)propertyValue, storageSession, context).ConfigureAwait(false)); } var lookupValues = context.GetOrCreate <SagaLookupValues>(); lookupValues.Add <TSagaData>(sagaPropertyName, propertyValue); return(await sagaPersister.Get <TSagaData>(sagaPropertyName, propertyValue, storageSession, context).ConfigureAwait(false)); }
IContainSagaData TryLoadSagaEntity(SagaMetadata metadata, LogicalMessage message) { string sagaId; if (message.Headers.TryGetValue(Headers.SagaId, out sagaId) && !string.IsNullOrEmpty(sagaId)) { var sagaEntityType = metadata.SagaEntityType; //since we have a saga id available we can now shortcut the finders and just load the saga var loaderType = typeof(LoadSagaByIdWrapper <>).MakeGenericType(sagaEntityType); var loader = (SagaLoader)Activator.CreateInstance(loaderType); return(loader.Load(SagaPersister, sagaId)); } SagaFinderDefinition finderDefinition = null; foreach (var messageType in message.Metadata.MessageHierarchy) { if (metadata.TryGetFinder(messageType.FullName, out finderDefinition)) { break; } } //check if we could find a finder if (finderDefinition == null) { return(null); } var finderType = finderDefinition.Type; var finder = currentContext.Builder.Build(finderType); return(((SagaFinder)finder).Find(currentContext.Builder, finderDefinition, message)); }
internal abstract IContainSagaData Find(IBuilder builder, SagaFinderDefinition finderDefinition, LogicalMessage message);
public abstract Task <IContainSagaData> Find(IServiceProvider builder, SagaFinderDefinition finderDefinition, SynchronizedStorageSession storageSession, ContextBag context, object message, IReadOnlyDictionary <string, string> messageHeaders, CancellationToken cancellationToken = default);
public abstract Task <IContainSagaData> Find(IBuilder builder, SagaFinderDefinition finderDefinition, SynchronizedStorageSession storageSession, ContextBag context, object message, IReadOnlyDictionary <string, string> messageHeaders);
public abstract Task <IContainSagaData> Find(IBuilder builder, SagaFinderDefinition finderDefinition, SynchronizedStorageSession storageSession, ContextBag context, object message);
public abstract Task<IContainSagaData> Find(IBuilder builder, SagaFinderDefinition finderDefinition, SynchronizedStorageSession storageSession, ContextBag context, object message);