public void TestMigratingOldDatabase() { string tmpPath = Path.Combine (Path.GetTempPath (), Path.GetRandomFileName ()); string homePath = Path.Combine (tmpPath, "LongoMatch"); string dbPath = Path.Combine (homePath, "db"); string lmdbPath = Path.Combine (dbPath, "longomatch.ldb"); string teamsPath = Path.Combine (dbPath, "teams"); string dashboardsPath = Path.Combine (dbPath, "analysis"); Directory.CreateDirectory (tmpPath); Directory.CreateDirectory (homePath); Directory.CreateDirectory (dbPath); Directory.CreateDirectory (lmdbPath); Directory.CreateDirectory (teamsPath); Directory.CreateDirectory (dashboardsPath); Utils.SaveResource ("spain.ltt", teamsPath); Utils.SaveResource ("france.ltt", teamsPath); Utils.SaveResource ("basket.lct", dashboardsPath); Utils.SaveResource ("spain_france_test.lgm", lmdbPath); // Create an empty project file that shouldn't be converter File.Open (Path.Combine (lmdbPath, "empty.lgm"), FileMode.Create); Directory.CreateDirectory (tmpPath); Environment.SetEnvironmentVariable ("LONGOMATCH_HOME", tmpPath); Environment.SetEnvironmentVariable ("LGM_UNINSTALLED", "1"); App.Init (); CoreServices.Init (); CoreServices.Start (guiToolkitMock.Object, multimediaToolkitMock.Object); Assert.AreEqual (0, App.Current.DatabaseManager.ActiveDB.Count<ProjectLongoMatch> ()); Assert.AreEqual (2, App.Current.TeamTemplatesProvider.Templates.Count); Assert.AreEqual (1, App.Current.CategoriesTemplatesProvider.Templates.Count); DatabaseMigration dbMigration = new DatabaseMigration (Mock.Of<IProgressReport> ()); dbMigration.Start (); App.Current.DatabaseManager.SetActiveByName ("longomatch"); Assert.AreEqual (4, App.Current.TeamTemplatesProvider.Templates.Count); Assert.AreEqual (2, App.Current.CategoriesTemplatesProvider.Templates.Count); Assert.AreEqual (1, App.Current.DatabaseManager.ActiveDB.Count<ProjectLongoMatch> ()); Assert.IsTrue (File.Exists (Path.Combine (dbPath, "templates", "backup", "spain.ltt"))); Assert.IsTrue (File.Exists (Path.Combine (dbPath, "templates", "backup", "france.ltt"))); Assert.IsTrue (File.Exists (Path.Combine (dbPath, "templates", "backup", "basket.lct"))); Assert.IsTrue (File.Exists (Path.Combine (dbPath, "old", "longomatch.ldb", "spain_france_test.lgm"))); CoreServices.Stop (); }
static async Task Init (SplashScreen splashScreen) { IProgressReport progress = splashScreen; try { bool haveCodecs = false; App.Current.DrawingToolkit = new CairoBackend (); App.Current.MultimediaToolkit = new MultimediaToolkit (); App.Current.GUIToolkit = GUIToolkit.Instance; App.Current.Navigation = GUIToolkit.Instance; App.Current.GUIToolkit.Register<IPlayerView, VASUi.PlayerView> (0); App.Current.Dialogs = VASUi.Dialogs.Instance; App.Current.KPIService.Init ("9dc114d23c6148719b4adbe585b811cc", "user", "email"); Task gstInit = Task.Factory.StartNew (() => InitGStreamer (progress)); App.Current.DependencyRegistry.Register<IFileStorage, LMDB.FileStorage> (0); InitAddins (progress); CoreServices.RegisterService (new UpdatesNotifier ()); CoreServices.Start (App.Current.GUIToolkit, App.Current.MultimediaToolkit); AddinsManager.LoadDashboards (App.Current.CategoriesTemplatesProvider); AddinsManager.LoadImportProjectAddins (CoreServices.ProjectsImporter); // Migrate the old databases now that the DB and Templates services have started DatabaseMigration dbMigration = new DatabaseMigration (progress); Task dbInit = Task.Factory.StartNew (dbMigration.Start); // Wait for Migration and the GStreamer initialization try { await Task.WhenAll (gstInit, dbInit); } catch (AggregateException ae) { throw ae.Flatten (); } if (!AddinsManager.RegisterGStreamerPlugins ()) { ShowCodecsDialog (); } splashScreen.Destroy (); ConfigureOSXApp (); (GUIToolkit.Instance.MainController as MainWindow).Initialize (); App.Current.StateController.SetHomeTransition ("Home", null); } catch (Exception ex) { ProcessExecutionError (ex); } }
public void TestNoOldDatabaseToMigrate() { string tmpPath = Path.Combine (Path.GetTempPath (), Path.GetRandomFileName ()); string homePath = Path.Combine (tmpPath, "LongoMatch"); string dbPath = Path.Combine (homePath, "db"); string lmdbPath = Path.Combine (dbPath, "longomatch.ldb"); string teamsPath = Path.Combine (dbPath, "teams"); string dashboardsPath = Path.Combine (dbPath, "analysis"); Directory.CreateDirectory (tmpPath); Directory.CreateDirectory (homePath); Environment.SetEnvironmentVariable ("LONGOMATCH_HOME", tmpPath); Environment.SetEnvironmentVariable ("LGM_UNINSTALLED", "1"); App.Init (); CoreServices.Init (); CoreServices.Start (guiToolkitMock.Object, multimediaToolkitMock.Object); Assert.AreEqual (0, App.Current.DatabaseManager.ActiveDB.Count<ProjectLongoMatch> ()); Assert.AreEqual (2, App.Current.TeamTemplatesProvider.Templates.Count); Assert.AreEqual (1, App.Current.CategoriesTemplatesProvider.Templates.Count); DatabaseMigration dbMigration = new DatabaseMigration (Mock.Of<IProgressReport> ()); dbMigration.Start (); Assert.AreEqual (0, App.Current.DatabaseManager.ActiveDB.Count<ProjectLongoMatch> ()); Assert.AreEqual (2, App.Current.TeamTemplatesProvider.Templates.Count); Assert.AreEqual (1, App.Current.CategoriesTemplatesProvider.Templates.Count); // Directory exists but it's empty Directory.CreateDirectory (dbPath); Directory.CreateDirectory (lmdbPath); Directory.CreateDirectory (teamsPath); Directory.CreateDirectory (dashboardsPath); dbMigration = new DatabaseMigration (Mock.Of<IProgressReport> ()); dbMigration.Start (); Assert.AreEqual (0, App.Current.DatabaseManager.ActiveDB.Count<ProjectLongoMatch> ()); Assert.AreEqual (2, App.Current.TeamTemplatesProvider.Templates.Count); Assert.AreEqual (1, App.Current.CategoriesTemplatesProvider.Templates.Count); CoreServices.Stop (); }