예제 #1
0
        public void TestMigrateFromV0()
        {
            LMTeam team;
            LMTeam origTeam;

            using (Stream resource = Assembly.GetExecutingAssembly().GetManifestResourceStream("spain.ltt")) {
                origTeam = Serializer.Instance.Load <LMTeam> (resource);
            }

            team    = origTeam.Clone();
            team.ID = Guid.Empty;
            Assert.AreEqual(0, team.Version);
            TeamMigration.Migrate(team);
            Assert.AreNotEqual(Guid.Empty, team.ID);
            Assert.AreEqual(1, team.Version);

            team    = origTeam.Clone();
            team.ID = Guid.Empty;
            var  teamNameToID = new Dictionary <string, Guid> ();
            Guid id           = Guid.NewGuid();

            teamNameToID [team.TeamName] = id;
            TeamMigration.Migrate0(team, teamNameToID);
            Assert.AreEqual(id, team.ID);
        }
예제 #2
0
        public void Migrate_FromV0ToV2_Ok()
        {
            // Arrange
            LMTeam team;
            LMTeam origTeam;

            using (Stream resource = Assembly.GetExecutingAssembly().GetManifestResourceStream("spain.ltt")) {
                origTeam = Serializer.Instance.Load <LMTeam> (resource);
            }

            team    = origTeam.Clone();
            team.ID = Guid.Empty;

            mockPreview.Setup(p => p.CreatePreview(team)).Returns(new Image(1, 1));

            // Act
            Assert.AreEqual(0, team.Version);
            TeamMigration.Migrate(team);

            // Assert
            Assert.AreNotEqual(Guid.Empty, team.ID);
            Assert.AreEqual(2, team.Version);
            Assert.IsNotNull(team.Preview);

            team    = origTeam.Clone();
            team.ID = Guid.Empty;
            var  teamNameToID = new Dictionary <string, Guid> ();
            Guid id           = Guid.NewGuid();

            teamNameToID [team.TeamName] = id;
            TeamMigration.Migrate0(team, teamNameToID);

            Assert.AreEqual(id, team.ID);
        }
예제 #3
0
        bool MigrateTeamsAndDashboards()
        {
            bool                        ret = true;
            float                       count;
            float                       percent        = 0;
            List <string>               teamFiles      = new List <string> ();
            List <string>               dashboardFiles = new List <string> ();
            Guid                        id             = Guid.NewGuid();
            ConcurrentQueue <LMTeam>    teams          = new ConcurrentQueue <LMTeam> ();
            ConcurrentQueue <Dashboard> dashboards     = new ConcurrentQueue <Dashboard> ();
            List <Task>                 tasks          = new List <Task> ();

            progress.Report(0, "Migrating teams and dashboards", id);

            try {
                teamFiles = Directory.EnumerateFiles(Path.Combine(App.Current.DBDir, "teams")).
                            Where(f => f.EndsWith(".ltt")).ToList();
            } catch (DirectoryNotFoundException ex) {
                percent += 0.5f;
                progress.Report(percent, "Migrated teams", id);
            }
            try {
                dashboardFiles = Directory.EnumerateFiles(Path.Combine(App.Current.DBDir, "analysis")).
                                 Where(f => f.EndsWith(".lct")).ToList();
            } catch (DirectoryNotFoundException ex) {
                percent += 0.5f;
                progress.Report(percent, "Migrated dashboards", id);
            }
            if (teamFiles.Count == 0 && dashboardFiles.Count == 0)
            {
                progress.Report(1, "Migrated teams and dashboards", id);
                return(true);
            }
            count = (teamFiles.Count + dashboardFiles.Count) * 2 + 1;

            // We can't use the FileStorage here, since it will migate the Team or Dashboard
            foreach (string teamFile in teamFiles)
            {
                try {
                    LMTeam team = Serializer.Instance.Load <LMTeam> (teamFile);
                    percent += 1 / count;
                    progress.Report(percent, "Imported team " + team.Name, id);
                    teams.Enqueue(team);
                } catch (Exception ex) {
                    Log.Exception(ex);
                }
            }

            foreach (string dashboardFile in dashboardFiles)
            {
                try {
                    Dashboard dashboard = Serializer.Instance.Load <Dashboard> (dashboardFile);
                    percent += 1 / count;
                    progress.Report(percent, "Imported dashboard " + dashboard.Name, id);
                    dashboards.Enqueue(dashboard);
                } catch (Exception ex) {
                    Log.Exception(ex);
                }
            }

            foreach (LMTeam team in teams)
            {
                var migrateTask = Task.Run(() => {
                    try {
                        Log.Information("Migrating team " + team.Name);
                        TeamMigration.Migrate0(team, teamNameToID);
                        App.Current.TeamTemplatesProvider.Save(team);
                        percent += 1 / count;
                        progress.Report(percent, "Migrated team " + team.Name, id);
                    } catch (Exception ex) {
                        Log.Exception(ex);
                        ret = false;
                    }
                });
                tasks.Add(migrateTask);
            }

            foreach (Dashboard dashboard in dashboards)
            {
                var migrateTask = Task.Run(() => {
                    try {
                        Log.Information("Migrating dashboard " + dashboard.Name);
                        DashboardMigration.Migrate0(dashboard, scoreNameToID, penaltyNameToID);
                        App.Current.CategoriesTemplatesProvider.Save(dashboard as LMDashboard);
                        percent += 1 / count;
                        progress.Report(percent, "Migrated team " + dashboard.Name, id);
                    } catch (Exception ex) {
                        Log.Exception(ex);
                        ret = false;
                    }
                });
                tasks.Add(migrateTask);
            }

            Task.WaitAll(tasks.ToArray());

            try {
                string backupDir = Path.Combine(App.Current.TemplatesDir, "backup");
                if (!Directory.Exists(backupDir))
                {
                    Directory.CreateDirectory(backupDir);
                }

                foreach (string templateFile in Directory.EnumerateFiles(Path.Combine(App.Current.DBDir, "teams")).Concat(
                             Directory.EnumerateFiles(Path.Combine(App.Current.DBDir, "analysis"))))
                {
                    string outputFile = Path.Combine(backupDir, Path.GetFileName(templateFile));
                    if (File.Exists(outputFile))
                    {
                        File.Delete(outputFile);
                    }
                    File.Move(templateFile, outputFile);
                }
            } catch (Exception ex) {
                Log.Error("Error moving templates to the backup directory.");
                Log.Exception(ex);
            }

            progress.Report(1, "Teams and dashboards migrated", id);
            return(ret);
        }