private GedcomRecord PopStack(int level) { GedcomRecord current = null; if (_ParseState.Records.Count != 0) { current = _ParseState.Records.Peek(); } while ((_ParseState.PreviousTags.Count > 0) && (_ParseState.PreviousTags.Peek().Second >= level)) { _ParseState.PreviousTags.Pop(); } while (current != null && level <= current.ParsingLevel) { switch (current.RecordType) { // hack for ADDR appearing on INDI, done by Family Tree Maker // convert it to a RESI case GedcomRecordType.Individual: GedcomIndividualRecord indi = (GedcomIndividualRecord)current; GedcomAddress address = indi.Address; if (address != null) { GedcomIndividualEvent resi = new GedcomIndividualEvent(); resi.EventType = GedcomEvent.GedcomEventType.RESIFact; resi.Database = Database; resi.Level = indi.Level + 1; resi.IndiRecord = indi; resi.Address = address; indi.Events.Add(resi); indi.Address = null; } break; // hacks to avoid allocating lots of strings, we use a string builder // as we have hit the end of the record set the value from the string builder case GedcomRecordType.Note: GedcomNoteRecord note = (GedcomNoteRecord)current; note.Text = note.ParsedText.ToString(); note.ParsedText = null; if (StringHelper.IsWhiteSpace(note.Text)) { _removedNotes.Add(note.XRefID); current = null; } break; case GedcomRecordType.SourceCitation: GedcomSourceCitation citation = (GedcomSourceCitation)current; if (citation.ParsedText != null) { citation.Text = citation.ParsedText.ToString(); citation.ParsedText = null; } break; case GedcomRecordType.Source: GedcomSourceRecord source = (GedcomSourceRecord)current; if (source.TitleText != null) { source.Title = source.TitleText.ToString(); source.TitleText = null; } else if (source.OriginatorText != null) { source.Originator = source.OriginatorText.ToString(); source.OriginatorText = null; } else if (source.PublicationText != null) { source.PublicationFacts = source.PublicationText.ToString(); source.PublicationText = null; } else if (source.TextText != null) { source.Text = source.TextText.ToString(); source.TextText = null; } break; } if (current != null) { // ensure database is set on all records // or at least those that have been pushed on the stack if (current.Database != Database) { current.Database = Database; } // pop as we are at a higher level now if (current.Level == 0 && current.RecordType != GedcomRecordType.Header) { _ParseState.Database.Add(current.XRefID,current); } current = null; } _ParseState.Records.Pop(); if (_ParseState.Records.Count > 0) { current = _ParseState.Records.Peek(); } } return current; }
private GedcomIndividualRecord GetGedIndi(string indi, string family, string nKitNbr, string pre, string sex, GedcomIndividualRecord sindi=null,GedcomIndividualRecord schild=null) { if (htIndi.Contains(indi)) { foreach (GedcomIndividualRecord ggir in _gd1.Individuals) { try { if (ggir.XRefID.Equals(indi)) return ggir; } catch { } } return null; } else htIndi.Add(indi, indi); string fatherid = String.Empty; string motherid = String.Empty; string npre = "http://www.gedmatch.com/individual_detail.php?id_family=" + family + "&id_ged=" + indi; foreach (char ichar in Path.GetInvalidFileNameChars()) indi.Replace(ichar, '_'); GetHTML(npre, WorkIndiDir + family + "\\GM_INDI_" + nKitNbr + "_" + indi + ".html", pre); StreamReader reader = new StreamReader(WorkIndiDir + family + "\\GM_INDI_" + nKitNbr + "_" + indi + ".html"); string line = reader.ReadLine(); GedcomIndividualRecord record=null; GedcomFamilyRecord ngfr = null; bool union = false; while (line != null) { //Check for Name if (line.StartsWith("<br><font size=+3><b>")) { int ine = line.IndexOf("</b>"); int ige = line.IndexOf("'>"); int iborn = line.IndexOf("Born:"); int ib = line.IndexOf("</b>"); int ideath = line.IndexOf("Died:"); string name = line.Substring(21, ine - 21).Replace(" ", " ").Trim(); record = new GedcomIndividualRecord(_gd1); GedcomName gn = new GedcomName(); gn.Database = _gd1; gn.Split(name); gn.Level = 1; gn.PreferedName = true; record.Names.Add(gn); record.XRefID = indi; record.Sex = GedcomSex.Undetermined; if (sex.Equals("M")) { record.Sex = GedcomSex.Male; } if (sex.Equals("F")) { record.Sex = GedcomSex.Female; } try { string born = line.Substring(iborn + 11).Replace("<br>", "").Replace(" ", " ").Trim(); string death = string.Empty; if (ideath > 0) { born = line.Substring(iborn + 11, ideath - iborn - 11).Replace("<br>", "").Replace(" ", " ").Trim(); death = line.Substring(ideath); } try { GedcomDate bd = new GedcomDate(born); bd.Database = _gd1; bd.Date1 = born.Substring(0, born.IndexOf(",")); bd.Level = record.Level + 2; GedcomIndividualEvent gieb = new GedcomIndividualEvent(); gieb.Database = _gd1; gieb.Date = bd; //record.Birth.Date = bd; GedcomAddress gab = new GedcomAddress(); gab.Database = _gd1; gab.AddressLine = born.Substring(born.IndexOf(",") + 1); gieb.Address = gab; //record.Birth.Address = gab; gieb.EventType = GedcomEvent.GedcomEventType.BIRT; gieb.IndiRecord = record; gieb.Level = record.Level + 1; record.Events.Add(gieb); } catch { } if (death.Equals(string.Empty)) { GedcomDate dd = new GedcomDate(death); dd.Database = _gd1; dd.Date1 = death.Substring(0, death.IndexOf(",")); dd.Level = record.Level + 2; GedcomIndividualEvent gieb = new GedcomIndividualEvent(); gieb.Database = _gd1; gieb.Date = dd; //record.Birth.Date = bd; GedcomAddress gab = new GedcomAddress(); gab.Database = _gd1; gab.AddressLine = born.Substring(death.IndexOf(",") + 1); gieb.Address = gab; //record.Birth.Address = gab; gieb.EventType = GedcomEvent.GedcomEventType.DEAT; gieb.IndiRecord = record; gieb.Level = record.Level+1; record.Events.Add(gieb); } } catch {} //GedcomFamilyRecord ngfr=null; //if (sindi != null) //{ // ngfr = new GedcomFamilyRecord(_gd1, record, sindi); // //sindi.SpouseIn.Add( //} //if (schild != null) //{ // //GedcomFamilyLink gfl = new GedcomFamilyLink(); // //gfl.Database = _gd1; // if (ngfr != null) // { // //gfl.XRefID = ngfr.XRefID; // ngfr.AddChild(schild); // } // else // { // ngfr = new GedcomFamilyRecord(_gd1, record, null); // ngfr.AddChild(schild); // } //} } //Check for if (line.StartsWith("<br>Father: ")) { try { int ifam = line.IndexOf("id_family="); int ig = line.IndexOf("&id_ged"); int ige = line.IndexOf("'>"); if (ifam > 0 && ig > 0) { string nfamily = line.Substring(ifam + 10, ig - ifam - 10); string nindi = line.Substring(ig + 8, ige - ig - 8); GetGedIndi(nindi, nfamily, nKitNbr, npre, "M", null, record); } } catch { } } if (line.StartsWith("<br>Mother: ")) { try { int ifam = line.IndexOf("id_family="); int ig = line.IndexOf("&id_ged"); int ige = line.IndexOf("'>"); if (ifam > 0 && ig > 0) { string nfamily = line.Substring(ifam + 10, ig - ifam - 10); string nindi = line.Substring(ig + 8, ige - ig - 8); GetGedIndi(nindi, nfamily, nKitNbr, npre, "F", null, record); } int iss = line.IndexOf("<br>Union with:"); if (iss > 0) line = line.Substring(iss); } catch { } } //Check for Spouse if (line.StartsWith("<br>Union with:") || line.StartsWith("<br><br>Union with: ") || union) { int ifam = line.IndexOf("id_family="); int ig = line.IndexOf("&id_ged"); int ige = line.IndexOf("'>"); if (ifam > 0 && ig > 0) { string nfamily = line.Substring(ifam + 10, ig - ifam - 10); string nindi = line.Substring(ig + 8, ige - ig - 8); string nsex = "U"; if (sex.Equals("M")) { nsex = "F"; } if (sex.Equals("F")) { nsex = "M"; } GedcomIndividualRecord spouse = GetGedIndi(nindi, nfamily, nKitNbr, npre, nsex); //ToDo Figure out if we already created the family with OTHER spouse ngfr = new GedcomFamilyRecord(_gd1, record, spouse); union = false; } else union = true; } bool gotchild = false; while (line.StartsWith("<br>Children: ") || (gotchild && (line.StartsWith(" <a href='./individual")||line.StartsWith(" +<a href='./individual")))) { union = false; int ifam = line.IndexOf("id_family="); int ig = line.IndexOf("&id_ged"); int ige = line.IndexOf("'>"); if (ifam > 0 && ig > 0) { string nfamily = line.Substring(ifam + 10, ig - ifam - 10); string nindi = line.Substring(ig + 8, ige - ig - 8); string nsex = "U"; GedcomIndividualRecord child = GetGedIndi(nindi, nfamily, nKitNbr, npre, nsex); if (ngfr == null) { //Add child to Group } else { ngfr.AddChild(child); } line = reader.ReadLine(); } gotchild = true; } //Add Children line = reader.ReadLine(); } reader.Close(); return record; }
private void ReadIndividualRecord() { GedcomIndividualRecord individualRecord; individualRecord = _ParseState.Records.Peek() as GedcomIndividualRecord; GedcomIndividualEvent individualEvent; // some custom tags we convert to generic facts/events // this means we have to set the line value to the type // they represent, so store the real line value and use // for the event classification. string customToGenericClassification = string.Empty; if (_tag.StartsWith("_")) { switch (_tag) { // we convert _MILT to EVEN Military Service case "_MILT": _tag = "EVEN"; _lineValue = "Military Service"; _lineValueType = GedcomLineValueType.DataType; break; // we convert _MDCL to FACT Medical case "_MDCL": _tag = "FACT"; customToGenericClassification = _lineValue; _lineValue = "Medical"; _lineValueType = GedcomLineValueType.DataType; break; // we convert _HEIG to FACT Height case "_HEIG": _tag = "FACT"; customToGenericClassification = _lineValue; _lineValue = "Height"; _lineValueType = GedcomLineValueType.DataType; break; // we convert _WEIG to FACT Weight case "_WEIG": _tag = "FACT"; customToGenericClassification = _lineValue; _lineValue = "Weight"; _lineValueType = GedcomLineValueType.DataType; break; default: GedcomCustomRecord custom = new GedcomCustomRecord(); custom.Level = _level; custom.XRefID = _xrefID; custom.Tag = _tag; if (_lineValueType == GedcomLineValueType.DataType) { custom.Classification = _lineValue; } // FIXME: may want to use customs at some point //individualRecord.Events.Add(custom); _ParseState.Records.Push(custom); break; } } if (_level == individualRecord.ParsingLevel + 1) { switch (_tag) { case "FAMC": if (_lineValueType == GedcomLineValueType.PointerType) { GedcomFamilyLink childIn = new GedcomFamilyLink(); childIn.Level = _level; childIn.Family = _lineValue; childIn.Indi = individualRecord.XRefID; _missingReferences.Add(_lineValue); individualRecord.ChildIn.Add(childIn); _ParseState.Records.Push(childIn); } break; case "FAMS": if (_lineValueType == GedcomLineValueType.PointerType) { GedcomFamilyLink spouseIn = new GedcomFamilyLink(); spouseIn.Level = _level; spouseIn.Family = _lineValue; spouseIn.Indi = individualRecord.XRefID; spouseIn.PreferedSpouse = (individualRecord.SpouseIn.Count == 0); _missingReferences.Add(_lineValue); individualRecord.SpouseIn.Add(spouseIn); _ParseState.Records.Push(spouseIn); } break; case "ASSO": if (_lineValueType == GedcomLineValueType.PointerType) { GedcomAssociation association = new GedcomAssociation(); association.Level = _level; association.Individual = _lineValue; _missingReferences.Add(_lineValue); individualRecord.Associations.Add(association); _ParseState.Records.Push(association); } break; case "RESN": if (_lineValueType == GedcomLineValueType.DataType) { try { individualRecord.RestrictionNotice = EnumHelper.Parse<GedcomRestrictionNotice>(_lineValue,true); } catch { Debug.WriteLine("Invalid restriction type: " + _lineValue); // default to confidential to protect privacy individualRecord.RestrictionNotice = GedcomRestrictionNotice.Confidential; } } break; case "NAME": if (_lineValueType == GedcomLineValueType.DataType) { GedcomName name = new GedcomName(); name.Database = _ParseState.Database; name.Level = _level; name.Name = _lineValue; name.PreferedName = (individualRecord.Names.Count == 0); individualRecord.Names.Add(name); _ParseState.Records.Push(name); } break; // Invalid, but seen from Family Origins, Family Tree Maker, Personal Ancestral File, and Legacy case "AKA": if (_lineValueType == GedcomLineValueType.DataType) { GedcomName name = new GedcomName(); name.Database = _ParseState.Database; name.Level = _level; name.Name = _lineValue; name.Type = "aka"; name.PreferedName = (individualRecord.Names.Count == 0); individualRecord.Names.Add(name); } break; case "SEX": if (_lineValueType == GedcomLineValueType.DataType) { switch (_lineValue) { case "M": individualRecord.Sex = GedcomSex.Male; break; case "F": individualRecord.Sex = GedcomSex.Female; break; // non standard case "B": individualRecord.Sex = GedcomSex.Both; break; // non standard case "N": individualRecord.Sex = GedcomSex.Neuter; break; // non standard case "U": individualRecord.Sex = GedcomSex.Undetermined; break; } } break; case "SUBM": if (_lineValueType == GedcomLineValueType.PointerType) { individualRecord.SubmitterRecords.Add(_lineValue); _missingReferences.Add(_lineValue); } else { GedcomSubmitterRecord submitter = new GedcomSubmitterRecord(); submitter.Level = 0; // new top level submitter, always 0 submitter.ParsingLevel = _level; submitter.XRefID = Database.GenerateXref("SUBM"); _ParseState.Records.Push(submitter); individualRecord.SubmitterRecords.Add(submitter.XRefID); } break; case "ALIA": if (_lineValueType == GedcomLineValueType.PointerType) { individualRecord.Alia.Add(_lineValue); _missingReferences.Add(_lineValue); } else if (_lineValueType == GedcomLineValueType.DataType) { // Family Tree Maker doing this? // ALIA is unsupported in gedcom 5.5 as a way of // adding multiple names, the spec // does say it should be a pointer to an individual // though, not another name. // spec allows multiple NAME though, so add one // with this name GedcomName name = new GedcomName(); name.Database = _ParseState.Database; name.Level = _level; name.Name = _lineValue; name.Type = "aka"; name.PreferedName = (individualRecord.Names.Count == 0); individualRecord.Names.Add(name); } break; case "ANCI": if (_lineValueType == GedcomLineValueType.PointerType) { individualRecord.Anci.Add(_lineValue); _missingReferences.Add(_lineValue); } break; case "DESI": if (_lineValueType == GedcomLineValueType.PointerType) { individualRecord.Desi.Add(_lineValue); _missingReferences.Add(_lineValue); } break; case "RFN": if (_lineValueType == GedcomLineValueType.DataType) { individualRecord.PermanentRecordFileNumber = _lineValue; } break; case "AFN": if (_lineValueType == GedcomLineValueType.DataType) { individualRecord.AncestralFileNumber = _lineValue; } break; case "REFN": if (_lineValueType == GedcomLineValueType.DataType) { individualRecord.UserReferenceNumber = _lineValue; } break; case "RIN": if (_lineValueType == GedcomLineValueType.DataType) { individualRecord.AutomatedRecordID = _lineValue; } break; case "CHAN": GedcomChangeDate date = new GedcomChangeDate(Database); date.Level = _level; _ParseState.Records.Push(date); break; case "NOTE": AddNoteRecord(individualRecord); break; case "SOUR": AddSourceCitation(individualRecord); break; case "OBJE": AddMultimediaRecord(individualRecord); break; case "BIRT": // event individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.BIRT; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; individualRecord.Events.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "CHR": // event individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.CHR; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; individualRecord.Events.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "DEAT": // event individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.DEAT; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; individualRecord.Events.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "BURI": // event individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.BURI; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; individualRecord.Events.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "CREM": // event individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.CREM; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; individualRecord.Events.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "ADOP": // event individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.ADOP; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; individualRecord.Events.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "BAPM": // event individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.BAPM; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; individualRecord.Events.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "BARM": // event individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.BARM; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; individualRecord.Events.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "BASM": // event individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.BASM; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; individualRecord.Events.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "BLES": // event individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.BLES; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; individualRecord.Events.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "CHRA": // event individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.CHRA; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; individualRecord.Events.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "CONF": // event individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.CONF; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; individualRecord.Events.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "FCOM": // event individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.FCOM; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; individualRecord.Events.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "ORDN": // event individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.ORDN; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; individualRecord.Events.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "NATU": // event individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.NATU; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; individualRecord.Events.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "EMIG": // event individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.EMIG; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; individualRecord.Events.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "IMMI": // event individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.IMMI; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; individualRecord.Events.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "CENS": // event individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.CENS; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; individualRecord.Events.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "PROB": // event individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.PROB; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; individualRecord.Events.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "WILL": // event individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.WILL; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; individualRecord.Events.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "GRAD": // event individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.GRAD; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; individualRecord.Events.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "RETI": // event individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.RETI; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; individualRecord.Events.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "EVEN": // event individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.GenericEvent; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; if (_lineValueType == GedcomLineValueType.DataType) { individualEvent.EventName = _lineValue; } individualRecord.Events.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "CAST": // fact individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.CASTFact; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; if (_lineValueType == GedcomLineValueType.DataType) { individualEvent.EventName = _lineValue; } individualRecord.Attributes.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "DSCR": // fact individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.DSCRFact; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; if (_lineValueType == GedcomLineValueType.DataType) { individualEvent.EventName = _lineValue; } individualRecord.Attributes.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "EDUC": // fact individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.EDUCFact; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; if (_lineValueType == GedcomLineValueType.DataType) { individualEvent.EventName = _lineValue; } individualRecord.Attributes.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "IDNO": // fact individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.IDNOFact; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; if (_lineValueType == GedcomLineValueType.DataType) { individualEvent.EventName = _lineValue; } individualRecord.Attributes.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "NATI": // fact individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.NATIFact; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; if (_lineValueType == GedcomLineValueType.DataType) { individualEvent.EventName = _lineValue; } individualRecord.Attributes.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "NCHI": // fact individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.NCHIFact; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; if (_lineValueType == GedcomLineValueType.DataType) { individualEvent.EventName = _lineValue; } individualRecord.Attributes.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "NMR": // fact individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.NMRFact; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; if (_lineValueType == GedcomLineValueType.DataType) { individualEvent.EventName = _lineValue; } individualRecord.Attributes.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "OCCU": // fact individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.OCCUFact; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; if (_lineValueType == GedcomLineValueType.DataType) { individualEvent.EventName = _lineValue; } individualRecord.Attributes.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "PROP": // fact individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.PROPFact; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; if (_lineValueType == GedcomLineValueType.DataType) { individualEvent.EventName = _lineValue; } individualRecord.Attributes.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "RELI": // fact individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.RELIFact; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; if (_lineValueType == GedcomLineValueType.DataType) { individualEvent.EventName = _lineValue; } individualRecord.Attributes.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "RESI": // fact individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.RESIFact; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; if (_lineValueType == GedcomLineValueType.DataType) { individualEvent.EventName = _lineValue; } individualRecord.Attributes.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "SSN": // fact individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.SSNFact; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; if (_lineValueType == GedcomLineValueType.DataType) { individualEvent.EventName = _lineValue; } individualRecord.Attributes.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "TITL": // fact individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.TITLFact; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; if (_lineValueType == GedcomLineValueType.DataType) { individualEvent.EventName = _lineValue; } individualRecord.Attributes.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "FACT": // fact individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.GenericFact; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; if (_lineValueType == GedcomLineValueType.DataType) { individualEvent.EventName = _lineValue; } if (!string.IsNullOrEmpty(customToGenericClassification)) { individualEvent.Classification = customToGenericClassification; } individualRecord.Attributes.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; // Not according to the spec, but Family Tree Maker sticks // an address under an individual so we will support reading it case "ADDR": if (individualRecord.Address == null) { individualRecord.Address = new GedcomAddress(); individualRecord.Address.Database = Database; } if (_lineValueType == GedcomLineValueType.DataType) { individualRecord.Address.AddressLine = _lineValue; } break; case "PHON": if (individualRecord.Address == null) { individualRecord.Address = new GedcomAddress(); individualRecord.Address.Database = Database; } if (_lineValueType == GedcomLineValueType.DataType) { if (string.IsNullOrEmpty(individualRecord.Address.Phone1)) { individualRecord.Address.Phone1 = _lineValue; } else if (string.IsNullOrEmpty(individualRecord.Address.Phone2)) { individualRecord.Address.Phone2 = _lineValue; } else if (string.IsNullOrEmpty(individualRecord.Address.Phone3)) { individualRecord.Address.Phone3 = _lineValue; } else { // should never occur only 3 phone numbers are allowed } } break; case "EMAIL": if (individualRecord.Address == null) { individualRecord.Address = new GedcomAddress(); individualRecord.Address.Database = Database; } if (_lineValueType == GedcomLineValueType.DataType) { if (string.IsNullOrEmpty(individualRecord.Address.Email1)) { individualRecord.Address.Email1 = _lineValue; } else if (string.IsNullOrEmpty(individualRecord.Address.Email2)) { individualRecord.Address.Email2 = _lineValue; } else if (string.IsNullOrEmpty(individualRecord.Address.Email3)) { individualRecord.Address.Email3 = _lineValue; } else { // should never occur only 3 emails are allowed } } break; case "FAX": if (individualRecord.Address == null) { individualRecord.Address = new GedcomAddress(); individualRecord.Address.Database = Database; } if (_lineValueType == GedcomLineValueType.DataType) { if (string.IsNullOrEmpty(individualRecord.Address.Fax1)) { individualRecord.Address.Fax1 = _lineValue; } else if (string.IsNullOrEmpty(individualRecord.Address.Fax2)) { individualRecord.Address.Fax2 = _lineValue; } else if (string.IsNullOrEmpty(individualRecord.Address.Fax3)) { individualRecord.Address.Fax3 = _lineValue; } else { // should never occur only 3 fax numbers are allowed } } break; case "WWW": if (individualRecord.Address == null) { individualRecord.Address = new GedcomAddress(); individualRecord.Address.Database = Database; } if (_lineValueType == GedcomLineValueType.DataType) { if (string.IsNullOrEmpty(individualRecord.Address.Www1)) { individualRecord.Address.Www1 = _lineValue; } else if (string.IsNullOrEmpty(individualRecord.Address.Www2)) { individualRecord.Address.Www2 = _lineValue; } else if (string.IsNullOrEmpty(individualRecord.Address.Www3)) { individualRecord.Address.Www3 = _lineValue; } else { // should never occur only 3 urls are allowed } } break; } } else if ( (!string.IsNullOrEmpty(_ParseState.PreviousTag)) && _level == _ParseState.PreviousLevel + 1) { string pTag = _ParseState.PreviousTag; if (pTag == "REFN" && _tag == "TYPE") { if (_lineValueType == GedcomLineValueType.DataType) { individualRecord.UserReferenceType = _lineValue; } } else { AddressParse(individualRecord.Address, _tag, _lineValue, _lineValueType); } } else if ( (!string.IsNullOrEmpty(_ParseState.PreviousTag)) && _level == _ParseState.PreviousLevel) { AddressParse(individualRecord.Address, _tag, _lineValue, _lineValueType); } else { // shouldn't be here Debug.WriteLine("Unknown state / tag parsing individual (" + individualRecord.XRefID + ") node: " + _tag + "\t at level: " + _level); System.Console.WriteLine("Unknown state / tag parsing individual (" + individualRecord.XRefID + ") node: " + _tag + "\t at level: " + _level); System.Console.WriteLine("Previous tag: " + _ParseState.PreviousTag + "\tPrevious Level: " + _ParseState.PreviousLevel); } }
public void SaveView() { if ((!_loading) && (_indi != null)) { GedcomName name = null; if (_indi.Names.Count > 0) { name = _indi.GetName(); } else { name = new GedcomName(); name.Database = _database; name.Level = _indi.Level + 1; name.PreferedName = true; _indi.Names.Add(name); } // don't care if the name is empty, set it anyway name.Name = NameEntry.Text; GedcomIndividualEvent birth = _indi.Birth; if (!string.IsNullOrEmpty(BornInEntry.Text) || !string.IsNullOrEmpty(DateBornEntry.Text)) { if (birth == null) { birth = new GedcomIndividualEvent(); birth.Database = _database; birth.EventType = GedcomEvent.GedcomEventType.BIRT; birth.Level = _indi.Level + 1; birth.IndiRecord = _indi; _indi.Events.Add(birth); } if (birth.Place == null) { birth.Place = new GedcomPlace(); birth.Place.Level = birth.Level + 1; } if (birth.Date == null) { birth.Date = new GedcomDate(_database); birth.Date.Level = birth.Level + 1; } birth.Place.Database = _database; birth.Place.Name = BornInEntry.Text; birth.Date.ParseDateString(DateBornEntry.Text); } else if (birth != null) { _indi.Events.Remove(birth); } GedcomIndividualEvent death = _indi.Death; if (!string.IsNullOrEmpty(DiedInEntry.Text) || !string.IsNullOrEmpty(DateDiedEntry.Text)) { if (death == null) { death = new GedcomIndividualEvent(); death.Database = _database; death.EventType = GedcomEvent.GedcomEventType.DEAT; death.Level = _indi.Level + 1; death.IndiRecord = _indi; _indi.Events.Add(death); } if (death.Place == null) { death.Place = new GedcomPlace(); death.Place.Level = death.Level + 1; } if (death.Date == null) { death.Date = new GedcomDate(_database); death.Date.Level = death.Level + 1; } death.Place.Database = _database; death.Place.Name = DiedInEntry.Text; death.Date.ParseDateString(DateDiedEntry.Text); } else if (death != null) { _indi.Events.Remove(death); } _indi.Sex = (GedcomSex)SexComboBox.Active; FactView.Save(); MarriageView.Save(); AddressView.SaveView(); GedcomIndividualEvent heightFact = _indi.Height; if (string.IsNullOrEmpty(HeightEntry.Text)) { if (heightFact != null) { _indi.Attributes.Remove(heightFact); } } else { if (heightFact == null) { heightFact = new GedcomIndividualEvent(); heightFact.Database = _database; heightFact.EventType = GedcomEvent.GedcomEventType.GenericFact; heightFact.Level = 1; heightFact.IndiRecord = _indi; heightFact.EventName = "Height"; _indi.Attributes.Add(heightFact); } heightFact.Classification = HeightEntry.Text; } GedcomIndividualEvent weightFact = _indi.Weight; if (string.IsNullOrEmpty(WeightEntry.Text)) { if (weightFact != null) { _indi.Attributes.Remove(weightFact); } } else { if (weightFact == null) { weightFact = new GedcomIndividualEvent(); weightFact.Database = _database; weightFact.EventType = GedcomEvent.GedcomEventType.GenericFact; weightFact.Level = 1; weightFact.IndiRecord = _indi; weightFact.EventName = "Weight"; _indi.Attributes.Add(weightFact); } weightFact.Classification = WeightEntry.Text; } if (_indi.Death != null) { _indi.Death.Cause = CauseOfDeathTextView.Buffer.Text; } GedcomIndividualEvent medicalFact = _indi.Medical; string medical = MedicalInformationTextView.Buffer.Text; if (string.IsNullOrEmpty(medical)) { if (medicalFact != null) { _indi.Attributes.Remove(medicalFact); } } else { if (medicalFact == null) { medicalFact = new GedcomIndividualEvent(); medicalFact.Database = _database; medicalFact.EventType = GedcomEvent.GedcomEventType.GenericFact; medicalFact.Level = 1; medicalFact.IndiRecord = _indi; medicalFact.EventName = "Medical"; _indi.Attributes.Add(medicalFact); } medicalFact.Classification = medical; } NotesView.Save(); } }