Ejemplo n.º 1
0
        //[TestMethod]
        public void D_CreateXMLV3()
        {
            var database = new TVTDatabase();

            database.Initialize();

            var dataRoot = TVTDataRoot.V2InUse;

            using (var connection = TVTSQLSession.GetSessionNewDB())
            {
                var programmes = TVTCommandsV3.Read <TVTProgramme>(connection, TVTCommandsV3.GetProgrammeSQLDefinition(), "master_id, episode_index, fake_title_de, title_de");
                //database.AddProgrammes( programmes.Where( x => (int)x.DataStatus >= (int)TVTDataStatus.OnlyDE ) );
                //var yames = programmes.Where( x => x.FakeTitleDE != null && x.FakeTitleDE.StartsWith( "Yams Pond" ) ).ToList();
                //var yames2 = yames.Where( x => x.DataRoot == dataRoot ).ToList();
                database.AddProgrammes(programmes.Where(x => x.DataRoot == dataRoot));

                var ads = TVTCommandsV3.Read <TVTAdvertising>(connection, TVTCommandsV3.GetAdvertisingSQLDefinition(), "fake_title_de, title_de");
                database.AddAdvertisings(ads.Where(x => x.DataRoot == dataRoot));

                var people = TVTCommandsV3.Read <TVTPerson>(connection, TVTCommandsV3.GetPersonSQLDefinition(), "fake_last_name, fake_first_name, last_name");
                database.AddPeople(people.Where(x => x.DataRoot == dataRoot));

                var news = TVTCommandsV3.Read <TVTNews>(connection, TVTCommandsV3.GetNewsSQLDefinition(), "news_thread_id, news_type, title_de");
                database.AddNews(news.Where(x => x.DataRoot == dataRoot));

                database.RefreshReferences();
            }

            var persister = new XmlPersisterV3();

            persister.SaveXML(database, "TVTDatabaseV3.xml", DatabaseVersion.V3, DataStructure.FakeData, false);
        }
Ejemplo n.º 2
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);
            }
        }