Example #1
0
 /// <summary>
 /// 获取或快速创建一个表配置
 /// </summary>
 /// <param name="name"></param>
 /// <returns></returns>
 public SettingTable this[string name] {
     get {
         // 从已有的平台配置中查找
         for (int i = 0; i < this.Tables.Count; i++)
         {
             if (this.Tables[i].Name == name)
             {
                 return(this.Tables[i]);
             }
         }
         // 添加一个新的平台配置
         SettingTable table = new SettingTable();
         table.Name = name;
         this.Tables.Add(table);
         return(table);
     }
 }
Example #2
0
        /// <summary>
        /// 对象实例化
        /// </summary>
        /// <param name="xml"></param>
        public Setting(string xml = null)
        {
            this.Platforms = new List <SettingPlatform>();
            if (!xml.IsNoneOrNull())
            {
                using (var doc = dpz3.Xml.Parser.GetDocument(xml)) {
                    // 读取数据库设置
                    var database = doc["database"];
                    this.FillData(database);

                    // 读取平台信息
                    var platforms = database.GetNodesByTagName("platform", false);
                    foreach (var platform in platforms)
                    {
                        // 添加平台信息
                        SettingPlatform settingPlatform = new SettingPlatform();
                        this.Platforms.Add(settingPlatform);

                        // 设置平台信息
                        settingPlatform.FillData(platform);

                        // 读取平台中的表定义
                        var tables = platform.GetNodesByTagName("table", false);
                        foreach (var table in tables)
                        {
                            // 添加表信息
                            SettingTable settingTable = new SettingTable();
                            settingPlatform.Tables.Add(settingTable);

                            // 设置表信息
                            settingTable.FillData(table);
                        }
                    }
                }
            }
        }