private GEDCOMChecker(IBaseContext baseContext, IProgressController progress) { fBaseContext = baseContext; fTree = fBaseContext.Tree; fFormat = GEDCOMProvider.GetGEDCOMFormat(fTree); fProgress = progress; }
private static void CheckTagWithLists(GDMTree tree, GEDCOMFormat format, GDMTagWithLists tag) { int num = tag.MultimediaLinks.Count; for (int i = 0; i < num; i++) { GDMMultimediaLink mmLink = tag.MultimediaLinks[i]; if (!mmLink.IsPointer) { TransformMultimediaLink(tree, mmLink); } } num = tag.Notes.Count; for (int i = 0; i < num; i++) { GDMNotes note = tag.Notes[i]; if (!note.IsPointer) { TransformNote(tree, note); } } num = tag.SourceCitations.Count; for (int i = 0; i < num; i++) { GDMSourceCitation sourCit = tag.SourceCitations[i]; if (!sourCit.IsPointer) { TransformSourceCitation(tree, sourCit); } } }
private static void CheckRecord(IBaseContext baseContext, GDMTree tree, GDMRecord rec, GEDCOMFormat format, int fileVer) { CheckStructWL(tree, format, rec); switch (rec.RecordType) { case GDMRecordType.rtIndividual: CheckIndividualRecord(baseContext, tree, format, rec as GDMIndividualRecord); break; case GDMRecordType.rtFamily: CheckFamilyRecord(baseContext, tree, format, rec as GDMFamilyRecord); break; case GDMRecordType.rtGroup: CheckGroupRecord(rec as GDMGroupRecord); break; case GDMRecordType.rtSource: CheckSourceRecord(rec as GDMSourceRecord); break; case GDMRecordType.rtMultimedia: CheckMultimediaRecord(rec as GDMMultimediaRecord, format, fileVer); break; } }
private static void CheckMultimediaRecord(GDMMultimediaRecord mmRec, GEDCOMFormat format, int fileVer) { for (int i = 0; i < mmRec.FileReferences.Count; i++) { GDMFileReferenceWithTitle fileRef = mmRec.FileReferences[i]; GDMMultimediaFormat mmFormat = fileRef.MultimediaFormat; if (mmFormat == GDMMultimediaFormat.mfUnknown || mmFormat == GDMMultimediaFormat.mfNone) { // tag 'FORM' can be corrupted or GEDCOMCore in past not recognize format attempt recovery fileRef.MultimediaFormat = GDMFileReference.RecognizeFormat(fileRef.StringValue); } if (format == GEDCOMFormat.gf_Native && fileVer == 39) { // the transition to normalized names after GKv39 // only for not direct references AND not relative references (platform specific paths) var mediaStore = GKUtils.GetStoreType(fileRef); if (mediaStore.StoreType != MediaStoreType.mstReference && mediaStore.StoreType != MediaStoreType.mstRelativeReference) { fileRef.StringValue = FileHelper.NormalizeFilename(fileRef.StringValue); } } } }
// TODO: refactor private static void CheckRecord_RepairTag(GDMTree tree, GEDCOMFormat format, GDMTagWithLists tag) { for (int i = tag.MultimediaLinks.Count - 1; i >= 0; i--) { GDMMultimediaLink mmLink = tag.MultimediaLinks[i]; if (mmLink.IsPointer && mmLink.Value == null) { tag.MultimediaLinks.DeleteAt(i); } } for (int i = tag.Notes.Count - 1; i >= 0; i--) { GDMNotes note = tag.Notes[i]; if (note.IsPointer && note.Value == null) { tag.Notes.DeleteAt(i); } } for (int i = tag.SourceCitations.Count - 1; i >= 0; i--) { GDMSourceCitation sourCit = tag.SourceCitations[i]; if (sourCit.IsPointer && sourCit.Value == null) { tag.SourceCitations.DeleteAt(i); } } }
private static void CheckRecord(IBaseContext baseContext, GDMTree tree, GDMRecord rec, GEDCOMFormat format, int fileVer) { if (format != GEDCOMFormat.gf_Native) { int num = rec.MultimediaLinks.Count; for (int i = 0; i < num; i++) { GDMMultimediaLink mmLink = rec.MultimediaLinks[i]; if (!mmLink.IsPointer) { TransformMultimediaLink(tree, mmLink); } } num = rec.Notes.Count; for (int i = 0; i < num; i++) { GDMNotes note = rec.Notes[i]; if (!note.IsPointer) { TransformNote(tree, note); } } num = rec.SourceCitations.Count; for (int i = 0; i < num; i++) { GDMSourceCitation sourCit = rec.SourceCitations[i]; if (!sourCit.IsPointer) { TransformSourceCitation(tree, sourCit); } } } switch (rec.RecordType) { case GDMRecordType.rtIndividual: CheckIndividualRecord(baseContext, tree, format, rec as GDMIndividualRecord); break; case GDMRecordType.rtFamily: CheckFamilyRecord(baseContext, tree, format, rec as GDMFamilyRecord); break; case GDMRecordType.rtGroup: CheckGroupRecord(rec as GDMGroupRecord); break; case GDMRecordType.rtSource: CheckSourceRecord(rec as GDMSourceRecord); break; case GDMRecordType.rtMultimedia: CheckMultimediaRecord(rec as GDMMultimediaRecord, format, fileVer); break; } }
private static void CheckPointerWithNotes(GDMTree tree, GEDCOMFormat format, GDMPointerWithNotes ptr) { GDMRecord val = ptr.Value; if (!string.IsNullOrEmpty(ptr.XRef) && val == null) { ptr.Value = null; } CheckTagWithNotes(tree, format, ptr); }
private static void CheckIndividualEvent(GDMCustomEvent evt, GEDCOMFormat format) { // Fix for Family Tree Maker 2008 which exports occupation as generic EVEN events if (format == GEDCOMFormat.gf_FamilyTreeMaker) { string subtype = evt.Classification.ToLower(); if (evt.Id == (int)GEDCOMTagType.EVEN && subtype == "occupation") { evt.SetName(GEDCOMTagType.OCCU); evt.Classification = string.Empty; } } }
private static void CheckEvent(GDMTree tree, GEDCOMFormat format, GDMCustomEvent evt) { CheckStructWL(tree, format, evt); // Fix for Family Tree Maker 2008 which exports occupation as generic EVEN events if (format == GEDCOMFormat.gf_FamilyTreeMaker) { string subtype = evt.Classification.ToLower(); if (evt.Id == (int)GEDCOMTagType.EVEN && subtype == "occupation") { evt.SetName(GEDCOMTagType.OCCU); evt.Classification = string.Empty; } } CheckEventPlace(tree, format, evt.Place); }
public static GEDCOMFormat GetGEDCOMFormat(GEDCOMTree tree) { if (tree != null) { string sour = tree.Header.Source.Trim(); for (GEDCOMFormat gf = GEDCOMFormat.gf_Native; gf <= GEDCOMFormat.gf_Last; gf++) { string fmtSign = GEDCOMProvider.GEDCOMFormats[(int)gf].Sign; if (string.Equals(fmtSign, sour, StringComparison.Ordinal)) { return(gf); } } } return(GEDCOMFormat.gf_Unknown); }
private static void CheckTagWithNotes(GDMTree tree, GEDCOMFormat format, IGDMStructWithNotes tag) { for (int i = tag.Notes.Count - 1; i >= 0; i--) { GDMNotes note = tag.Notes[i]; if (!note.IsPointer) { TransformNote(tree, note); } else { if (note.Value == null) { tag.Notes.DeleteAt(i); } } } }
private static void CheckTagWithMultimediaLinks(GDMTree tree, GEDCOMFormat format, IGDMStructWithMultimediaLinks tag) { for (int i = tag.MultimediaLinks.Count - 1; i >= 0; i--) { GDMMultimediaLink mmLink = tag.MultimediaLinks[i]; if (!mmLink.IsPointer) { TransformMultimediaLink(tree, mmLink); } else { if (mmLink.Value == null) { tag.MultimediaLinks.DeleteAt(i); } } } }
private static void CheckTagWithSourceCitations(GDMTree tree, GEDCOMFormat format, IGDMStructWithSourceCitations tag) { for (int i = tag.SourceCitations.Count - 1; i >= 0; i--) { GDMSourceCitation sourCit = tag.SourceCitations[i]; if (!sourCit.IsPointer) { TransformSourceCitation(tree, sourCit); } else { if (sourCit.Value == null) { tag.SourceCitations.DeleteAt(i); } } } }
private static void CheckEventPlace(GDMTree tree, GEDCOMFormat format, GDMPlace place) { GDMPointer placeLocation = place.Location; if (placeLocation.XRef != "" && placeLocation.Value == null) { placeLocation.XRef = ""; } if (place.StringValue != "") { GDMLocationRecord locRec = placeLocation.Value as GDMLocationRecord; if (locRec != null && place.StringValue != locRec.LocationName) { place.StringValue = locRec.LocationName; } } CheckTagWithNotes(tree, format, place); }
private static void CheckPointerWithNotes(GDMTree tree, GEDCOMFormat format, GDMPointerWithNotes ptr) { // TODO: checkit! GDMRecord val = ptr.Value; if (!string.IsNullOrEmpty(ptr.XRef) && val == null) { ptr.Value = null; } int num = ptr.Notes.Count; for (int i = 0; i < num; i++) { GDMNotes note = ptr.Notes[i]; if (!note.IsPointer) { TransformNote(tree, note); } } }
public override string ParseString(string strValue) { GEDCOMFormat format = GEDCOMProvider.GetGEDCOMFormat(Owner); fApproximated = GEDCOMApproximated.daExact; fCalendar = GEDCOMCalendar.dcGregorian; fYear = UNKNOWN_YEAR; fYearBC = false; fYearModifier = ""; fMonth = ""; fDay = 0; if (!string.IsNullOrEmpty(strValue)) { if (format == GEDCOMFormat.gf_Ahnenblatt) { strValue = PrepareAhnenblattDate(strValue); } var strTok = new StringTokenizer(strValue); strTok.IgnoreWhiteSpace = false; strTok.Next(); strTok.SkipWhiteSpaces(); // extract approximated var token = strTok.CurrentToken; if (token.Kind == TokenKind.Word) { string su = token.Value.ToUpperInvariant(); int idx = SysUtils.IndexOf(GEDCOMDateApproximatedArray, su); if (idx >= 0) { fApproximated = (GEDCOMApproximated)idx; strTok.Next(); strTok.SkipWhiteSpaces(); } } // extract escape token = strTok.CurrentToken; if (token.Kind == TokenKind.Symbol && token.Value[0] == '@') { var escapeStr = token.Value; do { token = strTok.Next(); escapeStr += token.Value; } while (token.Kind != TokenKind.Symbol || token.Value[0] != '@'); // FIXME: check for errors int idx = SysUtils.IndexOf(GEDCOMDateEscapeArray, escapeStr); if (idx >= 0) { fCalendar = (GEDCOMCalendar)idx; } strTok.Next(); strTok.SkipWhiteSpaces(); } // extract day token = strTok.CurrentToken; if (token.Kind == TokenKind.Number && token.Value.Length <= 2) { fDay = (byte)(int)token.ValObj; token = strTok.Next(); } // extract delimiter if (token.Kind == TokenKind.WhiteSpace && token.Value[0] == ' ') { fDateFormat = GEDCOMDateFormat.dfGEDCOMStd; token = strTok.Next(); } else if (token.Kind == TokenKind.Symbol && token.Value[0] == '.') { fDateFormat = GEDCOMDateFormat.dfSystem; token = strTok.Next(); } // extract month string[] monthes = GetMonthNames(fCalendar); if (token.Kind == TokenKind.Word) { string mth = token.Value; int idx = SysUtils.IndexOf(monthes, mth); if (idx >= 0) { fMonth = mth; } token = strTok.Next(); } else if (fDateFormat == GEDCOMDateFormat.dfSystem && token.Kind == TokenKind.Number) { int idx = (int)token.ValObj; fMonth = monthes[idx - 1]; token = strTok.Next(); } // extract delimiter if (fDateFormat == GEDCOMDateFormat.dfSystem) { if (token.Kind == TokenKind.Symbol && token.Value[0] == '.') { token = strTok.Next(); } } else { if (token.Kind == TokenKind.WhiteSpace && token.Value[0] == ' ') { token = strTok.Next(); } } // extract year if (token.Kind == TokenKind.Number) { fYear = (short)(int)token.ValObj; token = strTok.Next(); // extract year modifier if (token.Kind == TokenKind.Symbol && token.Value[0] == '/') { token = strTok.Next(); if (token.Kind != TokenKind.Number) { // error } fYearModifier = token.Value; token = strTok.Next(); } // extract bc/ad if (token.Kind == TokenKind.Word && token.Value[0] == 'B') { token = strTok.Next(); if (token.Kind != TokenKind.Symbol || token.Value[0] != '.') { // error } token = strTok.Next(); if (token.Kind != TokenKind.Word || token.Value[0] != 'C') { // error } token = strTok.Next(); if (token.Kind != TokenKind.Symbol || token.Value[0] != '.') { // error } strTok.Next(); fYearBC = true; } } strValue = strTok.GetRest(); } DateChanged(); return(strValue); }
public static bool CheckGEDCOMFormat(GDMTree tree, IBaseContext baseContext, IProgressController pc) { if (tree == null) { throw new ArgumentNullException("tree"); } if (baseContext == null) { throw new ArgumentNullException("baseContext"); } if (pc == null) { throw new ArgumentNullException("pc"); } bool result = false; try { GEDCOMFormat format = GEDCOMProvider.GetGEDCOMFormat(tree); int fileVer; // remove a deprecated features if (format == GEDCOMFormat.gf_Native) { GDMHeader header = tree.Header; GDMTag tag; tag = header.FindTag("_ADVANCED", 0); if (tag != null) { header.DeleteTag("_ADVANCED"); } tag = header.FindTag("_EXT_NAME", 0); if (tag != null) { header.DeleteTag("_EXT_NAME"); } fileVer = ConvertHelper.ParseInt(header.Source.Version, GKData.APP_FORMAT_DEFVER); } else { fileVer = -1; } pc.ProgressInit(LangMan.LS(LSID.LSID_FormatCheck), 100); try { bool xrefValid = true; bool isExtraneous = (format != GEDCOMFormat.gf_Native); int progress = 0; int num = tree.RecordsCount; for (int i = 0; i < num; i++) { GDMRecord rec = tree[i]; CheckRecord(baseContext, tree, rec, format, fileVer); if (isExtraneous && xrefValid && !CheckRecordXRef(rec)) { xrefValid = false; } int newProgress = (int)Math.Min(100, ((i + 1) * 100.0f) / num); if (progress != newProgress) { progress = newProgress; pc.ProgressStep(progress); } } // obsolete: AppHost.StdDialogs.ShowQuestionYN(LangMan.LS(LSID.LSID_IDsCorrectNeed)) if (!xrefValid) { ConvertIdentifiers(tree, pc); } result = true; } finally { pc.ProgressDone(); } } catch (Exception ex) { Logger.LogWrite("GEDCOMChecker.CheckGEDCOMFormat(): " + ex.Message); AppHost.StdDialogs.ShowError(LangMan.LS(LSID.LSID_CheckGedComFailed)); } return(result); }
private static void CheckPersonalName(IBaseContext baseContext, GDMTree tree, GEDCOMFormat format, GDMPersonalName persName) { CheckTagWithNotes(tree, format, persName); CheckTagWithSourceCitations(tree, format, persName); baseContext.CollectNameLangs(persName); }
private static void CheckFamilyRecord(IBaseContext baseContext, GDMTree tree, GEDCOMFormat format, GDMFamilyRecord fam) { if (format == GEDCOMFormat.gf_Native) { int num = fam.Events.Count; for (int i = 0; i < num; i++) { CheckEventPlace(fam.Events[i]); } } else { int num2 = fam.Events.Count; for (int i = 0; i < num2; i++) { CheckTagWithLists(tree, format, fam.Events[i]); } } for (int i = fam.Children.Count - 1; i >= 0; i--) { if (fam.Children[i].Value == null) { fam.Children.DeleteAt(i); } } GDMRecord val = fam.Husband.Value; if (!string.IsNullOrEmpty(fam.Husband.XRef) && val == null) { fam.Husband.Value = null; } val = fam.Wife.Value; if (!string.IsNullOrEmpty(fam.Wife.XRef) && val == null) { fam.Wife.Value = null; } }
private static void CheckIndividualRecord(IBaseContext baseContext, GDMTree tree, GEDCOMFormat format, GDMIndividualRecord iRec) { if (format == GEDCOMFormat.gf_Native) { for (int i = 0, num = iRec.Events.Count; i < num; i++) { GDMCustomEvent evt = iRec.Events[i]; CheckEventPlace(evt); CheckAttrCompatible(tree, format, iRec, evt); CheckRecord_RepairTag(tree, format, evt); baseContext.CollectEventValues(evt); } for (int i = 0, num = iRec.UserReferences.Count; i < num; i++) { CheckURefCompatible(iRec, iRec.UserReferences[i]); } for (int i = 0, num = iRec.PersonalNames.Count; i < num; i++) { CheckPersonalName(iRec, iRec.PersonalNames[i], baseContext); } } else { for (int i = 0, num = iRec.Events.Count; i < num; i++) { GDMCustomEvent evt = iRec.Events[i]; CheckIndividualEvent(evt, format); CheckTagWithLists(tree, format, evt); } for (int i = 0, num = iRec.ChildToFamilyLinks.Count; i < num; i++) { CheckPointerWithNotes(tree, format, iRec.ChildToFamilyLinks[i]); } for (int i = 0, num = iRec.SpouseToFamilyLinks.Count; i < num; i++) { CheckPointerWithNotes(tree, format, iRec.SpouseToFamilyLinks[i]); } for (int i = 0, num = iRec.Associations.Count; i < num; i++) { CheckPointerWithNotes(tree, format, iRec.Associations[i]); } } for (int i = iRec.ChildToFamilyLinks.Count - 1; i >= 0; i--) { if (iRec.ChildToFamilyLinks[i].Family == null) { iRec.ChildToFamilyLinks.DeleteAt(i); } } for (int i = iRec.SpouseToFamilyLinks.Count - 1; i >= 0; i--) { if (iRec.SpouseToFamilyLinks[i].Family == null) { iRec.SpouseToFamilyLinks.DeleteAt(i); } } baseContext.ImportNames(iRec); }
private static void CheckAttrCompatible(GDMTree tree, GEDCOMFormat format, GDMIndividualRecord iRec, GDMCustomEvent aEvent) { }
private static void CheckIndividualRecord(IBaseContext baseContext, GDMTree tree, GEDCOMFormat format, GDMIndividualRecord iRec) { for (int i = 0, num = iRec.Events.Count; i < num; i++) { GDMCustomEvent evt = iRec.Events[i]; CheckEvent(tree, format, evt); baseContext.CollectEventValues(evt); } for (int i = 0, num = iRec.UserReferences.Count; i < num; i++) { CheckUserRef(iRec, iRec.UserReferences[i]); } for (int i = 0, num = iRec.PersonalNames.Count; i < num; i++) { CheckPersonalName(baseContext, tree, format, iRec.PersonalNames[i]); } for (int i = iRec.ChildToFamilyLinks.Count - 1; i >= 0; i--) { var cfl = iRec.ChildToFamilyLinks[i]; if (cfl.Family == null) { iRec.ChildToFamilyLinks.DeleteAt(i); } else { CheckPointerWithNotes(tree, format, cfl); } } for (int i = iRec.SpouseToFamilyLinks.Count - 1; i >= 0; i--) { var sfl = iRec.SpouseToFamilyLinks[i]; if (sfl.Family == null) { iRec.SpouseToFamilyLinks.DeleteAt(i); } else { CheckPointerWithNotes(tree, format, sfl); } } for (int i = 0, num = iRec.Associations.Count; i < num; i++) { var asso = iRec.Associations[i]; CheckPointerWithNotes(tree, format, asso); CheckTagWithSourceCitations(tree, format, asso); } baseContext.ImportNames(iRec); }
private static void CheckFamilyRecord(IBaseContext baseContext, GDMTree tree, GEDCOMFormat format, GDMFamilyRecord fam) { for (int i = 0, num = fam.Events.Count; i < num; i++) { GDMCustomEvent evt = fam.Events[i]; CheckEvent(tree, format, evt); } for (int i = fam.Children.Count - 1; i >= 0; i--) { if (fam.Children[i].Value == null) { fam.Children.DeleteAt(i); } } GDMRecord val = fam.Husband.Value; if (!string.IsNullOrEmpty(fam.Husband.XRef) && val == null) { fam.Husband.Value = null; } val = fam.Wife.Value; if (!string.IsNullOrEmpty(fam.Wife.XRef) && val == null) { fam.Wife.Value = null; } }
private static void CheckStructWL(GDMTree tree, GEDCOMFormat format, IGDMStructWithLists swl) { CheckTagWithNotes(tree, format, swl); CheckTagWithMultimediaLinks(tree, format, swl); CheckTagWithSourceCitations(tree, format, swl); }