Ejemplo n.º 1
0
        /// <summary>
        /// Raises the specified event if <paramref name="onRightOnly" /> is false or the <paramref name="serviceResponse" />.IsRight.
        /// Event handlers may be executed in parallel. All handlers are run even if one throws an exception.
        /// If an exception is thrown, this method returns a new <see cref="ServiceResponse{T}" /> with an error representing the thrown exceptions.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="TEvent">The type of the T event.</typeparam>
        /// <param name="serviceResponse">The service response.</param>
        /// <param name="eventManager">The event manager.</param>
        /// <param name="event">The event.</param>
        /// <param name="onRightOnly">Determines whether to raise the event in the case the serviceResponse is left.</param>
        /// <returns>Task&lt;IServiceResponse&lt;T&gt;&gt;.</returns>
        public static Task <IServiceResponse <T> > RaiseAsync <T, TEvent>(
            this IServiceResponse <T> serviceResponse,
            IManageEvents eventManager,
            TEvent @event,
            Boolean onRightOnly = true)
        {
            if (onRightOnly && serviceResponse.IsLeft)
            {
                return(Task.FromResult(serviceResponse));
            }

            return(serviceResponse.RaiseAsync(eventManager, _ => @event, onRightOnly));
        }