Пример #1
0
        public static void AddDictor(XmlNode ChildNodeItem, Dictionary<string, XmlConfigModels> xmlData, string FunctionTitle)
        {
            XmlConfigModels XmlConfigModel = new XmlConfigModels();
            XmlConfigModel.FatherNode = FunctionTitle;
            XmlConfigModel.Name = Convert.ToString(ChildNodeItem.SelectSingleNode("Name").InnerText);
            XmlConfigModel.Value = Convert.ToString(ChildNodeItem.SelectSingleNode("Value").InnerText);

            XmlConfigModel.FunctionTitle = ChildNodeItem.Name;
            xmlData.Add(Convert.ToString(ChildNodeItem.Name), XmlConfigModel);
        }
Пример #2
0
        /// <summary>
        /// 读取配置管理文件的Xml
        /// 作者:答旭
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static Dictionary<string, XmlConfigModels> ReadConfigXmlFile(string path)
        {
            //测试数据
            Dictionary<string, XmlConfigModels> xmlData = new Dictionary<string, XmlConfigModels>();
            Dictionary<string, XmlConfigModels> obj = HttpContext.Current.Cache.Get("ReadConfigXmlFile") as Dictionary<string, XmlConfigModels>;
            if (obj == null)
            {

                XmlConfigModels TimeXmList = new XmlConfigModels();
                if (!string.IsNullOrEmpty(path))
                {
                    XmlDocument xmlConvertMapping = new XmlDocument();
                    string filename = HttpContext.Current.Server.MapPath(path);
                    if (File.Exists(filename))
                    {
                        xmlConvertMapping.Load(filename);
                    }
                    else
                    {
                        xmlConvertMapping = null;
                    }
                    if (xmlConvertMapping != null)
                    {
                        if (xmlConvertMapping.SelectNodes("DataInfo/Module/Contents").Count > 0)
                        {
                            XmlNodeList NodeList = xmlConvertMapping.SelectNodes("DataInfo/Module/Contents/Item");
                            //获取所有Item
                            foreach (XmlNode Item in NodeList)
                            {

                                string FunctionTitle = Item.SelectSingleNode("FunctionTitle").InnerText;
                                //获取Item下的项目
                                XmlNodeList ItemList = Item.SelectNodes("ItemList");
                                //给实体数据赋值
                                foreach (XmlNode ItemNodeList in ItemList)
                                {
                                    XmlNodeList ChildItem = ItemNodeList.ChildNodes;
                                    foreach (XmlNode ChildNodeItem in ChildItem)
                                    {

                                        switch (ChildNodeItem.Name)
                                        {
                                            case "Admin":
                                                AddDictor(ChildNodeItem, xmlData, FunctionTitle);
                                                break;
                                            case "Copyright":
                                                AddDictor(ChildNodeItem, xmlData, FunctionTitle);
                                                break;
                                            case "NetworkAddress":
                                                AddDictor(ChildNodeItem, xmlData, FunctionTitle);
                                                break;
                                            case "OutsideAddress":
                                                AddDictor(ChildNodeItem, xmlData, FunctionTitle);
                                                break;
                                            case "Port":
                                                AddDictor(ChildNodeItem, xmlData, FunctionTitle);
                                                break;
                                            case "Prefix":
                                                AddDictor(ChildNodeItem, xmlData, FunctionTitle);
                                                break;
                                            case "Psw":
                                                AddDictor(ChildNodeItem, xmlData, FunctionTitle);
                                                break;
                                            case "SystemTitle":
                                                AddDictor(ChildNodeItem, xmlData, FunctionTitle);
                                                break;
                                            case "VAddress":
                                                AddDictor(ChildNodeItem, xmlData, FunctionTitle);
                                                break;
                                            case "VAdmin":
                                                AddDictor(ChildNodeItem, xmlData, FunctionTitle);
                                                break;
                                            case "VALLuserPsw":
                                                AddDictor(ChildNodeItem, xmlData, FunctionTitle);
                                                break;
                                            case "VANameRules":
                                                AddDictor(ChildNodeItem, xmlData, FunctionTitle);
                                                break;
                                            case "VApsw":
                                                AddDictor(ChildNodeItem, xmlData, FunctionTitle);
                                                break;
                                            case "VAptVersion":
                                                AddDictor(ChildNodeItem, xmlData, FunctionTitle);
                                                break;
                                            case "VAuserCount":
                                                AddDictor(ChildNodeItem, xmlData, FunctionTitle);
                                                break;
                                            case "WebAddres":
                                                AddDictor(ChildNodeItem, xmlData, FunctionTitle);
                                                break;
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            return null;
                        }
                        HttpContext.Current.Cache.Add("ReadConfigXmlFile", xmlData, null, System.Web.Caching.Cache.NoAbsoluteExpiration, System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Normal, null);
                    }
                }
                return xmlData;
            }
            else
            {
                return obj;
            }
        }
Пример #3
0
        /// <summary>
        /// 修改配置管理中的Xml文件
        /// 作者:答旭
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static bool UpdataConfigXmlFile(XmlConfigModels XmlConfigModel, string path)
        {
            //实现思路:
            //1,清除历史缓存
            //2,遍历节点,修改节点的值
            //3,在加入到缓存中
            bool isDel = false;
            HttpContext.Current.Cache.Remove("ReadConfigXmlFile");
            XmlConfigModels TimeXmList = new XmlConfigModels();
            if (!string.IsNullOrEmpty(path))
            {

                XmlDocument xmlConvertMapping = new XmlDocument();
                string filename = HttpContext.Current.Server.MapPath(path);
                if (File.Exists(filename))
                    xmlConvertMapping.Load(filename);

                if (xmlConvertMapping != null)
                {
                    if (xmlConvertMapping.SelectNodes("DataInfo/Module/Contents").Count > 0)
                    {
                        XmlNodeList NodeList = xmlConvertMapping.SelectNodes("DataInfo/Module/Contents/Item");
                        //获取所有Item
                        foreach (XmlNode Item in NodeList)
                        {

                            string FunctionTitle = Item.SelectSingleNode("FunctionTitle").InnerText;

                            //获取Item下的项目
                            XmlNodeList ItemList = Item.SelectNodes("ItemList");
                            //给实体数据赋值
                            foreach (XmlNode ItemNodeList in ItemList)
                            {

                                XmlNodeList ChildItem = ItemNodeList.ChildNodes;

                                foreach (XmlNode ChildNodeItem in ChildItem)
                                {

                                    switch (ChildNodeItem.Name)
                                    {
                                        case "Admin":
                                            ChildNodeItem.SelectSingleNode("Value").InnerText = XmlConfigModel.Admin;
                                            break;
                                        case "Copyright":
                                            ChildNodeItem.SelectSingleNode("Value").InnerText = XmlConfigModel.Copyright;
                                            break;
                                        case "NetworkAddress":
                                            ChildNodeItem.SelectSingleNode("Value").InnerText = XmlConfigModel.NetworkAddress;
                                            break;
                                        case "OutsideAddress":
                                            ChildNodeItem.SelectSingleNode("Value").InnerText = XmlConfigModel.OutsideAddress;
                                            break;
                                        case "Port":
                                            ChildNodeItem.SelectSingleNode("Value").InnerText = XmlConfigModel.Port;
                                            break;
                                        case "Prefix":
                                            ChildNodeItem.SelectSingleNode("Value").InnerText = XmlConfigModel.Prefix;
                                            break;
                                        case "Psw":
                                            ChildNodeItem.SelectSingleNode("Value").InnerText = XmlConfigModel.Psw;
                                            break;
                                        case "SystemTitle":
                                            ChildNodeItem.SelectSingleNode("Value").InnerText = XmlConfigModel.SystemTitle;
                                            break;
                                        case "VAddress":
                                            ChildNodeItem.SelectSingleNode("Value").InnerText = XmlConfigModel.VAddress;
                                            break;
                                        case "VAdmin":
                                            ChildNodeItem.SelectSingleNode("Value").InnerText = XmlConfigModel.VAdmin;
                                            break;
                                        case "VALLuserPsw":
                                            ChildNodeItem.SelectSingleNode("Value").InnerText = XmlConfigModel.VALLuserPsw;
                                            break;
                                        case "VANameRules":
                                            ChildNodeItem.SelectSingleNode("Value").InnerText = XmlConfigModel.VANameRules;
                                            break;
                                        case "VApsw":
                                            ChildNodeItem.SelectSingleNode("Value").InnerText = XmlConfigModel.VApsw;
                                            break;
                                        case "VAptVersion":
                                            ChildNodeItem.SelectSingleNode("Value").InnerText = XmlConfigModel.VAptVersion;
                                            break;
                                        case "VAuserCount":
                                            ChildNodeItem.SelectSingleNode("Value").InnerText = XmlConfigModel.VAuserCount;
                                            break;
                                        case "WebAddres":
                                            ChildNodeItem.SelectSingleNode("Value").InnerText = XmlConfigModel.WebAddres;
                                            break;
                                    }
                                }
                            }
                        }
                        xmlConvertMapping.Save(System.Web.HttpContext.Current.Server.MapPath(path));//保存
                        isDel = true;

                    }
                    else
                    {
                        return isDel;
                    }
                }
            }
            return isDel;
        }