Пример #1
0
		public static object GetWebSiteFileNodes()
		{
			string rootPath = HttpContextHelper.AppRootPath;

			JsTreeNode root = new JsTreeNode();
			RecursiveDirectory(rootPath, root);

			return new JsonResult(root.children);
		}
Пример #2
0
		private static void RecursiveDirectory(string fullPath, JsTreeNode root)
		{
			DirectoryInfo dir = new DirectoryInfo(fullPath);
			DirectoryInfo[] subDirArray = dir.GetDirectories();
			FileInfo[] fileArray = dir.GetFiles();

			List<JsTreeNode> children = new List<JsTreeNode>(subDirArray.Length + fileArray.Length);

			foreach( DirectoryInfo dinfo in subDirArray ) {
				if( Array.Find<string>(s_IgnoreFolders, x => string.Compare(x, dinfo.Name, true) == 0) != null )
					continue;

				JsTreeNode node = new JsTreeNode();
				node.text = dinfo.Name;
				node.attributes = new JsTreeNodeCustAttr();

				RecursiveDirectory(dinfo.FullName, node);

				if( node.children != null && node.children.Count > 0 ) {
					children.Add(node);
				}
			}


			Dictionary<string, JsTreeNode> nestNodes = new Dictionary<string, JsTreeNode>(fileArray.Length, StringComparer.OrdinalIgnoreCase);

			foreach( FileInfo finfo in fileArray ) {
				JsTreeNode node = new JsTreeNode();
				node.text = finfo.Name;
				node.iconCls = GetIconByFileName(finfo.Name);
				node.attributes = new JsTreeNodeCustAttr(finfo.FullName, finfo.Extension.ToLower());

				if( node.iconCls == "icon-cs2" )
					nestNodes.Add(finfo.Name, node);
				else
					children.Add(node);
			}

			foreach( JsTreeNode node in children ) {
				if( node.iconCls == "icon-aspx" || node.iconCls == "icon-ascx" || node.iconCls == "icon-master" ) {
					JsTreeNode nestNode;
					if( nestNodes.TryGetValue(string.Concat(node.text, ".cs"), out nestNode) ) {
						node.children = new List<JsTreeNode>(1);
						node.children.Add(nestNode);
					}
				}
			}

			foreach( JsTreeNode child in children )
				if( child.children != null && child.children.Count > 0 )
					child.state = "closed";

			if( children.Count > 0 )
				root.children = children;
		}