Ejemplo n.º 1
0
        /// <summary>
        /// Инициализирует SiteMap и добавляет его в коллекцию карт сайта
        /// </summary>
        /// <param name="siteMapPath">Путь до карты сайта(меню)</param>
        /// <param name="needSortMenuItems">Нужно ли отсортировать элементы меню</param>
        public static void ConfigureSiteMap(string siteMapPath, bool needSortMenuItems = true)
        {
            var map = new XmlSiteMap();

            map.LoadFrom(siteMapPath);
            ConfigureSiteMap(map, needSortMenuItems);
        }
Ejemplo n.º 2
0
        public IHttpActionResult Get()
        {
            try
            {
                //Build the sitemap
                XmlSiteMap sitemap = new XmlSiteMap();

                foreach (ContentPageModelBase page in Find.Query <ContentPageModelBase>().Where(x => x.State == ContentState.Published).AsEnumerable().Where(x => !x.NoIndex))
                {
                    sitemap.Add(page.Url.ToAbsoluteUrl(Request.RequestUri), ChangeFrequency.Weekly, page.Published.Value);
                }

                HttpResponseMessage response = new HttpResponseMessage
                {
                    Content = new StringContent(sitemap.ToString())
                };
                response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/xml");

                return(ResponseMessage(response));
            }
            catch (Exception exc) when(Log.WriteError(exc))
            {
                throw;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 接口初始化
        /// </summary>
        public void Install()
        {
            var xmlSiteMap = new XmlSiteMap();

            xmlSiteMap.LoadFrom(Path.Combine(_environment.ContentRootPath, "sitemap.xml"));
            List <Entities.sys_category> sysApis = new List <Entities.sys_category>();

            xmlSiteMap.SiteMapNodes.ForEach(item =>
            {
                sysApis.Add(new Entities.sys_category()
                {
                    id             = CombGuid.NewGuidAsString(),
                    name           = item.Name,
                    route_template = item.RouteTemplate ?? "",
                    code           = item.Code,
                    father_code    = item.FatherCode,
                    uid            = item.UID,
                    target         = item.Target ?? "",
                    is_menu        = item.IsMenu == "1" ? true : false,
                    sort           = item.Sort,
                    action         = item.Action ?? "",
                    controller     = item.Controller ?? "",
                    icon_class     = item.IconClass ?? "",
                    route_name     = item.RouteName ?? ""
                });
            });
            _sysCategoryService.Init(sysApis);
            _settingService.Init();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 接口初始化
        /// </summary>
        public void Install()
        {
            var xmlSiteMap = new XmlSiteMap();

            xmlSiteMap.LoadFrom(Path.Combine(_environment.ContentRootPath, "sitemap.xml"));
            List <Entities.Sys_Category> sysApis = new List <Entities.Sys_Category>();

            xmlSiteMap.SiteMapNodes.ForEach(item =>
            {
                sysApis.Add(new Entities.Sys_Category()
                {
                    Id            = CombGuid.NewGuid(),
                    Name          = item.Name,
                    RouteTemplate = item.RouteTemplate ?? "",
                    Code          = item.Code,
                    FatherCode    = item.FatherCode,
                    UID           = item.UID,
                    Target        = item.Target ?? "",
                    IsMenu        = item.IsMenu ?? "",
                    Sort          = item.Sort,
                    Action        = item.Action ?? "",
                    Controller    = item.Controller ?? "",
                    IconClass     = item.IconClass ?? "",
                    RouteName     = item.RouteName ?? ""
                });
            });
            _sysCategoryService.Init(sysApis);
            _settingService.Init();
        }
Ejemplo n.º 5
0
        private List <Entities.sys_category> GetCategories()
        {
            List <Entities.sys_category> list = new List <Entities.sys_category>();
            var xmlSiteMap = new XmlSiteMap();

            xmlSiteMap.LoadFrom(Path.Combine(_webHostEnvironment.ContentRootPath, "sitemap.xml"));
            xmlSiteMap.SiteMapNodes.ForEach(item =>
            {
                list.Add(new Entities.sys_category()
                {
                    id             = CombGuid.NewGuidAsString(),
                    name           = item.Name,
                    route_template = item.RouteTemplate ?? "",
                    code           = item.Code,
                    father_code    = item.FatherCode,
                    uid            = item.UID,
                    target         = item.Target ?? "",
                    is_menu        = item.IsMenu == "1" ? true : false,
                    sort           = item.Sort,
                    action         = item.Action ?? "",
                    controller     = item.Controller ?? "",
                    icon_class     = item.IconClass ?? "",
                    route_name     = item.RouteName ?? ""
                });
            });
            return(list);
        }
Ejemplo n.º 6
0
        public ActionResult GetSubOfMenu(string siteName)
        {
            var siteMap = new XmlSiteMap();

            if (HttpContext.Cache["SiteMap"] == null)
            {
                siteMap.LoadFrom("~/Mvc.sitemap");
                HttpContext.Cache["SiteMap"] = siteMap;
            }
            else if (HttpContext.Cache["ChangeLanguage"] != null && HttpContext.Cache["ChangeLanguage"].ToString() == bool.TrueString)
            {
                siteMap.LoadFrom("~/Mvc.sitemap");
                HttpContext.Cache["SiteMap"]        = siteMap;
                HttpContext.Cache["ChangeLanguage"] = false;
            }
            else
            {
                siteMap = (HRM.Presentation.UI.Controls.Menu.XmlSiteMap)HttpContext.Cache["SiteMap"];
            }
            var listMenu = siteMap.RootNode.ChildNodes.Where(w => w.ModuleName == siteName).FirstOrDefault();

            if (listMenu == null)
            {
                return(null);
            }
            return(Json(listMenu.ChildNodes));
        }
Ejemplo n.º 7
0
        public XmlSiteMapTests()
        {
            _pathResolver = new Mock<IPathResolver>();
            _fileSystem = new Mock<IFileSystem>();
            _cacheManager = new Mock<ICacheManager>();

            _siteMap = new XmlSiteMap(_pathResolver.Object, _fileSystem.Object, _cacheManager.Object);
        }
Ejemplo n.º 8
0
        public XmlSiteMapTests()
        {
            pathResolver = new Mock<IPathResolver>();
            fileSystem = new Mock<IVirtualPathProvider>();
            cacheProvider = new Mock<ICacheProvider>();

            _siteMap = new XmlSiteMap(pathResolver.Object, fileSystem.Object, cacheProvider.Object);
        }
Ejemplo n.º 9
0
        public void Should_be_able_to_set_site_map()
        {
            SiteMapBase siteMap = new XmlSiteMap();

            _sitemaps["foo"] = siteMap;

            Assert.Same(siteMap, _sitemaps["foo"]);
        }
Ejemplo n.º 10
0
            _siteMap = new XmlSiteMap(pathResolver.Object, fileSystem.Object, cacheProvider.Object);
        }

        [Fact]
        public void Default_constructor_should_not_throw_exception()
        {
            Assert.DoesNotThrow(() => new XmlSiteMap());
Ejemplo n.º 11
0
        public void Should_be_able_to_set_default_site_map()
        {
            SiteMapBase xml = new XmlSiteMap();

            _sitemaps.DefaultSiteMap = xml;

            Assert.Same(xml, _sitemaps.DefaultSiteMap);
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Инициализирует SiteMap и добавляет его в коллекцию карт сайта
 /// </summary>
 /// <param name="siteMap">Экземпляр карты сайта(меню)</param>
 /// <param name="needSortMenuItems">Нужно ли отсортировать элементы меню</param>
 public static void ConfigureSiteMap(XmlSiteMap siteMap, bool needSortMenuItems = true)
 {
     if (needSortMenuItems)
     {
         SortMenuItems(siteMap.RootNode);
     }
     if (!SiteMapManager.SiteMaps.ContainsKey("menu"))
     {
         SiteMapManager.SiteMaps.Add("menu", siteMap);
     }
 }
Ejemplo n.º 13
0
        public static string ExampleTitle(this HtmlHelper html)
        {
            XmlSiteMap sitemap    = (XmlSiteMap)html.ViewData["telerik.mvc.examples"];
            string     controller = (string)html.ViewContext.RouteData.Values["controller"];
            string     action     = (string)html.ViewContext.RouteData.Values["action"];

            SiteMapNode exampleSiteMapNode = sitemap.RootNode.ChildNodes
                                             .SelectRecursive(node => node.ChildNodes)
                                             .FirstOrDefault(node => controller.Equals(node.ControllerName, StringComparison.OrdinalIgnoreCase) &&
                                                             action.Equals(node.ActionName, StringComparison.OrdinalIgnoreCase));

            if (exampleSiteMapNode != null)
            {
                return(exampleSiteMapNode.Title);
            }

            return(string.Empty);
        }
Ejemplo n.º 14
0
        private TreeNode <MenuItem> PrepareAdminMenu()
        {
            XmlSiteMap siteMap = new XmlSiteMap(this._cache("static"));

            siteMap.LoadFrom(_webHelper.MapPath("~/Administrator/sitemap.config"));

            var rootNode = ConvertSitemapNodeToMenuItemNode(siteMap.RootNode);

            _menuPublisher.Value.RegisterMenus(rootNode, "admin");

            // hide based on permissions
            rootNode.TraverseTree(x =>
            {
                if (!x.IsRoot)
                {
                    if (!MenuItemAccessPermitted(x.Value))
                    {
                        x.Value.Visible = false;
                    }
                }
            });

            // hide dropdown nodes when no child is visible
            rootNode.TraverseTree(x =>
            {
                if (!x.IsRoot)
                {
                    var item = x.Value;
                    if (!item.IsGroupHeader && !item.HasRoute())
                    {
                        if (!x.Children.Any(child => child.Value.Visible))
                        {
                            item.Visible = false;
                        }
                    }
                }
            });

            return(rootNode);
        }
        public override void OnResultExecuting(System.Web.Mvc.ResultExecutingContext filterContext)
        {
            base.OnResultExecuting(filterContext);

            var fullSiteMap    = (XmlSiteMap)filterContext.Controller.ViewData[ViewDataKey];
            var productSiteMap = new XmlSiteMap();

            productSiteMap.RootNode = new SiteMapNode();

            foreach (SiteMapNode node in fullSiteMap.RootNode.ChildNodes)
            {
                var controller = node.ControllerName ?? node.Title;
                var action     = node.ActionName ?? "firstlook";
                var clone      = new SiteMapNode
                {
                    ActionName     = action,
                    ControllerName = controller,
                    Title          = node.Title
                };

                clone.Attributes.Merge(node.Attributes);
                productSiteMap.RootNode.ChildNodes.Add(clone);
            }

            filterContext.Controller.ViewData["telerik.web.mvc.products"] = productSiteMap;

            var examplesSiteMap = new XmlSiteMap();

            var controllerName     = (string)filterContext.RouteData.Values["controller"];
            var productSiteMapNode = fullSiteMap.RootNode.ChildNodes
                                     .FirstOrDefault(node => controllerName.Equals(node.Title, StringComparison.OrdinalIgnoreCase));

            if (productSiteMapNode != null && !controllerName.Equals("Home", StringComparison.OrdinalIgnoreCase))
            {
                examplesSiteMap.RootNode = new SiteMapNode();
                examplesSiteMap.RootNode.ChildNodes.Add(productSiteMapNode);
                filterContext.Controller.ViewData["telerik.web.mvc.products.examples"] = examplesSiteMap;
            }
        }
        public override void OnResultExecuting(System.Web.Mvc.ResultExecutingContext filterContext)
        {
            base.OnResultExecuting(filterContext);

            var fullSiteMap = (XmlSiteMap)filterContext.Controller.ViewData[ViewDataKey];
            var productSiteMap = new XmlSiteMap();
            productSiteMap.RootNode = new SiteMapNode();

            foreach (SiteMapNode node in fullSiteMap.RootNode.ChildNodes)
            {
                var controller = node.ControllerName ?? node.Title;
                var action = node.ActionName ?? "firstlook";
                var clone = new SiteMapNode
                {
                    ActionName = action,
                    ControllerName = controller,
                    Title = node.Title
                };

                clone.Attributes.Merge(node.Attributes);
                productSiteMap.RootNode.ChildNodes.Add(clone);
            }

            filterContext.Controller.ViewData["telerik.web.mvc.products"] = productSiteMap;

            var examplesSiteMap = new XmlSiteMap();

            var controllerName = (string)filterContext.RouteData.Values["controller"];
            var productSiteMapNode = fullSiteMap.RootNode.ChildNodes
                .FirstOrDefault(node => controllerName.Equals(node.Title, StringComparison.OrdinalIgnoreCase));

            if (productSiteMapNode != null && !controllerName.Equals("Home", StringComparison.OrdinalIgnoreCase))
            {
                examplesSiteMap.RootNode = new SiteMapNode();
                examplesSiteMap.RootNode.ChildNodes.Add(productSiteMapNode);
                filterContext.Controller.ViewData["telerik.web.mvc.products.examples"] = examplesSiteMap;
            }
        }
Ejemplo n.º 17
0
        private TreeNode<MenuItem> PrepareAdminMenu()
        {
            XmlSiteMap siteMap = new XmlSiteMap();
			siteMap.LoadFrom("~/Administration/sitemap.config");
            
            var rootNode = ConvertSitemapNodeToMenuItemNode(siteMap.RootNode);

			_menuPublisher.Value.RegisterMenus(rootNode, "admin");

			// hide based on permissions
            rootNode.TraverseTree(x => {
                if (!x.IsRoot)
                {
					if (!MenuItemAccessPermitted(x.Value))
                    {
                        x.Value.Visible = false;
                    }
                }
            });

            // hide dropdown nodes when no child is visible
			rootNode.TraverseTree(x =>
			{
				if (!x.IsRoot)
				{
					var item = x.Value;
					if (!item.IsGroupHeader && !item.HasRoute())
					{
						if (!x.Children.Any(child => child.Value.Visible))
						{
							item.Visible = false;
						}
					}
				}
			});

            return rootNode;
        }
Ejemplo n.º 18
0
        private TreeNode<MenuItem> PrepareAdminMenu()
        {
            XmlSiteMap siteMap = new XmlSiteMap();
            siteMap.LoadFrom("~/Administration/sitemap.config");

            var rootNode = ConvertSitemapNodeToMenuItemNode(siteMap.RootNode);

            _menuPublisher.Value.RegisterMenus(rootNode, "admin");

            //TreeNode<MenuItem> pluginNode = null;

            //// "collect" menus from plugins
            //var providers = new List<IMenuProvider>();
            //var providerTypes = _typeFinder.FindClassesOfType<IMenuProvider>(ignoreInactivePlugins: true);

            //foreach (var type in providerTypes)
            //{
            //	try
            //	{
            //		var provider = Activator.CreateInstance(type) as IMenuProvider;
            //		if (provider.MenuName.IsCaseInsensitiveEqual("admin"))
            //		{
            //			providers.Add(provider);
            //		}
            //	}
            //	catch { }
            //}

            //if (providers.Any())
            //{
            //	pluginNode = rootNode.Children.FirstOrDefault(x => x.Value.Id == "plugins");
            //	providers.Each(x => x.BuildMenu(pluginNode));
            //}

            // hide based on permissions
            rootNode.TraverseTree(x => {
                if (!x.IsRoot)
                {
                    if (!MenuItemAccessPermitted(x.Value))
                    {
                        x.Value.Visible = false;
                    }
                }
            });

            // hide dropdown nodes when no child is visible
            rootNode.TraverseTree(x =>
            {
                if (!x.IsRoot)
                {
                    var item = x.Value;
                    if (!item.IsGroupHeader && !item.HasRoute())
                    {
                        if (!x.Children.Any(child => child.Value.Visible))
                        {
                            item.Visible = false;
                        }
                    }
                }
            });

            return rootNode;
        }
Ejemplo n.º 19
0
        public ActionResult Navigation()
        {
            var adminNode = new XmlSiteMap(Server.MapPath(settings.GetSetting("AdminSiteMapPath"))).Node;

            return(PartialView(adminNode));
        }
        public void Should_be_able_to_set_default_site_map()
        {
            SiteMapBase xml = new XmlSiteMap();

            _sitemaps.DefaultSiteMap = xml;

            Assert.Same(xml, _sitemaps.DefaultSiteMap);
        }
Ejemplo n.º 21
0
 public void TestLoad()
 {
     XmlSiteMap siteMap = new XmlSiteMap(AppDomain.CurrentDomain.BaseDirectory + "/TestData/Web.sitemap");
 }
Ejemplo n.º 22
0
 public override void ExecuteResult(ControllerContext context)
 {
     context.HttpContext.Response.ContentType = "application/rss+xml";
     context.HttpContext.Response.Flush();
     context.HttpContext.Response.Write(XmlSiteMap.Create(items));
 }
        public void Should_be_able_to_set_site_map()
        {
            SiteMapBase siteMap = new XmlSiteMap();

            _sitemaps["foo"] = siteMap;

            Assert.Same(siteMap, _sitemaps["foo"]);
        }
Ejemplo n.º 24
0
        private TreeNode <MenuItem> PrepareAdminMenu()
        {
            XmlSiteMap siteMap = new XmlSiteMap();

            siteMap.LoadFrom("~/Administration/sitemap.config");

            var rootNode = ConvertSitemapNodeToMenuItemNode(siteMap.RootNode);

            _menuPublisher.Value.RegisterMenus(rootNode, "admin");

            //TreeNode<MenuItem> pluginNode = null;

            //// "collect" menus from plugins
            //var providers = new List<IMenuProvider>();
            //var providerTypes = _typeFinder.FindClassesOfType<IMenuProvider>(ignoreInactivePlugins: true);

            //foreach (var type in providerTypes)
            //{
            //	try
            //	{
            //		var provider = Activator.CreateInstance(type) as IMenuProvider;
            //		if (provider.MenuName.IsCaseInsensitiveEqual("admin"))
            //		{
            //			providers.Add(provider);
            //		}
            //	}
            //	catch { }
            //}

            //if (providers.Any())
            //{
            //	pluginNode = rootNode.Children.FirstOrDefault(x => x.Value.Id == "plugins");
            //	providers.Each(x => x.BuildMenu(pluginNode));
            //}

            // hide based on permissions
            rootNode.TraverseTree(x => {
                if (!x.IsRoot)
                {
                    if (!MenuItemAccessPermitted(x.Value))
                    {
                        x.Value.Visible = false;
                    }
                }
            });

            // hide dropdown nodes when no child is visible
            rootNode.TraverseTree(x =>
            {
                if (!x.IsRoot)
                {
                    var item = x.Value;
                    if (!item.IsGroupHeader && !item.HasRoute())
                    {
                        if (!x.Children.Any(child => child.Value.Visible))
                        {
                            item.Visible = false;
                        }
                    }
                }
            });

            return(rootNode);
        }