Пример #1
0
        private static NodeCollection BuildAreasLevel()
        {
            string        path = HttpContext.Current.Server.MapPath(ExamplesModel.ExamplesRoot);
            DirectoryInfo root = new DirectoryInfo(path);

            DirectoryInfo[] folders = root.GetDirectories();
            folders = ExamplesModel.SortFolders(root, folders);

            NodeCollection nodes = new NodeCollection(false);

            var staticIcons = new StaticNodeIcon(path);

            foreach (DirectoryInfo folder in folders)
            {
                if ((folder.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden ||
                    excludeList.Contains(folder.Name) || folder.Name.StartsWith("_"))
                {
                    continue;
                }

                ExampleConfig cfg = new ExampleConfig(folder.FullName + "\\config.xml");

                string iconCls = string.IsNullOrEmpty(cfg.IconCls) ? "" : cfg.IconCls;
                Node   node    = null;
                var    index   = folder.Name.IndexOf('_');

                if (cfg.MainGroup || index < 0)
                {
                    node        = new Node();
                    node.NodeID = BaseControl.GenerateID();
                    node.Text   = folder.Name.Replace("_", " ");

                    nodes.Add(node);

                    if (String.IsNullOrWhiteSpace(iconCls))
                    {
                        staticIcons.TryGetIconCLS(out iconCls, folder.Name);
                    }

                    node.IconCls = iconCls;
                    if (ExamplesModel.IsNew(folder.FullName))
                    {
                        node.CustomAttributes.Add(new ConfigItem("isNew", "true", ParameterMode.Raw));
                    }
                }
                else
                {
                    string otherIconCls;
                    var    mainGroupName = folder.Name.Substring(0, index);
                    node = nodes.FirstOrDefault(n => n.Text == mainGroupName);

                    if (node == null)
                    {
                        node        = new Node();
                        node.NodeID = BaseControl.GenerateID();
                        node.Text   = mainGroupName;
                        nodes.Add(node);
                    }

                    if (staticIcons.TryGetIconCLS(out otherIconCls, mainGroupName))
                    {
                        node.IconCls = otherIconCls;
                    }

                    if (ExamplesModel.IsNew(folder.FullName) && !node.CustomAttributes.Contains("isNew"))
                    {
                        node.CustomAttributes.Add(new ConfigItem("isNew", "true", ParameterMode.Raw));
                    }

                    var groupNode        = new Node();
                    var subGroupNodeName = folder.Name.Substring(index + 1);

                    groupNode.NodeID = BaseControl.GenerateID();
                    groupNode.Text   = subGroupNodeName.Replace("_", " ");

                    if (iconCls.IsNotEmpty())
                    {
                        groupNode.IconCls = iconCls;
                    }
                    else if (staticIcons.TryGetIconCLS(out otherIconCls, mainGroupName, subGroupNodeName))
                    {
                        groupNode.IconCls = otherIconCls;
                    }

                    if (ExamplesModel.IsNew(folder.FullName) && !groupNode.CustomAttributes.Contains("isNew"))
                    {
                        groupNode.CustomAttributes.Add(new ConfigItem("isNew", "true", ParameterMode.Raw));
                    }

                    node.Children.Add(groupNode);
                    node = groupNode;
                }

                ExamplesModel.BuildViewsLevel(folder, node);
            }

            return(nodes);
        }
        private static NodeCollection BuildAreasLevel()
        {
            string        path = HttpContext.Current.Server.MapPath(ExamplesModel.ExamplesRoot);
            DirectoryInfo root = new DirectoryInfo(path);

            DirectoryInfo[] folders = root.GetDirectories();
            folders = ExamplesModel.SortFolders(root, folders);

            NodeCollection nodes = new NodeCollection(false);

            var staticIcons = new StaticNodeIcon(path);

            foreach (DirectoryInfo folder in folders)
            {
                if ((folder.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden ||
                    excludeList.Contains(folder.Name) || folder.Name.StartsWith("_"))
                {
                    continue;
                }

                ExampleConfig cfg = new ExampleConfig(folder.FullName + "\\config.xml");

                string iconCls = string.IsNullOrEmpty(cfg.IconCls) ? "" : cfg.IconCls;
                Node   node    = null;
                int    index   = 0;
                if (cfg.MainGroupSplitAt < 2)
                {
                    index = folder.Name.IndexOf('_');
                }
                else
                {
                    var split_folder = folder.Name.Split('_');

                    if (split_folder.Length <= cfg.MainGroupSplitAt)
                    {
                        // The setting specifies to split the group beyond the
                        // available amount of underscore splitters in the
                        // folder string.
                        index = -1;
                    }
                    else
                    {
                        index += cfg.MainGroupSplitAt - 1;
                        for (var i = 0; i < cfg.MainGroupSplitAt; i++)
                        {
                            index += split_folder[i].Length;
                        }
                    }
                }

                if (cfg.MainGroup || index < 1)
                {
                    node        = new Node();
                    node.NodeID = BaseControl.GenerateID();
                    node.Text   = folder.Name.Replace("_", " ");

                    nodes.Add(node);

                    if (String.IsNullOrWhiteSpace(iconCls))
                    {
                        staticIcons.TryGetIconCLS(out iconCls, folder.Name);
                    }

                    node.IconCls = iconCls;

                    flagNode(ref node, folder.FullName);
                }
                else
                {
                    string otherIconCls;

                    var rawMainGroupName = folder.Name.Substring(0, index);
                    var mainGroupName    = rawMainGroupName.Replace('_', ' ');

                    node = nodes.FirstOrDefault(n => n.Text == mainGroupName);

                    if (node == null)
                    {
                        node        = new Node();
                        node.NodeID = BaseControl.GenerateID();
                        node.Text   = mainGroupName;
                        nodes.Add(node);
                    }

                    if (staticIcons.TryGetIconCLS(out otherIconCls, rawMainGroupName))
                    {
                        node.IconCls = otherIconCls;
                    }

                    flagNode(ref node, folder.FullName);

                    var groupNode        = new Node();
                    var subGroupNodeName = folder.Name.Substring(index + 1);

                    groupNode.NodeID = BaseControl.GenerateID();
                    groupNode.Text   = subGroupNodeName.Replace("_", " ");

                    if (iconCls.IsNotEmpty())
                    {
                        groupNode.IconCls = iconCls;
                    }
                    else if (staticIcons.TryGetIconCLS(out otherIconCls, rawMainGroupName, subGroupNodeName))
                    {
                        groupNode.IconCls = otherIconCls;
                    }

                    flagNode(ref groupNode, folder.FullName);

                    node.Children.Add(groupNode);
                    node = groupNode;
                }

                ExamplesModel.BuildViewsLevel(folder, node);
            }

            return(nodes);
        }