internal static DatePlace ParseDatePlace(this ResultContainer resultContainer, GedcomChunk chunk) { var datePlace = new DatePlace { Date = chunk.SubChunks.SingleOrDefault(c => c.Type == "DATE")?.Data, Place = chunk.SubChunks.SingleOrDefault(c => c.Type == "PLAC")?.Data }; var map = chunk.SubChunks.SingleOrDefault(c => c.Type == "MAP"); if (map != null) { datePlace.Latitude = map.SubChunks.SingleOrDefault(c => c.Type == "LATI")?.Data; datePlace.Longitude = map.SubChunks.SingleOrDefault(c => c.Type == "LONG")?.Data; } var note = chunk.SubChunks.SingleOrDefault(c => c.Type == "NOTE"); if (note != null) { datePlace.Note = resultContainer.ParseNote(datePlace.Note, note); } return(datePlace); }
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 }); } } }