public static TVTProgramme GetIconicProgramme() { var programme = new TVTProgramme(); programme.GenerateGuid(); programme.OldId = "110"; programme.DataType = TVTDataType.Undefined; programme.DataStatus = TVTDataStatus.Approved; programme.DataRoot = TVTDataRoot.MadTV; programme.DataUsage = TVTDataUsage.MadTVOriginal; programme.Approved = true; programme.CreatorId = "creatorX"; programme.EditorId = "editorY"; programme.LastModified = DateTime.Now.AddDays(-1); programme.IsNew = true; programme.IsChanged = true; programme.TitleDE = "ValueA"; programme.TitleEN = "ValueB"; programme.DescriptionDE = "ValueC"; programme.DescriptionEN = "ValueD"; programme.ProductType = TVTProductType.Programme; programme.ProgrammeType = TVTProgrammeType.Reportage; programme.FakeTitleDE = "fakeA"; programme.FakeTitleEN = "fakeB"; programme.FakeDescriptionDE = "fakeDescA"; programme.FakeDescriptionEN = "fakeDescB"; programme.DescriptionMovieDB = "hkh"; var personA = GetMinimalPerson("PersA", "PersALast"); var personB = GetMinimalPerson("PersB", "PersBLast"); var personC = GetMinimalPerson("PersC", "PersCLast"); programme.Staff.Add(new TVTStaff(personA, TVTPersonFunction.Actor)); programme.Staff.Add(new TVTStaff(personB, TVTPersonFunction.Actor)); programme.Staff.Add(new TVTStaff(personC, TVTPersonFunction.Director)); programme.BettyBonus = 11; programme.PriceMod = (float)1.22; programme.CriticsRate = 33; programme.ViewersRate = 44; programme.BoxOfficeRate = 55; programme.Country = "FR"; programme.Year = 1952; programme.DistributionChannel = TVTDistributionChannel.Auction; programme.MainGenre = TVTProgrammeGenre.Drama; programme.SubGenre = TVTProgrammeGenre.Fantasy; programme.Blocks = 3; programme.LiveHour = 20; programme.Flags.Add(TVTProgrammeFlag.Cult); programme.Flags.Add(TVTProgrammeFlag.BMovie); programme.TargetGroups.Add(TVTTargetGroup.Manager); programme.TargetGroups.Add(TVTTargetGroup.Pensioners); programme.ProPressureGroups = new List <TVTPressureGroup>(); programme.ProPressureGroups.Add(TVTPressureGroup.AntiSmoker); programme.ProPressureGroups.Add(TVTPressureGroup.ArmsLobby); programme.ContraPressureGroups = new List <TVTPressureGroup>(); programme.ContraPressureGroups.Add(TVTPressureGroup.Capitalists); programme.ContraPressureGroups.Add(TVTPressureGroup.Communists); programme.ImdbId = "pp"; programme.TmdbId = 55; programme.RottenTomatoesId = 99; programme.ImageUrl = "urlX"; return(programme); }
public void MergeProgrammeData(TVTProgramme target, TVTProgramme leading, bool mergeStaffOnlyWhenEmpty = false) { //new List<string>() { "Staff", "Children", "SeriesMaster", "MasterId" } var type = typeof(TVTProgramme); foreach (var property in type.GetProperties()) { if (property.Name == "Staff") { if (!mergeStaffOnlyWhenEmpty || (target.Staff == null || target.Staff.Count == 0)) { target.Staff.Clear(); foreach (var member in leading.Staff) { var person = FindPersonMatch(member.Person); if (person == null) { if (member.Person.FakeLastName != "-" && member.Person.FakeLastName != "XXX") { person = new TVTPerson(); person.GenerateGuid(); CopyPropertyValues <TVTPerson>(person, member.Person); person.IsNew = true; person.IsChanged = true; LeadingDatabase.AddPerson(person); } } if (person != null) { target.Staff.Add(new TVTStaff(person, member.Function, member.Index)); } } } } else if (property.Name == "Children") { if (target.ProductType == TVTProductType.Series || target.ProductType == TVTProductType.Bundle) { if (target.Children != null) { target.Children.Clear(); } else { target.Children = new List <TVTProgramme>(); } foreach (var child in leading.Children) { var episode = FindProgrammeMatch(child); if (episode == null) { episode = new TVTProgramme(); episode.GenerateGuid(); MergeProgrammeData(episode, child); episode.IsNew = true; LeadingDatabase.AddProgramme(episode); } if (episode != null) { episode.SeriesMaster = new WeakReference <TVTProgramme>(target); episode.MasterId = target.Id.ToString(); episode.IsChanged = true; target.Children.Add(episode); } } } } else if (property.Name == "Children" || property.Name == "SeriesMaster" || property.Name == "MasterId") { //TODO: Später mehr } else { if (property.Name != "Id") { if (property.CanWrite && property.CanRead) { property.SetValue(target, property.GetValue(leading, null), null); } } } } }
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); } }