public CompareTreeWorker( object sender, SavedMatches matches, AsyncWorkerProgress progress, FamilyTreeStoreBaseClass familyTree1, FamilyTreeStoreBaseClass familyTree2, ReportCompareResult resultReporter) { trace = new TraceSource("CompareTreeWorker", SourceLevels.All); resultReporterFunction = resultReporter; progressReporter = progress; this.matches = matches; backgroundWorker = new BackgroundWorker(); backgroundWorker.WorkerReportsProgress = true; if (matches == null) { backgroundWorker.DoWork += new DoWorkEventHandler(DoWork); } else { backgroundWorker.DoWork += new DoWorkEventHandler(DoWorkLoadFile); } backgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(Completed); backgroundWorker.ProgressChanged += new ProgressChangedEventHandler(ProgressChanged); WorkerInterface workerInterface = new WorkerInterface(); workerInterface.familyTree1 = familyTree1; workerInterface.familyTree2 = familyTree2; backgroundWorker.RunWorkerAsync(workerInterface); }
public static void CompareTrees(IFamilyTreeStoreBaseClass familyTree1, IFamilyTreeStoreBaseClass familyTree2, ReportCompareResult reportDuplicate, IProgressReporterInterface reporter = null) { IEnumerator <IndividualClass> iterator1; int cnt1 = 0; NameEquivalenceDb equivDb = NameEquivalenceDb.LoadFile(NameEquivalenceDb.GetDefaultFilePath()); if (equivDb == null) { equivDb = new DefaultNameEquivalenceDb(); equivDb.LoadDefault(); bool result = NameEquivalenceDb.SaveFile(NameEquivalenceDb.GetDefaultFilePath(), equivDb); if (!result) { trace.TraceData(TraceEventType.Warning, 0, "File db write failed"); } else { trace.TraceData(TraceEventType.Information, 0, "File db write ok"); } } iterator1 = familyTree1.SearchPerson(null, reporter); trace.TraceData(TraceEventType.Information, 0, "CompareTrees() started"); if (iterator1 != null) { do { IndividualClass person1 = iterator1.Current; cnt1++; if (person1 != null) { trace.TraceData(TraceEventType.Information, 0, " 1:" + cnt1 + " " + person1.GetName()); SearchDuplicates(person1, familyTree1, familyTree2, reportDuplicate, reporter, equivDb); } else { trace.TraceData(TraceEventType.Warning, 0, " 1: person is null" + cnt1); } } while (iterator1.MoveNext()); iterator1.Dispose(); } else { trace.TraceInformation("iter=null"); } trace.TraceInformation("CompareTrees() done"); }
public static void SearchDuplicates(IndividualClass person1, IFamilyTreeStoreBaseClass familyTree1, IFamilyTreeStoreBaseClass familyTree2, ReportCompareResult reportDuplicate, IProgressReporterInterface reporter = null, NameEquivalenceDb nameEqDb = null) { IndividualEventClass birth = person1.GetEvent(IndividualEventClass.EventType.Birth); IndividualEventClass death = person1.GetEvent(IndividualEventClass.EventType.Death); if (reporter != null) { trace.TraceInformation(reporter.ToString()); } if (((birth != null) && (birth.GetDate() != null) && (birth.GetDate().ValidDate())) || ((death != null) && (death.GetDate() != null) && (death.GetDate().ValidDate()))) { string searchString; if (familyTree2.GetCapabilities().jsonSearch) { searchString = SearchDescriptor.ToJson(SearchDescriptor.GetSearchDescriptor(person1)); } else { searchString = person1.GetName().Replace("*", ""); } IEnumerator <IndividualClass> iterator2 = familyTree2.SearchPerson(searchString); int cnt2 = 0; if (iterator2 != null) { int cnt3 = 0; do { IndividualClass person2 = iterator2.Current; if (person2 != null) { cnt3++; //trace.TraceInformation(reporter.ToString() + " 2:" + person2.GetName()); if ((familyTree1 != familyTree2) || (person1.GetXrefName() != person2.GetXrefName())) { if (ComparePerson(person1, person2, nameEqDb)) { trace.TraceData(TraceEventType.Information, 0, " 2:" + person2.GetName() + " " + person1.GetXrefName() + " " + person2.GetXrefName()); reportDuplicate(familyTree1, person1.GetXrefName(), familyTree2, person2.GetXrefName()); } cnt2++; } } } while (iterator2.MoveNext()); iterator2.Dispose(); trace.TraceInformation(" " + searchString + " matched with " + cnt2 + "," + cnt3); } if (cnt2 == 0) // No matches found for full name { if ((person1.GetPersonalName().GetName(PersonalNameClass.PartialNameType.BirthSurname).Length > 0) && (person1.GetPersonalName().GetName(PersonalNameClass.PartialNameType.Surname).Length > 0) && !person1.GetPersonalName().GetName(PersonalNameClass.PartialNameType.Surname).Equals(person1.GetPersonalName().GetName(PersonalNameClass.PartialNameType.BirthSurname))) { String strippedName = person1.GetName().Replace("*", ""); if (strippedName.Contains(person1.GetPersonalName().GetName(PersonalNameClass.PartialNameType.Surname))) { String maidenName = strippedName.Replace(person1.GetPersonalName().GetName(PersonalNameClass.PartialNameType.Surname), "").Replace(" ", " "); IEnumerator <IndividualClass> iterator3 = familyTree2.SearchPerson(maidenName); //trace.TraceInformation(" Searching Maiden name " + maidenName); if (iterator3 != null) { int cnt3 = 0; do { IndividualClass person2 = iterator3.Current; if (person2 != null) { if ((familyTree1 != familyTree2) || (person1.GetXrefName() != person2.GetXrefName())) { cnt3++; if (ComparePerson(person1, person2, nameEqDb)) { trace.TraceData(TraceEventType.Information, 0, " 2b:" + person2.GetName()); reportDuplicate(familyTree1, person1.GetXrefName(), familyTree2, person2.GetXrefName()); } } } } while (iterator3.MoveNext()); iterator3.Dispose(); trace.TraceInformation(" Maiden name " + maidenName + " mathched with " + cnt3); } } if (strippedName.Contains(person1.GetPersonalName().GetName(PersonalNameClass.PartialNameType.BirthSurname))) { String marriedName = strippedName.Replace(person1.GetPersonalName().GetName(PersonalNameClass.PartialNameType.BirthSurname), "").Replace(" ", " "); IEnumerator <IndividualClass> iterator3 = familyTree2.SearchPerson(marriedName); //trace.TraceInformation(" Searching Married name " + marriedName); if (iterator3 != null) { int cnt3 = 0; do { //IndividualClass person1 = iterator1.Current; IndividualClass person2 = iterator3.Current; if (person2 != null) { //trace.TraceInformation(reporter.ToString() + " 2:" + person2.GetName()); if ((familyTree1 != familyTree2) || (person1.GetXrefName() != person2.GetXrefName())) { cnt3++; if (ComparePerson(person1, person2, nameEqDb)) { trace.TraceData(TraceEventType.Information, 0, " 2c:" + person2.GetName()); reportDuplicate(familyTree1, person1.GetXrefName(), familyTree2, person2.GetXrefName()); } } } } while (iterator3.MoveNext()); iterator3.Dispose(); trace.TraceInformation(" Married name " + marriedName + " matched to " + cnt3); } } } } } else { trace.TraceData(TraceEventType.Information, 0, "No valid birth or death date for " + person1.GetName().ToString() + " skip duplicate search"); } }
public static void CompareTrees(FamilyTreeStoreBaseClass familyTree1, FamilyTreeStoreBaseClass familyTree2, ReportCompareResult reportDuplicate, ProgressReporterInterface reporter = null) { IEnumerator <IndividualClass> iterator1; int cnt1 = 0; iterator1 = familyTree1.SearchPerson(null, reporter); trace.TraceInformation("CompareTrees() started"); if (iterator1 != null) { do { IndividualClass person1 = iterator1.Current; cnt1++; if (person1 != null) { trace.TraceInformation(" 1:" + person1.GetName()); SearchDuplicates(person1, familyTree1, familyTree2, reportDuplicate, reporter); } } while (iterator1.MoveNext()); iterator1.Dispose(); } else { trace.TraceInformation("iter=null"); } trace.TraceInformation("CompareTrees() done"); }