Beispiel #1
0
        public void B_ReadXMLV2AndMerge()
        {
            System.Diagnostics.Trace.WriteLine(Directory.GetCurrentDirectory());
            Assert.IsTrue(File.Exists("database.xml"));

            var databaseV2 = new TVTDatabase();

            databaseV2.Initialize();

            var persister = new XmlPersisterV2();

            persister.LoadXML("database.xml", databaseV2, TVTDataRoot.V2InUse);

            var sqlDB = new TVTDatabase();

            sqlDB.Initialize();
            sqlDB.Clear();
            using (var connection = TVTSQLSession.GetSessionNewDB())
            {
                string myConnectionString = "SERVER=localhost;" +
                                            "DATABASE=tvtower_new;" +
                                            "UID=TVTowerUser;" +
                                            "PASSWORD=123;";

                var mvSQLDatabase = new TVTSQLDatabase(myConnectionString);
                mvSQLDatabase.FillTVTDatabase(sqlDB);
            }

            var merging = new DatabaseMerging(sqlDB);

            {
                foreach (var currMovie in databaseV2.GetAllProgrammes(true, true))
                {
                    var found = merging.FindProgrammeMatch(currMovie);
                    if (found != null)
                    {
                        merging.MergeProgrammeData(found, currMovie, true);
                        found.DataRoot  = TVTDataRoot.V2InUse;
                        found.IsChanged = true;
                        foreach (var member in found.Staff)
                        {
                            if (member.Person != null)
                            {
                                member.Person.DataRoot  = TVTDataRoot.V2InUse;
                                member.Person.IsChanged = true;
                            }
                        }
                    }
                    else
                    {
                        var newProgramme = new TVTProgramme();
                        newProgramme.GenerateGuid();
                        merging.MergeProgrammeData(newProgramme, currMovie);
                        newProgramme.DataRoot  = TVTDataRoot.V2InUse;
                        newProgramme.IsNew     = true;
                        newProgramme.IsChanged = true;
                        foreach (var member in newProgramme.Staff)
                        {
                            member.Person.DataRoot  = TVTDataRoot.V2InUse;
                            member.Person.IsChanged = true;
                        }
                        sqlDB.AddProgramme(newProgramme);
                    }
                }
            }

            {
                foreach (var currNews in databaseV2.GetAllNews())
                {
                    var found = merging.FindNewsMatchWithV2(currNews);
                    if (found != null)
                    {
                        merging.MergeNewsData(found, currNews, true);
                        found.DataRoot  = TVTDataRoot.V2InUse;
                        found.IsChanged = true;
                    }
                    else
                    {
                        var newNews = new TVTNews();
                        newNews.GenerateGuid();
                        merging.CopyPropertyValues <TVTNews>(newNews, currNews);
                        newNews.DataRoot  = TVTDataRoot.V2InUse;
                        newNews.IsNew     = true;
                        newNews.IsChanged = true;
                        sqlDB.AddNews(newNews);
                    }
                }
            }

            {
                foreach (var currAd in databaseV2.GetAllAdvertisings())
                {
                    var found = merging.FindAdMatchWithV2(currAd);
                    if (found != null)
                    {
                        merging.CopyPropertyValues <TVTAdvertising>(found, currAd);
                        found.DataRoot  = TVTDataRoot.V2InUse;
                        found.IsChanged = true;
                    }
                    else
                    {
                        var newAd = new TVTAdvertising();
                        newAd.GenerateGuid();
                        merging.CopyPropertyValues <TVTAdvertising>(newAd, currAd);
                        newAd.DataRoot  = TVTDataRoot.V2InUse;
                        newAd.IsNew     = true;
                        newAd.IsChanged = true;
                        sqlDB.AddAdvertising(newAd);
                    }
                }
            }

            using (var connection = TVTSQLSession.GetSessionNewDB())
            {
                string myConnectionString = "SERVER=localhost;" +
                                            "DATABASE=tvtower_new;" +
                                            "UID=TVTowerUser;" +
                                            "PASSWORD=123;";

                var mvSQLDatabase = new TVTSQLDatabase(myConnectionString);
                mvSQLDatabase.WriteChangesToDatabase(sqlDB);
            }
        }