Ejemplo n.º 1
0
        /// <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);
            }
        }
        public virtual bool SetCurrentLanguage(string language)
        {
            CultureInfo cultureInfo;

            if (!TryGetLanguage(language, out cultureInfo))
            {
                return(false);
            }

            _defaultUpdateCurrentLanguage.UpdateLanguage(language);
            _cookieService.Set(LanguageCookie, language);
            return(true);
        }
Ejemplo n.º 3
0
        public void UpdateLanguage(string languageId)
        {
            var chosenLanguage = languageId;
            var cookieLanguage = _cookieService.Get(LanguageCookie);

            if (string.IsNullOrEmpty(chosenLanguage))
            {
                if (cookieLanguage != null)
                {
                    chosenLanguage = cookieLanguage;
                }
                else
                {
                    var currentMarket = _currentMarket.GetCurrentMarket();
                    if (currentMarket?.DefaultLanguage != null)
                    {
                        chosenLanguage = currentMarket.DefaultLanguage.Name;
                    }
                }
            }

            _defaultUpdateCurrentLanguage.UpdateLanguage(chosenLanguage);

            if (cookieLanguage == null || cookieLanguage != chosenLanguage)
            {
                _cookieService.Set(LanguageCookie, chosenLanguage);
            }
        }
Ejemplo n.º 4
0
        public void UpdateLanguage(string languageId)
        {
            var currentPreferredLanguage = ContentLanguage.PreferredCulture;

            _existingClass.UpdateLanguage(languageId);

            var newLanguage = ContentLanguage.PreferredCulture;

            if (languageId == null && currentPreferredLanguage.Name != newLanguage.Name)
            {
                throw new Exception($"ContentLanguage.PreferredCulture was set to '{currentPreferredLanguage.Name}' but routing set the language to null, which in turn changed language to '{newLanguage.Name}'. It doesn't matter that {currentPreferredLanguage.Name} doesn't exist in enabled languages, had it existed the code for calculating new language from null don't take the current value into account.");
            }
        }