Beispiel #1
0
        private string GetLanguageName(string languageCode)
        {
            if (string.IsNullOrEmpty(languageCode))
            {
                return(string.Empty);
            }
            var languageBranch = _languageBranchRepository.Load(languageCode);

            return(languageBranch == null ? string.Empty : languageBranch.Name);
        }
        /// <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));
        }
Beispiel #3
0
        /// <summary>
        /// Returns host with language.
        /// For example en/sitemap.xml
        /// </summary>
        /// <param name="sitemapData"></param>
        /// <returns></returns>
        public string GetHostWithLanguage(SitemapData sitemapData)
        {
            if (string.IsNullOrWhiteSpace(sitemapData.Language))
            {
                return(sitemapData.Host.ToLowerInvariant());
            }

            var languageBranch = _languageBranchRepository.Load(sitemapData.Language);

            if (languageBranch != null)
            {
                return(string.Format("{0}/{1}", languageBranch.CurrentUrlSegment, sitemapData.Host).ToLowerInvariant());
            }
            return(sitemapData.Host.ToLowerInvariant());
        }
        private bool TryGetCultureInfo(out string language, out CultureInfo cultureInfo)
        {
            var query = Request.GetQueryNameValuePairs().Where(kv => kv.Key == "language").FirstOrDefault();

            language = query.Value;

            if (!String.IsNullOrEmpty(language))
            {
                ILanguageBranchRepository languageRepo = ServiceLocator.Current.GetInstance <ILanguageBranchRepository>();

                cultureInfo = languageRepo.Load(language)?.Culture;
                return(cultureInfo != null);
            }

            cultureInfo = null; // ContentLanguage.PreferredCulture;
            return(true);
        }
        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);
            }
        }
        private bool TryGetCultureInfo(string language, out CultureInfo cultureInfo)
        {
            ILanguageBranchRepository languageRepo = ServiceLocator.Current.GetInstance <ILanguageBranchRepository>();

            cultureInfo = languageRepo.Load(language)?.Culture;
            if (cultureInfo != null)
            {
                return(true);
            }
            try
            {
                cultureInfo = CultureInfo.GetCultureInfo(language);
            }
            catch (Exception)
            {
            }
            return(false);
        }
        private DataTable ConvertPageTypeProperties(
            int blockLinkId,
            int fromBlockTypeId,
            List <KeyValuePair <int, int> > propertyTypeMap,
            bool recursive,
            bool isTest)
        {
            DataTable dataTable = new DataTable("Properties");

            dataTable.Locale = CultureInfo.InvariantCulture;
            dataTable.Columns.Add("FromPropertyID");
            dataTable.Columns.Add("ToPropertyID");
            dataTable.Columns.Add("Count");

            var content        = (ILocalizable)_contentRepository.Get <IContent>(new ContentReference(blockLinkId));
            var languageBranch = content.MasterLanguage;
            int id             = _languageBranchRepository.Load(languageBranch).ID;

            foreach (KeyValuePair <int, int> propertyType in propertyTypeMap)
            {
                DbCommand command = CreateCommand("netConvertPropertyForPageType");
                command.Parameters.Add(CreateReturnParameter());
                command.Parameters.Add(CreateParameter("PageID", blockLinkId));
                command.Parameters.Add(CreateParameter("FromPageType", fromBlockTypeId));
                command.Parameters.Add(CreateParameter("FromPropertyID", propertyType.Key));
                command.Parameters.Add(CreateParameter("ToPropertyID", propertyType.Value));
                command.Parameters.Add(CreateParameter("Recursive", recursive));
                command.Parameters.Add(CreateParameter("MasterLanguageID", id));
                command.Parameters.Add(CreateParameter("IsTest", isTest));
                command.ExecuteNonQuery();
                DataRow row = dataTable.NewRow();
                row[0] = propertyType.Key;
                row[1] = propertyType.Value;
                row[2] = GetReturnValue(command);
                dataTable.Rows.Add(row);
                if (_propertyDefinitionRepository.Load(propertyType.Key).Type.DataType == PropertyDataType.Category)
                {
                    command.CommandText = "netConvertCategoryPropertyForPageType";
                    command.ExecuteNonQuery();
                }
            }
            return(dataTable);
        }