Пример #1
0
        public SiteMapNode(ProjectionInfo projection)
        {
            using (LogGroup logGroup = LogGroup.StartDebug("Constructing SiteMapNode from the provided projection."))
            {
                Category       = projection.MenuCategory;
                Title          = projection.MenuTitle;
                Action         = projection.Action;
                TypeName       = projection.TypeName;
                ProjectionName = projection.Name;

                LogWriter.Debug("Category: " + Category);
                LogWriter.Debug("Title: " + Title);
                LogWriter.Debug("Action: " + Action);
                LogWriter.Debug("Type name: " + TypeName);
                LogWriter.Debug("Projection name: " + ProjectionName);

                if (Action != String.Empty && TypeName != String.Empty)
                {
                    Url = new UrlCreator().CreateUrl(Action, TypeName);
                }
                else
                {
                    Url = new UrlCreator().CreateUrl(ProjectionName);
                }
            }
        }
Пример #2
0
        public SiteMapNode(ProjectionInfo projection)
        {
            using (LogGroup logGroup = LogGroup.StartDebug("Constructing SiteMapNode from the provided projection."))
            {

                Category = projection.MenuCategory;
                Title = projection.MenuTitle;
                Action = projection.Action;
                TypeName = projection.TypeName;
                ProjectionName = projection.Name;

                LogWriter.Debug("Category: " + Category);
                LogWriter.Debug("Title: " + Title);
                LogWriter.Debug("Action: " + Action);
                LogWriter.Debug("Type name: " + TypeName);
                LogWriter.Debug("Projection name: " + ProjectionName);

                if (Action != String.Empty && TypeName != String.Empty)
                    Url = new UrlCreator().CreateUrl(Action, TypeName);
                else
                    Url = new UrlCreator().CreateUrl(ProjectionName);
            }
        }
Пример #3
0
        /// <summary>
        /// Removes the provided item from the site map.
        /// </summary>
        /// <param name="item">The item to remove from the site map.</param>
        public void Remove(ISiteMapNode item)
        {
            using (LogGroup logGroup = LogGroup.Start("Removing item from site map.", NLog.LogLevel.Debug))
            {
                if (item == null)
                {
                    throw new ArgumentNullException("item");
                }

                if (UrlCreator == null)
                {
                    throw new InvalidOperationException("The UrlCreator property has not been initialized.");
                }

                LogWriter.Debug("Item title: " + item.Title);
                LogWriter.Debug("Item URL: " + item.Url);
                LogWriter.Debug("Item category: " + item.Category);
                LogWriter.Debug("Item action: " + item.Action);
                LogWriter.Debug("Item type name: " + item.TypeName);

                string url = item.Url;

                if (url == String.Empty)
                {
                    if (item.Action != String.Empty && item.TypeName != String.Empty)
                    {
                        url = UrlCreator.CreateUrl(item.Action, item.TypeName);
                    }
                    else
                    {
                        url = UrlCreator.CreateUrl(item.ProjectionName);
                    }
                }

                LogWriter.Debug("URL: " + url);

                SiteMapNode existingNode = GetNodeByUrl(ChildNodes, url);

                if (existingNode != null)
                {
                    if (item.Category != null && item.Category != String.Empty)
                    {
                        SiteMapNode categoryNode = GetNodeByTitle(ChildNodes, item.Category);

                        if (categoryNode == null)
                        {
                            throw new Exception("No node found with title '" + item.Category + "'.");
                        }

                        categoryNode.ChildNodes.Remove(existingNode);

                        // If no nodes are left in the category then remove it
                        if (categoryNode.ChildNodes.Count == 0)
                        {
                            ChildNodes.Remove(categoryNode);
                        }

                        LogWriter.Debug("Removed node from category.");
                    }
                    else
                    {
                        LogWriter.Debug("Removed node from root.");

                        ChildNodes.Remove(existingNode);
                    }
                }
                else
                {
                    LogWriter.Debug("Node not found. Skipping remove.");

                    throw new Exception("No existing node found with URL '" + url + "'.");
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Adds the provided item to the site map.
        /// </summary>
        /// <param name="item">The item to add to the site map.</param>
        public void Add(ISiteMapNode item)
        {
            using (LogGroup logGroup = LogGroup.Start("Adding item to site map.", NLog.LogLevel.Debug))
            {
                if (item == null)
                {
                    throw new ArgumentNullException("item");
                }

                if (UrlCreator == null)
                {
                    throw new InvalidOperationException("The UrlCreator property has not been initialized.");
                }

                LogWriter.Debug("Item title: " + item.Title);
                LogWriter.Debug("Item URL: " + item.Url);
                LogWriter.Debug("Item category: " + item.Category);
                LogWriter.Debug("Item action: " + item.Action);
                LogWriter.Debug("Item type name: " + item.TypeName);

                if (item.Title == null || item.Title == String.Empty)
                {
                    throw new ArgumentException("A title must be specified on the provided site map item. URL: '" + item.Url + "', Action: '" + item.Action + "', TypeName: '" + item.TypeName + "', Category: '" + item.Category + "'");
                }

                SiteMapNode node = new SiteMapNode();

                node.Title = item.Title;
                node.Url   = item.Url;

                if (node.Url == String.Empty)
                {
                    if (item.Action != String.Empty && item.TypeName != String.Empty)
                    {
                        node.Url = UrlCreator.CreateUrl(item.Action, item.TypeName);
                    }
                    else
                    {
                        node.Url = UrlCreator.CreateUrl(item.ProjectionName);
                    }
                }

                string url = node.Url;

                LogWriter.Debug("URL: " + node.Url);

                SiteMapNode existingNode = GetNodeByUrl(ChildNodes, node.Url);

                if (existingNode == null)
                {
                    LogWriter.Debug("Node title: " + node.Title);
                    LogWriter.Debug("Node URL:" + node.Url);

                    if (item.Category != null && item.Category != String.Empty)
                    {
                        SiteMapNode categoryNode = GetNodeByTitle(ChildNodes, item.Category);

                        if (categoryNode == null)
                        {
                            categoryNode = CreateCategoryNode(item.Category);
                        }

                        categoryNode.SelectAction = TreeNodeSelectAction.None;
                        categoryNode.ChildNodes.Add(node);

                        LogWriter.Debug("Added node to category.");
                    }
                    else
                    {
                        LogWriter.Debug("Added node to root.");
                        ChildNodes.Add(node);
                    }
                }
                else
                {
                    LogWriter.Debug("Node exists. Skipping add.");
                }
            }
        }