Ejemplo n.º 1
0
        public FuncTreeNode AddNodes(string xpath)
        {
            string[] paths = xpath.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
            if (paths.Length == 0)
            {
                throw new Exception("无法添加根节点");
            }
            int          index = 0;
            FuncTreeNode tmp   = this;

            while (index < paths.Length)
            {
                string tmpNodeName = paths[index];
                if (!tmp.Nodes.ContainsKey(tmpNodeName))
                {
                    tmp = tmp.AddNode(tmpNodeName);
                }
                else
                {
                    tmp = tmp.Nodes[tmpNodeName];
                }
                index++;
            }
            return(tmp);
        }
Ejemplo n.º 2
0
 public FuncTreeNode(string name)
 {
     this._name = name;
     this._parent = null;
     this._funcs = new Dictionary<string, CustomShellType.FuncCode>();
     this._nodes = new Dictionary<string, FuncTreeNode>();
 }
Ejemplo n.º 3
0
 public FuncTreeNode(string name)
 {
     this._name   = name;
     this._parent = null;
     this._funcs  = new Dictionary <string, CustomShellType.FuncCode>();
     this._nodes  = new Dictionary <string, FuncTreeNode>();
 }
Ejemplo n.º 4
0
        public CustomShellType(Basic basicSetting,
                               MainCode mainCodeSetting)
        {
            _shellTypeName   = basicSetting.ShellTypeName;
            _basicSetting    = basicSetting;
            _mainCodeSetting = mainCodeSetting;

            //初始化方法树
            _funcTreeRoot = new FuncTreeNode(_shellTypeName);
        }
Ejemplo n.º 5
0
        public CustomShellType(Basic basicSetting,
                               MainCode mainCodeSetting)
        {
            _shellTypeName = basicSetting.ShellTypeName;
            _basicSetting = basicSetting;
            _mainCodeSetting = mainCodeSetting;

            //初始化方法树
            _funcTreeRoot = new FuncTreeNode(_shellTypeName);
        }
Ejemplo n.º 6
0
 public FuncTreeNode AddNode(string nodeName)
 {
     if (!this.Nodes.ContainsKey(nodeName))
     {
         FuncTreeNode newNode = new FuncTreeNode(nodeName);
         newNode._parent = this;
         this.Nodes.Add(newNode.Name, newNode);
         return newNode;
     }
     return this.Nodes[nodeName];
 }
Ejemplo n.º 7
0
 public FuncTreeNode AddNode(string nodeName)
 {
     if (!this.Nodes.ContainsKey(nodeName))
     {
         FuncTreeNode newNode = new FuncTreeNode(nodeName);
         newNode._parent = this;
         this.Nodes.Add(newNode.Name, newNode);
         return(newNode);
     }
     return(this.Nodes[nodeName]);
 }
Ejemplo n.º 8
0
        public FuncTreeNode AddFuncTreeNode(string nodeXpath)
        {
            FuncTreeNode tmp = _funcTreeRoot.FindNodes(nodeXpath);

            //如果节点不存在
            if (tmp == null)
            {
                return(_funcTreeRoot.AddNodes(nodeXpath));
            }
            return(tmp);
        }
Ejemplo n.º 9
0
 /// <summary>
 /// 显示树节点
 /// </summary>
 /// <param name="node"></param>
 /// <returns></returns>
 public static TreeNode GetTreeNodes(FuncTreeNode node)
 {
     TreeNode tree = new TreeNode(node.Name);
     foreach (var func in node.Funcs.Keys)
     {
         tree.Nodes.Add(func);
     }
     if (node.Nodes.Count > 0)
     {
         foreach (var child in node.Nodes)
         {
             tree.Nodes.Add(GetTreeNodes(child.Value));
         }
     }
     return tree;
 }
Ejemplo n.º 10
0
        public FuncCode GetFuncCode(string nodeXpath, string funcCodeName)
        {
            FuncTreeNode tmp = _funcTreeRoot.FindNodes(nodeXpath);

            //如果节点存在
            if (tmp != null)
            {
                //如果funcCode已经注册
                if (tmp.Funcs.ContainsKey(funcCodeName))
                {
                    return(tmp.Funcs[funcCodeName]);
                }
            }
            //其他情况均为未注册
            throw new Exception(string.Format("FuncCode:[{0}/{1}] hasn't been registered", nodeXpath, funcCodeName));
        }
Ejemplo n.º 11
0
        public void AddFuncCode(string nodeXpath, FuncCode funcCode)
        {
            FuncTreeNode tmp = _funcTreeRoot.FindNodes(nodeXpath);

            //如果节点不存在
            if (tmp == null)
            {
                throw new Exception(string.Format("FuncTreeNode:[{0}] has't been defined", nodeXpath));
            }
            //如果funcCode已经注册
            if (tmp.Funcs.ContainsKey(funcCode.Name))
            {
                throw new Exception(string.Format("FuncCode:[{0}] has been registered", funcCode.Name));
            }
            else
            {
                tmp.Funcs.Add(funcCode.Name, funcCode);
            }
        }
Ejemplo n.º 12
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new FormMain());

            //启动自定义shelltype
            //Application.Run(new FormCustomShellTypeWizard());

            //test
            //XmlDocument xmlDoc = XmlHelper.ReadXml("data.xml", false,"body");
            //XmlHelper.SaveXml("data1.xml", xmlDoc,true, "body");

            //test
            FuncTreeNode root = new FuncTreeNode("root");
            root.AddNode("A");
            FuncTreeNode d =root.AddNodes("/a/b/c/d");
            string dpath = d.FullPath;
            FuncTreeNode find_a = root.FindNode("a");
            FuncTreeNode find_c = root.FindNodes("a/b/c");
            FuncTreeNode find_d = root.FindNodes("a");
        }
Ejemplo n.º 13
0
        public FuncTreeNode FindNodes(string xpath)
        {
            string[] paths = xpath.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
            if (paths.Length == 0)
            {
                return(this);
            }
            int          index = 0;
            FuncTreeNode tmp   = this;

            while (index < paths.Length)
            {
                tmp = tmp.FindNode(paths[index]);
                if (tmp != null)
                {
                    index++;
                }
                else
                {
                    break;
                }
            }
            return(tmp);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// 注册CustomShellType
        /// </summary>
        public static void RegisterCustomShellType()
        {
            //清空CustomShellTypeProvider
            CustomShellTypeProvider.Clear();

            //读取shelltype列表(.type)
            List <string> typeList = XmlHelper.LoadXMlList(CustomShellTypePath, "type");

            //1.注册CustomShellType
            foreach (string c in typeList)
            {
                var basicSetting    = new CustomShellType.Basic();
                var mainCodeSetting = new CustomShellType.MainCode();

                //读取basicSetting,mainCodeSetting
                CustomShellTypeXmlHandle.ReadXml(c, CustomShellTypePath, ref basicSetting, ref mainCodeSetting);
                //生成customShellType
                var customShellType = new CustomShellType(basicSetting, mainCodeSetting);
                //将CustomShellType注册到全局
                CustomShellTypeProvider.AddShellType(customShellType);
            }

            //读取funcTree定义列表(.tree)
            List <string> funcTreeList = XmlHelper.LoadXMlList(CustomShellTypePath, "tree");

            //2.初始化funcTree方法树
            foreach (string c in funcTreeList)
            {
                var treeInfoList = new List <CustomShellType.TreeInfo>();

                //读取funcCodeList
                CustomShellTypeXmlHandle.ReadXml(c, CustomShellTypePath, ref treeInfoList);
                //将func注册到CustomShellType
                foreach (CustomShellType.TreeInfo info in treeInfoList)
                {
                    /***
                     * 获取节点的类型
                     * 允许多个类型,以英文逗号分隔,如"aspx,aspx1"
                     */
                    string[] types = info.Type.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (string type in types)
                    {
                        CustomShellType shellType = CustomShellTypeProvider.GetShellType(type);
                        FuncTreeNode    node      = shellType.AddFuncTreeNode(info.Path);
                        node.Info = info.Info;
                    }
                }
            }

            //读取funcCode列表(.func)
            List <string> funcList = XmlHelper.LoadXMlList(CustomShellTypePath, "func");

            //3.注册funcCode到functree
            foreach (string c in funcList)
            {
                var funcCodeList = new List <CustomShellType.FuncCode>();

                //读取funcCodeList
                CustomShellTypeXmlHandle.ReadXml(c, CustomShellTypePath, ref funcCodeList);
                //将func注册到CustomShellType
                foreach (CustomShellType.FuncCode func in funcCodeList)
                {
                    /***
                     * 获取func的类型
                     * type允许多个类型,以英文逗号分隔,如"aspx,aspx1"
                     */
                    string[] types = func.Type.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (string type in types)
                    {
                        CustomShellType shellType = CustomShellTypeProvider.GetShellType(type);
                        //获取映射节点
                        //path为xpath形式,如"/cmder",
                        //允许多个,以英文逗号分隔,如"/cmder,/cmder1"
                        string[] xpaths = func.Path.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                        foreach (string xpath in xpaths)
                        {
                            shellType.AddFuncCode(xpath, func);
                        }
                    }
                }
            }
        }