Example #1
0
        private void ParseFamily(GedcomChunk famChunk)
        {
            GedcomEvent marriage    = null;
            GedcomEvent divorce     = null;
            string      relation    = null;
            string      note        = null;
            var         parentsIds  = new List <string>();
            var         childrenIds = new List <string>();

            foreach (var chunk in famChunk.Subchunks)
            {
                switch (chunk.Key)
                {
                case "CHIL":
                    childrenIds.AddRange(chunk.Value.Select(value => value.Reference));
                    break;

                case "HUSB":
                case "WIFE":
                    parentsIds.AddRange(chunk.Value.Select(value => value.Reference));
                    break;

                case "DIV":
                    TryParseEvent(chunk.Key, chunk.Value.FirstOrDefault(), out divorce);
                    break;

                case "_REL":
                    relation = chunk.Value.FirstOrDefault()?.Data;
                    break;

                case "MARR":
                    TryParseEvent(chunk.Key, chunk.Value.FirstOrDefault(), out marriage);
                    break;

                case "NOTE":
                    note = ParseNote(note, chunk.Value.FirstOrDefault());
                    break;

                default:
                    Logger?.LogInfo(ToString(chunk) + " skipped");
                    break;
                }
            }

            // Spouses
            if (parentsIds.Count == 2)
            {
                _parseResult.Relations.Add(new SpouseRelation(famChunk.Id, parentsIds[0], parentsIds[1])
                {
                    Marriage = marriage,
                    Divorce  = divorce,
                    Relation = relation,
                    Note     = note
                });
            }

            // Parents / Children
            foreach (string parent in parentsIds)
            {
                foreach (string child in childrenIds)
                {
                    var childRelation = new ChildRelation(famChunk.Id, child, parent);
                    AddStatus(childRelation);
                    _parseResult.Relations.Add(childRelation);
                }
            }
        }
Example #2
0
        private bool TryParseEvent(string key, GedcomChunk chunk, out GedcomEvent gedcomEvent)
        {
            if (key == null || chunk == null)
            {
                gedcomEvent = null;
                return(false);
            }

            string dateString = chunk.Subchunks.TryGetFirstValue("DATE", out GedcomChunk value) ? value.Data : null;

            EventType eventType;

            if (!GedcomEvent.EventTypesMap.TryGetValue(key, out eventType))
            {
                eventType = EventType.Other;
            }

            if (eventType != EventType.Adoption)
            {
                gedcomEvent = new GedcomEvent(eventType);
            }
            else
            {
                var adoptionEvent = new GedcomAdoptionEvent();

                foreach (var adoptionSubChunk in chunk.Subchunks)
                {
                    switch (adoptionSubChunk.Key)
                    {
                    case "NOTE":
                        adoptionEvent.Note = ParseNote(adoptionEvent.Note, adoptionSubChunk.Value.FirstOrDefault());
                        break;

                    case "TYPE":
                        adoptionEvent.AdoptionType = adoptionSubChunk.Value.FirstOrDefault()?.Data;
                        break;

                        // Skip for now
                    }
                }

                gedcomEvent = adoptionEvent;
            }

            if (dateString != null)
            {
                gedcomEvent.Date = dateString;
            }
            gedcomEvent.Place = chunk.Subchunks.TryGetFirstValue("PLAC", out GedcomChunk data) ? data.Data : null;

            if (chunk.Subchunks.TryGetFirstValue("MAP", out GedcomChunk map))
            {
                gedcomEvent.Latitude  = map.Subchunks.TryGetFirstValue("LATI", out GedcomChunk value1) ? value1.Data : null;
                gedcomEvent.Longitude = map.Subchunks.TryGetFirstValue("LONG", out GedcomChunk value2) ? value2.Data : null;
            }

            if (chunk.Subchunks.TryGetFirstValue("NOTE", out GedcomChunk note))
            {
                gedcomEvent.Note = ParseNote(gedcomEvent.Note, note);
            }

            return(true);
        }