private static T InitRepository <T>() { if (GetInstance() == null) { throw new InvalidOperationException("Database is not specified"); } var type = typeof(T); var instance = _repos[type]; if (instance == null) { // ugly if-else. will be refactored if will cause problems if (type == typeof(FileRepository)) { instance = FileRepository.Create(); } else if (type == typeof(FavoritesRepository)) { instance = FavoritesRepository.Create(); } else if (type == typeof(FolderRefRepository)) { instance = FolderRefRepository.Create(); } else { throw new InvalidOperationException(); } _repos[type] = instance; } return((T)instance); }
private void Create() { if (DatabaseFileExists()) { throw new InvalidOperationException(String.Format("Database file {0} already exists", _dbFileName)); } SQLiteConnection.CreateFile(_dbFileName); FileRepository.Create(this); FavoritesRepository.Create(this); FolderRefRepository.Create(this); }