private async Task <bool> InitializeDatabaseAsync() { bool isSuccess = true; try { var migrator = new DbMigrator(); if (!migrator.DatabaseExists()) { // Create the database if it doesn't exist this.ShowProgressRing = true; LogClient.Info("Creating database"); await Task.Run(() => migrator.InitializeNewDatabase()); } else { // Upgrade the database if it is not the latest version if (migrator.DatabaseNeedsUpgrade()) { this.ShowProgressRing = true; LogClient.Info("Upgrading database"); await Task.Run(() => migrator.UpgradeDatabase()); } } } catch (Exception ex) { LogClient.Error("There was a problem initializing the database. Exception: {0}", ex.Message); this.errorMessage = ex.Message; isSuccess = false; } return(isSuccess); }
private async Task InitializeStorageIfRequiredAsync(string newLocation) { await Task.Run(() => { // Database file var migrator = new DbMigrator(newLocation); if (migrator.DatabaseExists()) { migrator.UpgradeDatabase(); } else { migrator.InitializeNewDatabase(); } // Notes directory string notesDirectoryPath = newLocation; if (!Directory.Exists(notesDirectoryPath)) { Directory.CreateDirectory(notesDirectoryPath); } }); }