예제 #1
0
 /// <summary>
 /// 获取或快速创建一个平台配置
 /// </summary>
 /// <param name="name"></param>
 /// <returns></returns>
 public SettingPlatform this[string name] {
     get {
         // 从已有的平台配置中查找
         for (int i = 0; i < this.Platforms.Count; i++)
         {
             if (this.Platforms[i].Name == name)
             {
                 return(this.Platforms[i]);
             }
         }
         // 添加一个新的平台配置
         SettingPlatform platform = new SettingPlatform();
         platform.Name = name;
         this.Platforms.Add(platform);
         return(platform);
     }
 }
예제 #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);
                        }
                    }
                }
            }
        }