public static void ReadXml(string fileName,
                            string basePathDir,
                            ref CustomShellType.Basic basicSetting,
                            ref CustomShellType.MainCode mainCode)
 {
     string filePath = basePathDir + fileName;
     try
     {
         XmlDocument xml = new XmlDocument(); //初始化一个xml实例
         xml.Load(filePath); //导入指定xml文件
         XmlNode root = xml.SelectSingleNode("/customShellType"); //指定一个节点
         XmlNodeList childlist = root.ChildNodes; //获取节点下所有直接子节点
         foreach (XmlNode child in childlist)
         {
             if (child.Name == "basicSetting")
             {
                 basicSetting = ReadBasicSettingNode(child);
             }
             else if (child.Name == "mainCodeSetting")
             {
                 mainCode = ReadMainCodeSettingNode(child);
             }
         }
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
 public static void AddShellType(CustomShellType newShellType)
 {
     try
     {
         //检查基本字段是否被设置
         if (string.IsNullOrEmpty(newShellType.ShellTypeName))
         {
             throw new Exception("ShellTypeName is Null Or Empty");
         }
         //检查shelltype是否被已经存储
         if (_shellTypeStyleContainer.ContainsKey(newShellType.ShellTypeName))
         {
             throw new Exception("The ShellTypeName already exists");
         }
         //存储
         _shellTypeStyleContainer.Add(newShellType.ShellTypeName, newShellType);
     }
     catch
     {
         throw;
     }
 }
Example #3
0
 public static void AddShellType(CustomShellType newShellType)
 {
     try
     {
         //检查基本字段是否被设置
         if (string.IsNullOrEmpty(newShellType.ShellTypeName))
         {
             throw new Exception("ShellTypeName is Null Or Empty");
         }
         //检查shelltype是否被已经存储
         if (_shellTypeStyleContainer.ContainsKey(newShellType.ShellTypeName))
         {
             throw new Exception("The ShellTypeName already exists");
         }
         //存储
         _shellTypeStyleContainer.Add(newShellType.ShellTypeName, newShellType);
     }
     catch
     {
         throw;
     }
 }
Example #4
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);
                        }
                    }
                }
            }
        }
        /// <summary>
        /// 写xml文件
        /// </summary>
        public static void WriteXml(string shellTypeName,
                                    string basePathDir,
                                    CustomShellType.Basic basicSetting,
                                    CustomShellType.MainCode mainCode,
                                    List<CustomShellType.FuncCode> funcCodeList)
        {
            XmlTextWriter xmlWriter = null;
            string filename = string.Format(basePathDir + "{0}", shellTypeName);
            try
            {
                xmlWriter = new XmlTextWriter(filename, Encoding.UTF8);
                xmlWriter.Formatting = Formatting.Indented;
                xmlWriter.WriteStartDocument();

                xmlWriter.WriteStartElement("customShellType");
                {
                    //BasicSetting
                    xmlWriter.WriteStartElement("basicSetting");
                    {
                        xmlWriter.WriteStartElement("name");
                        xmlWriter.WriteString(shellTypeName.Substring(0, shellTypeName.Length - 4));
                        xmlWriter.WriteEndElement();

                        xmlWriter.WriteStartElement("serviceExample");
                        xmlWriter.WriteCData(basicSetting.ServiceExample);
                        xmlWriter.WriteEndElement();

                        xmlWriter.WriteStartElement("mainCodeParam");
                        {
                            xmlWriter.WriteStartAttribute("location");
                            xmlWriter.WriteString(basicSetting.MainCodeParam.Location);
                            xmlWriter.WriteEndAttribute();

                            xmlWriter.WriteStartAttribute("encrymode");
                            xmlWriter.WriteString(basicSetting.MainCodeParam.EncryMode.ToString());
                            xmlWriter.WriteEndAttribute();

                            xmlWriter.WriteString(basicSetting.MainCodeParam.Name);
                        }
                        xmlWriter.WriteEndElement();
                    }
                    xmlWriter.WriteEndElement();

                    //MainCodeSetting
                    xmlWriter.WriteStartElement("mainCodeSetting");
                    {
                        xmlWriter.WriteStartElement("funcCodeParam");
                        {
                            xmlWriter.WriteStartAttribute("location");
                            xmlWriter.WriteString(mainCode.FuncCodeParam.Location);
                            xmlWriter.WriteEndAttribute();

                            xmlWriter.WriteStartAttribute("encrymode");
                            xmlWriter.WriteString(mainCode.FuncCodeParam.EncryMode.ToString());
                            xmlWriter.WriteEndAttribute();

                            xmlWriter.WriteString(mainCode.FuncCodeParam.Name);
                        }
                        xmlWriter.WriteEndElement();

                        xmlWriter.WriteStartElement("item");
                        xmlWriter.WriteCData(mainCode.Item);
                        xmlWriter.WriteEndElement();
                    }
                    xmlWriter.WriteEndElement();

                    //FuncCodeSetting
                    xmlWriter.WriteStartElement("funcCodeSetting");
                    {
                        foreach (CustomShellType.FuncCode func in funcCodeList)
                        {
                            xmlWriter.WriteStartElement("func");
                            {
                                xmlWriter.WriteStartElement("name");
                                xmlWriter.WriteString(func.Name);
                                xmlWriter.WriteEndElement();

                                foreach (CustomShellType.ParamStruct par in func.FuncParams)
                                {
                                    xmlWriter.WriteStartElement("funcParameter");
                                    {
                                        xmlWriter.WriteStartAttribute("location");
                                        xmlWriter.WriteString(par.Location);
                                        xmlWriter.WriteEndAttribute();

                                        xmlWriter.WriteStartAttribute("encrymode");
                                        xmlWriter.WriteString(par.EncryMode.ToString());
                                        xmlWriter.WriteEndAttribute();

                                        xmlWriter.WriteString(par.Name);
                                    }
                                    xmlWriter.WriteEndElement();
                                }

                                xmlWriter.WriteStartElement("item");
                                xmlWriter.WriteCData(func.Item);
                                xmlWriter.WriteEndElement();
                            }
                            xmlWriter.WriteEndElement();
                        }
                    }
                    xmlWriter.WriteEndElement();
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                xmlWriter.Close();
            }
        }
Example #6
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);
                        }
                    }
                }
            }
        }
Example #7
0
 public CustomCommandCode(CustomShellType customShellType, string pass)
 {
     _customShellType = customShellType;
     _pass = pass;
     _randomParam = new Dictionary<string, string>();
 }
Example #8
0
        private Dictionary<string, string> GetCode(CustomShellType customShellType,
                                                   string pass,
                                                   CustomShellType.FuncCode funcCode,
                                                   string[] parmas)
        {
            DataCombine dataCombine = new DataCombine();
            Dictionary<string, string> dic = new Dictionary<string, string>();
            //MainCodeSetting
            string mainCodeString =
                FillParams(customShellType.MainCodeSetting.Item, customShellType.MainCodeSetting.FuncCodeParam);

            NameValueCollection mainCodeItem = new NameValueCollection
            {
                {pass, EncryItem(customShellType.BasicSetting.MainCodeParam.EncryMode, mainCodeString)}
            };
            AddItemToDic(dic, customShellType.BasicSetting.MainCodeParam.Location, dataCombine.CombineToStr(mainCodeItem));

            //FuncCode
            string funcCodeString = "";
            if (funcCode.FuncParams.Count > 0)
            {
                funcCodeString = FillParams(funcCode.Item, funcCode.FuncParams);
            }
            else
            {
                funcCodeString = funcCode.Item;
            }
            //判断是否随机参数
            string funcParamName = customShellType.MainCodeSetting.FuncCodeParam.Name;
            if (GlobalSetting.IsParamRandom)
            {
                string newguid = _randomParam[funcParamName];
                funcParamName = newguid;
            }
            NameValueCollection funcCodeItem = new NameValueCollection
            {
                {funcParamName, EncryItem(customShellType.MainCodeSetting.FuncCodeParam.EncryMode, funcCodeString)}
            };
            AddItemToDic(dic, customShellType.MainCodeSetting.FuncCodeParam.Location, dataCombine.CombineToStr(funcCodeItem));
            //FunParma
            if (parmas != null && parmas.Length > 0)
            {
                if (parmas.Length != funcCode.FuncParams.Count)
                {
                    throw new Exception("调用方法的参数个数与实现代码的参数个数不符合");
                }
                for (int i = 0; i < parmas.Length; i++)
                {
                    string parName = funcCode.FuncParams[i].Name;
                    if (GlobalSetting.IsParamRandom)
                    {
                        string newguid = _randomParam[parName];
                        parName = newguid;
                    }

                    NameValueCollection item = new NameValueCollection
                    {
                        {parName, EncryItem(funcCode.FuncParams[i].EncryMode, parmas[i])}
                    };
                    AddItemToDic(dic, funcCode.FuncParams[i].Location, dataCombine.CombineToStr(item));

                    //dataCombine.AddFuncParmaItem("z" + (i + 1), EncryItem(FuncCode.FuncParmaEncryMode, parmas[i]));
                }
                //AddItemToDic(dic, FuncCode.FuncParmaLocation, dataCombine.CombineToStr(dataCombine.FuncParmaItems));
            }
            return dic;
        }
Example #9
0
 public CustomCommandCode(CustomShellType customShellType, string pass)
 {
     _customShellType = customShellType;
     _pass            = pass;
     _randomParam     = new Dictionary <string, string>();
 }
Example #10
0
        private Dictionary <string, string> GetCode(CustomShellType customShellType,
                                                    string pass,
                                                    CustomShellType.FuncCode funcCode,
                                                    string[] parmas)
        {
            DataCombine dataCombine         = new DataCombine();
            Dictionary <string, string> dic = new Dictionary <string, string>();
            //MainCodeSetting
            string mainCodeString =
                FillParams(customShellType.MainCodeSetting.Item, customShellType.MainCodeSetting.FuncCodeParam);

            NameValueCollection mainCodeItem = new NameValueCollection
            {
                { pass, EncryItem(customShellType.BasicSetting.MainCodeParam.EncryMode, mainCodeString) }
            };

            AddItemToDic(dic, customShellType.BasicSetting.MainCodeParam.Location, dataCombine.CombineToStr(mainCodeItem));

            //FuncCode
            string funcCodeString = "";

            if (funcCode.FuncParams.Count > 0)
            {
                funcCodeString = FillParams(funcCode.Item, funcCode.FuncParams);
            }
            else
            {
                funcCodeString = funcCode.Item;
            }
            //判断是否随机参数
            string funcParamName = customShellType.MainCodeSetting.FuncCodeParam.Name;

            if (GlobalSetting.IsParamRandom)
            {
                string newguid = _randomParam[funcParamName];
                funcParamName = newguid;
            }
            NameValueCollection funcCodeItem = new NameValueCollection
            {
                { funcParamName, EncryItem(customShellType.MainCodeSetting.FuncCodeParam.EncryMode, funcCodeString) }
            };

            AddItemToDic(dic, customShellType.MainCodeSetting.FuncCodeParam.Location, dataCombine.CombineToStr(funcCodeItem));
            //FunParma
            if (parmas != null && parmas.Length > 0)
            {
                if (parmas.Length != funcCode.FuncParams.Count)
                {
                    throw new Exception("调用方法的参数个数与实现代码的参数个数不符合");
                }
                for (int i = 0; i < parmas.Length; i++)
                {
                    string parName = funcCode.FuncParams[i].Name;
                    if (GlobalSetting.IsParamRandom)
                    {
                        string newguid = _randomParam[parName];
                        parName = newguid;
                    }

                    NameValueCollection item = new NameValueCollection
                    {
                        { parName, EncryItem(funcCode.FuncParams[i].EncryMode, parmas[i]) }
                    };
                    AddItemToDic(dic, funcCode.FuncParams[i].Location, dataCombine.CombineToStr(item));

                    //dataCombine.AddFuncParmaItem("z" + (i + 1), EncryItem(FuncCode.FuncParmaEncryMode, parmas[i]));
                }
                //AddItemToDic(dic, FuncCode.FuncParmaLocation, dataCombine.CombineToStr(dataCombine.FuncParmaItems));
            }
            return(dic);
        }