コード例 #1
0
        private async Task RestoreToc(NavigationRecord record, TOCAccessMode mode)
        {
            if (record.BookId != Publication.BookId)
            {
                var publications = SessionService.SessionState[ALL_PUBLICATIONS_SESSION_KEY] as List <PublicationViewModel>;
                Publication = publications.FirstOrDefault(x => x.BookId == record.BookId);
                root        = await PublicationUtil.Instance.GetDlBookTOC(Publication.BookId);

                listAll   = root.ChildNodes;
                firstNode = null;
                GetFirstTocNode(listAll, ref firstNode);
                var indexs = await InitialIndexMenu(Publication.BookId);

                IndexMenuCollections = new ObservableCollection <IndexMenuItem>(indexs);
                HasIndex             = IndexMenuCollections == null || IndexMenuCollections.Count == 0 ? false : true;
                Keywords             = string.Empty;
                IsPBO = await PageSearchUtil.Instance.IsPBO(Publication.BookId);
            }
            CurrentTocNode = new TocCurrentNode
            {
                ID   = record.TOCId,
                Role = NodeExpandStatue.Leaf
            };
            var nodes = await InitialBreadcrumMenu(record, mode);

            BreadcrumbNavigator = new ObservableCollection <BreadcrumbNav>(nodes);
        }
コード例 #2
0
        private async Task <List <BreadcrumbNav> > InitialBreadcrumMenu(NavigationRecord record, TOCAccessMode mode)
        {
            List <BreadcrumbNav> selectedBreadcrumbNavs = null;

            //restore toc and get content
            if (CurrentTocNode != null && CurrentTocNode.ID != 0)
            {
                List <TOCNode> selectedNodes = new List <TOCNode>();
                TOCNode        tocNode       = null;
                GetTocNodeByID(listAll, ref tocNode, CurrentTocNode.ID);

                if (CurrentTocNode.Role == NodeExpandStatue.Leaf)
                {
                    switch (mode)
                    {
                    case TOCAccessMode.All:
                        var content1 = await PublicationContentUtil.Instance.GetContentFromTOC(record.BookId, tocNode);

                        ChangeTocContent(await HtmlHelper.PageSplit(content1, record), record.TOCId);
                        HistoryNavigator.Record(Publication.BookId, tocNode.ID, record.Type, record.PageNum, record.Tag);
                        break;

                    case TOCAccessMode.IgnoreHistory:
                        var content2 = await PublicationContentUtil.Instance.GetContentFromTOC(record.BookId, tocNode, false);

                        ChangeTocContent(await HtmlHelper.PageSplit(content2, record), record.TOCId);
                        break;

                    case TOCAccessMode.NoReload:
                        break;
                    }
                    CurrentLevel = tocNode.NodeLevel - 1;
                }
                else if (CurrentTocNode.Role == NodeExpandStatue.Expand)
                {
                    CurrentLevel = tocNode.NodeLevel;
                }
                else if (CurrentTocNode.Role == NodeExpandStatue.Collapse)
                {
                    CurrentLevel = tocNode.NodeLevel - 1;
                }
                //add parent
                TOCNode tempNode = tocNode.ParentNode;
                while (tempNode != null && tempNode.NodeLevel > 0)
                {
                    selectedNodes.Insert(0, tempNode);
                    tempNode = tempNode.ParentNode;
                }

                //add me and children
                if (CurrentTocNode.Role == NodeExpandStatue.Expand)
                {
                    selectedNodes.Add(tocNode);
                    selectedNodes.AddRange(tocNode.ChildNodes);
                }
                else
                {
                    selectedNodes.AddRange(tocNode.ParentNode.ChildNodes);
                }

                selectedBreadcrumbNavs = selectedNodes.Select(node => new BreadcrumbNav
                {
                    ID             = node.ID,
                    Title          = node.Title,
                    GuideCardTitle = node.GuideCardTitle,
                    Role           = node.Role,
                    NodeLevel      = node.NodeLevel,
                    ChildNodes     = node.ChildNodes,
                    ParentId       = node.ParentId,
                    ParentNode     = node.ParentNode,
                    Icon           = node.Role == Constants.ANCESTOR ? (node.NodeLevel > CurrentLevel ? COLLAPSED_ICON : EXPAND_ICON) : LEAF_NODE_ICON,
                    IsHighLight    = node.ID == CurrentTocNode.ID
                }).ToList <BreadcrumbNav>();
            }
            else
            {
                CurrentTocNode = new TocCurrentNode
                {
                    ID   = record.TOCId,
                    Role = NodeExpandStatue.Leaf
                };
                CurrentLevel = 0;
                var content = await PublicationContentUtil.Instance.GetContentFromTOC(record.BookId, firstNode);

                ChangeTocContent(await HtmlHelper.PageSplit(content, record), record.TOCId);
                HistoryNavigator.Record(Publication.BookId, record.TOCId, record.Type, record.PageNum, record.Tag);
                selectedBreadcrumbNavs = listAll.Select(node => new BreadcrumbNav
                {
                    ID             = node.ID,
                    Title          = node.Title,
                    GuideCardTitle = node.GuideCardTitle,
                    Role           = node.Role,
                    NodeLevel      = node.NodeLevel,
                    ChildNodes     = node.ChildNodes,
                    ParentId       = node.ParentId,
                    ParentNode     = root,
                    Icon           = node.Role == Constants.ANCESTOR ? COLLAPSED_ICON : LEAF_NODE_ICON,
                    IsHighLight    = false
                }).ToList();
                selectedBreadcrumbNavs[0].IsHighLight = true;
            }
            selectedBreadcrumbNavs.Insert(0, new BreadcrumbNav
            {
                ID         = 0,
                Title      = "Table of Contents",
                NodeLevel  = 0,
                ChildNodes = root.ChildNodes
            });
            return(selectedBreadcrumbNavs);
        }