From ba9363623a00eb70c8e4c0c204dee1e85b478325 Mon Sep 17 00:00:00 2001 From: mtx500 Date: Mon, 1 Jan 2024 16:13:08 +0100 Subject: [PATCH] Add support for custom records on event records. (#144) * Fixed some typos in comments and strings. * Generate XML documentation files in output- instead of source-directory. Remove them from repository as they are generated. * Store the record change dates that are read in from GED file * Fix exception when reading ChangeDate when file contains bad submitter reference. * Add support for custom records on event records. --- GeneGenie.Gedcom.Tests/Data/UidAndBurg.ged | 20 ++++++++ .../GeneGenie.Gedcom.Tests.csproj | 3 ++ .../GecomCustomRecordTest.cs | 46 +++++++++++++++++++ GeneGenie.Gedcom/GedcomEvent.cs | 3 ++ GeneGenie.Gedcom/Parser/GedcomRecordReader.cs | 2 +- 5 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 GeneGenie.Gedcom.Tests/Data/UidAndBurg.ged create mode 100644 GeneGenie.Gedcom.Tests/RecordReaderTests/GecomCustomRecordTest.cs diff --git a/GeneGenie.Gedcom.Tests/Data/UidAndBurg.ged b/GeneGenie.Gedcom.Tests/Data/UidAndBurg.ged new file mode 100644 index 0000000..d761a50 --- /dev/null +++ b/GeneGenie.Gedcom.Tests/Data/UidAndBurg.ged @@ -0,0 +1,20 @@ +0 HEAD +1 SOUR PhpGedView +2 NAME PhpGedView Online Genealogy +2 VERS 3.3.8 final +1 DATE 1 Apr 2006 +0 @I1@ INDI +1 _UID A5A812A4C0FE44C9A98F8D4627073B69AB88 +1 NAME TestGivenName /TestSurname/ +2 SURN TestSurname +2 GIVN TestGivenName +1 SEX M +1 BIRT +2 DATE 9 OCT 1990 +2 _BURG unbekannt +1 CHAN +2 DATE 28 DEC 2023 +3 TIME 11:21:46 +0 @SUBM@ SUBM +1 NAME Test for GeneGenie +0 TRLR diff --git a/GeneGenie.Gedcom.Tests/GeneGenie.Gedcom.Tests.csproj b/GeneGenie.Gedcom.Tests/GeneGenie.Gedcom.Tests.csproj index dbebb56..49bfdbc 100644 --- a/GeneGenie.Gedcom.Tests/GeneGenie.Gedcom.Tests.csproj +++ b/GeneGenie.Gedcom.Tests/GeneGenie.Gedcom.Tests.csproj @@ -74,6 +74,9 @@ Always + + Always + diff --git a/GeneGenie.Gedcom.Tests/RecordReaderTests/GecomCustomRecordTest.cs b/GeneGenie.Gedcom.Tests/RecordReaderTests/GecomCustomRecordTest.cs new file mode 100644 index 0000000..555fc91 --- /dev/null +++ b/GeneGenie.Gedcom.Tests/RecordReaderTests/GecomCustomRecordTest.cs @@ -0,0 +1,46 @@ +// +// Copyright (c) GeneGenie.com. All Rights Reserved. +// Licensed under the GNU Affero General Public License v3.0. See LICENSE in the project root for license information. +// +// Copyright (C) 2023 Herbert Oppmann gith@memotech.franken.de + + +namespace GeneGenie.Gedcom.Tests.RecordReaderTests +{ + using GeneGenie.Gedcom.Parser; + using System; + using Xunit; + + /// + /// Tests to ensure that custom records are correctly read in. + /// + public class GedcomCustomRecordTest + { + /// + /// Test for custom record '_UID' in individual record. + /// + [Fact] + public void Record_UID() + { + var reader = GedcomRecordReader.CreateReader("./Data/UidAndBurg.ged"); + GedcomIndividualRecord indi = reader.Database.Individuals[0]; + GedcomCustomRecord cr = indi.Custom[0]; + Assert.Equal("_UID", cr.Tag); + Assert.Equal("A5A812A4C0FE44C9A98F8D4627073B69AB88", cr.Classification); + } + + /// + /// Test for custom record '_BURG' in event record. + /// + [Fact] + public void Record_BURG() + { + var reader = GedcomRecordReader.CreateReader("./Data/UidAndBurg.ged"); + GedcomIndividualRecord indi = reader.Database.Individuals[0]; + GedcomEvent er = indi.Events[0]; + GedcomCustomRecord cr = er.Custom[0]; + Assert.Equal("_BURG", cr.Tag); + Assert.Equal("unbekannt", cr.Classification); + } + } +} diff --git a/GeneGenie.Gedcom/GedcomEvent.cs b/GeneGenie.Gedcom/GedcomEvent.cs index 4e210ee..9415fdc 100644 --- a/GeneGenie.Gedcom/GedcomEvent.cs +++ b/GeneGenie.Gedcom/GedcomEvent.cs @@ -212,6 +212,9 @@ public override GedcomRecordType RecordType get { return GedcomRecordType.Event; } } + /// Gets or sets the list of entries found when parsing an event. + public GedcomRecordList Custom { get; set; } = new GedcomRecordList(); + /// /// Gets the gedcom tag. /// diff --git a/GeneGenie.Gedcom/Parser/GedcomRecordReader.cs b/GeneGenie.Gedcom/Parser/GedcomRecordReader.cs index 2c37c78..a17630d 100644 --- a/GeneGenie.Gedcom/Parser/GedcomRecordReader.cs +++ b/GeneGenie.Gedcom/Parser/GedcomRecordReader.cs @@ -3807,7 +3807,7 @@ private void ReadEventRecord() custom.Classification = lineValue; } - // TODO: may want to use customs at some point + eventRecord.Custom.Add(custom); parseState.Records.Push(custom); break; }