Exemple #1
0
        private void PopulateControls()
        {
            if (HttpContext.Current == null)
            {
                return;
            }

            if (rootNode == null)
            {
                return;
            }

            XmlDocument doc = new XmlDocument();

            doc.LoadXml("<ZoneList></ZoneList>");

            XmlElement root = doc.DocumentElement;

            XmlHelper.AddNode(doc, root, "ModuleTitle", this.Title);
            XmlHelper.AddNode(doc, root, "ZoneTitle", CurrentZone.Name);
            XmlHelper.AddNode(doc, root, "Title", GetZoneTitle(currentNode));
            XmlHelper.AddNode(doc, root, "Url", FormatUrl(currentNode));
            XmlHelper.AddNode(doc, root, "Target", (currentNode.OpenInNewWindow == true ? "_blank" : "_self"));
            XmlHelper.AddNode(doc, root, "ImageUrl", (currentNode != null ? currentNode.PrimaryImage : string.Empty));
            XmlHelper.AddNode(doc, root, "SecondImageUrl", (currentNode != null ? currentNode.SecondImage : string.Empty));

            if (ModuleConfiguration.ResourceFileDef.Length > 0 && ModuleConfiguration.ResourceKeyDef.Length > 0)
            {
                List <string> lstResourceKeys = ModuleConfiguration.ResourceKeyDef.SplitOnCharAndTrim(';');

                foreach (string item in lstResourceKeys)
                {
                    XmlHelper.AddNode(doc, root, item, ResourceHelper.GetResourceString(ModuleConfiguration.ResourceFileDef, item));
                }
            }

            SiteMapNodeCollection allNodes = null;

            if (config.IsSubZone)
            {
                allNodes = startingNode.ChildNodes;
            }
            else
            {
                allNodes = startingNode.GetAllNodes();
            }

            foreach (SiteMapNode childNode in allNodes)
            {
                gbSiteMapNode gbNode = childNode as gbSiteMapNode;
                if (gbNode == null)
                {
                    continue;
                }

                RenderNode(doc, root, gbNode);
            }

            XmlHelper.XMLTransform(xmlTransformer, SiteUtils.GetXsltBasePath("product", ModuleConfiguration.XsltFileName), doc);
        }
Exemple #2
0
        //http://msdn.microsoft.com/en-us/library/system.web.sitemapnodecollection.aspx

        //http://stackoverflow.com/questions/1960364/asp-net-enumerate-through-sitemapnode-childnodes

        //foreach (var childNode in node.ChildNodes.OrderBy(x => x.Key))

        //public static IEnumerable<SiteMapNode> OrderBy(this SiteMapNodeCollection smnc, Func<SiteMapNode, TKey> expression)
        //{
        //    return smnc.Cast<SiteMapNode>().OrderBy(expression);
        //}

        //http://stackoverflow.com/questions/703130/linq-query-loses-order

        public static SiteMapNode FindNodeAllowedForParentPage(SiteMapNode rootNode, string pageName)
        {
            //SiteMapNode node = rootNode.GetAllNodes().Cast().FirstOrDefault(n => n.Key.Equals(pagekey));
            //return node != null ? node.Url : String.Empty;

            SiteMapNode foundNode = (
                from SiteMapNode cr in rootNode.GetAllNodes()
                where cr.Title.StartsWith(pageName)
                orderby cr.Title
                select cr
                ).First();

            mojoSiteMapNode mojoNode = foundNode as mojoSiteMapNode;

            if (mojoNode != null)
            {
                if ((WebUser.IsInRoles(mojoNode.CreateChildPageRoles)) || (WebUser.IsInRoles(mojoNode.CreateChildDraftPageRoles)))
                {
                    return(foundNode);
                }
            }


            return(null);
        }
Exemple #3
0
        public static string GetRangeZoneIdsToSemiColonSeparatedString(int siteId, int parentZoneId)
        {
            SiteMapDataSource siteMapDataSource = new SiteMapDataSource();

            siteMapDataSource.SiteMapProvider = "canhcamsite" + siteId.ToInvariantString();

            SiteMapNode rootNode     = siteMapDataSource.Provider.RootNode;
            SiteMapNode startingNode = null;

            if (rootNode == null)
            {
                return(null);
            }

            string listChildZoneIds = parentZoneId + ";";

            if (parentZoneId > -1)
            {
                SiteMapNodeCollection allNodes = rootNode.GetAllNodes();
                foreach (SiteMapNode childNode in allNodes)
                {
                    gbSiteMapNode gbNode = childNode as gbSiteMapNode;
                    if (gbNode == null)
                    {
                        continue;
                    }

                    if (Convert.ToInt32(gbNode.Key) == parentZoneId)
                    {
                        startingNode = gbNode;
                        break;
                    }
                }
            }
            else
            {
                startingNode = rootNode;
            }

            if (startingNode == null)
            {
                return(string.Empty);
            }

            SiteMapNodeCollection childNodes = startingNode.GetAllNodes();

            foreach (gbSiteMapNode childNode in childNodes)
            {
                listChildZoneIds += childNode.Key + ";";
            }

            return(listChildZoneIds);
        }
        /// <summary>
        /// Adds the child nodes to the <see cref="Nodes"/> collection.
        /// </summary>
        /// <param name="startNode">
        /// The start node.
        /// </param>
        /// <param name="addParentNode">
        /// if set to <c>true</c> adds parent node.
        /// </param>
        protected void AddChildNodes(SiteMapNode startNode, bool addParentNode)
        {
            this.viewModelNodeIds.Add(startNode.Key);
            foreach (SiteMapNode node in startNode.GetAllNodes())
            {
                var pageNode = node as PageSiteNode;
                if (pageNode != null && pageNode.NodeType == NodeType.Group)
                {
                    this.viewModelNodeIds.Add(pageNode.Key);
                }
            }

            if (this.LevelsToInclude != 0 && startNode != null)
            {
                if (addParentNode && this.CheckSiteMapNode(startNode) && startNode.Key != this.RootNodeId.ToString().ToUpperInvariant())
                {
                    var nodeViewModel = this.CreateNodeViewModelRecursive(startNode, this.LevelsToInclude);

                    if (nodeViewModel != null)
                    {
                        this.Nodes.Add(nodeViewModel);
                    }
                }
                else
                {
                    var directChildren = startNode.ChildNodes;

                    foreach (SiteMapNode childNode in directChildren)
                    {
                        var nodeViewModel = this.CreateNodeViewModelRecursive(childNode, this.LevelsToInclude);

                        if (nodeViewModel != null)
                        {
                            this.Nodes.Add(nodeViewModel);
                        }
                    }
                }
            }
        }
Exemple #5
0
        public static XmlDocument BuildNewsDataXml(XmlDocument doc, XmlElement newsXml, News news, TimeZoneInfo timeZone,
                                                   double timeOffset, string editLink, int siteId = 1)
        {
            XmlHelper.AddNode(doc, newsXml, "Title", news.Title);
            XmlHelper.AddNode(doc, newsXml, "SubTitle", news.SubTitle);
            XmlHelper.AddNode(doc, newsXml, "Url", NewsHelper.FormatNewsUrl(news.Url, news.NewsID, news.ZoneID));
            XmlHelper.AddNode(doc, newsXml, "Target", NewsHelper.GetNewsTarget(news.OpenInNewWindow));
            XmlHelper.AddNode(doc, newsXml, "ShowOption", news.ShowOption.ToString());
            XmlHelper.AddNode(doc, newsXml, "ZoneId", news.ZoneID.ToInvariantString());

            SiteMapDataSource siteMapDataSource = new SiteMapDataSource();

            siteMapDataSource.SiteMapProvider = "canhcamsite" + siteId.ToInvariantString();

            SiteMapNode rootNode     = siteMapDataSource.Provider.RootNode;
            SiteMapNode startingNode = null;

            if (rootNode == null)
            {
                return(null);
            }

            if (news.ZoneID > -1)
            {
                SiteMapNodeCollection allNodes = rootNode.GetAllNodes();
                foreach (SiteMapNode childNode in allNodes)
                {
                    gbSiteMapNode gbNode = childNode as gbSiteMapNode;
                    if (gbNode == null)
                    {
                        continue;
                    }

                    if (Convert.ToInt32(gbNode.Key) == news.ZoneID)
                    {
                        startingNode = gbNode;
                        XmlHelper.AddNode(doc, newsXml, "ZoneDescription", gbNode.Description);
                        XmlHelper.AddNode(doc, newsXml, "ZoneTitle", gbNode.Title);
                        break;
                    }
                }
            }

            string imageFolderPath          = NewsHelper.MediaFolderPath(news.SiteId, news.NewsID);
            string thumbnailImageFolderPath = imageFolderPath + "thumbs/";

            if (news.ImageFile.Length > 0)
            {
                XmlHelper.AddNode(doc, newsXml, "ImageUrl", VirtualPathUtility.ToAbsolute(imageFolderPath + news.ImageFile));
            }
            if (news.ThumbnailFile.Length > 0)
            {
                XmlHelper.AddNode(doc, newsXml, "ThumbnailUrl",
                                  VirtualPathUtility.ToAbsolute(thumbnailImageFolderPath + news.ThumbnailFile));
            }

            XmlHelper.AddNode(doc, newsXml, "EditLink", editLink);

            XmlHelper.AddNode(doc, newsXml, "BriefContent", news.BriefContent);
            XmlHelper.AddNode(doc, newsXml, "FullContent", news.FullContent);
            XmlHelper.AddNode(doc, newsXml, "ViewCount", news.Viewed.ToString());
            XmlHelper.AddNode(doc, newsXml, "CommentCount", news.CommentCount.ToString());
            XmlHelper.AddNode(doc, newsXml, "FileUrl", news.FileAttachment);

            object startDate = news.StartDate;

            XmlHelper.AddNode(doc, newsXml, "CreatedDate", FormatDate(startDate, timeZone, timeOffset,
                                                                      ResourceHelper.GetResourceString("NewsResources", "NewsDateFormat")));
            XmlHelper.AddNode(doc, newsXml, "CreatedTime", FormatDate(startDate, timeZone, timeOffset,
                                                                      ResourceHelper.GetResourceString("NewsResources", "NewsTimeFormat")));
            XmlHelper.AddNode(doc, newsXml, "CreatedDD", FormatDate(startDate, timeZone, timeOffset, "dd"));
            XmlHelper.AddNode(doc, newsXml, "CreatedYY", FormatDate(startDate, timeZone, timeOffset, "yy"));
            XmlHelper.AddNode(doc, newsXml, "CreatedYYYY", FormatDate(startDate, timeZone, timeOffset, "yyyy"));
            XmlHelper.AddNode(doc, newsXml, "CreatedMM", FormatDate(startDate, timeZone, timeOffset, "MM"));
            if (System.Globalization.CultureInfo.CurrentCulture.Name.ToLower() == "vi-vn")
            {
                string monthVI = "Tháng " + FormatDate(startDate, timeZone, timeOffset, "MM");
                XmlHelper.AddNode(doc, newsXml, "CreatedMMM", monthVI);
                XmlHelper.AddNode(doc, newsXml, "CreatedMMMM", monthVI);
            }
            else
            {
                XmlHelper.AddNode(doc, newsXml, "CreatedMMM", FormatDate(startDate, timeZone, timeOffset, "MMM"));
                XmlHelper.AddNode(doc, newsXml, "CreatedMMMM", FormatDate(startDate, timeZone, timeOffset, "MMMM"));
            }
            if (news.EndDate != null && news.EndDate != DateTime.MaxValue)
            {
                XmlHelper.AddNode(doc, newsXml, "EndDate", FormatDate(news.EndDate, timeZone, timeOffset,
                                                                      ResourceHelper.GetResourceString("NewsResources", "NewsDateFormat")));
            }

            return(doc);
        }