Esempio n. 1
0
            private static SiteMapNode GetParentNodeFromDataReader(Dictionary <string, SiteMapNodeEx> nodes, SiteMapNode rootNode, PageOrdinal ordinal, IDataReader r, bool findSection)
            {
                if (r.IsDBNull(ordinal.TreeId))
                {
                    throw new ProviderException("Missing parent ID");
                }
                // Get the parent ID from the DataReader
                var parentTreeId = r.GetString(ordinal.TreeId);
                var nodeLength   = (!parentTreeId.StartsWith("/@Draft/") ? 4 : 11);

                if (parentTreeId.Length == nodeLength)
                {
                    return(rootNode);
                }
                // Make sure the parent ID is valid
                SiteMapNodeEx value;

                parentTreeId = parentTreeId.Substring(0, (!findSection ? parentTreeId.Length - nodeLength : nodeLength));
                if (!nodes.TryGetValue(parentTreeId, out value))
                {
                }
                //throw new ProviderException("Invalid parent ID");
                return(!findSection ? value : value as SiteMapSectionNode);
            }
Esempio n. 2
0
            protected virtual SiteMapNode CreateSiteMapNodeFromDataReader(SiteMapNode parentNode, Dictionary <string, SiteMapNodeEx> nodes, List <VirtualNode> virtualNodes, List <AddProviderNode> addProviderNodes, PageOrdinal ordinal, IDataReader r, ref string hiddenRootTreeId)
            {
                if (r.IsDBNull(ordinal.TreeId))
                {
                    throw new ProviderException("Missing node ID");
                }
                var treeId = r.GetString(ordinal.TreeId);

                if (nodes.ContainsKey(treeId))
                {
                    throw new ProviderException("Duplicate node ID");
                }
                var visible       = !r.Field <bool>(ordinal.IsHidden);
                var key           = r.Field <int>(ordinal.Key);
                var uid           = r.Field <string>(ordinal.Uid);
                var defaultTreeId = r.Field <string>(ordinal.DefaultTreeId);
                var type          = r.Field <string>(ordinal.Type);
                var id            = r.Field <string>(ordinal.Id);
                var name          = r.Field <string>(ordinal.Name);
                var sectionId     = r.Field <string>(ordinal.SectionId);
                //var attrib = r.Field<Nattrib>(ordinal.AttribStream);
                var attrib = BuildAttrib(r.Field <string>(ordinal.AttribStream));
                //
                var pageDynamism   = r.Field <string>(ordinal.PageDynamism);
                var lastModifyDate = r.Field <DateTime?>(ordinal.LastModifyDate);
                var virtualize     = r.Field <string>(ordinal.Virtualize);

                // hidden branches
                if (!visible)
                {
                    if (hiddenRootTreeId == null || !treeId.StartsWith(hiddenRootTreeId))
                    {
                        hiddenRootTreeId = treeId;
                    }
                }
                else if (hiddenRootTreeId != null)
                {
                    if (treeId.StartsWith(hiddenRootTreeId))
                    {
                        visible = false;
                    }
                    else
                    {
                        hiddenRootTreeId = null;
                    }
                }
                // make url
                Action        setRoute = null;
                SiteMapNodeEx node;

                switch (type)
                {
                case "X-AddProvider":
                    addProviderNodes.Add(new AddProviderNode(virtualize, parentNode, x =>
                    {
                        x.Title = name;
                        var externalProvider = (x.Provider as StaticSiteMapProviderEx);
                        if (externalProvider != null)
                        {
                            externalProvider.RebaseNodesRecurse(x, "/" + id);
                        }
                    }));
                    return(null);

                case "X-Section":
                    SiteMapVirtualNode virtualNode;
                    node     = virtualNode = new SiteMapSectionNode(_provider, uid, "/" + id, name);
                    setRoute = () => SetRouteInNode(_routeCreator.CreateRoutes(node, id, virtualize), node);
                    virtualNodes.Add(new VirtualNode(virtualNode, defaultTreeId));
                    break;

                case "E-Form":
                    node = new SiteMapFormNode(_provider, uid, "/" + id, name);
                    node.Set <SiteMapNodePartialProviderExtent>(new SiteMapNodePartialProviderExtent());
                    setRoute = () => SetRouteInNode(_routeCreator.CreateRoutes(node, id, virtualize), node);
                    break;

                case "E-ListDetail":
                    node = new SiteMapListDetailNode(_provider, uid, "/" + id, name);
                    node.Set <SiteMapNodePartialProviderExtent>(new SiteMapNodePartialProviderExtent());
                    setRoute = () => SetRouteInNode(_routeCreator.CreateRoutes(node, id, virtualize), node);
                    break;

                case "X-Link":
                    id = StringEx.Axb(sectionId, "/", id);
                    string linkUri;
                    if (!attrib.TryGetValue("LinkUri", out linkUri))
                    {
                        linkUri = "/";
                    }
                    node = new SiteMapLinkNode(_provider, uid, "/" + id, name)
                    {
                        LinkUri = linkUri
                    };
                    node.Set <Func <IDynamicNode, RouteData> >(nodeEx =>
                    {
                        var linkNodeEx = (nodeEx as SiteMapLinkNode);
                        if (linkNodeEx != null)
                        {
                            var context = HttpContext.Current;
                            var query   = context.Request.Url.Query;
                            context.Response.Redirect(query.Length == 0 ? linkNodeEx.LinkUri : linkNodeEx.LinkUri + query);
                        }
                        return(null);
                    });
                    break;

                case "X-Content":
                    id       = StringEx.Axb(sectionId, "/", id);
                    node     = new SiteMapPageNode(_provider, uid, "/" + id, name);
                    setRoute = () => SetRouteInNode(_routeCreator.CreateRoutes(node, id, virtualize), node);
                    break;

                default:
                    throw new InvalidOperationException();
                }
                node.Visible = visible;
                // map attrib
                if (attrib != null)
                {
                    foreach (var attribKey in attrib.Keys)
                    {
                        node[attribKey] = attrib[attribKey];
                    }
                }
                // content
                var sectionNode = GetParentNodeFromDataReader(nodes, _rootNode, ordinal, r, true);

                node.Set <SiteMapNodeContentExtent>(new SiteMapNodeContentExtent {
                    Shard = _connectShard, Key = key, TreeId = treeId, SectionNode = sectionNode, Sequence = _sequence++
                });
                var contentNode = (node as SiteMapPageNode);

                if (contentNode != null)
                {
                    contentNode.LastModifyDate = lastModifyDate;
                    contentNode.PageDynamism   = pageDynamism;
                    contentNode.PagePriority   = null;
                }
                nodes.Add(treeId, node);
                // set route last so node values are populated before routes are determined.
                if (setRoute != null)
                {
                    setRoute();
                }
                return(node);
            }