Пример #1
0
        /// <summary>
        /// 添加点击到导航中
        /// </summary>
        /// <param name="context">上下文</param>
        /// <param name="label">当前画面名称</param>
        public void Push(ActionExecutingContext context, string label)
        {
            string controller = context.RouteData.Values["controller"].ToString();
            string action     = context.RouteData.Values["action"].ToString();
            var    key        = ("/" + controller + "/" + action)
                                .ToLower()
                                .GetHashCode();

            if (Crumbs.Any(x => x.Key == key))
            {
                var newCrumbs = new List <StateEntry>();
                var remove    = false;
                // We've seen this route before, maybe user clicked on a breadcrumb
                foreach (var crumb in Crumbs)
                {
                    if (crumb.Key == key)
                    {
                        remove = true;
                    }
                    if (!remove)
                    {
                        newCrumbs.Add(crumb);
                    }
                }
                Crumbs = newCrumbs;
            }

            Current = new StateEntry().WithKey(key)
                      .SetContext(context)
                      .WithUrl(context.HttpContext.Request.Url.ToString())
                      .WithLabel(label);

            Crumbs.Add(Current);
        }
Пример #2
0
        public void Push(ActionExecutingContext context, string label, Type resourceType)
        {
            var key =
                context.HttpContext.Request.Url.LocalPath
                .ToLower()
                .GetHashCode();

            if (Crumbs.Any(x => x.Key == key))
            {
                var newCrumbs = new List <StateEntry>();
                var remove    = false;
                // We've seen this route before, maybe user clicked on a breadcrumb
                foreach (var crumb in Crumbs)
                {
                    if (crumb.Key == key)
                    {
                        remove = true;
                    }
                    if (!remove)
                    {
                        newCrumbs.Add(crumb);
                    }
                }
                Crumbs = newCrumbs;
            }

            Current = new StateEntry().WithKey(key)
                      .SetContext(context)
                      .WithUrl(context.HttpContext.Request.Url.ToString())
                      .WithLabel(ResourceHelper.GetResourceLookup(resourceType, label));

            Crumbs.Add(Current);
        }
        public int AddCrumb(ICrumb crumb)
        {
            if (crumb == null)
            {
                throw new ArgumentNullException("Crumb");
            }

            Crumbs.Add(crumb);
            AddViewToRegion(crumb.Content);
            return(Crumbs.Count);
        }
Пример #4
0
        private void Add(string url, string label, Type resourceType = null, ActionExecutingContext actionContext = null)
        {
            var key = url.ToLowerInvariant().GetHashCode();

            // when pushing entries into the list determine their level in hierarchy so that
            // deeper links are added to the end of the list
            int levels = BreadCrumb.HierarchyProvider.GetLevel(url);

            if (Crumbs.Any(x => x.Key == key))
            {
                var newCrumbs = new SortedSet <StateEntry>(new StateEntryComparer());
                var remove    = false;
                // We've seen this route before, maybe user clicked on a breadcrumb
                foreach (var crumb in Crumbs)
                {
                    if (crumb.Key == key)
                    {
                        remove = true;
                    }
                    if (!remove)
                    {
                        newCrumbs.Add(crumb);
                    }
                }
                Crumbs = newCrumbs;
            }

            Current = new StateEntry()
                      .WithKey(key)
                      .SetContext(actionContext)
                      .WithUrl(url)
                      .WithLevel(levels)
                      .WithLabel(ResourceHelper.GetResourceLookup(resourceType, label));

            Crumbs.Add(Current);
        }