Ejemplo n.º 1
0
        private bool PageExistsInLanguageContext(PageData page, ILanguageSelector languageSelector)
        {
            //Checks if page exist in current language context or if a fallback exist
            LanguageSelectorContext args = new LanguageSelectorContext(page);

            languageSelector.SelectPageLanguage(args);
            return(!String.IsNullOrEmpty(args.SelectedLanguage));
        }
        /// <summary>
        /// Load the content for a <see cref="ContentReference"/>.
        /// </summary>
        /// <param name="contentLink">
        /// The content link.
        /// </param>
        /// <param name="languageSelector">
        /// The language selector.
        /// </param>
        /// <returns>
        /// The <see cref="IContent"/>.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">
        /// contentLink
        /// </exception>
        /// <exception cref="System.NotSupportedException">
        /// Only cloning of pages is supported
        /// </exception>
        protected override IContent LoadContent(ContentReference contentLink, ILanguageSelector languageSelector)
        {
            if (ContentReference.IsNullOrEmpty(contentLink) || contentLink.ID == 0)
            {
                throw new ArgumentNullException("contentLink");
            }

            if (languageSelector == null)
            {
                languageSelector = LanguageSelector.AutoDetect();
            }

            if (contentLink.WorkID > 0)
            {
                return(this.ContentStore.LoadVersion(contentLink, -1));
            }

            ILanguageBranchRepository languageBranchRepository =
                ServiceLocator.Current.GetInstance <ILanguageBranchRepository>();

            LanguageSelectorContext context = new LanguageSelectorContext(
                contentLink, languageBranchRepository, this.Load);

            if (contentLink.GetPublishedOrLatest)
            {
                languageSelector.SelectPageLanguage(context);

                LanguageBranch langBr = null;

                if (context.SelectedLanguage != null)
                {
                    langBr = languageBranchRepository.Load(context.SelectedLanguage);
                }

                return(this.ContentStore.LoadVersion(contentLink, langBr != null ? langBr.ID : -1));
            }

            languageSelector.SetInitializedLanguageBranch(context);

            // Get published version of Content
            IContent originalContent = this.ContentStore.Load(
                contentLink, context.SelectedLanguageBranch != null ? context.SelectedLanguageBranch.ID : -1);

            PageData page = originalContent as PageData;

            if (page == null)
            {
                throw new NotSupportedException("Only cloning of pages is supported");
            }

            return(this.ClonePage(page));
        }
        protected override IContent LoadContent(ContentReference contentLink, ILanguageSelector languageSelector)
        {
            if (ContentReference.IsNullOrEmpty(contentLink) || contentLink.ID == 0)
            {
                throw new ArgumentNullException("contentLink");
            }

            if (contentLink.WorkID > 0)
            {
                return ContentStore.LoadVersion(contentLink, -1);
            }

            var languageBranchRepository = ServiceLocator.Current.GetInstance<ILanguageBranchRepository>();

            var context = new LanguageSelectorContext(contentLink, languageBranchRepository, Load);

            if (contentLink.GetPublishedOrLatest)
            {
                languageSelector.SelectPageLanguage(context);

                LanguageBranch langBr = null;

                if (context.SelectedLanguage != null)
                {
                    langBr = languageBranchRepository.Load(context.SelectedLanguage);
                }

                return ContentStore.LoadVersion(contentLink, langBr != null ? langBr.ID : -1);
            }

            languageSelector.SetInitializedLanguageBranch(context);

            // Get published version of Content
            var originalContent = ContentStore.Load(contentLink, context.SelectedLanguageBranch != null ? context.SelectedLanguageBranch.ID : -1);

            var page = originalContent as PageData;

            if(page == null)
            {
                throw new NotSupportedException("Only cloning of pages is supported");
            }

            return ClonePage(page);
        }