Пример #1
0
        public static XConfig Load()
        {
            if (!File.Exists(DefaultFile))
            {
                return(Create());
            }

            //XmlSerializer xml = new XmlSerializer(typeof(XConfig));
            NewLife.Xml.XmlReaderX xml = new NewLife.Xml.XmlReaderX();
            using (XmlReader xr = XmlReader.Create(DefaultFile))
            {
                try
                {
                    Object obj = null;
                    xml.Reader = xr;
                    if (xml.ReadObject(typeof(XConfig), ref obj, null) && obj != null)
                    {
                        return(obj as XConfig);
                    }
                    return(Create());
                    //return xml.Deserialize(stream) as XConfig;
                }
                catch { return(Create()); }
            }
        }
Пример #2
0
        /// <summary>
        /// 静态构造函数
        /// </summary>
        static AssemblyType()
        {
            s_xmlFilePath = MapPath("~/App_Data") + "\\" + s_xmlFilePath;

            StartXmlWriterThread();

            if (File.Exists(s_xmlFilePath))
            {
                NewLife.Xml.XmlReaderX xml = new NewLife.Xml.XmlReaderX();
                using (XmlReader xr = XmlReader.Create(s_xmlFilePath))
                {
                    try
                    {
                        Object obj = null;
                        xml.Reader = xr;

                        if (xml.ReadObject(typeof(Dictionary <String, AssemblyType>), ref obj, null) && obj != null)
                        {
                            s_dictAssemblyType = obj as Dictionary <String, AssemblyType>;
                        }
                    }
                    catch (Exception ex) { XTrace.WriteException(ex); }
                }
            }
        }
Пример #3
0
        /// <summary>
        /// 静态构造函数
        /// </summary>
        static AssemblyType()
        {
            s_xmlFilePath = MapPath("~/App_Data") + "\\" + s_xmlFilePath;

            StartXmlWriterThread();

            if (File.Exists(s_xmlFilePath))
            {
                NewLife.Xml.XmlReaderX xml = new NewLife.Xml.XmlReaderX();
                using (XmlReader xr = XmlReader.Create(s_xmlFilePath))
                {
                    try
                    {
                        Object obj = null;
                        xml.Reader = xr;

                        if (xml.ReadObject(typeof(Dictionary<String, AssemblyType>), ref obj, null) && obj != null)
                        {
                            s_dictAssemblyType = obj as Dictionary<String, AssemblyType>;
                        }
                    }
                    catch (Exception ex) { XTrace.WriteException(ex); }
                }
            }
        }
Пример #4
0
 /// <summary>
 /// 读取配置文件的配置信息:可能在首次使用初始化的时候存在异常
 /// </summary>   
 public static Dictionary<string, string> LoadDic(string DefaultFile)
 {
     if (!File.Exists(DefaultFile))                
         return new Dictionary<string, string>();               
     NewLife.Xml.XmlReaderX xml = new NewLife.Xml.XmlReaderX();
     using (XmlReader xr = XmlReader.Create(DefaultFile))
     {
         try
         {
             Object obj = null;
             xml.Reader = xr;
             if (xml.ReadObject(typeof(ConfigDictionary ), ref obj, null) && obj != null)
             {
                 return (obj as ConfigDictionary).Items  ;
             }
             throw new XException (ErrorCode.Serializ_ConvertFailed );                    
         }
         catch(Exception err)
         { throw new XException( err.Message ); }
     }
 }
Пример #5
0
        public static XConfig Load()
        {
            if (!File.Exists(DefaultFile)) return Create();

            NewLife.Xml.XmlReaderX xml = new NewLife.Xml.XmlReaderX();
            using (XmlReader xr = XmlReader.Create(DefaultFile))
            {
                try
                {
                    Object obj = null;
                    xml.Reader = xr;
                    if (xml.ReadObject(typeof(XConfig), ref obj, null) && obj != null)
                    {
                        return obj as XConfig;
                    }
                    return Create();
                }
                catch { return Create(); }
            }
        }