/// <summary> /// Gets the providers for the books and geography data. /// </summary> /// <param name="geographyProvider">The geography data provider on exit.</param> /// <param name="booksReadProvider">The books data provider on exit.</param> /// <returns>True if successful, false otherwise.</returns> protected bool GetProviders(out GeographyProvider geographyProvider, out BooksReadProvider booksReadProvider) { geographyProvider = null; booksReadProvider = null; if (!_booksReadDatabase.ReadFromDatabase) { _booksReadDatabase.ConnectToDatabase(); } if (!_nationsReadDatabase.ReadFromDatabase) { _nationsReadDatabase.ConnectToDatabase(); } if (_booksReadDatabase.ReadFromDatabase && _nationsReadDatabase.ReadFromDatabase) { // Setup the providers. geographyProvider = new GeographyProvider(); geographyProvider.Setup(_nationsReadDatabase.LoadedItems); booksReadProvider = new BooksReadProvider(); booksReadProvider.Setup(_booksReadDatabase.LoadedItems, geographyProvider); return(true); } return(false); }
/// <summary> /// The get books from database command action. /// </summary> private void GetBooksCommandAction() { _booksReadDatabase.ConnectToDatabase(); if (_booksReadDatabase.ReadFromDatabase) { _booksReadFromDatabase = _booksReadDatabase.LoadedItems; OnPropertyChanged(() => Books); } }
public async Task SetupRemoteCollections() { string connection = SettingsVm.LocalConnectionString; try { RemoteDatabaseCollections.Clear(); _remoteBooksReadDatabase = new BooksReadDatabase(connection, true); _remoteBooksReadDatabase.MongoClientFunc = GetRemoteConnection; //_remoteBooksReadDatabase.ResetLoadedItems(); _remoteBooksReadDatabase.ConnectToDatabase(); RemoteDatabaseCollections.Add(new DataCollectionSettings(_remoteBooksReadDatabase)); _remoteNationDatabase = new NationDatabase(connection, true); _remoteNationDatabase.MongoClientFunc = GetRemoteConnection; //_remoteNationDatabase.ResetLoadedItems(); _remoteNationDatabase.ConnectToDatabase(); RemoteDatabaseCollections.Add(new DataCollectionSettings(_remoteNationDatabase)); _remoteUserDatabase = new UserDatabase(connection, true); _remoteUserDatabase.MongoClientFunc = GetRemoteConnection; //_remoteUserDatabase.ResetLoadedItems(); _remoteUserDatabase.ConnectToDatabase(); RemoteDatabaseCollections.Add(new DataCollectionSettings(_remoteUserDatabase)); NotifyOfPropertyChange(() => RemoteDatabaseCollections); } catch (Exception e) { Console.WriteLine(e); throw; } }
public async Task SetupLocalCollections() { string connection = SettingsVm.LocalConnectionString; LocalDatabaseCollections.Clear(); _localBooksReadDatabase = new BooksReadDatabase(connection); _localBooksReadDatabase.ConnectToDatabase(); LocalDatabaseCollections.Add(new DataCollectionSettings(_localBooksReadDatabase)); _localNationDatabase = new NationDatabase(LocalConnectionString); _localNationDatabase.ConnectToDatabase(); LocalDatabaseCollections.Add(new DataCollectionSettings(_localNationDatabase)); _localUserDatabase = new UserDatabase(LocalConnectionString); _localUserDatabase.ConnectToDatabase(); LocalDatabaseCollections.Add(new DataCollectionSettings(_localUserDatabase)); NotifyOfPropertyChange(() => LocalDatabaseCollections); }
public BooksDataControllerUtilities(MongoDbSettings dbSettings, SmtpConfig mailConfig) : base(dbSettings) { _smtpConfig = mailConfig; DatabaseConnectionString = dbSettings.DatabaseConnectionString; ExportDirectory = dbSettings.ExportDirectory; _books = new ObservableCollection <Book>(); _booksReadFromDatabase = new ObservableCollection <BookRead>(); _nationsReadFromDatabase = new ObservableCollection <Nation>(); _usersReadFromDatabase = new ObservableCollection <User>(); if (!dbSettings.UseRemoteHost) { _booksReadDatabase = new BooksReadDatabase(DatabaseConnectionString); _nationsReadDatabase = new NationDatabase(DatabaseConnectionString); _userDatabase = new UserDatabase(DatabaseConnectionString); } else { _booksReadDatabase = new BooksReadDatabase(string.Empty, false) { MongoClientFunc = GetRemoteConnection }; _booksReadDatabase.ConnectToDatabase(); _nationsReadDatabase = new NationDatabase(string.Empty, false) { MongoClientFunc = GetRemoteConnection }; _nationsReadDatabase.ConnectToDatabase(); _userDatabase = new UserDatabase(string.Empty, false) { MongoClientFunc = GetRemoteConnection }; _userDatabase.ConnectToDatabase(); } }