Example #1
0
        /// <summary>
        /// 通过键读取配置文件信息
        /// </summary>
        /// <param name="PathMap">自定义属性信息</param>
        /// <returns>值</returns>
        private static string GetConfigValue(PathMapAttribute PathMap)
        {
            if (!File.Exists(ConfigPath))
            {
                return("");
            }
            string       path = GetXmlPath(PathMap.Key, PathMap.XmlPath);
            XmlNode      node = null;
            XmlAttribute attr = null;

            try
            {
                //读取服务器配置文件信息
                doc.Load(ConfigPath);
                node = doc.SelectSingleNode(path);
                if (node != null)
                {
                    attr = node.Attributes["value"];
                    if (attr == null)
                    {
                        throw new Exception("服务器配置文件设置异常,节点" + PathMap.Key + "没有相应的value属性,请检查!");
                    }
                    return(GetRealValue(attr.Value, PathMap.IsDecrypt));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return("");
        }
Example #2
0
 /// <summary>
 /// 初始化配置信息
 /// </summary>
 public static void InitConfig()
 {
     try
     {
         doc = new XmlDocument();
         if (!File.Exists(ConfigPath))
         {
             return;
         }
         Type             type    = typeof(SysConfig);
         PropertyInfo[]   Props   = type.GetProperties(flags);
         PathMapAttribute PathMap = null;
         foreach (var prop in Props)
         {
             PathMap = GetMyAttribute <PathMapAttribute>(prop, false);
             if (PathMap != null)
             {
                 prop.SetValue(null, Convert.ChangeType(GetConfigValue(PathMap), prop.PropertyType), null);
             }
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }