Exemple #1
0
        /// <summary>
        /// Implements <see cref="INotificationFormatter"/>
        /// Delayed notification. In our demo handled by <see cref="IftttNotificationProvider"/>.
        /// </summary>
        /// <param name="notifications">Notifications to send out.</param>
        /// <param name="recipient">Recipient of the notification. Transformed and filtered by <see cref="IftttNotificationProvider"/>.</param>
        /// <param name="format">Parameters for supported format by <see cref="IftttNotificationProvider"/></param>
        /// <param name="channelName">Channel name, but we only support one so it's ignored here.</param>
        /// <returns>The formatted messages.</returns>
        public IEnumerable <FormatterNotificationMessage> FormatMessages(
            IEnumerable <FormatterNotificationMessage> notifications,
            string recipient,
            NotificationFormat format,
            string channelName)
        {
            // Join messages with the same content.
            var groupedMessages = notifications.GroupBy(x => x.Content);

            foreach (var group in groupedMessages)
            {
                // Get the serialized content data
                var data = _objectSerializer.Deserialize <TweetedPageViewModel>(group.Last().Content);

                // Respect the provider's Format.
                var content = $@"Your article ""{data.PageName}"" has {data.ShareCount} shares!";
                if (format.MaxLength.HasValue)
                {
                    content = content.Substring(0, Math.Min(content.Length, format.MaxLength.Value));
                }

                // Mark all ID's as processed (otherwise the dispatcher will try again with them)
                var messageIds       = group.SelectMany(y => y.ContainedIDs);
                var formattedMessage = new FormatterNotificationMessage(messageIds)
                {
                    Content = content
                };

                yield return(formattedMessage);
            }
        }
 public IEnumerable<FormatterNotificationMessage> FormatMessages(
     IEnumerable<FormatterNotificationMessage> notifications, 
     string recipient, 
     NotificationFormat format, 
     string notificationChannelName)
 {
     // we do not want to change the messages, so we just return them as they are
     // but you have the possibility to group several messages into one if you would like to
     return notifications;
 }
 /// <summary>
 ///     Performs formatting of messages.
 /// </summary>
 /// <param name="notifications">Messages to format</param>
 /// <param name="recipient">The receiver of the message</param>
 /// <param name="format">The format to format to</param>
 /// <param name="channelName">The message channel</param>
 /// <returns>A list of formatted messages</returns>
 /// <remarks>One use case for a formatter might be to combine several messages into one.</remarks>
 public IEnumerable <FormatterNotificationMessage> FormatMessages(IEnumerable <FormatterNotificationMessage> notifications, string recipient, NotificationFormat format, string channelName)
 {
     return(notifications);
 }