Пример #1
0
        /// <summary>
        /// 获取指定名称的数据库
        /// </summary>
        /// <param name="databaseName">数据库名称</param>
        /// <returns>数据库</returns>
        public virtual MagpieDatabase GetDatabase(string databaseName)
        {
            if (string.IsNullOrEmpty(databaseName))
            {
                throw new ArgumentNullException("databaseName");
            }

            var databaseSettings = new MagpieDatabaseSettings(this, databaseName);

            return(GetDatabase(databaseSettings));
        }
Пример #2
0
        /// <summary>
        /// 删除指定名称的数据库
        /// </summary>
        /// <param name="databaseName">数据库名称</param>
        public virtual void DropDatabase(string databaseName)
        {
            if (string.IsNullOrEmpty(databaseName))
            {
                throw new ArgumentNullException("databaseName");
            }

            lock (_serverLock)
            {
                var databaseSettings = new MagpieDatabaseSettings(this, databaseName);
                _databases.Remove(databaseSettings);

                Directory.Delete(databaseSettings.Path, true);
            }
        }
Пример #3
0
        /// <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;
        }
Пример #4
0
        /// <summary>
        /// 获取指定配置的数据库
        /// </summary>
        /// <param name="databaseSettings">数据库配置</param>
        /// <returns>数据库</returns>
        protected virtual MagpieDatabase GetDatabase(MagpieDatabaseSettings databaseSettings)
        {
            if (databaseSettings == null)
            {
                throw new ArgumentNullException("databaseSettings");
            }

            lock (_serverLock)
            {
                MagpieDatabase database;
                if (!_databases.TryGetValue(databaseSettings, out database))
                {
                    database = new MagpieDatabase(this, databaseSettings);
                    _databases.Add(databaseSettings, database);

                    Directory.CreateDirectory(databaseSettings.Path);
                }
                return(database);
            }
        }
Пример #5
0
    /// <summary>
    /// 删除指定名称的数据库
    /// </summary>
    /// <param name="databaseName">数据库名称</param>
    public virtual void DropDatabase(string databaseName)
    {
      if (string.IsNullOrEmpty(databaseName))
      {
        throw new ArgumentNullException("databaseName");
      }

      lock (_serverLock)
      {
        var databaseSettings = new MagpieDatabaseSettings(this, databaseName);
        _databases.Remove(databaseSettings);

        Directory.Delete(databaseSettings.Path, true);
      }
    }
Пример #6
0
    /// <summary>
    /// 获取指定配置的数据库
    /// </summary>
    /// <param name="databaseSettings">数据库配置</param>
    /// <returns>数据库</returns>
    protected virtual MagpieDatabase GetDatabase(MagpieDatabaseSettings databaseSettings)
    {
      if (databaseSettings == null)
        throw new ArgumentNullException("databaseSettings");

      lock (_serverLock)
      {
        MagpieDatabase database;
        if (!_databases.TryGetValue(databaseSettings, out database))
        {
          database = new MagpieDatabase(this, databaseSettings);
          _databases.Add(databaseSettings, database);

          Directory.CreateDirectory(databaseSettings.Path);
        }
        return database;
      }
    }
Пример #7
0
    /// <summary>
    /// 获取指定名称的数据库
    /// </summary>
    /// <param name="databaseName">数据库名称</param>
    /// <returns>数据库</returns>
    public virtual MagpieDatabase GetDatabase(string databaseName)
    {
      if (string.IsNullOrEmpty(databaseName))
      {
        throw new ArgumentNullException("databaseName");
      }

      var databaseSettings = new MagpieDatabaseSettings(this, databaseName);
      return GetDatabase(databaseSettings);
    }