Esempio n. 1
0
        /// <summary>
        /// Returns first page's of a given type content reference under the root rootPage by root rootPage's content reference.
        /// </summary>
        /// <param name="rootPageLink">The root page's content reference under which to search.</param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static ContentReference GetSingletonPageLink <T>(this ContentReference rootPageLink)
            where T : PageData, new()
        {
            var singletonPage = ContentLoader.GetDescendents(rootPageLink)
                                .Select(ContentLoader.Get <IContent>)
                                .OfType <T>()
                                .FirstOrDefault();

            return(singletonPage != null ? singletonPage.ContentLink : ContentReference.EmptyReference);
        }
        public override object GetValue(IContent content, PropertyInfo property, Type collectionItemType)
        {
            // Let's support both Pages and ContentReference collections
            bool returnReferences = collectionItemType.Is <ContentReference>();

            var descendents = ContentLoader.GetDescendents(content.ContentLink);

            var result = returnReferences
                ? descendents.ToList()
                : GetPagesCollection(() => descendents, collectionItemType);

            return(result);
        }
Esempio n. 3
0
        protected void OnClick_Translate(object sender, EventArgs e)
        {
            var existingCulture = new CultureInfo(SourceLanguageDropDownList.SelectedValue);
            var newCulture      = new CultureInfo(TargetLanguageDropDownList.SelectedValue);

            Project project = null;

            if (CreateProjectCheckBox.Checked)
            {
                project = new Project {
                    Name = ProjectNameTextBox.Text
                };
                ProjectRepository.Save(project);
            }

            var list = new List <ContentReference> {
                CurrentContentLink
            };

            if (TranslateDescendentsCheckBox.Checked)
            {
                list.AddRange(ContentLoader.GetDescendents(CurrentContentLink));
            }

            var result = new StringBuilder();

            foreach (var descendent in list)
            {
                string message;

                try
                {
                    message = TranslateContent(descendent, existingCulture, newCulture, project);

                    var blocks = GetBlocks(descendent, existingCulture, newCulture);
                    foreach (var blockReference in blocks)
                    {
                        message += "<br />" + TranslateContent(blockReference, existingCulture, newCulture, project) + " (block)";
                    }
                }
                catch (Exception ex)
                {
                    message = $"Could not translate {CurrentContentLink.ID} from {existingCulture.DisplayName} to {newCulture.NativeName}.<br /> {ex.Message}<br /> {ex.StackTrace}<br />";
                }

                result.AppendLine("<br />" + message);
            }

            ResultPlaceHolder.Visible = true;
            ResultLiteral.Text        = result.ToString();
        }