Ejemplo n.º 1
0
        /// <summary>
        /// Gets the saga type to instantiate and invoke if an existing saga couldn't be found by
        /// the given finder using the given message.
        /// </summary>
        /// <param name="message"></param>
        /// <param name="finder"></param>
        /// <returns></returns>
        public static Type GetSagaTypeToStartIfMessageNotFoundByFinder(object message, IFinder finder)
        {
            Type sagaEntityType;
            FinderTypeToSagaEntityTypeLookup.TryGetValue(finder.GetType(), out sagaEntityType);

            if (sagaEntityType == null)
                return null;

            Type sagaType;
            SagaEntityTypeToSagaTypeLookup.TryGetValue(sagaEntityType, out sagaType);

            if (sagaType == null)
                return null;

            List<Type> messageTypes;
            SagaTypeToMessagTypesRequiringSagaStartLookup.TryGetValue(sagaType, out messageTypes);

            if (messageTypes == null)
                return null;

            if (messageTypes.Contains(message.GetType()))
                return sagaType;
            
            foreach (Type msgTypeHandleBySaga in messageTypes)
                if (msgTypeHandleBySaga.IsAssignableFrom(message.GetType()))
                    return sagaType;

            return null;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the saga type to instantiate and invoke if an existing saga couldn't be found by
        /// the given finder using the given message.
        /// </summary>
        /// <param name="message"></param>
        /// <param name="finder"></param>
        /// <returns></returns>
        public static Type GetSagaTypeToStartIfMessageNotFoundByFinder(object message, IFinder finder)
        {
            Type sagaEntityType;

            FinderTypeToSagaEntityTypeLookup.TryGetValue(finder.GetType(), out sagaEntityType);

            if (sagaEntityType == null)
            {
                return(null);
            }

            Type sagaType;

            SagaEntityTypeToSagaTypeLookup.TryGetValue(sagaEntityType, out sagaType);

            if (sagaType == null)
            {
                return(null);
            }

            List <Type> messageTypes;

            SagaTypeToMessagTypesRequiringSagaStartLookup.TryGetValue(sagaType, out messageTypes);

            if (messageTypes == null)
            {
                return(null);
            }

            if (messageTypes.Contains(message.GetType()))
            {
                return(sagaType);
            }

            foreach (Type msgTypeHandleBySaga in messageTypes)
            {
                if (msgTypeHandleBySaga.IsInstanceOfType(message))
                {
                    return(sagaType);
                }
            }

            return(null);
        }