private void ParseTopChunks(ICollection <GedcomChunk> chunks) { foreach (var chunk in chunks) { switch (chunk.Type) { case "FAM": ParseFamily(chunk); break; case "INDI": GedcomPerson person = ParseIndividual(chunk); _parseResult.Persons.Add(person.Id, person); break; default: Logger?.LogInfo(chunk + " skipped"); break; } // Save for lookup if (!string.IsNullOrEmpty(chunk.Reference)) { _idChunks.Add(chunk.Id, chunk); } } }
private GedcomPerson ParseIndividual(GedcomChunk indiChunk) { var person = new GedcomPerson(indiChunk.Id); foreach (var chunk in indiChunk.Subchunks) { switch (chunk.Key) { case "_UID": person.Uid = chunk.Value.FirstOrDefault()?.Data; break; case "CHAN": person.Changed = ParseDateTime(chunk.Value.FirstOrDefault()); break; case "ADOP": case "BAPM": case "BIRT": case "BURI": case "CHR": case "DEAT": case "EMIG": case "GRAD": case "IMMI": case "NATU": case "RESI": foreach (GedcomChunk value in chunk.Value) { if (TryParseEvent(chunk.Key, value, out GedcomEvent gedcomEvent)) { person.Events.Add(gedcomEvent); } } break; case "EDUC": person.Education = chunk.Value.FirstOrDefault()?.Data; break; case "FACT": person.Note = ParseNote(person.Note, chunk.Value.FirstOrDefault()); break; case "HEAL": person.Health = chunk.Value.FirstOrDefault()?.Data; break; case "IDNO": person.IdNumber = chunk.Value.FirstOrDefault()?.Data; break; case "NAME": var nameSections = chunk.Value.FirstOrDefault()?.Data.Split("/".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (nameSections.Length > 0) { person.FirstName = nameSections[0].Trim(); } if (nameSections.Length > 1) { person.LastName = nameSections[1].Trim(); } break; case "NOTE": person.Note = ParseNote(person.Note, chunk.Value.FirstOrDefault()); break; case "OCCU": person.Occupation = chunk.Value.FirstOrDefault()?.Data; break; case "RELI": person.Religion = chunk.Value.FirstOrDefault()?.Data; break; case "SEX": person.Gender = chunk.Value.FirstOrDefault()?.Data; break; case "TITL": person.Title = chunk.Value.FirstOrDefault()?.Data; break; default: Logger?.LogInfo(ToString(chunk) + " skipped"); break; } } return(person); }