Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }