Beispiel #1
0
        protected override void InitializeControls(Telerik.Sitefinity.Web.UI.GenericContainer container)
        {
            var url = System.Web.HttpContext.Current.Session["PageUrl"].ToString();
            var regEx = new System.Text.RegularExpressions.Regex(@"^/([a-zA-Z]+)/[a-zA-Z/]*$");
            var match = regEx.Match(url);
            string pageName = "";

            if (!match.Success)
                throw new NullReferenceException("The url did not contain the current page name");

            pageName = match.Groups[1].ToString().ToLower();

            var pManager = Telerik.Sitefinity.Modules.Pages.PageManager.GetManager();

            var sites = new Telerik.Sitefinity.Multisite.MultisiteManager();

            var homePage = pManager.GetPageDataList().Where(p => p.NavigationNode.Title.ToString().ToLower() == pageName && p.NavigationNode.ParentId == new Guid(System.Web.SiteMap.RootNode.Key)).FirstOrDefault();

            if (homePage == null)
                throw new NullReferenceException("The current published page could not be found");

            var homePagePreview = pManager.GetPreview(homePage.NavigationNode.PageId);

            if (homePagePreview == null)
                throw new NullReferenceException("The current preview page could not be found");

            var configPage = pManager.GetPageDataList().Where(p => p.NavigationNode.Title.ToString().ToLower() == "config" && p.NavigationNode.ParentId == new Guid(System.Web.SiteMap.RootNode.Key)).FirstOrDefault();

            if (configPage == null)
                throw new NullReferenceException("The config page could not be found");

            var parentName = configPage.Controls[0].Properties.FirstOrDefault(p => p.Name == "ParentName");

            if (parentName == null)
                throw new NullReferenceException("The ParentName property could not be found");

            var parentSiteName = parentName.Value;

            if (parentSiteName == "")
                throw new NullReferenceException("The ParentName property is empty");

            var parentSite = sites.GetSites().Where(p => p.Name == parentSiteName).FirstOrDefault();

            if (parentSite == null)
                throw new NullReferenceException("The parent site name: " + parentSiteName + " could not be found");

            var thisPage = pManager.GetPageDataList().Where(p => p.NavigationNode.Title.ToString().ToLower() == pageName && p.NavigationNode.ParentId == parentSite.SiteMapRootNodeId).FirstOrDefault();

            if (thisPage == null)
                throw new NullReferenceException("The current page of the parent site could not be found");

            thisPage.Controls[0].Properties.ToList().ForEach(p =>
            {
                ControlProperty homeProperty = null;
                if ((homeProperty = homePagePreview.Controls[0].Properties.FirstOrDefault(n => n.Name == p.Name)) != null)
                {
                    if (p.Value != homeProperty.Value)
                    {
                        StandardValue.Visible = false;
                    }
                }
            });

            //var url = System.Web.HttpContext.Current.Session["PageUrl"].ToString();
            //var regEx = new System.Text.RegularExpressions.Regex(@"^/([a-zA-Z]+)/[a-zA-Z/]*$");
            //var match = regEx.Match(url);
            //string pageName = "";

            //if(!match.Success)
            //    throw new NullReferenceException("The url did not contain the current page name");

            //pageName = match.Groups[1].ToString().ToLower();

            //var pManager = Telerik.Sitefinity.Modules.Pages.PageManager.GetManager();

            //var sites = new Telerik.Sitefinity.Multisite.MultisiteManager();

            //var homePage = pManager.GetPageDataList().Where(p => p.NavigationNode.Title.ToString().ToLower() == pageName && p.NavigationNode.ParentId == new Guid(System.Web.SiteMap.RootNode.Key)).FirstOrDefault();

            //if (homePage == null)
            //    throw new NullReferenceException("The current published page could not be found");

            //var homePagePreview = pManager.GetPreview(homePage.NavigationNode.PageId);

            //if (homePagePreview == null)
            //    throw new NullReferenceException("The current preview page could not be found");

            //var configPage = pManager.GetPageDataList().Where(p => p.NavigationNode.Title.ToString().ToLower() == "config" && p.NavigationNode.ParentId == new Guid(System.Web.SiteMap.RootNode.Key)).FirstOrDefault();

            //if(configPage == null)
            //    throw new NullReferenceException("The config page could not be found");

            //var parentName = configPage.Controls[0].Properties.FirstOrDefault(p => p.Name == "ParentName");

            //if (parentName == null)
            //    throw new NullReferenceException("The ParentName property could not be found");

            //var parentSiteName = parentName.Value;

            //if (parentSiteName == "")
            //    throw new NullReferenceException("The ParentName property is empty");

            //var parentSite = sites.GetSites().Where(p => p.Name == parentSiteName).FirstOrDefault();

            //if(parentSite == null)
            //    throw new NullReferenceException("The parent site name: " + parentSiteName + " could not be found");

            //var thisPage = pManager.GetPageDataList().Where(p => p.NavigationNode.Title.ToString().ToLower() == pageName && p.NavigationNode.ParentId == parentSite.SiteMapRootNodeId).FirstOrDefault();

            //if(thisPage == null)
            //    throw new NullReferenceException("The current page of the parent site could not be found");

            //thisPage.Controls[0].Properties.ToList().ForEach(p =>
            //{
            //    ControlProperty homeProperty = null;
            //    if ((homeProperty = homePagePreview.Controls[0].Properties.FirstOrDefault(n => n.Name == p.Name)) != null)
            //    {
            //        if (p.Value != homeProperty.Value)
            //        {
            //            StandardValue.Visible = false;
            //        }
            //    }
            //});
        }
        protected override void InitializeControls(Telerik.Sitefinity.Web.UI.GenericContainer container)
        {
            var    url      = System.Web.HttpContext.Current.Session["PageUrl"].ToString();
            var    regEx    = new System.Text.RegularExpressions.Regex(@"^/([a-zA-Z]+)/[a-zA-Z/]*$");
            var    match    = regEx.Match(url);
            string pageName = "";

            if (!match.Success)
            {
                throw new NullReferenceException("The url did not contain the current page name");
            }

            pageName = match.Groups[1].ToString().ToLower();

            var pManager = Telerik.Sitefinity.Modules.Pages.PageManager.GetManager();

            var sites = new Telerik.Sitefinity.Multisite.MultisiteManager();

            var homePage = pManager.GetPageDataList().Where(p => p.NavigationNode.Title.ToString().ToLower() == pageName && p.NavigationNode.ParentId == new Guid(System.Web.SiteMap.RootNode.Key)).FirstOrDefault();

            if (homePage == null)
            {
                throw new NullReferenceException("The current published page could not be found");
            }

            var homePagePreview = pManager.GetPreview(homePage.NavigationNode.PageId);

            if (homePagePreview == null)
            {
                throw new NullReferenceException("The current preview page could not be found");
            }

            var configPage = pManager.GetPageDataList().Where(p => p.NavigationNode.Title.ToString().ToLower() == "config" && p.NavigationNode.ParentId == new Guid(System.Web.SiteMap.RootNode.Key)).FirstOrDefault();

            if (configPage == null)
            {
                throw new NullReferenceException("The config page could not be found");
            }

            var parentName = configPage.Controls[0].Properties.FirstOrDefault(p => p.Name == "ParentName");

            if (parentName == null)//no parent, most likely is parent site
            {
                return;
            }

            var parentSiteName = parentName.Value;

            if (parentSiteName == "")
            {
                throw new NullReferenceException("The ParentName property is empty");
            }

            var parentSite = sites.GetSites().Where(p => p.Name == parentSiteName).FirstOrDefault();

            if (parentSite == null)
            {
                throw new NullReferenceException("The parent site name: " + parentSiteName + " could not be found");
            }

            var thisPage = pManager.GetPageDataList().Where(p => p.NavigationNode.Title.ToString().ToLower() == pageName && p.NavigationNode.ParentId == parentSite.SiteMapRootNodeId).FirstOrDefault();

            if (thisPage == null)
            {
                throw new NullReferenceException("The current page of the parent site could not be found");
            }

            thisPage.Controls[0].Properties.ToList().ForEach(p =>
            {
                ControlProperty homeProperty = null;
                if ((homeProperty = homePagePreview.Controls[0].Properties.FirstOrDefault(n => n.Name == p.Name)) != null)
                {
                    if (p.Value != homeProperty.Value)
                    {
                        StandardValue.Visible = false;
                    }
                }
            });
        }