public Database(string path, string databaseName) { if (string.IsNullOrEmpty(path)) throw new ArgumentNullException("path"); if (string.IsNullOrEmpty(databaseName)) throw new ArgumentNullException("databaseName"); _server = MagpieServer.Create(path); _database = _server.GetDatabase(databaseName); }
/// <summary> /// 数据库配置 /// </summary> /// <param name="server">数据库服务器</param> /// <param name="databaseName">数据库名称</param> public MagpieDatabaseSettings(MagpieServer server, string databaseName) { if (server == null) { throw new ArgumentNullException("server"); } if (databaseName == null) { throw new ArgumentNullException("databaseName"); } _server = server; _databaseName = databaseName; }
/// <summary> /// 数据库配置 /// </summary> /// <param name="server">数据库服务器</param> /// <param name="databaseName">数据库名称</param> public MagpieDatabaseSettings(MagpieServer server, string databaseName) { if (server == null) { throw new ArgumentNullException("server"); } if (databaseName == null) { throw new ArgumentNullException("databaseName"); } _server = server; _databaseName = databaseName; }
/// <summary> /// 数据库 /// </summary> /// <param name="server">数据库所属服务器</param> /// <param name="settings">数据库配置</param> public MagpieDatabase(MagpieServer server, MagpieDatabaseSettings settings) { if (server == null) { throw new ArgumentNullException("server"); } if (settings == null) { throw new ArgumentNullException("settings"); } if (!server.IsDatabaseNameValid(settings.DatabaseName)) { throw new ArgumentException("Invalid database name."); } _server = server; _settings = settings; _name = settings.DatabaseName; }
/// <summary> /// 根据数据库配置生成数据库服务器 /// </summary> /// <param name="settings">数据库配置</param> /// <returns>数据库服务器</returns> public static MagpieServer Create(MagpieServerSettings settings) { if (settings == null) { throw new ArgumentNullException("settings"); } lock (__staticLock) { MagpieServer server; if (!__servers.TryGetValue(settings, out server)) { if (__servers.Count >= MaxServerCount) { var message = string.Format(CultureInfo.InvariantCulture, "Already created {0} servers which is the maximum number of servers allowed.", MaxServerCount); throw new MagpieException(message); } server = new MagpieServer(settings); __servers.Add(settings, server); } return(server); } }
/// <summary> /// 根据数据库配置生成数据库服务器 /// </summary> /// <param name="settings">数据库配置</param> /// <returns>数据库服务器</returns> public static MagpieServer Create(MagpieServerSettings settings) { if (settings == null) throw new ArgumentNullException("settings"); lock (__staticLock) { MagpieServer server; if (!__servers.TryGetValue(settings, out server)) { if (__servers.Count >= MaxServerCount) { var message = string.Format(CultureInfo.InvariantCulture, "Already created {0} servers which is the maximum number of servers allowed.", MaxServerCount); throw new MagpieException(message); } server = new MagpieServer(settings); __servers.Add(settings, server); } return server; } }