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); }