예제 #1
0
 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);
     }
 }
        void MigrateDashboards()
        {
            if (dashboardsMigrated)
            {
                return;
            }

            var dashboards = App.Current.CategoriesTemplatesProvider.Templates;

            foreach (var dashboard in dashboards)
            {
                DashboardMigration.Migrate(dashboard);
                App.Current.CategoriesTemplatesProvider.Save(dashboard);
            }

            dashboardsMigrated = true;
        }
예제 #3
0
        public void TestMigrateDashboardFromV0()
        {
            Dashboard dashboard, origDashboard;

            using (Stream resource = Assembly.GetExecutingAssembly().GetManifestResourceStream("basket.lct")) {
                origDashboard = Serializer.Instance.Load <Dashboard> (resource);
            }
            dashboard    = origDashboard.Clone();
            dashboard.ID = Guid.Empty;

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

            Assert.AreEqual(0, dashboard.Version);
            DashboardMigration.Migrate(dashboard);
            Assert.AreNotEqual(Guid.Empty, dashboard.ID);
            Assert.IsNotNull(dashboard.Preview);
            Assert.AreEqual(2, dashboard.Version);

            // Check that every Score and PenaltyCard buttons have now different event types
            Assert.AreNotEqual(1, dashboard.List.OfType <ScoreButton> ().Select(b => b.EventType).Distinct());
            Assert.AreEqual(6, dashboard.List.OfType <ScoreButton> ().Count());
            Assert.AreEqual(0, dashboard.List.OfType <ScoreButton> ().Count(b => b.ScoreEventType.ID == Constants.ScoreID));
            Assert.AreEqual(6, dashboard.List.OfType <ScoreButton> ().GroupBy(b => b.ScoreEventType.ID).Count());

            Assert.AreNotEqual(1, dashboard.List.OfType <PenaltyCardButton> ().Select(b => b.EventType).Distinct());
            Assert.AreEqual(2, dashboard.List.OfType <PenaltyCardButton> ().Count());
            Assert.AreEqual(0, dashboard.List.OfType <PenaltyCardButton> ().
                            Count(b => b.PenaltyCardEventType.ID == Constants.PenaltyCardID));
            Assert.AreEqual(2, dashboard.List.OfType <PenaltyCardButton> ().GroupBy(b => b.PenaltyCardEventType.ID).Count());
            Assert.AreEqual(19, dashboard.List.Count);

            // Change that each ScoreEventType has now a Score
            foreach (ScoreButton b in  dashboard.List.OfType <ScoreButton> ())
            {
                Assert.IsNotNull(b.ScoreEventType.Score);
            }

            // Change that each PenaltyCardEventType has now a PenaltyCard
            foreach (PenaltyCardButton b in  dashboard.List.OfType <PenaltyCardButton> ())
            {
                Assert.IsNotNull(b.PenaltyCardEventType.PenaltyCard);
            }
        }
예제 #4
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);
        }