Пример #1
0
        /// <summary>
        /// Gets the saga metadata for the specified <paramref name="sagaType"/> validating against the known <paramref name="handleMethods"/>.
        /// </summary>
        /// <remarks>Called once during saga discovery.</remarks>
        private static SagaMetadata GetSagaMetadata(Type sagaType, HandleMethodCollection handleMethods)
        {
            var saga             = (Saga)Activator.CreateInstance(sagaType);
            var metadata         = saga.GetMetadata();
            var initiatingEvents = 0;

            foreach (var handleMethod in handleMethods)
            {
                if (metadata.CanStartWith(handleMethod.Key))
                {
                    initiatingEvents++;
                }

                if (metadata.CanHandle(handleMethod.Key))
                {
                    continue;
                }

                throw new MappingException(Exceptions.EventTypeNotConfigured.FormatWith(sagaType, handleMethod.Key));
            }

            if (initiatingEvents == 0)
            {
                throw new MappingException(Exceptions.SagaMustHaveAtLeastOneInitiatingEvent.FormatWith(sagaType));
            }

            return(metadata);
        }
        /// <summary>
        /// Gets the saga metadata for the specified <paramref name="sagaType"/> validating against the known <paramref name="handleMethods"/>.
        /// </summary>
        /// <remarks>Called once during saga discovery.</remarks>
        private static SagaMetadata GetSagaMetadata(Type sagaType, HandleMethodCollection handleMethods)
        {
            var saga = (Saga)Activator.CreateInstance(sagaType);
            var metadata = saga.GetMetadata();
            var initiatingEvents = 0;

            foreach (var handleMethod in handleMethods)
            {
                if (metadata.CanStartWith(handleMethod.Key))
                    initiatingEvents++;

                if (metadata.CanHandle(handleMethod.Key))
                    continue;

                throw new MappingException(Exceptions.EventTypeNotConfigured.FormatWith(sagaType, handleMethod.Key));
            }

            if (initiatingEvents == 0)
                throw new MappingException(Exceptions.SagaMustHaveAtLeastOneInitiatingEvent.FormatWith(sagaType));

            return metadata;
        }