/// <summary>Send subscription data to handler</summary> /// <param name="profile">The profile for a subscriber</param> /// <param name="rootPage">Root for subscription</param> /// <param name="changedPages">The pages that has changed</param> protected virtual void SendToHandler(EPiServerProfile profile, PageData rootPage, PageDataCollection changedPages) { IUpdateCurrentLanguage instance = ServiceLocator.Current.GetInstance <IUpdateCurrentLanguage>(); if (this._languageBranchRepository.Load(profile.Language) != null) { instance.UpdateLanguage(profile.Language); } else { instance.UpdateLanguage(ContentLanguage.Instance.FinalFallbackCulture.Name); } string subscriptionHandler1 = SubscriptionJob.FindSubscriptionHandler(rootPage); SubscriptionJob.log.Debug((object)string.Format("Start processing subscription mail for {0}", (object)profile.DisplayName)); SubscriptionJob.log.Debug((object)string.Format("Uses subscription handler: {0}", subscriptionHandler1.Length == 0 ? (object)"Default" : (object)subscriptionHandler1)); ISubscriptionHandler subscriptionHandler2; if (string.IsNullOrEmpty(subscriptionHandler1)) { subscriptionHandler2 = (ISubscriptionHandler) new Gosso.EpiserverLegacy.Personalization.Internal.SubscriptionMail(this._localizationService, this._siteDefinitionResolver); } else { subscriptionHandler2 = Activator.CreateInstance(Type.GetType(subscriptionHandler1, true, true)) as ISubscriptionHandler; if (subscriptionHandler2 == null) { throw new EPiServerException(string.Format("Failed to create a instance of \"{0}\", does it implement ISubscriptionHandler?", (object)Settings.Instance.SubscriptionHandler)); } } subscriptionHandler2.User = profile.UserName; subscriptionHandler2.UserData = profile; try { subscriptionHandler2.Send(rootPage, changedPages); SubscriptionJob.log.Debug((object)string.Format("Finished processing subscription mail for {0}", (object)profile.DisplayName)); } catch (ConfigurationErrorsException ex) { SubscriptionJob.log.Error((object)string.Format("Failed to send subscription to {0} due to a configuration error", (object)profile.DisplayName), (Exception)ex); throw; } catch (SmtpException ex) { SubscriptionJob.log.Error((object)string.Format("Failed to send subscription to {0}", (object)profile.DisplayName), (Exception)ex); if (ex.StatusCode == SmtpStatusCode.MailboxUnavailable) { return; } throw; } catch (Exception ex) { SubscriptionJob.log.Error((object)string.Format("Failed to send subscription to {0}", (object)profile.DisplayName), ex); } }
/// <summary>Execute subscription job</summary> protected virtual string InternalExecute() { int num1 = 0; int num2 = 0; label_1: int totalRecords; ProfileInfoCollection allProfiles = ProfileManager.GetAllProfiles(ProfileAuthenticationOption.All, num2++, 1000, out totalRecords); if (allProfiles.Count == 0) { return(string.Format("{0} user profiles were found. {1} subscription e-mails were sent.", (object)totalRecords, (object)num1)); } IEnumerator enumerator = allProfiles.GetEnumerator(); try { while (enumerator.MoveNext()) { EPiServerProfile profile = EPiServerProfile.Get(((ProfileInfo)enumerator.Current).UserName); if (!SubscriptionJob.IsInInterval(profile.SubscriptionInfo.Interval, profile.SubscriptionInfo.LastMessage)) { int num3 = this.SendSubscriptions(profile); if (num3 >= 0) { profile.SubscriptionInfo.LastMessage = DateTime.Now; num1 += num3; profile.Save(); } } } goto label_1; } finally { IDisposable disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } } }
/// <summary> /// Process subscriptions and send notification about changes to subscribers. /// </summary> /// <param name="profile">The profile for the subscriber</param> /// <returns> /// Actual number of subscription notification messages sent. /// </returns> protected virtual int SendSubscriptions(EPiServerProfile profile) { int num = 0; IPrincipal principal = _userImpersonation.CreatePrincipal(profile.UserName); foreach (SubscriptionDescriptor subscribedPage in profile.SubscriptionInfo.SubscribedPages) { PageData pageData; try { pageData = this._contentRepository.Get <PageData>((ContentReference) new PageReference(subscribedPage.PageID)); } catch (ContentNotFoundException) { if (SubscriptionJob.log.IsWarnEnabled) { SubscriptionJob.log.WarnFormat("The user {0} subscribes to the page {1} that does not exists.", (object)profile.UserName, (object)subscribedPage.PageID); continue; } continue; } if (pageData != null && pageData["EPSUBSCRIBE"] != null) { foreach (string language in subscribedPage.Languages) { PageDataCollection changedPages = this.GetChangedPages(profile, language, subscribedPage, principal); if (changedPages.Count != 0) { PageData rootPage = this.GetPage(subscribedPage.PageID, language, principal, false) ?? SubscriptionJob.CreateLanguageBranchContainer(language); if (this.CanSendSubscription(profile, rootPage, changedPages)) { ++num; this.SendToHandler(profile, rootPage, changedPages); } } } } } if (num > 0) { return(num); } return(profile.SubscriptionInfo.SubscribedPages.Count != 0 ? 0 : -1); }