private void LocalizePage(PageElement pageElement, string lang = "")
        {
            if (!string.IsNullOrEmpty(lang))
            {
                pageElement.Locale = lang;
            }

            if (pageElement.Icon != null && !string.IsNullOrEmpty(pageElement.Icon.Source))
            {
                pageElement.Icon.Source = ResolveUri(pageElement.Icon.Source, lang);
            }

            if (pageElement.Image != null && !string.IsNullOrEmpty(pageElement.Image.Source))
            {
                pageElement.Image.Source = ResolveUri(pageElement.Image.Source, lang);
            }

            if (pageElement.StyleSheets != null && pageElement.StyleSheets.Count > 0)
            {
                foreach (var style in pageElement.StyleSheets)
                {
                    if (!string.IsNullOrEmpty(style.Source))
                    {
                        style.Source = ResolveUri(style.Source, lang);
                    }
                }
            }

            if (pageElement.Scripts != null && pageElement.Scripts.Count > 0)
            {
                foreach (var script in pageElement.Scripts)
                {
                    if (!string.IsNullOrEmpty(script.Source))
                    {
                        script.Source = ResolveUri(script.Source, lang);
                    }
                }
            }

            if (pageElement.Children != null && pageElement.Children.Count > 0)
            {
                foreach (var child in pageElement.Children)
                {
                    LocalizePage(child, lang);
                }
            }

            ///TODO:Localize the widget resources
        }
        internal static PageElement ToXmlElement(this WebPage page, bool includeChilden = true, bool includeWidgets = true)
        {
            var web = page.Web;
            var _pg = new PageElement()
            {
                Title = new LocalizableElement() { Text = page.Title, },
                Description = new LocalizableElement() { Text = page.Description },
                Keywords = new LocalizableElement() { Text = page.Keywords },
                Image = new ImageElement() { Source = page.ImageUrl },
                Icon = new ImageElement() { Source = page.IconUrl },
                LinkUrl = page.LinkTo,
                Target = page.Target,
                IsStatic = page.IsStatic,
                IsShared = page.IsShared,
                AllowAnonymous = page.AllowAnonymous,
                ShowInMenu = page.ShowInMenu,
                Slug = page.Slug
            };
            if (!string.IsNullOrEmpty(page.ViewData) || !string.IsNullOrEmpty(page.ViewName))
                _pg.Layout = new LayoutElement()
                {
                    Name = page.ViewName,
                    Text = page.ViewData
                };
            //_pg.Path = _pg.Path.ToLower().Replace("/" + web.Name.ToLower() + "/", "/{website}/");

            if (includeWidgets)
            {
                if (page.Widgets.Count > 0)
                {
                    _pg.Widgets = new List<WidgetDataElement>();
                    foreach (var widget in page.Widgets)
                    {
                        if (!widget.IsStatic && widget.TrackState == (int)TrackStates.NoChange)
                            _pg.Widgets.Add(widget.ToXmlElement());
                    }
                }
            }

            if (includeChilden)
            {
                var children = web.Pages.Where(p => p.ParentID == page.ID);
                if (children.Count() > 0)
                {
                    _pg.Children = new List<PageElement>();
                    foreach (var pc in children)
                        _pg.Children.Add(pc.ToXmlElement(true));
                }
            }

            return _pg;
        }
Example #3
0
        public PageElement Clone()
        {
            var copy = new PageElement()
            {
                AllowAnonymous = this.AllowAnonymous,
                //Data = this.Data,
                Title = this.Title != null ? this.Title.Clone() : null,
                Description = this.Description != null ? this.Description.Clone() : null,
                Keywords = this.Keywords != null ? this.Keywords.Clone() : null,
                IsShared = this.IsShared,
                IsStatic = this.IsStatic,
                ShowInMenu = this.ShowInMenu,
                ShowInSitemap = this.ShowInSitemap,
                Layout = this.Layout!=null ? this.Layout.Clone() : null,
                Slug = this.Slug,
                LinkUrl = this.LinkUrl,
                Locale = this.Locale,
                Direction = this.Direction,
                Icon = this.Icon != null ? this.Icon.Clone() : null,
                Image = this.Image != null ? this.Image.Clone() : null,
                Target = this.Target,
                ViewMode = this.ViewMode
            };

            if (this.StyleSheets != null)
            {
                copy.StyleSheets = new List<ResElement>();
                foreach (var s in this.StyleSheets)
                    copy.StyleSheets.Add(s.Clone());
            }

            if (this.Scripts != null)
            {
                copy.Scripts = new List<ScriptElement>();
                foreach (var s in this.Scripts)
                    copy.Scripts.Add(s.Clone());
            }

            if (this.Widgets != null)
            {
                copy.Widgets = new List<WidgetDataElement>();
                foreach (var w in this.Widgets)
                    copy.Widgets.Add(w.Clone());
            }

            if (this.Children != null)
            {
                copy.Children = new List<PageElement>();
                foreach (var p in copy.Children)
                    copy.Children.Add(p.Clone());
            }

            return copy;
        }
Example #4
0
        public PageElement Clone()
        {
            var copy = new PageElement()
            {
                AllowAnonymous = this.AllowAnonymous,
                //Data = this.Data,
                Title = this.Title != null?this.Title.Clone() : null,
                            Description = this.Description != null?this.Description.Clone() : null,
                                              Keywords = this.Keywords != null?this.Keywords.Clone() : null,
                                                             IsShared                                                         = this.IsShared,
                                                             IsStatic                                                         = this.IsStatic,
                                                             ShowInMenu                                                       = this.ShowInMenu,
                                                             ShowInSitemap                                                    = this.ShowInSitemap,
                                                             Layout                                                           = this.Layout != null?this.Layout.Clone() : null,
                                                                                                 Slug                         = this.Slug,
                                                                                                 LinkUrl                      = this.LinkUrl,
                                                                                                 Locale                       = this.Locale,
                                                                                                 Direction                    = this.Direction,
                                                                                                 Icon                         = this.Icon != null?this.Icon.Clone() : null,
                                                                                                                        Image = this.Image != null?this.Image.Clone() : null,
                                                                                                                                    Target   = this.Target,
                                                                                                                                    ViewMode = this.ViewMode
            };

            if (this.StyleSheets != null)
            {
                copy.StyleSheets = new List <ResElement>();
                foreach (var s in this.StyleSheets)
                {
                    copy.StyleSheets.Add(s.Clone());
                }
            }

            if (this.Scripts != null)
            {
                copy.Scripts = new List <ScriptElement>();
                foreach (var s in this.Scripts)
                {
                    copy.Scripts.Add(s.Clone());
                }
            }

            if (this.Widgets != null)
            {
                copy.Widgets = new List <WidgetDataElement>();
                foreach (var w in this.Widgets)
                {
                    copy.Widgets.Add(w.Clone());
                }
            }

            if (this.Children != null)
            {
                copy.Children = new List <PageElement>();
                foreach (var p in copy.Children)
                {
                    copy.Children.Add(p.Clone());
                }
            }

            return(copy);
        }