private static string GetAllMessageErrors(
            string correlationId,
            DomainNotificationUseCase notificationUseCase,
            string patternLog)
        {
            var errorsMessage = new StringBuilder();

            errorsMessage.Append($"{patternLog} Event item with {nameof(correlationId)}: {correlationId} processing failed.");

            if (notificationUseCase.HasNotifications())
            {
                notificationUseCase
                .GetNotifications()?
                .ForEach(n => n.Messages?.ToList()?.ForEach(m => errorsMessage.Append($"{n.MessageType}|{m.Key}: {m.Value};")));
            }

            return(errorsMessage.ToString());
        }
        /// <summary>
        /// End event process logging notification messages.
        /// </summary>
        /// <typeparam name="TResult">Type of result data.</typeparam>
        /// <param name="result">Result data. If the object is null, throw exception. Otherwise, the event was processed successfully.</param>
        /// <param name="correlationId">Correlation id.</param>
        /// <param name="notificationUseCase">Use case to extract notifications.</param>
        /// <param name="serverlessLogger">Logger to save log.</param>
        /// <param name="patternLog">Pattern log.</param>
        public static void EndEventProcess <TResult>(
            TResult result,
            string correlationId,
            DomainNotificationUseCase notificationUseCase,
            IServerlessLogger serverlessLogger,
            string patternLog)
            where TResult : IResult
        {
            if (result == null)
            {
                if (notificationUseCase.HasNotifications())
                {
                    var errors = GetAllMessageErrors(correlationId, notificationUseCase, patternLog);

                    throw new Exception(errors);
                }

                throw new Exception($"{patternLog} Event item with {nameof(correlationId)}: {correlationId} processing failed.");
            }

            serverlessLogger.LogInformation($"{patternLog} Event item with {nameof(correlationId)}: {correlationId} successfully processed!");
        }
Exemple #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BasePresenter"/> class.
 /// </summary>
 /// <param name="notifications">Domain notifications.</param>
 public BasePresenter(INotificationHandler <DomainNotification> notifications)
 {
     this.notifications = (DomainNotificationUseCase)notifications;
 }