Esempio n. 1
0
        private static void ConfigureSettings(UserNotification notification, UserEventMessage userEvent, User user)
        {
            notification.Channels = new Dictionary <string, UserNotificationChannel>();

            OverrideBy(notification, user.Settings);
            OverrideBy(notification, userEvent.Settings);
        }
Esempio n. 2
0
        public Task TrackFailedAsync(UserEventMessage userEvent, CancellationToken ct)
        {
            Guard.NotNull(userEvent, nameof(userEvent));

            var counterMap = CounterMap.ForNotification(ProcessStatus.Failed);
            var counterKey = CounterKey.ForUserEvent(userEvent);

            return(StoreCountersAsync(counterKey, counterMap));
        }
Esempio n. 3
0
        public Task TrackAttemptAsync(UserEventMessage userEvent,
                                      CancellationToken ct = default)
        {
            Guard.NotNull(userEvent);

            var counterMap = CounterMap.ForNotification(ProcessStatus.Attempt);
            var counterKey = CounterKey.ForUserEvent(userEvent);

            return(StoreCountersAsync(counterKey, counterMap, ct));
        }
Esempio n. 4
0
        public static IEnumerable <ActivityLink> Links(this UserEventMessage message)
        {
            if (message.UserEventActivity != default)
            {
                yield return(new ActivityLink(message.UserEventActivity));
            }

            if (message.EventActivity != default)
            {
                yield return(new ActivityLink(message.EventActivity));
            }
        }
Esempio n. 5
0
        public static CounterKey ForUserEvent(UserEventMessage @event)
        {
            Guard.NotNull(@event, nameof(@event));

            var result = default(CounterKey);

            result.eventId = @event.EventId;
            result.appId   = @event.AppId;
            result.topic   = @event.Topic;
            result.userId  = @event.UserId;

            return(result);
        }
Esempio n. 6
0
        public UserNotification?Create(App app, User user, UserEventMessage userEvent)
        {
            Guard.NotNull(user, nameof(user));
            Guard.NotNull(userEvent, nameof(userEvent));

            if (userEvent.Formatting == null ||
                string.IsNullOrWhiteSpace(userEvent.AppId) ||
                string.IsNullOrWhiteSpace(userEvent.EventId) ||
                string.IsNullOrWhiteSpace(userEvent.Topic) ||
                string.IsNullOrWhiteSpace(userEvent.UserId))
            {
                return(null);
            }

            var language = user.PreferredLanguage;

            if (!app.Languages.Contains(language))
            {
                logstore.LogAsync(app.Id, string.Format(Texts.UserLanguage_NotValid, language, app.Language));

                language = app.Language;
            }

            var formatting = userEvent.Formatting.SelectText(language);

            if (!formatting.HasSubject())
            {
                return(null);
            }

            var notification = SimpleMapper.Map(userEvent, new UserNotification
            {
                Id = Guid.NewGuid()
            });

            notification.Formatting   = formatting;
            notification.UserLanguage = language;

            ConfigureTracking(notification, language, userEvent);
            ConfigureSettings(notification, user, userEvent);

            notification.Updated = clock.GetCurrentInstant();

            return(notification);
        }
Esempio n. 7
0
        private void ConfigureTracking(UserNotification notification, UserEventMessage userEvent)
        {
            var confirmMode = userEvent.Formatting.ConfirmMode;

            if (confirmMode == ConfirmMode.Explicit)
            {
                notification.ConfirmUrl = url.TrackConfirmed(notification.Id, notification.UserLanguage);

                if (string.IsNullOrWhiteSpace(notification.Formatting.ConfirmText))
                {
                    notification.Formatting.ConfirmText = DefaultConfirmText;
                }
            }
            else
            {
                notification.Formatting.ConfirmText = null;
            }

            notification.TrackDeliveredUrl = url.TrackDelivered(notification.Id, notification.UserLanguage);
            notification.TrackSeenUrl      = url.TrackSeen(notification.Id, notification.UserLanguage);
        }
        private UserEventMessage CreateMinimumUserEvent()
        {
            var userEvent = new UserEventMessage
            {
                Formatting = new NotificationFormatting <LocalizedText>
                {
                    Subject = new LocalizedText
                    {
                        ["en"] = "enText",
                        ["de"] = "deText"
                    }
                }
            };

            userEvent.AppId   = "app";
            userEvent.Created = now;
            userEvent.EventId = "eventId";
            userEvent.Topic   = "topic";
            userEvent.UserId  = "user";

            return(userEvent);
        }
Esempio n. 9
0
        private static void ConfigureSettings(UserNotification notification, User user, UserEventMessage userEvent)
        {
            notification.Settings = new NotificationSettings();
            notification.Settings.OverrideBy(user.Settings);
            notification.Settings.OverrideBy(userEvent.SubscriptionSettings);
            notification.Settings.OverrideBy(userEvent.EventSettings);

            notification.Sending = new Dictionary <string, ChannelSendInfo>();
        }
Esempio n. 10
0
 private async Task ProduceAsync(Subscription subscription, UserEventMessage userEventMessage)
 {
     await userEventProducer.ProduceAsync(subscription.UserId, userEventMessage);
 }