private static string GetEventTemplate(MessageTemplate template, NotificationType notificationType) { switch (notificationType) { case NotificationType.Created: return template.CreatedTemplate; case NotificationType.MajorVersionModified: return template.MajorVersionModifiedTemplate; case NotificationType.MinorVersionModified: return template.MinorVersionModifiedTemplate; case NotificationType.CopiedFrom: return template.CopiedFromTemplate; case NotificationType.MovedFrom: return template.MovedFromTemplate; case NotificationType.MovedTo: return template.MovedToTemplate; case NotificationType.RenamedFrom: return template.RenamedFromTemplate; case NotificationType.RenamedTo: return template.RenamedToTemplate; case NotificationType.Deleted: return template.DeletedTemplate; case NotificationType.Restored: return template.RestoredTemplate; default: throw new NotImplementedException("Unknown NotificationType: " + notificationType); } }
private static Message GenerateMessage(Subscription subscription, Dictionary<string, NotificationConfig> configs) { if (subscription.RelatedEvents.Count == 0) return null; // we will process those content only for which no config is available. if there is no such content, we are done. if (!subscription.RelatedEvents.Any(e => configs[e.ContentPath] == null)) return null; var template = new MessageTemplate(subscription.Language); var cultureInfo = CultureInfo.CreateSpecificCulture(subscription.Language); string subjectTemplate = null; switch (subscription.Frequency) { case NotificationFrequency.Immediately: subjectTemplate = template.ImmediatelySubject; break; case NotificationFrequency.Daily: subjectTemplate = template.DailySubject; break; case NotificationFrequency.Weekly: subjectTemplate = template.WeeklySubject; break; case NotificationFrequency.Monthly: subjectTemplate = template.MonthlySubject; break; default: throw GetUnknownFrequencyException(subscription.Frequency); } var subject = ReplaceParameters(subjectTemplate, subscription); var body = new StringBuilder(); string headTemplate = null; switch (subscription.Frequency) { case NotificationFrequency.Immediately: headTemplate = template.ImmediatelyHeader; break; case NotificationFrequency.Daily: headTemplate = template.DailyHeader; break; case NotificationFrequency.Weekly: headTemplate = template.WeeklyHeader; break; case NotificationFrequency.Monthly: headTemplate = template.MonthlyHeader; break; default: throw GetUnknownFrequencyException(subscription.Frequency); } body.Append(ReplaceParameters(headTemplate, subscription)); foreach (var @event in subscription.RelatedEvents) { // a custom config exists for this contentpath, email for that has already been processed previously if (configs[@event.ContentPath] != null) continue; body.Append(ReplaceParameters(GetEventTemplate(template, @event.NotificationType), subscription.SitePath, subscription.SiteUrl, @event, cultureInfo)); } string footTemplate = null; switch (subscription.Frequency) { case NotificationFrequency.Immediately: footTemplate = template.ImmediatelyFooter; break; case NotificationFrequency.Daily: footTemplate = template.DailyFooter; break; case NotificationFrequency.Weekly: footTemplate = template.WeeklyFooter; break; case NotificationFrequency.Monthly: footTemplate = template.MonthlyFooter; break; default: throw GetUnknownFrequencyException(subscription.Frequency); } body.Append(ReplaceParameters(footTemplate, subscription)); return new Message { Address = subscription.UserEmail, Subject = subject, Body = body.ToString() }; }