예제 #1
0
        public CommandsExecutor(INotificationsHub notificationsHub, NotificationService toastrNotificationService,
                                IDateTimeProvider dateTimeProvider)
        {
            _notificationsHub          = notificationsHub;
            _toastrNotificationService = toastrNotificationService;
            _dateTimeProvider          = dateTimeProvider;
            _notificationsHub.Subscribe <CommandResultEvent>(_notificationHubSubscriptionId, commandResult =>
            {
                if (!PendingCommands.TryRemove(commandResult.CorrelationId, out var pendingCommand))
                {
                    return(Task.CompletedTask);
                }

                switch (commandResult.Status)
                {
                case StatusCode.Success:
                    if (!pendingCommand.HideNotifications)
                    {
                        _toastrNotificationService.Notify(NotificationSeverity.Success, string.Empty,
                                                          pendingCommand.SuccessMessage);
                    }

                    break;

                case StatusCode.Error:
                    _toastrNotificationService.Notify(NotificationSeverity.Error, string.Empty,
                                                      string.Format(pendingCommand.ErrorMessage, commandResult.ErrorMessage));
                    break;

                case StatusCode.Refused:
                    _toastrNotificationService.Notify(NotificationSeverity.Error, string.Empty,
                                                      string.Format(pendingCommand.ErrorMessage, commandResult.ErrorMessage));
                    break;

                case StatusCode.ValidationError:
                    _toastrNotificationService.Notify(NotificationSeverity.Error, string.Empty,
                                                      string.Format(pendingCommand.ErrorMessage, commandResult.ErrorMessage));
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                pendingCommand.TimeOutTaskCancellation.Cancel();
                pendingCommand.OnCommandExecuted(commandResult);
                return(Task.CompletedTask);
            });
        }
예제 #2
0
        public NotificationService(IUnitOfWorkFactory unitOfWorkFactory)
        {
            _unitOfWorkFactory = unitOfWorkFactory;

            _notificationHub = NotificationsHub.Instance;
        }