コード例 #1
0
        /// <summary>
        /// Checks whether the provided exception message is the end message or an exception message for the awaited <see cref="SendAndAwait"/> operation.
        /// </summary>
        /// <param name="message">The message to check.</param>
        /// <returns><c>true</c>, if the message was the end message or an exception message for the <see cref="SendAndAwait"/> operation.</returns>
        /// <remarks>For an example how to use this class see the type documentation.</remarks>
        public bool Check(Message message)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            if (!IsActive ||
                !(message.Is <TEnd>() ||
                  message.Is <ExceptionMessage>()))
            {
                return(false);
            }

            MessageDomain domain = message.MessageDomain;

            while (domain?.IsTerminated == true)
            {
                domain = domain.Parent;
            }

            if (domain != null &&
                continueActions.TryGetValue(domain, out OneTimeAction action))
            {
                action.Execute(message);
                return(true);
            }
            return(false);
        }
コード例 #2
0
        /// <summary>
        /// Checks whether the <paramref name="message"/> is a decorated message or not.
        /// </summary>
        /// <param name="message">The message to check.</param>
        /// <returns><c>true</c> if the message is decorated; otherwise <c>false</c>.</returns>
        /// <exception cref="ArgumentNullException">If the <paramref name="message"/> is <c>null</c>.</exception>
        /// <remarks>
        /// An example when this method can be used is shown in the FileManipulationBenchmark benchmark test.
        /// </remarks>
        public static bool IsDecorated(Message message)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            return(message.Is <MessageDecorator>());
        }
コード例 #3
0
        /// <summary>
        /// Tries to add the message to this instance.
        /// </summary>
        /// <param name="message">The message to add to this instance.</param>
        /// <returns><c>true</c> if the message was added; otherwise <c>false</c></returns>
        /// <exception cref="ArgumentNullException">Thrown if the message is <c>null</c>.</exception>
        /// <remarks>
        /// This is useful, when the <see cref="Agent"/> consumes more than the aggregated message.
        /// </remarks>
        public bool TryAggregate(Message message)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            if (!message.Is <T>())
            {
                return(false);
            }
            Aggregate(message);
            return(true);
        }