Exemple #1
0
        SagaFinderDefinition GetFinder(SagaMetadata metadata, string messageType)
        {
            if (!metadata.TryGetFinder(messageType, out var finder))
            {
                throw new Exception("Finder not found");
            }

            return(finder);
        }
Exemple #2
0
 SagaFinderDefinition GetSagaFinder(SagaMetadata metadata, IInvokeHandlerContext context)
 {
     foreach (var messageType in context.MessageMetadata.MessageHierarchy)
     {
         if (metadata.TryGetFinder(messageType.FullName, out var finderDefinition))
         {
             return(finderDefinition);
         }
     }
     return(null);
 }
        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));
        }