internal void PrepareNotifications(int contentId, int[] articleIds, string[] codes, bool disableNotifications = false) { Notifications = new Notification[0]; ArticleIds = new int[0]; Articles = new Article[0]; ValidateCodes(codes); Codes = codes.Distinct().ToArray(); if (!disableNotifications) { ContentId = contentId; SiteId = ContentRepository.GetSiteId(contentId); Notifications = NotificationRepository.GetContentNotifications(contentId, codes).ToArray(); if (Notifications.Any()) { ArticleIds = articleIds; if (!Codes.Contains(NotificationCode.Create) && ServiceNotifications.Any()) { Articles = GetArticles(); } } } }
internal void SendServiceNotifications() { if (!ServiceNotifications.Any()) { return; } try { IEnumerable <ExternalNotificationModel> notificationQueue; if (Codes.Contains(NotificationCode.Delete)) { notificationQueue = from notification in ServiceNotifications join article in Articles on notification.ContentId equals article.ContentId select new ExternalNotificationModel { EventName = NotificationCode.Delete, ArticleId = article.Id, ContentId = ContentId, SiteId = SiteId, Url = notification.ExternalUrl, OldXml = GetXDocument(article).ToString(), NewXml = null }; } else if (Codes.Contains(NotificationCode.Create)) { notificationQueue = from notification in ServiceNotifications join article in GetArticles() on notification.ContentId equals article.ContentId select new ExternalNotificationModel { EventName = NotificationCode.Create, ArticleId = article.Id, ContentId = ContentId, SiteId = SiteId, Url = notification.ExternalUrl, OldXml = null, NewXml = GetXDocument(article).ToString() }; } else { var oldArticles = Articles; var newArticles = GetArticles(); notificationQueue = from notification in ServiceNotifications from code in Codes join oldArticle in oldArticles on notification.ContentId equals oldArticle.ContentId join newArticle in newArticles on oldArticle.Id equals newArticle.Id where notification.ForModify && code == NotificationCode.Update || notification.ForFrontend && code == NotificationCode.Custom || notification.ForStatusChanged && code == NotificationCode.ChangeStatus || notification.ForStatusPartiallyChanged && code == NotificationCode.PartialChangeStatus || notification.ForDelayedPublication && code == NotificationCode.DelayedPublication select new ExternalNotificationModel { EventName = code, ArticleId = oldArticle.Id, ContentId = ContentId, SiteId = SiteId, Url = notification.ExternalUrl, OldXml = GetXDocument(oldArticle).ToString(), NewXml = GetXDocument(newArticle).ToString() }; } new ExternalInterfaceNotificationService().Insert(notificationQueue); } catch (Exception ex) { HandleException(ex); } }