Ejemplo n.º 1
0
        /// <summary>
        /// Matches one <see cref="CompositeHandlingStatus"/> to another using the provided <see cref="CompositeHandlingStatusMatchStrategy"/>.
        /// </summary>
        /// <param name="actualStatus">The status to inspect.</param>
        /// <param name="statusToMatch">The status to compare it to.</param>
        /// <param name="compositeHandlingStatusMatchStrategy">The strategy to use for comparing tags.</param>
        /// <returns>
        /// <c>true</c> if the tags match, otherwise <c>false</c>.
        /// </returns>
        public static bool MatchesAccordingToStrategy(
            this CompositeHandlingStatus actualStatus,
            CompositeHandlingStatus statusToMatch,
            CompositeHandlingStatusMatchStrategy compositeHandlingStatusMatchStrategy)
        {
            actualStatus.MustForArg(nameof(actualStatus)).NotBeEqualTo(CompositeHandlingStatus.Unknown);
            statusToMatch.MustForArg(nameof(statusToMatch)).NotBeEqualTo(CompositeHandlingStatus.Unknown);
            compositeHandlingStatusMatchStrategy.MustForArg(nameof(compositeHandlingStatusMatchStrategy)).NotBeEqualTo(CompositeHandlingStatusMatchStrategy.Unknown);

            var actualFlags  = actualStatus.GetIndividualFlags <CompositeHandlingStatus>().Where(_ => _ != CompositeHandlingStatus.Unknown).ToArray();
            var flagsToMatch = statusToMatch.GetIndividualFlags <CompositeHandlingStatus>().Where(_ => _ != CompositeHandlingStatus.Unknown).ToArray();

            bool result;

            if (compositeHandlingStatusMatchStrategy == CompositeHandlingStatusMatchStrategy.ActualCompositeStatusHasAnyQueryCompositeStatusFlag)
            {
                result = flagsToMatch.Intersect(actualFlags).Any();
            }
            else if (compositeHandlingStatusMatchStrategy == CompositeHandlingStatusMatchStrategy.ActualCompositeStatusHasAllQueryCompositeStatusFlags)
            {
                result = !flagsToMatch.Except(actualFlags).Any();
            }
            else if (compositeHandlingStatusMatchStrategy == CompositeHandlingStatusMatchStrategy.ActualCompositeStatusEqualsQueryCompositeStatus)
            {
                result = actualStatus == statusToMatch;
            }
            else
            {
                throw new NotSupportedException(Invariant($"This {nameof(CompositeHandlingStatusMatchStrategy)} is not supported {compositeHandlingStatusMatchStrategy}."));
            }

            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EventToPutWithIdOnHandlingStatusMatch{TId}"/> class.
        /// </summary>
        /// <param name="statusToMatch">The <see cref="CompositeHandlingStatus"/> to match.</param>
        /// <param name="compositeHandlingStatusMatchStrategy">The <see cref="CompositeHandlingStatusMatchStrategy"/> to use with <paramref name="statusToMatch"/>.</param>
        /// <param name="eventToPut">The event to put on a match.</param>
        /// <param name="chainOfResponsibilityLinkMatchStrategy">OPTIONAL strategy override to determine what to do in the execution on a match; DEFAULT is Halt and Complete.</param>
        public EventToPutWithIdOnHandlingStatusMatch(
            CompositeHandlingStatus statusToMatch,
            CompositeHandlingStatusMatchStrategy compositeHandlingStatusMatchStrategy,
            EventToPutWithId <TId> eventToPut,
            ChainOfResponsibilityLinkMatchStrategy chainOfResponsibilityLinkMatchStrategy = ChainOfResponsibilityLinkMatchStrategy.MatchHaltsEvaluationOfChainAndCompletes)
        {
            statusToMatch.MustForArg(nameof(statusToMatch)).NotBeEqualTo(CompositeHandlingStatus.Unknown);
            compositeHandlingStatusMatchStrategy.MustForArg(nameof(compositeHandlingStatusMatchStrategy)).NotBeEqualTo(CompositeHandlingStatusMatchStrategy.Unknown);
            eventToPut.MustForArg(nameof(eventToPut)).NotBeNull();
            chainOfResponsibilityLinkMatchStrategy.MustForArg(nameof(chainOfResponsibilityLinkMatchStrategy)).NotBeEqualTo(ChainOfResponsibilityLinkMatchStrategy.Unknown);

            this.StatusToMatch = statusToMatch;
            this.CompositeHandlingStatusMatchStrategy = compositeHandlingStatusMatchStrategy;
            this.EventToPut = eventToPut;
            this.ChainOfResponsibilityLinkMatchStrategy = chainOfResponsibilityLinkMatchStrategy;
        }
        public EventToPutWithIdOnHandlingStatusMatch <TId> DeepCloneWithCompositeHandlingStatusMatchStrategy(CompositeHandlingStatusMatchStrategy compositeHandlingStatusMatchStrategy)
        {
            var result = new EventToPutWithIdOnHandlingStatusMatch <TId>(
                this.StatusToMatch.DeepClone(),
                compositeHandlingStatusMatchStrategy,
                this.EventToPut?.DeepClone(),
                this.ChainOfResponsibilityLinkMatchStrategy.DeepClone());

            return(result);
        }