Exemplo n.º 1
0
        private void AddComponent(Type type, DBConfigEntity sysConfig, DBConfigEntity logConfig, MongoClient sysDbClient, MongoClient logDbClient, IMongoDatabase sysDb, IMongoDatabase logDb)
        {
            if (!typeof(IRpository).IsAssignableFrom(type))
            {
                return;
            }

            var isSingle = ObjectStorage.IsSingleType(type);

            if (!isSingle)
            {
                throw new ComponentException("规定Rpository类型组件只能定义成单例(SingleCase)组件。");
            }

            var component = ObjectStorage.Fetch(type);
            var rpository = component as IRpository;

            if (rpository.DBType == DBType.SysDb)
            {
                rpository.SetDBContext(sysDb, sysConfig.DatabaseName, sysDbClient);
                Game.Scene.AddComponent(component);
            }
            else if (rpository.DBType == DBType.LoggerDb)
            {
                rpository.SetDBContext(logDb, logConfig.DatabaseName, logDbClient);
                Game.Scene.AddComponent(component);
            }
        }
Exemplo n.º 2
0
        private async void SaveConfigFile(string fullName)
        {
            Config = new DBConfigEntity
            {
                ConnectionString = "mongodb://localhost:27017",
                DatabaseName     = "H6Game",
            };

            using (var fileStream = new FileStream(fullName, FileMode.OpenOrCreate))
            {
                using (var sr = new StreamWriter(fileStream))
                {
                    var json = Config.ToJson();
                    await sr.WriteAsync(json);

                    await sr.FlushAsync();

                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine($"数据库连接信息未配置,系统会自动生成模板:{fullName}");
                }
            }
        }
Exemplo n.º 3
0
        private bool ReadConfigFile(string path)
        {
            using (var fileStream = new FileStream(path, FileMode.OpenOrCreate))
            {
                using (var sr = new StreamReader(fileStream))
                {
                    var json = sr.ReadToEnd();
                    if (string.IsNullOrEmpty(json))
                    {
                        return(false);
                    }

                    Config = BsonSerializer.Deserialize <DBConfigEntity>(json);
                }
            }

            if (Config == null || string.IsNullOrWhiteSpace(Config.ConnectionString) || string.IsNullOrWhiteSpace(Config.DatabaseName))
            {
                return(false);
            }

            return(true);
        }