Esempio n. 1
0
        private async Task SendNotification(string referenceId, string message, NotifyLevel level)
        {
            CommandPreservationNotify command = new CommandPreservationNotify();

            command.Message     = message;
            command.NotifyLevel = level;
            command.ReferenceId = referenceId;

            await Mediator.Send(command);
        }
        private async Task SendNotification(string referenceId, string message, NotifyLevel level, ICollection <NotificationDetailModel> details, bool isComplete = false)
        {
            CommandPreservationNotify command = new CommandPreservationNotify();

            command.Message     = message;
            command.NotifyLevel = level;
            command.ReferenceId = referenceId;
            command.Complete    = isComplete;
            command.Details     = details;

            await Mediator.Send(command);
        }
        public override async Task Execute(CommandModel commandModel)
        {
            await Task.Run(() =>
            {
                if (!(commandModel is CommandPreservationNotify))
                {
                    _logger.Error($"Command is not of type {nameof(CommandPreservationNotify)}");
                    return;
                }

                CommandPreservationNotify @command = commandModel as CommandPreservationNotify;
                if (string.IsNullOrEmpty(command.ReferenceId))
                {
                    return;
                }

                if (ConnectionShared.Connections.Any(x => x.Value.Equals(command.ReferenceId)) &&
                    _hubContext.Clients.Client(ConnectionShared.Connections.Single(x => x.Value.Equals(command.ReferenceId)).Key) != null)
                {
                    string connectionId = ConnectionShared.Connections.Single(x => x.Value.Equals(command.ReferenceId.ToString())).Key;
                    _hubContext.Clients.Client(connectionId).notify(command);
                }
            });
        }