/// <summary>
        ///   Send all SerializedNotification derived classes through this extension method
        /// </summary>
        public static Task ReceiveNotification(this INotifications receiver, SerializedNotification notification)
        {
            // TODO: unify with the startup code
            var serialized =
                JsonSerializer.Serialize(notification, new JsonSerializerOptions()
            {
                Converters = { Converter }
            });

            return(receiver.ReceiveNotificationJSON(serialized));
        }
Esempio n. 2
0
        private async Task AddNotification(INotification notification)
        {
            T tNotification = notification as T;

            if (tNotification == null)
            {
                throw new ArgumentException(
                          $"Invalid notification passed to {this.GetType().FullName}.PushNotificationAsync: {notification.GetType().FullName}");
            }

            SerializedNotification serialized = notificationSerializer.ToJson(notification);

            Guid bufferId = await bufferSelector.SelectBufferIdAsync(tNotification);

            await bufferedNotificationStore.Add(serialized, bufferId, Clock.Current.Now,
                                                bufferGovernor.Id, notificationPipeline.Id);
        }
        public async Task SendNotificationAsync_SavesNotificationToBuffer()
        {
            Notification1          n1       = new Notification1();
            Guid                   bufferId = Guid.NewGuid();
            SerializedNotification serializedNotification = new SerializedNotification()
            {
                NotificationClassName = "Notification1",
                NotificationJson      = "{}"
            };

            notificationSerializer.ToJson(n1).Returns(serializedNotification);
            bufferSelector.SelectBufferIdAsync(n1).Returns(bufferId);

            await sut.PushNotificationAsync(n1);

            bufferedNotificationStore.Received(1)
            .Add(serializedNotification, bufferId, FakeClock.Now, bufferGovernor.Id,
                 notificationPipeline.Id);
        }
Esempio n. 4
0
        LoadSerializedNotificationParameters(
            Configuration.Notifications type)
        {
            var path = Path.Combine(CORRADE_CONSTANTS.TEMPLATES_DIRECTORY,
                                    CORRADE_CONSTANTS.NOTIFICATIONS_TEMPLATE_DIRECTORY,
                                    Reflection.GetNameFromEnumValue(type) + ".xml");

            if (!File.Exists(path))
            {
                Corrade.Feedback(
                    Reflection.GetDescriptionFromEnumValue(
                        Enumerations.ConsoleMessage.COULD_NOT_FIND_NOTIFICATION_FILE));
                return(null);
            }

            // Deserialize the notification data.
            SerializedNotification notification;

            try
            {
                notification =
                    SerializedNotification.LoadFromFile(path);
            }
            catch (Exception ex)
            {
                Corrade.Feedback(
                    Reflection.GetDescriptionFromEnumValue(
                        Enumerations.ConsoleMessage.UNABLE_TO_DESERIALIZE_NOTIFICATION_DATA), ex.PrettyPrint());
                return(null);
            }

            if (!notification.Notification.Equals(type))
            {
                Corrade.Feedback(
                    Reflection.GetDescriptionFromEnumValue(
                        Enumerations.ConsoleMessage.PARAMETERS_FOR_REQUESTED_EVENT_NOT_FOUND));
                return(null);
            }

            return(notification);
        }
        public async Task Add(SerializedNotification serializedNotification, Guid bufferId,
                              DateTimeOffset timeQueued, Guid bufferGovernorId, Guid notificationPipelineId)
        {
            NotificationBuffer buffer = await crudRepository.FindAsync <NotificationBuffer>(bufferId);

            if (buffer == null)
            {
                buffer = new NotificationBuffer(bufferId, bufferGovernorId, notificationPipelineId);
                crudRepository.Add(buffer); // TODO race condition - use AddOrUpdate instead
            }

            BufferedNotification notification = new BufferedNotification(
                id: Guid.NewGuid(),
                buffer: buffer,
                notificationClassName: serializedNotification.NotificationClassName,
                notificationJson: serializedNotification.NotificationJson,
                timeQueued: timeQueued
                );

            crudRepository.Add(notification);
        }
 private async Task SendNotification(SerializedNotification notification)
 {
     await _hubContext.Clients.All.SendAsync("Notification", notification);
 }