/// <summary> /// Prédit les référentiels potentiels à merger. /// </summary> /// <param name="data">Les données contenant l'export.</param> public virtual async Task <ProjectImport> PredictMergedReferentialsProject(byte[] data) => await Task.Run(async() => { using (var context = ContextFactory.GetNewContext()) { ProjectMigration migration = new ProjectMigration(data); ProjectExport project = await migration.Migrate(); // Charger les référentiels Referentials dbStandardReferentials = await LoadAllStandardReferentials(context); Dictionary <IActionReferentialProcess, IActionReferential> referentialsProject = new Dictionary <IActionReferentialProcess, IActionReferential>(); Dictionary <IActionReferential, IActionReferential> referentialsStd = new Dictionary <IActionReferential, IActionReferential>(); DetermineMergeCandidates(project.ReferentialsProject, dbStandardReferentials, referentialsProject); DetermineMergeCandidates(project.ReferentialsStandard, dbStandardReferentials, referentialsStd); return(new ProjectImport() { ExportedProject = project, ProjectReferentialsMergeCandidates = referentialsProject, StandardReferentialsMergeCandidates = referentialsStd, }); } });
public void TestMigrateFromV0() { LMProject project; using (Stream resource = Assembly.GetExecutingAssembly().GetManifestResourceStream("spain_france_test.lgm")) { project = Serializer.Instance.Load <LMProject> (resource); } Assert.AreEqual(0, project.Version); Assert.AreEqual(0, project.Dashboard.Version); Assert.AreEqual(0, project.LocalTeamTemplate.Version); Assert.AreEqual(0, project.VisitorTeamTemplate.Version); ProjectMigration.Migrate(project); // Check that dashboard and teams are migrated Assert.AreEqual(1, project.Version); Assert.AreEqual(1, project.Dashboard.Version); Assert.AreEqual(1, project.LocalTeamTemplate.Version); Assert.AreEqual(1, project.VisitorTeamTemplate.Version); Assert.AreEqual(3, project.Timeline.Count(e => (e as LMTimelineEvent).Teams.Contains(project.LocalTeamTemplate))); Assert.AreEqual(2, project.Timeline.Count(e => (e as LMTimelineEvent).Teams.Contains(project.VisitorTeamTemplate))); // Check that team tags have changed from TeamType to List<Team> correctly foreach (LMTimelineEvent evt in project.Timeline) { if (evt.Team == TeamType.LOCAL) { Assert.AreEqual(evt.Teams, new ObservableCollection <LMTeam> { project.LocalTeamTemplate }); } else if (evt.Team == TeamType.VISITOR) { Assert.AreEqual(evt.Teams, new ObservableCollection <LMTeam> { project.VisitorTeamTemplate }); } else if (evt.Team == TeamType.BOTH) { Assert.AreEqual(evt.Teams, new ObservableCollection <LMTeam> { project.LocalTeamTemplate, project.VisitorTeamTemplate }); } else if (evt.Team == TeamType.NONE) { Assert.AreEqual(evt.Teams, new ObservableCollection <LMTeam> ()); } } // Check that ScoreEvents and PenaltyCardEvents have now different Score and PenaltyCatd EventType instead // of the generic one. Assert.AreEqual(6, project.ScoreEvents.GroupBy(e => e.EventType).Count()); Assert.AreEqual(2, project.PenaltyCardsEvents.GroupBy(e => e.EventType).Count()); // Check that all the timeline events have a FileSet Assert.IsFalse(project.Timeline.Any(e => e.FileSet == null)); }
public static Project Import(string file) { Project project = null; project = Project.Import(file); ProjectMigration.Migrate(project as LMProject); return(project); }
public void ImportProjectMigrationTest() { var importData = PrepareImport(); var migration = new ProjectMigration(importData); var pe = migration.Migrate(); Assert.IsTrue(pe.Project.Label.EndsWith(" migré")); }
protected override void MigrateStorable(IStorable storable) { if (storable is Project) { ProjectMigration.Migrate(storable as LMProject); } else if (storable is Team) { TeamMigration.Migrate(storable as LMTeam); } else if (storable is LMDashboard) { DashboardMigration.Migrate(storable as LMDashboard); } }
public Project ImportProject() { LMProject project = null; string filename = App.Current.Dialogs.OpenFile(Catalog.GetString("Import project"), null, App.Current.HomeDir, FilterName, FilterExtensions); if (filename == null) { return(null); } IBusyDialog busy = App.Current.Dialogs.BusyDialog(Catalog.GetString("Importing project...")); busy.ShowSync(() => { project = Project.Import(filename) as LMProject; }); ProjectMigration.Migrate(project as LMProject); return(project); }
bool MigrateDB(IStorageManager manager, string databaseName, List <string> projectFiles) { IStorage database; Guid id = Guid.NewGuid(); int indexSteps = 4; float step = (float)1 / (projectFiles.Count * 2 + indexSteps); float percent = 0; List <Task> tasks = new List <Task> (); bool ret = true; Log.Information("Start migrating " + databaseName); try { database = manager.Add(databaseName); } catch { database = manager.Databases.FirstOrDefault(d => d.Info.Name == databaseName); } if (database == null) { Log.Error("Database with name " + databaseName + " is null"); return(false); } foreach (string projectFile in projectFiles) { var importTask = Task.Run(() => { LMProject project = null; try { Log.Information("Migrating project " + projectFile); project = Serializer.Instance.Load <LMProject> (projectFile); } catch (Exception ex) { Log.Exception(ex); ret = false; } percent += step; progress.Report(percent, "Imported project " + project?.Description.Title, id); if (project != null) { if (project.LocalTeamTemplate.ID != Guid.Empty) { teamNameToID [project.LocalTeamTemplate.Name] = project.LocalTeamTemplate.ID; } if (project.VisitorTeamTemplate.ID != Guid.Empty) { teamNameToID [project.VisitorTeamTemplate.Name] = project.VisitorTeamTemplate.ID; } try { ProjectMigration.Migrate0(project, scoreNameToID, penaltyNameToID, teamNameToID, dashboardNameToID); database.Store(project, true); } catch (Exception ex) { Log.Exception(ex); ret = false; } percent += step; progress.Report(percent, "Migrated project " + project?.Description.Title, id); project.Dispose(); project = null; GC.Collect(); } }); tasks.Add(importTask); } Task.WaitAll(tasks.ToArray()); // Create a query and print the result to traverse the iterator Log.Information("Projects index created:" + database.RetrieveAll <LMProject> ().Count()); percent += step; progress.Report(percent, "Projects index created", id); Log.Information("Timeline events index created:" + database.RetrieveAll <LMTimelineEvent> ().Count()); percent += step; progress.Report(percent, "Events index created", id); Log.Information("Teams index created:" + database.RetrieveAll <Team> ().Count()); percent += step; progress.Report(percent, "Teams index created", id); Log.Information("DAshboards index created:" + database.RetrieveAll <Dashboard> ().Count()); percent += step; progress.Report(percent, "Dashboards index created", id); Log.Information("Database " + databaseName + " migrated correctly"); return(ret); }