internal static Adoption ParseAdoption(this ResultContainer resultContainer, GedcomChunk adoptionChunk) { var adoption = new Adoption { DatePlace = resultContainer.ParseDatePlace(adoptionChunk) }; foreach (var chunk in adoptionChunk.SubChunks) { switch (chunk.Type) { case "NOTE": adoption.Note = resultContainer.ParseNote(adoption.Note, chunk); break; case "TYPE": adoption.Type = chunk.Data; break; // Deliberately skipped for now case "DATE": case "FAMC": case "PLAC": case "SOUR": resultContainer.Warnings.Add($"Skipped Adoption Type='{chunk.Type}"); break; default: resultContainer.Errors.Add($"Failed to handle Adoption Type='{chunk.Type}"); break; } } return(adoption); }
internal static void ParseFamily(this ResultContainer resultContainer, GedcomChunk famChunk) { DatePlace marriage = null; string relation = null; string note = null; DatePlace divorce = null; var parents = new List <Person>(); var children = new List <Person>(); foreach (var chunk in famChunk.SubChunks) { switch (chunk.Type) { case "CHIL": var child = resultContainer.Persons.SingleOrDefault(p => p.Id == chunk.Reference); if (child != null) { children.Add(child); } break; case "DIV": divorce = resultContainer.ParseDatePlace(chunk); break; case "HUSB": var husband = resultContainer.Persons.SingleOrDefault(p => p.Id == chunk.Reference); if (husband != null) { parents.Add(husband); } break; case "_REL": relation = chunk.Data; break; case "MARR": marriage = resultContainer.ParseDatePlace(chunk); break; case "NOTE": note = resultContainer.ParseNote(note, chunk); break; case "WIFE": var wife = resultContainer.Persons.SingleOrDefault(p => p.Id == chunk.Reference); if (wife != null) { parents.Add(wife); } break; // Deliberately skipped for now case "CHAN": case "DSCR": case "EVEN": case "FAMS": case "FAMC": case "HIST": case "MARS": case "NCHI": case "NMR": case "OBJE": case "PAGE": case "SOUR": resultContainer.Warnings.Add($"Skipped Family Type='{chunk.Type}"); break; default: resultContainer.Errors.Add($"Failed to handle Family Type='{chunk.Type}"); break; } } // Spouses if (parents.Count == 2) { resultContainer.SpouseRelations.Add(new SpouseRelation { FamilyId = famChunk.Id, From = parents[0], To = parents[1], Marriage = marriage, Divorce = divorce, Relation = relation, Note = note }); } // Parents / Children foreach (var parent in parents) { foreach (var child in children) { var childRelation = new ChildRelation { FamilyId = famChunk.Id, From = child, To = parent }; AddStatus(resultContainer, childRelation); resultContainer.ChildRelations.Add(childRelation); } } // Siblings foreach (var child1 in children) { foreach (var child2 in children.Where(c => c.Id != child1.Id)) { resultContainer.SiblingRelations.Add(new SiblingRelation { FamilyId = famChunk.Id, From = child1, To = child2 }); } } }
internal static void ParsePerson(this ResultContainer resultContainer, GedcomChunk indiChunk) { var person = new Person { Id = indiChunk.Id }; foreach (var chunk in indiChunk.SubChunks) { switch (chunk.Type) { case "_UID": person.Uid = chunk.Data; break; case "ADOP": person.Adoption = resultContainer.ParseAdoption(chunk); break; case "BAPM": person.Baptized = resultContainer.ParseDatePlace(chunk); break; case "BIRT": person.Birth = resultContainer.ParseDatePlace(chunk); break; case "BURI": person.Buried = resultContainer.ParseDatePlace(chunk); break; case "CHAN": person.Changed = chunk.ParseDateTime(); break; case "CHR": person.Baptized = resultContainer.ParseDatePlace(chunk); break; case "DEAT": person.Death = resultContainer.ParseDatePlace(chunk); break; case "EDUC": person.Education = chunk.Data; break; case "EMIG": person.Emigrated = resultContainer.ParseDatePlace(chunk); break; case "FACT": person.Note = resultContainer.ParseNote(person.Note, chunk); break; case "GRAD": person.Graduation = resultContainer.ParseDatePlace(chunk); break; case "HEAL": person.Health = chunk.Data; break; case "IDNO": person.IdNumber = chunk.Data; break; case "IMMI": person.Immigrated = resultContainer.ParseDatePlace(chunk); break; case "NAME": var nameSections = chunk.Data.Split("/".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (nameSections.Length > 0) { person.FirstName = nameSections[0]; } if (nameSections.Length > 1) { person.LastName = nameSections[1]; } break; case "NATU": person.BecomingCitizen = resultContainer.ParseDatePlace(chunk); break; case "NOTE": person.Note = resultContainer.ParseNote(person.Note, chunk); break; case "OCCU": person.Occupation = chunk.Data; break; case "RESI": person.Residence = resultContainer.ParseDatePlace(chunk); break; case "RELI": person.Religion = chunk.Data; break; case "SEX": person.Gender = chunk.Data; break; case "TITL": person.Title = chunk.Data; break; // Deliberately skipped for now case "_GRP": case "CONF": case "DSCR": case "EVEN": case "FAMS": case "FAMC": case "HIST": case "NCHI": case "NMR": case "OBJE": case "PAGE": case "RIN": case "SOUR": resultContainer.Warnings.Add($"Skipped Person Type='{chunk.Type}"); break; default: resultContainer.Errors.Add($"Failed to handle Person Type='{chunk.Type}"); break; } } resultContainer.Persons.Add(person); }