Beispiel #1
0
 private void ApplyNodeManipulator()
 {
     RootNode =
         new WebSiteNode(
             ((INodeManipulator)Activator.CreateInstance(BuildManager.GetType(menuSettings.NodeManipulator, true, true))).
             ManipulateNodes(RootNode.Children));
 }
Beispiel #2
0
 private WebSiteNodeCollection GetNodes(WebSiteNode node)
 {
     if (this.ShowStartingNode)
     {
         return(new WebSiteNodeCollection(node));
     }
     return(node.ChildNodes);
 }
 internal void ResetProvider()
 {
     nodes    = null;
     rootWeb  = null;
     siteMap  = null;
     rootNode = null;
     InitiateProvider();
 }
        public WebSiteNode GetParentNode(WebSiteNode node)
        {
            if (nodes.Count == 0)
            {
                //PopulateSiteMap();
            }

            return(nodes[node].Parent);
        }
 public WebSiteNode this[WebSiteNode Value]
 {
     get
     {
         return(this.InnerList.Find(item => item == Value));
     }
     set
     {
         this[Value.Id] = Value;
     }
 }
        protected void AddNode(WebSiteNode node, WebSiteNode parentNode)
        {
            if (nodes.Count == 0)
            {
                //PopulateSiteMap();
            }

            if (parentNode == null)
            {
                nodes.Add(node);
            }
            else
            {
                nodes[parentNode].Children.Add(node);
            }
        }
Beispiel #7
0
        public WebSiteNode Clone(bool blnDeep)
        {
            WebSiteNode cnode = (WebSiteNode)this.MemberwiseClone();

            if (this.ExtendedAttributes != null)
            {
                cnode.ExtendedAttributes = (SortedList)this.ExtendedAttributes.Clone();
            }
            if (this.XmlDoc != null)
            {
                cnode.XmlDoc = (XmlDocument)this.XmlDoc.Clone();
            }
            return(cnode);

            //return new WebSiteNode(this);
        }
        public WebSiteNodeCollection GetChildNodes(WebSiteNode node)
        {
            WebSiteNodeCollection collection = new WebSiteNodeCollection();

            if (node != null)
            {
                List <WebSiteNode> Children = nodes[node].Children;

                foreach (WebSiteNode childNode in Children)
                {
                    collection.Add(childNode);
                }
            }

            return(collection);
        }
Beispiel #9
0
        public object Clone()
        {
            WebSiteNode cnode = (WebSiteNode)this.MemberwiseClone();

            if (this.ExtendedAttributes != null)
            {
                cnode.ExtendedAttributes = (SortedList)this.ExtendedAttributes.Clone();
            }
            if (this.XmlDoc != null)
            {
                cnode.XmlDoc = (XmlDocument)this.XmlDoc.Clone();
            }
            return(cnode);

            //return this.Clone(true);
        }
Beispiel #10
0
        private void RemoveSelectedNodes(ref WebSiteNode root)
        {
            List <WebSiteNode> selected = root.Children.Where(n => n.Selected == true).ToList <WebSiteNode>();

            foreach (WebSiteNode item in selected)
            {
                root.FindById(item.Id).Selected = false;

                /*
                 * if (item.HasChildren())
                 * {
                 *  RemoveSelectedNodes(ref item);
                 * }
                 */
            }
        }
        public override SiteMapNodeCollection GetChildNodes(SiteMapNode node)
        {
            //SPListItem item = siteMap.Items[new Guid(node.Key)];
            WebSiteNode websitenode = (WebSiteNode)nodes[node.Key];

            if (websitenode != null && websitenode.HasChildren())
            {
                SiteMapNodeCollection childeren = new SiteMapNodeCollection();
                foreach (WebSiteNode childNode in websitenode.Children)
                {
                    childeren.Add(new SiteMapNode(this, childNode.Key, childNode.Url, childNode.Title, childNode.Description));
                }
                return(childeren);
            }
            else
            {
                return(null);
            }
        }
        protected WebSiteNode GetWebSiteRootNodeCore()
        {
            WebSiteNode rootNode = new WebSiteNode();

            if (nodes.Count == 0)
            {
                //PopulateSiteMap();
            }

            foreach (WebSiteNode node in nodes)
            {
                if (node.Parent == null)
                {
                    rootNode = node;
                    break;
                }
            }
            return(rootNode);
        }
        private void FindChildNodes(WebSiteNode node)
        {
            InitiateProvider();

            try
            {
                SPQuery query = new SPQuery();
                query.Query      = "<Where><Eq><FieldRef Name=\"Parent\" /><Value Type=\"Lookup\">" + node.Title + "</Value></Eq></Where>";
                query.ViewFields = "<FieldRef Name=\"Title\" /><FieldRef Name=\"Description\" /><FieldRef Name=\"URL\" /><FieldRef Name=\"Enabled\" /><FieldRef Name=\"Selected\" /><FieldRef Name=\"Breadcrumb\" /><FieldRef Name=\"Separator\" /><FieldRef Name=\"Icon\" /><FieldRef Name=\"LargeImage\" /><FieldRef Name=\"Parent\" /><FieldRef Name=\"ID\" />";
                SPListItemCollection childeren = siteMap.GetItems(query);
                //DataTable childerenDT = ConvertToTable(childeren);

                if (childeren.Count >= 1)
                {
                    foreach (SPListItem item in childeren)
                    {
                        string xmlData = ConvertZRowToRegularXml(item.Xml);

                        using (System.IO.StringReader sr = new System.IO.StringReader(xmlData))
                        {
                            XmlReader reader = XmlReader.Create(sr);
                            node.ReadXml(reader);
                            //nodes[node].Children.Add(wsnode);
                        }
                    }

                    if (node.HasChildren())
                    {
                        foreach (WebSiteNode cnode in node.Children)
                        {
                            FindChildNodes(cnode);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ex.ToString();
                //throw;
            }
        }
Beispiel #14
0
        internal WebSiteNodeCollection GetPathNodeCollection(string viewPath)
        {
            WebSiteNodeCollection childNodes = null;

            if (string.IsNullOrEmpty(viewPath))
            {
                childNodes = this.GetNodes();
            }
            else
            {
                WebSiteNode node = this.Provider.FindSiteMapNodeFromKey(viewPath);
                if (node != null)
                {
                    childNodes = node.ChildNodes;
                }
            }
            if (childNodes == null)
            {
                childNodes = WebSiteNodeCollection.Empty;
            }
            return(childNodes);
        }
Beispiel #15
0
        private HierarchicalDataSourceView GetTreeView(string viewPath)
        {
            WebSiteNode node = null;

            if (string.IsNullOrEmpty(viewPath))
            {
                WebSiteNodeCollection nodes = this.GetNodes();
                if (nodes != null)
                {
                    return(nodes.GetHierarchicalDataSourceView());
                }
            }
            else
            {
                node = this.Provider.FindSiteMapNodeFromKey(viewPath);
                if (node != null)
                {
                    return(node.ChildNodes.GetHierarchicalDataSourceView());
                }
            }
            return(WebSiteNodeCollection.Empty.GetHierarchicalDataSourceView());
        }
 public void HintAncestorNodes(WebSiteNode node, int upLevel)
 {
     this.HintAncestorNodes(node, upLevel);
 }
 public void Insert(int index, WebSiteNode value)
 {
     this.InnerList.Insert(index, value);
 }
Beispiel #18
0
 public WebSiteNode(WebSiteNode node)
 {
     this.node = node;
 }
Beispiel #19
0
        private WebSiteNodeCollection GetNodes()
        {
            WebSiteNode currentNode        = null;
            int         startingNodeOffset = this.StartingNodeOffset;

            if (!string.IsNullOrEmpty(this.StartingNodeUrl) && this.StartFromCurrentNode)
            {
                //throw new InvalidOperationException(SR.GetString("SiteMapDataSource_StartingNodeUrlAndStartFromcurrentNode_Defined"));
            }
            if (this.StartFromCurrentNode)
            {
                currentNode = this.Provider.CurrentNode;
            }
            else if (!string.IsNullOrEmpty(this.StartingNodeUrl))
            {
                currentNode = this.Provider.FindWebSiteNode(this.MakeUrlAbsolute(this.StartingNodeUrl));
                if (currentNode == null)
                {
                    //throw new ArgumentException(SR.GetString("SiteMapPath_CannotFindUrl", new object[] { this.StartingNodeUrl }));
                }
            }
            else
            {
                currentNode = this.Provider.RootNode;
            }
            if (currentNode == null)
            {
                return(null);
            }
            if (startingNodeOffset <= 0)
            {
                if (startingNodeOffset != 0)
                {
                    this.Provider.HintNeighborhoodNodes(currentNode, Math.Abs(startingNodeOffset), 0);
                    WebSiteNode parentNode = currentNode.ParentNode;
                    while ((startingNodeOffset < 0) && (parentNode != null))
                    {
                        currentNode = currentNode.ParentNode;
                        parentNode  = currentNode.ParentNode;
                        startingNodeOffset++;
                    }
                }
                return(this.GetNodes(currentNode));
            }
            WebSiteNode currentNodeAndHintAncestorNodes = this.Provider.GetCurrentNodeAndHintAncestorNodes(-1);

            if (((currentNodeAndHintAncestorNodes == null) || !currentNodeAndHintAncestorNodes.IsDescendantOf(currentNode)) || currentNodeAndHintAncestorNodes.Equals(currentNode))
            {
                return(null);
            }
            WebSiteNode node4 = currentNodeAndHintAncestorNodes;

            for (int i = 0; i < startingNodeOffset; i++)
            {
                node4 = node4.ParentNode;
                if ((node4 == null) || node4.Equals(currentNode))
                {
                    return(this.GetNodes(currentNodeAndHintAncestorNodes));
                }
            }
            WebSiteNode node5 = currentNodeAndHintAncestorNodes;

            while ((node4 != null) && !node4.Equals(currentNode))
            {
                node5 = node5.ParentNode;
                node4 = node4.ParentNode;
            }
            return(this.GetNodes(node5));
        }
 protected void RemoveNode(WebSiteNode node)
 {
     this.RemoveNode(node);
 }
 public int Add(WebSiteNode node)
 {
     this.InnerList.Add(node);
     return(this.InnerList.FindIndex(item => item == node));
 }
 public void HintNeighborhoodNodes(WebSiteNode node, int upLevel, int downLevel)
 {
     this.HintNeighborhoodNodes(node, upLevel, downLevel);
 }
 public bool IsAccessibleToUser(HttpContext context, WebSiteNode node)
 {
     return(this.IsAccessibleToUser(context, node));
 }
 public int IndexOf(WebSiteNode value)
 {
     return(this.InnerList.IndexOf(value));
 }
 public WebSiteNode GetParentNodeRelativeToNodeAndHintDownFromParent(WebSiteNode node, int walkupLevels, int relativeDepthFromWalkup)
 {
     return(this.GetParentNodeRelativeToNodeAndHintDownFromParent(node, walkupLevels, relativeDepthFromWalkup));
 }
 public bool Contains(WebSiteNode value)
 {
     return(this.InnerList.Contains(value));
 }
Beispiel #27
0
        public void ReadXml(XmlReader reader)
        {
            try
            {
                var empty = reader.IsEmptyElement;

                if (reader.Name == "row")
                {
                    XmlReader valueReader = reader.ReadSubtree();
                    while (valueReader.Read())
                    {
                        XmlNodeType nType  = valueReader.NodeType;
                        string      nName  = valueReader.Name;
                        string      nValue = valueReader.Value;
                        Type        type   = valueReader.ValueType;

                        switch (valueReader.NodeType)
                        {
                        case XmlNodeType.Element:
                        {
                            switch (valueReader.Name.ToLowerInvariant())
                            {
                            case "id":
                                valueReader.Read();
                                Id = int.Parse(reader.Value);
                                //Id = reader.ReadElementContentAsInt();
                                break;

                            case "uniqueid":
                                valueReader.Read();
                                Key = reader.Value;
                                //Key = reader.ReadElementContentAsString().Trim();
                                break;

                            case "description":
                                valueReader.Read();
                                Description = reader.Value;
                                break;

                            case "title":
                                valueReader.Read();
                                Title = reader.Value;
                                //Title = reader.ReadElementContentAsString().Trim();//valueReader.Value;
                                break;

                            case "url":
                                valueReader.Read();
                                string[] _url = reader.Value.Split(new char[1] {
                                        ','
                                    });
                                Url         = _url[0];
                                Description = _url[1];
                                //Url = reader.ReadElementContentAsString().Trim();
                                break;

                            /*
                             * case "parent":
                             *  Parent = reader.ReadElementContentAsString().Trim();
                             *  break;
                             */
                            case "enabled":
                                //valueReader.ReadElementContentAsBoolean();
                                valueReader.Read();
                                bool boolenabled = false;
                                if (bool.TryParse(reader.Value, out boolenabled))
                                {
                                    Enabled = boolenabled;            // bool.Parse(reader.Value);
                                }
                                if (reader.Value == "1")
                                {
                                    boolenabled = true;
                                }
                                Enabled = boolenabled;
                                break;

                            case "selected":
                                valueReader.Read();
                                Selected = bool.Parse(reader.Value);
                                break;

                            case "breadcrumb":
                                valueReader.Read();
                                Breadcrumb = bool.Parse(reader.Value);
                                break;

                            case "separator":
                                valueReader.Read();
                                Separator = bool.Parse(reader.Value);
                                break;

                            case "icon":
                                valueReader.Read();
                                Icon = reader.Value;
                                break;

                            case "largeimage":
                                valueReader.Read();
                                LargeImage = reader.Value;
                                break;

                            case "commandname":
                                valueReader.Read();
                                CommandName = reader.Value;
                                break;

                            case "commandargument":
                                valueReader.Read();
                                CommandArgument = reader.Value;
                                break;

                            case "row":
                                break;

                                /*
                                 * default:
                                 *  string _name = valueReader.Name;
                                 *  valueReader.Read();
                                 *  string _value = valueReader.Value;
                                 *  if (ExtendedAttributes == null)
                                 *  {
                                 *      ExtendedAttributes = new SortedList();
                                 *  }
                                 *
                                 *  ExtendedAttributes.Add(_name,_value);
                                 *  break;
                                 */
                            }
                            break;
                        }
                        }
                    }
                }

                /*
                 * if (empty)
                 * {
                 *  return;
                 * }
                 */

                while (reader.Read())
                {
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:
                        switch (reader.Name.ToLowerInvariant())
                        {
                        case "rows":
                            ReadXml(reader);
                            break;

                        case "row":
                            WebSiteNode child = new WebSiteNode {
                                Parent = this
                            };
                            child.ReadXml(reader);
                            Children.Add(child);
                            break;

                        /*
                         * case "keywords":
                         *     Keywords = reader.ReadElementContentAsString().Trim();
                         *     break;
                         * case "description":
                         *     Description = reader.ReadElementContentAsString().Trim();
                         *     break;
                         */
                        default:
                            throw new XmlException(String.Format("Unexpected element '{0}'", reader.Name));
                        }
                        break;

                    case XmlNodeType.EndElement:
                        reader.ReadEndElement();
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                ex.ToString();
                throw;
            }
        }
 protected void AddNode(WebSiteNode node)
 {
     this.AddNode(node, null);
 }
Beispiel #29
0
 internal bool IsDescendantOf(WebSiteNode currentNode)
 {
     throw new NotImplementedException();
 }
        private void InitiateProvider()
        {
            if (nodes == null)
            {
                nodes = new WebSiteNodeCollection();
            }

            if (rootWeb != null)
            {
                string url = rootWeb.Url;
            }
            SPWeb  currentWeb = SPContext.Current.Site.RootWeb;
            string curl       = currentWeb.Url;

            if (rootWeb == null || rootWeb != currentWeb)
            {
                SPSite site = SPContext.Current.Site;
                site.CatchAccessDeniedException = false;
                rootWeb  = site.RootWeb;
                rootNode = null;
                //if (siteMap == null)
                //{

                siteMap = rootWeb.Lists.TryGetList("SiteMap");

                if (rootNode == null && siteMap != null)
                {
                    SPListItemCollection rootNodes = null;

                    try
                    {
                        SPQuery query = new SPQuery();
                        query.Query = "<Where><Eq><FieldRef Name=\"Parent\" /><Value Type=\"Lookup\">Root</Value></Eq></Where><OrderBy><FieldRef Name=\"Position\" Ascending=\"True\" /></OrderBy>";
                        //query.Query = "<Where><IsNull><FieldRef Name=\"Parent\"/></IsNull></Where>";
                        query.ViewFields = "<FieldRef Name=\"Title\" /><FieldRef Name=\"Description\" /><FieldRef Name=\"URL\" /><FieldRef Name=\"Enabled\" /><FieldRef Name=\"Selected\" /><FieldRef Name=\"Breadcrumb\" /><FieldRef Name=\"Separator\" /><FieldRef Name=\"Icon\" /><FieldRef Name=\"LargeImage\" /><FieldRef Name=\"Parent\" /><FieldRef Name=\"Position\" /><FieldRef Name=\"ID\" />";
                        rootNodes        = siteMap.GetItems(query);
                    }
                    catch (Exception ex)
                    {
                        ex.ToString();
                    }

                    /*
                     * try
                     * {
                     *  string url = rootWeb.RootFolder.WelcomePage;
                     * }
                     * catch (Exception)
                     * {
                     *  HttpApplication application = HttpContext.Current.ApplicationInstance;
                     *  application.Server.ClearError();
                     *  application.Response.StatusCode = (int)HttpStatusCode.Forbidden;
                     *  throw (new HttpException((int)HttpStatusCode.Forbidden, ""));
                     * }
                     */

                    if (rootNodes != null)
                    {
                        rootNode = new WebSiteNode();
                        //nodes.Add(rootNode);
                        try
                        {
                            foreach (SPListItem item in rootNodes)
                            {
                                string xmlData = ConvertZRowToRegularXml(item.Xml);

                                using (System.IO.StringReader sr = new System.IO.StringReader(xmlData))
                                {
                                    XmlReader reader = XmlReader.Create(sr);
                                    rootNode.ReadXml(reader);
                                }
                            }

                            if (rootNode.HasChildren())
                            {
                                //bool isSet = false;
                                foreach (WebSiteNode cnode in rootNode.Children)
                                {
                                    try
                                    {
                                        nodes.Add(cnode);
                                        //int i = nodes.Add(cnode);
                                        //if (!isSet)
                                        //{
                                        //    rootNode = (WebSiteNode)nodes[i];
                                        //    isSet = true;
                                        //}
                                        FindChildNodes(cnode);
                                    }
                                    catch (Exception ex)
                                    {
                                        ex.ToString();
                                        //throw;
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            ex.ToString();
                        }
                    }
                    //}
                }
            }
        }