Esempio n. 1
0
 public DictionaryReplacementNotificationContent(IDictionaryReplacementNotificationContentConfiguration dictionaryReplacementNotificationContent, INotificationContent notificationContent, IDictionary <string, string> replacements, string defaultValueIfNoMatch = "[INVALID_TOKEN:{0}]")
 {
     this.Configuration          = dictionaryReplacementNotificationContent;
     this._notificationContent   = notificationContent;
     this._replacements          = replacements;
     this._defaultValueIfNoMatch = defaultValueIfNoMatch;
 }
 public Notification(INotificationContact sender, INotificationContent content)
 {
     this.Sender      = sender;
     this.Content     = content;
     this.Deliveries  = new List <INotificationDelivery>();
     this.Attachments = new List <NotificationAttachment>();
 }
        public async Task <NotifyStatus> ScheduleAndExecuteAsync(INotificationContent content, TRecipient recipient)
        {
            if (content == null)
            {
                throw new ArgumentNullException(nameof(content));
            }
            else if (recipient == null)
            {
                throw new ArgumentNullException(nameof(recipient));
            }

            var notifications = await ScheduleAsync(content, recipient);

            if (notifications != null)
            {
                var result = NotifyStatus.Successful;
                foreach (var notification in notifications)
                {
                    // If we've failed to notify our notification, then we'll tell the caller that all notifications are scheduled.
                    if (await NotifyAsync(notification) != NotifyStatus.Successful)
                    {
                        result = NotifyStatus.Scheduled;
                    }
                }

                return(result);
            }

            return(NotifyStatus.Failed);
        }
Esempio n. 4
0
        private static void AssertPayload(string expectedXml, INotificationContent notificationContent)
        {
            AssertHelper.AssertXml(expectedXml, notificationContent.GetContent());

#if WINDOWS_UWP
            // For WinRT, we'll test the XmlDocument method too, make sure it works.
            AssertHelper.AssertXml(expectedXml, notificationContent.GetXml().GetXml());
#endif
        }
Esempio n. 5
0
 public static NotificationMessage CreateNotificationMessage(this INotificationContent c, IMessage msg)
 {
     return(new NotificationMessage
     {
         Content = JsonConvert.SerializeObject(c),
         Id = Guid.NewGuid(),
         NotificationType = c.NotificationType,
         TimeStampUtc = msg.TimeStampUtc,
         UserId = msg.UserId
     });
 }
        private void PublishToast(INotificationContent toast, string tag)
        {
            var xmlDocument = new XmlDocument();

            xmlDocument.LoadXml(toast.GetContent());
            var toastNotification = new ToastNotification(xmlDocument)
            {
                Tag = tag, Group = ToastNotificationProcessor.Group
            };

            ToastNotificationManager.CreateToastNotifier(ToastNotificationProcessor.ApplicationId).Show(toastNotification);
        }
Esempio n. 7
0
        public string GetEmailBody(INotificationContent content)
        {
            var taskContent = content as ClientServiceCollectiveTaskNotificationContent;

            var pathGenerator = _assetPathGeneratorFactory.GetGenerator(PathGeneratorType.Notification);

            string htmlBody = File.ReadAllText(pathGenerator.GeneratePath(Constants.EmailTemplatePath));

            var mainBody =
                string.Format(Constants.CollectiveClientServiceTasksNotificationBody, GetDynamicTableContent(content), taskContent.OfferingName);

            return(mainBody);
        }
        public Task <EmailRecipients> ResolveAsync(User user, INotificationContent notificationContext, string transporterType)
        {
            // We're using IEmailNotification interface to determine if our notification has been marked to be
            // sent via email. If it doesn't implement it, then we don't provide our email.
            if (notificationContext is IEmailNotification)
            {
                return(Task.FromResult(new EmailRecipients()
                {
                    To = new string[1] {
                        user.EmailAddress
                    }
                }));
            }

            // If our context doesn't implement
            return(Task.FromResult <EmailRecipients>(null));
        }
Esempio n. 9
0
        public string GetEmailBody(INotificationContent content)
        {
            if (content == null)
            {
                throw new ArgumentNullException(nameof(content));
            }

            var pathGenerator = _assetPathGeneratorFactory.GetGenerator(PathGeneratorType.Notification);

            var fiContent = content as FirmInitiativeTaskNotificationContent;

            string htmlBody = File.ReadAllText(pathGenerator.GeneratePath(Constants.EmailTemplatePath));

            var mainBody =
                string.Format(Constants.FirmInitiativeNotificationBody, GetDynamicTableContent(content), fiContent.OfferingName);

            return(mainBody);
        }
        public ActionResult SendNotification(
            [ModelBinder(typeof(NotificationTemplateModelBinder))] INotificationContent notification,
            string channelUrl,
            NotificationPriority priority = NotificationPriority.Normal)
        {
            var options = new NotificationSendOptions()
            {
                Priority = priority
            };

            NotificationSendResult result = notification.Send(new Uri(channelUrl), this.tokenProvider, options);

            object response = new
            {
                DeviceConnectionStatus = result.DeviceConnectionStatus.ToString(),
                NotificationStatus     = result.NotificationStatus.ToString(),
                Status = result.LookupHttpStatusCode()
            };

            return(this.Json(response));
        }
Esempio n. 11
0
        public string GetDynamicTableContent(INotificationContent content)
        {
            if (content == null)
            {
                throw new ArgumentNullException(nameof(content));
            }

            var tableContent = content as ClientServiceCollectiveTaskNotificationContent;

            var tableHtml = string.Empty;

            tableHtml += $"<tr><th style='border:1px solid #4d4d4d;text-align:left;padding:8px;'>Task Name</th><th style='border:1px solid #4d4d4d;text-align:left;padding:8px;'>Task Description</th><th style='border:1px solid #4d4d4d;text-align:left;padding:8px;'>Requestor</th></tr>";

            foreach (var item in tableContent.ProjectData)
            {
                tableHtml += $"<tr><td style='border:1px solid #4d4d4d;text-align:left;padding:8px;'>{item.Item1}</td><td style='border:1px solid #4d4d4d;text-align:left;padding:8px;'>{item.Item2}</td><td style='border:1px solid #4d4d4d;text-align:left;padding:8px;'>{item.Item3}</td></tr>";
            }

            var finalTableHtml = $"<table style='border-collapse:collapse;width:80%;'>{tableHtml}</table>";

            return($"<p>{finalTableHtml}</p>");
        }
        public async Task <IEnumerable <INotificationData> > ScheduleAsync(INotificationContent content, TRecipient recipient)
        {
            if (content == null)
            {
                throw new ArgumentNullException(nameof(content));
            }
            else if (recipient == null)
            {
                throw new ArgumentNullException(nameof(recipient));
            }

            var notificationsToAdd = new List <CreatableNotification>();

            foreach (var transporter in _manager.GetTransporters())
            {
                if (transporter.RecipientResolver == null)
                {
                    throw new InvalidOperationException($"'{transporter.GetType().Name}' does not have a valid resolver");
                }

                var destination = await transporter.RecipientResolver.ResolveAsync(recipient, content, transporter.TransporterType);

                if (destination != null)
                {
                    notificationsToAdd.Add(new CreatableNotification()
                    {
                        NotificationType = content.NotificationType,
                        TransportType    = transporter.TransporterType,
                        Recipients       = destination,
                        Content          = content
                    });
                }
            }

            return(notificationsToAdd.Count > 0 ? await _repository.AddAsync(notificationsToAdd) : new INotificationData[0]);
        }
Esempio n. 13
0
 public DictionaryReplacementNotificationContent(INotificationContent notificationContent, IDictionary <string, string> replacements, string defaultValueIfNoMatch = "[INVALID_TOKEN:{0}]")
     : this(DefaultConfiguration, notificationContent, replacements, defaultValueIfNoMatch)
 {
 }
 async Task <object> INotificationRecipientResolver <User> .ResolveAsync(User user, INotificationContent notificationContext, string transporterType)
 {
     return(await ResolveAsync(user, notificationContext, transporterType));
 }
Esempio n. 15
0
 private void Show(INotificationContent content)
 {
     ToastNotificationManager.CreateToastNotifier().Show(new ToastNotification(content.GetXml()));
 }
 private static void AssertBadgeValue(string expectedValue, INotificationContent notificationContent)
 {
     AssertPayload("<badge version='1' value='" + expectedValue + "'/>", notificationContent);
 }
Esempio n. 17
0
 private static void AssertBadgeValue(string expectedValue, INotificationContent notificationContent)
 {
     AssertPayload("<badge value='" + expectedValue + "'/>", notificationContent);
 }
Esempio n. 18
0
 private static void AssertPayload(string expectedXml, INotificationContent notificationContent)
 {
     AssertHelper.AssertXml(expectedXml, notificationContent.GetContent());
 }