/// <summary> /// Checks if a database exists within the current context. /// </summary> /// <param name="config"></param> /// <param name="name">The name of the database.</param> /// <remarks> /// Databases are stored in a file-system hieratical way: the /// existance of a database within the current context is verified /// by combining the name of the database with the path of the /// current context. /// </remarks> /// <returns> /// Returns true if a database exists at the given path, false otherwise. /// </returns> public bool DatabaseExists(IDbConfig config, string name) { // a fast fail... var database = databases[name] as Database; if (database != null) { if (database.IsInitialized) return true; if (database.Exists) return true; } IDbConfig testConfig; if (config == null) { testConfig = DbConfig.Default; } else { testConfig = (IDbConfig) config.Clone(); } testConfig.Parent = Config; StorageType storageType = GetStorageType(testConfig); if (storageType == StorageType.File) { var basePath = testConfig.BasePath(); if (String.IsNullOrEmpty(basePath)) basePath = ConfigDefaultValues.BasePath; // we ensure that the BasePath points to where we want it to point string path = Path.Combine(basePath, name); return Directory.Exists(path); } return false; }