public void Execute()
        {
            var branch = _repository.Load(Culture);

            if (branch != null)
            {
                branch = branch.CreateWritableClone();

                branch.Enabled = Enabled;
                _repository.Save(branch);
            }
            else
            {
                branch         = new LanguageBranch(Culture);
                branch.Enabled = Enabled;
                _repository.Save(branch);
            }
        }
Exemplo n.º 2
0
        public Task ExecuteAsync()
        {
            var enabledLanguages = new[] { "en", "no" };

            var languageDefinitions = _languageBranchRepository.ListAll();

            foreach (var languageDefinition in languageDefinitions.Where(ld =>
                                                                         enabledLanguages.Contains(ld.LanguageID, StringComparer.OrdinalIgnoreCase)))
            {
                if (languageDefinition.Enabled == false)
                {
                    var d = languageDefinition.CreateWritableClone();
                    d.Enabled = true;
                    _languageBranchRepository.Save(d);
                }
            }

            foreach (var languageDefinition in languageDefinitions.Where(ld =>
                                                                         enabledLanguages.Contains(ld.LanguageID, StringComparer.OrdinalIgnoreCase) == false))
            {
                if (languageDefinition.Enabled)
                {
                    var d = languageDefinition.CreateWritableClone();
                    d.Enabled = false;
                    _languageBranchRepository.Save(d);
                }
            }


            var rootLanguageSettings = _contentLanguageSettingRepository.Load(ContentReference.RootPage);

            foreach (var languageSetting in rootLanguageSettings)
            {
                var isActive =
                    enabledLanguages.Contains(languageSetting.LanguageBranch, StringComparer.OrdinalIgnoreCase);
                if (languageSetting.IsActive == isActive)
                {
                    continue;
                }

                var c = languageSetting.CreateWritableClone();
                c.IsActive = isActive;
                _contentLanguageSettingRepository.Save(c);
            }

            foreach (var language in enabledLanguages)
            {
                var languageSettings = rootLanguageSettings.SingleOrDefault(s =>
                                                                            s.LanguageBranch.Equals(language, StringComparison.OrdinalIgnoreCase));
                if (languageSettings == null)
                {
                    languageSettings = new ContentLanguageSetting(ContentReference.RootPage, language)
                    {
                        IsActive = true
                    };

                    _contentLanguageSettingRepository.Save(languageSettings);
                }
            }

            if (enabledLanguages.Contains("no"))
            {
                ContentLanguage.PreferredCulture = CultureInfo.GetCultureInfo("no");
            }

            return(Task.CompletedTask);
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="CmsContext" /> class.
        /// </summary>
        public CmsContext()
        {
            ContentReference.RootPage = new PageReference(1).CreateWritableClone();

            ////ContentReference.StartPage.CreateWritableClone().ID = 4;

            SiteDefinition.Current           = A.Fake <SiteDefinition>();
            SiteDefinition.Current.StartPage = new PageReference(4);

            this.StartPageUrl = "/";

            Context.Current = A.Fake <IContext>();

            ServiceLocator.SetLocator(A.Fake <IServiceLocator>());

            this.ContentLoader = A.Fake <IContentLoader>();

            this.UrlResolver = A.Fake <UrlResolver>();

            this.TemplateResolver = A.Fake <TemplateResolver>();

            this.ContentRepository = A.Fake <IContentRepository>();

            this.ContentTypeRepository = A.Fake <IContentTypeRepository>();

            this.LanguageBranchRepository = A.Fake <ILanguageBranchRepository>();

            this.LoaderOptions = A.Fake <LoaderOptions>();

            this.LocalizationService = A.Fake <LocalizationService>();

            this.ProviderBasedLocalizationService = new ProviderBasedLocalizationService();

            A.CallTo(() => Context.Current.RequestTime).Returns(DateTime.Now);

            A.CallTo(() => ServiceLocator.Current.GetInstance <IContentRepository>()).Returns(this.ContentRepository);

            A.CallTo(() => ServiceLocator.Current.GetInstance <IContentTypeRepository>())
            .Returns(this.ContentTypeRepository);

            A.CallTo(() => ServiceLocator.Current.GetInstance <ILanguageBranchRepository>())
            .Returns(this.LanguageBranchRepository);

            A.CallTo(() => ServiceLocator.Current.GetInstance <TemplateResolver>()).Returns(this.TemplateResolver);

            A.CallTo(() => this.UrlResolver.GetUrl(ContentReference.StartPage)).Returns(this.StartPageUrl);

            A.CallTo(() => ServiceLocator.Current.GetInstance <ProviderBasedLocalizationService>())
            .Returns(this.ProviderBasedLocalizationService);

            A.CallTo(() => ServiceLocator.Current.GetInstance <LocalizationService>())
            .Returns(this.ProviderBasedLocalizationService);

            // Also fake the TryGetExistingInstance for the LocalizationService
            LocalizationService ignored;

            A.CallTo(() => ServiceLocator.Current.TryGetExistingInstance(out ignored))
            .Returns(true)
            .AssignsOutAndRefParameters(this.ProviderBasedLocalizationService);

            ILanguageBranchRepository languageBranchRepository = this.LanguageBranchRepository;

            if (languageBranchRepository != null)
            {
                languageBranchRepository.Save(new LanguageBranch(MasterLanguage));
                languageBranchRepository.Save(new LanguageBranch(SecondLanguage));

                A.CallTo(() => languageBranchRepository.ListEnabled())
                .Returns(new[] { new LanguageBranch(MasterLanguage), new LanguageBranch(SecondLanguage) });
            }

            this.RegisterMocks();

            HttpContextBase = this.CreateFakeHttpContext();
        }