Exemplo n.º 1
0
        public FuncTreeNode AddNodes(string xpath)
        {
            string[] paths = xpath.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
            if (paths.Length == 0)
            {
                throw new Exception("Unable to add the root node");
            }
            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);
        }
Exemplo 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>();
 }
Exemplo n.º 3
0
        public CustomShellType(Basic basicSetting,
                               MainCode mainCodeSetting)
        {
            _shellTypeName   = basicSetting.ShellTypeName;
            _basicSetting    = basicSetting;
            _mainCodeSetting = mainCodeSetting;

            //初始化方法树
            _funcTreeRoot = new FuncTreeNode(_shellTypeName);
        }
Exemplo n.º 4
0
        public FuncTreeNode AddFuncTreeNode(string nodeXpath)
        {
            FuncTreeNode tmp = _funcTreeRoot.FindNodes(nodeXpath);

            //如果节点不存在
            if (tmp == null)
            {
                return(_funcTreeRoot.AddNodes(nodeXpath));
            }
            return(tmp);
        }
Exemplo n.º 5
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]);
 }
Exemplo n.º 6
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}/{2}] hasn't been registered", _shellTypeName, nodeXpath, funcCodeName));
        }
Exemplo n.º 7
0
        public void AddFuncCode(string nodeXpath, FuncCode funcCode)
        {
            FuncTreeNode tmp = _funcTreeRoot.FindNodes(nodeXpath);

            //如果节点不存在
            if (tmp == null)
            {
                throw new Exception(string.Format("FuncTreeNode:[{0}/{1}] has't been defined", _shellTypeName, nodeXpath));
            }
            //如果funcCode已经注册
            if (tmp.Funcs.ContainsKey(funcCode.Name))
            {
                throw new Exception(string.Format("FuncCode:[{0}/{1}/{2}] has been registered", _shellTypeName, nodeXpath, funcCode.Name));
            }
            else
            {
                tmp.Funcs.Add(funcCode.Name, funcCode);
            }
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
0
        private static readonly string SettingXmlPath      = Environment.CurrentDirectory + "/";//const是编译时常数(默认是静态),readonly是运行时常数(默认不是静态)

        /// <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);
                        }
                    }
                }
            }
        }