Esempio n. 1
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;
     }
 }
Esempio n. 2
0
 /// <summary>
 /// 获取配置文件真实值
 /// </summary>
 /// <param name="value">原始值</param>
 /// <param name="map">设置信息</param>
 /// <returns>真实值</returns>
 private static string GetRealValue(string value, PathMapAttribute map)
 {
     if (map.IsDecrypt)
     {
         return(DESEncrypt.Decrypt(value));
     }
     else if (map.AppDataDirectoryConvert)
     {
         if (value.Contains("|DataDirectory|"))
         {
             return(value.Replace("|DataDirectory|", AppDomain.CurrentDomain.BaseDirectory + "App_Data"));
         }
     }
     return(value);
 }
Esempio n. 3
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
            {
                if (File.Exists(ConfigLocalPath))
                {
                    //读取本地配置文件
                    doc.Load(ConfigLocalPath);
                    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));
                    }
                }
                //读取服务器配置文件信息
                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));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return("");
        }