private void ReadSourceRecord() { GedcomSourceRecord sourceRecord; sourceRecord = _ParseState.Records.Peek() as GedcomSourceRecord; if (_level == sourceRecord.ParsingLevel + 1) { // hack, at this level won't have CONT/CONC so end any building we // are doing if (sourceRecord.TitleText != null) { sourceRecord.Title = sourceRecord.TitleText.ToString(); sourceRecord.TitleText = null; } else if (sourceRecord.OriginatorText != null) { sourceRecord.Originator = sourceRecord.OriginatorText.ToString(); sourceRecord.OriginatorText = null; } else if (sourceRecord.PublicationText != null) { sourceRecord.PublicationFacts = sourceRecord.PublicationText.ToString(); sourceRecord.PublicationText = null; } else if (sourceRecord.TextText != null) { sourceRecord.Text = sourceRecord.TextText.ToString(); sourceRecord.TextText = null; } switch (_tag) { case "DATA": // info held in child nodes break; case "AUTH": if (_lineValueType == GedcomLineValueType.DataType) { sourceRecord.OriginatorText = new StringBuilder(_lineValue); } break; case "TITL": if (_lineValueType == GedcomLineValueType.DataType) { sourceRecord.TitleText = new StringBuilder(_lineValue); } break; case "ABBR": if (_lineValueType == GedcomLineValueType.DataType) { sourceRecord.FiledBy = _lineValue; } break; case "PUBL": if (_lineValueType == GedcomLineValueType.DataType) { sourceRecord.PublicationText = new StringBuilder(_lineValue); } break; case "TEXT": if (_lineValueType == GedcomLineValueType.DataType) { int capacity = _lineValue.Length; if (!string.IsNullOrEmpty(sourceRecord.Text)) { capacity += sourceRecord.Text.Length; capacity += Environment.NewLine.Length; } sourceRecord.TextText = new StringBuilder(capacity); if (string.IsNullOrEmpty(sourceRecord.Text)) { sourceRecord.TextText.Append(_lineValue); } else { sourceRecord.TextText.Append(sourceRecord.Text); sourceRecord.TextText.Append(Environment.NewLine); sourceRecord.TextText.Append(_lineValue); } } break; case "REPO": GedcomRepositoryCitation citation = new GedcomRepositoryCitation(); citation.Level = _level; if (_lineValueType == GedcomLineValueType.PointerType) { citation.Repository = _lineValue; _missingReferences.Add(_lineValue); } sourceRecord.RepositoryCitations.Add(citation); _ParseState.Records.Push(citation); break; case "REFN": if (_lineValueType == GedcomLineValueType.DataType) { sourceRecord.UserReferenceNumber = _lineValue; } break; case "RIN": if (_lineValueType == GedcomLineValueType.DataType) { sourceRecord.AutomatedRecordID = _lineValue; } break; case "CHAN": GedcomChangeDate date = new GedcomChangeDate(Database); date.Level = _level; _ParseState.Records.Push(date); break; case "NOTE": AddNoteRecord(sourceRecord); break; case "OBJE": AddMultimediaRecord(sourceRecord); break; } } else if ( (!string.IsNullOrEmpty(_ParseState.PreviousTag)) && _level == sourceRecord.Level + 2) // _ParseState.PreviousLevel + 2) { if (_ParseState.PreviousTag == "REFN" && _tag == "TYPE") { if (_lineValueType == GedcomLineValueType.DataType) { sourceRecord.UserReferenceType = _lineValue; } } else if (sourceRecord.OriginatorText != null) // (_ParseState.PreviousTag == "AUTH") { switch (_tag) { case "CONT": sourceRecord.OriginatorText.Append(Environment.NewLine); sourceRecord.OriginatorText.Append(_lineValue); break; case "CONC": sourceRecord.OriginatorText.Append(_lineValue); break; } } else if (sourceRecord.TitleText != null) // (_ParseState.PreviousTag == "TITL") { switch (_tag) { case "CONT": sourceRecord.TitleText.Append(Environment.NewLine); sourceRecord.TitleText.Append(_lineValue); break; case "CONC": sourceRecord.TitleText.Append(_lineValue); break; } } else if (sourceRecord.PublicationText != null) // (_ParseState.PreviousTag == "PUBL") { switch (_tag) { case "CONT": sourceRecord.PublicationText.Append(Environment.NewLine); sourceRecord.PublicationText.Append(_lineValue); break; case "CONC": sourceRecord.PublicationText.Append(_lineValue); break; } } else if (sourceRecord.TextText != null) //(_ParseState.PreviousTag == "TEXT") { switch (_tag) { case "CONT": sourceRecord.TextText.Append(Environment.NewLine); sourceRecord.TextText.Append(_lineValue); break; case "CONC": sourceRecord.TextText.Append(_lineValue); break; } } else //if (_ParseState.PreviousTag == "DATA") { switch (_tag) { case "AGNC": if (_lineValueType == GedcomLineValueType.DataType) { sourceRecord.Agency = _lineValue; } break; case "EVEN": if (_lineValueType == GedcomLineValueType.DataType) { GedcomRecordedEvent recordedEvent = new GedcomRecordedEvent(); sourceRecord.EventsRecorded.Add(recordedEvent); string[] events = _lineValue.Split(new char[]{','}, StringSplitOptions.RemoveEmptyEntries); foreach (string e in events) { string ev = e.Trim(); GedcomEvent.GedcomEventType eventType; if (ev == "EVEN") { eventType = GedcomEvent.GedcomEventType.GenericEvent; recordedEvent.Types.Add(eventType); } else if (ev == "FACT") { eventType = GedcomEvent.GedcomEventType.GenericFact; recordedEvent.Types.Add(eventType); } else { try { eventType = EnumHelper.Parse<GedcomEvent.GedcomEventType>(ev,true); recordedEvent.Types.Add(eventType); } catch { try { eventType = EnumHelper.Parse<GedcomEvent.GedcomEventType>(ev + "Fact",true); recordedEvent.Types.Add(eventType); } catch { // FIXME: shouldn't lose data like this } } } } } break; case "NOTE": string xref = AddNoteRecord(sourceRecord); // belongs in data records, not top level record notes sourceRecord.Notes.Remove(xref); sourceRecord.DataNotes.Add(xref); break; } } } else if ( (!string.IsNullOrEmpty(_ParseState.PreviousTag)) && _level == sourceRecord.Level + 3) //_ParseState.PreviousLevel + 3) { // if (_ParseState.PreviousTag == "EVEN") // { GedcomRecordedEvent recordedEvent = sourceRecord.EventsRecorded[sourceRecord.EventsRecorded.Count - 1]; switch (_tag) { case "DATE": GedcomDate date = new GedcomDate(Database); date.Level = _level; _ParseState.Records.Push(date); recordedEvent.Date = date; _level ++; ReadDateRecord(); _level --; _ParseState.Records.Pop(); break; case "PLAC": GedcomPlace place = new GedcomPlace(); place.Level = _level; recordedEvent.Place = place; if (_lineValueType == GedcomLineValueType.DataType) { place.Name = Database.PlaceNameCollection[_lineValue]; } else { // invalid, provide a name anyway place.Name = "Unknown"; Debug.WriteLine("invalid place node, no name at level: " + _level); } _ParseState.Records.Push(place); break; } // } } else { // shouldn't be here Debug.WriteLine("Unknown state / tag parsing note node: " + _tag + "\t at level: " + _level); } }
private void ReadEventRecord() { GedcomEvent eventRecord; bool done = false; eventRecord = _ParseState.Records.Peek() as GedcomEvent; if (_tag.StartsWith("_")) { switch (_tag) { 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 _ParseState.Records.Push(custom); break; } } switch (eventRecord.RecordType) { case GedcomRecordType.FamilyEvent: GedcomFamilyEvent famEvent = eventRecord as GedcomFamilyEvent; if (_level == eventRecord.ParsingLevel + 2 && _tag == "AGE") { if (_ParseState.PreviousTag == "HUSB") { GedcomAge age = GedcomAge.Parse(_lineValue, Database); famEvent.HusbandAge = age; done = true; } else if (_ParseState.PreviousTag == "WIFE") { GedcomAge age = GedcomAge.Parse(_lineValue, Database); famEvent.WifeAge = age; done = true; } } else if (_level == eventRecord.ParsingLevel + 1) { done = (_tag == "HUSB" || _tag == "WIFE"); } break; case GedcomRecordType.IndividualEvent: GedcomIndividualEvent individualEvent = eventRecord as GedcomIndividualEvent; if (_level == eventRecord.ParsingLevel + 1) { if (_tag == "AGE") { GedcomAge age = GedcomAge.Parse(_lineValue, Database); individualEvent.Age = age; done = true; } else if (_tag == "FAMC" && (eventRecord.EventType == GedcomEvent.GedcomEventType.BIRT || eventRecord.EventType == GedcomEvent.GedcomEventType.CHR || eventRecord.EventType == GedcomEvent.GedcomEventType.ADOP)) { if (_lineValueType == GedcomLineValueType.PointerType) { individualEvent.Famc = _lineValue; _missingReferences.Add(_lineValue); } done = true; } else if (_tag == "CONT" && eventRecord.EventType == GedcomEvent.GedcomEventType.DSCRFact) { eventRecord.Classification += Environment.NewLine; eventRecord.Classification += _lineValue; } else if (_tag == "CONC" && eventRecord.EventType == GedcomEvent.GedcomEventType.DSCRFact) { //eventRecord.Description += " "; eventRecord.Classification += _lineValue; } } else if (_level == eventRecord.ParsingLevel + 2) { if (_tag == "ADOP" && eventRecord.EventType == GedcomEvent.GedcomEventType.ADOP) { if (_lineValueType == GedcomLineValueType.DataType) { if (_lineValue == "HUSB") { individualEvent.AdoptedBy = GedcomAdoptionType.Husband; } else if (_lineValue == "WIFE") { individualEvent.AdoptedBy = GedcomAdoptionType.Wife; } else if (_lineValue == "BOTH") { individualEvent.AdoptedBy = GedcomAdoptionType.HusbandAndWife; } } done = true; } } break; } if (!done) { if (_level == eventRecord.ParsingLevel + 1) { switch (_tag) { case "TYPE": if (_lineValueType == GedcomLineValueType.DataType) { // if the event is generic, but the type // can be mapped to an actual event type // convert it. bool convertedEventType = false; if ((eventRecord.EventType == GedcomEvent.GedcomEventType.GenericEvent || eventRecord.EventType == GedcomEvent.GedcomEventType.GenericFact) && string.IsNullOrEmpty(eventRecord.EventName)) { GedcomEvent.GedcomEventType type = GedcomEvent.ReadableToType(_lineValue); if (type != GedcomEvent.GedcomEventType.GenericEvent) { eventRecord.EventType = type; convertedEventType = true; } } if (!convertedEventType) { // in TGC551LF (torture test gedcom file) TYPE is set // to the same as the event tag name in some instances // this is stupid, so if _lineValue is the same // as the event tag, don't set it. string eventTag = _ParseState.ParentTag(_level); if (_lineValue != eventTag) { eventRecord.Classification = _lineValue; } } } break; case "DATE": GedcomDate date = new GedcomDate(Database); date.Database = Database; date.Level = _level; _ParseState.Records.Push(date); eventRecord.Date = date; _level ++; ReadDateRecord(); _level --; _ParseState.Records.Pop(); break; case "PLAC": GedcomPlace place = new GedcomPlace(); place.Database = Database; place.Level = _level; eventRecord.Place = place; if (_lineValueType == GedcomLineValueType.DataType) { place.Name = _lineValue; } else { // invalid, provide a name anyway place.Name = string.Empty; //"Unknown"; Debug.WriteLine("invalid place node, no name at level: " + _level); } _ParseState.Records.Push(place); break; case "ADDR": if (eventRecord.Address == null) { eventRecord.Address = new GedcomAddress(); eventRecord.Address.Database = Database; } if (_lineValueType == GedcomLineValueType.DataType) { eventRecord.Address.AddressLine = _lineValue; } break; case "PHON": if (eventRecord.Address == null) { eventRecord.Address = new GedcomAddress(); eventRecord.Address.Database = Database; } if (_lineValueType == GedcomLineValueType.DataType) { if (string.IsNullOrEmpty(eventRecord.Address.Phone1)) { eventRecord.Address.Phone1 = _lineValue; } else if (string.IsNullOrEmpty(eventRecord.Address.Phone2)) { eventRecord.Address.Phone2 = _lineValue; } else if (string.IsNullOrEmpty(eventRecord.Address.Phone3)) { eventRecord.Address.Phone3 = _lineValue; } else { // should never occur only 3 phone numbers are allowed } } break; case "EMAIL": if (eventRecord.Address == null) { eventRecord.Address = new GedcomAddress(); eventRecord.Address.Database = Database; } if (_lineValueType == GedcomLineValueType.DataType) { if (string.IsNullOrEmpty(eventRecord.Address.Email1)) { eventRecord.Address.Email1 = _lineValue; } else if (string.IsNullOrEmpty(eventRecord.Address.Email2)) { eventRecord.Address.Email2 = _lineValue; } else if (string.IsNullOrEmpty(eventRecord.Address.Email3)) { eventRecord.Address.Email3 = _lineValue; } else { // should never occur only 3 emails are allowed } } break; case "FAX": if (eventRecord.Address == null) { eventRecord.Address = new GedcomAddress(); eventRecord.Address.Database = Database; } if (_lineValueType == GedcomLineValueType.DataType) { if (string.IsNullOrEmpty(eventRecord.Address.Fax1)) { eventRecord.Address.Fax1 = _lineValue; } else if (string.IsNullOrEmpty(eventRecord.Address.Fax2)) { eventRecord.Address.Fax2 = _lineValue; } else if (string.IsNullOrEmpty(eventRecord.Address.Fax3)) { eventRecord.Address.Fax3 = _lineValue; } else { // should never occur only 3 fax numbers are allowed } } break; case "WWW": if (eventRecord.Address == null) { eventRecord.Address = new GedcomAddress(); eventRecord.Address.Database = Database; } if (_lineValueType == GedcomLineValueType.DataType) { if (string.IsNullOrEmpty(eventRecord.Address.Www1)) { eventRecord.Address.Www1 = _lineValue; } else if (string.IsNullOrEmpty(eventRecord.Address.Www2)) { eventRecord.Address.Www2 = _lineValue; } else if (string.IsNullOrEmpty(eventRecord.Address.Www3)) { eventRecord.Address.Www3 = _lineValue; } else { // should never occur only 3 urls are allowed } } break; case "AGNC": if (_lineValueType == GedcomLineValueType.DataType) { eventRecord.ResponsibleAgency = _lineValue; } break; case "RELI": if (_lineValueType == GedcomLineValueType.DataType) { eventRecord.ReligiousAffiliation = _lineValue; } break; case "CAUS": if (_lineValueType == GedcomLineValueType.DataType) { eventRecord.Cause = _lineValue; } break; case "RESN": // restriction notice if (_lineValueType == GedcomLineValueType.DataType) { try { eventRecord.RestrictionNotice = EnumHelper.Parse<GedcomRestrictionNotice>(_lineValue,true); } catch { Debug.WriteLine("Invalid restriction type: " + _lineValue); // default to confidential to protect privacy eventRecord.RestrictionNotice = GedcomRestrictionNotice.Confidential; } } break; case "NOTE": AddNoteRecord(eventRecord); break; case "SOUR": AddSourceCitation(eventRecord); break; case "OBJE": AddMultimediaRecord(eventRecord); break; case "QUAY": if (_lineValueType == GedcomLineValueType.DataType) { int certainty = Convert.ToInt32(_lineValue); if ((certainty > (int)GedcomCertainty.Primary) || (certainty < (int)GedcomCertainty.Unreliable)) { certainty = (int)GedcomCertainty.Unreliable; } eventRecord.Certainty = (GedcomCertainty)certainty; } break; } } else if (_ParseState.PreviousTag != string.Empty && _level == eventRecord.ParsingLevel + 2) { AddressParse(eventRecord.Address, _tag, _lineValue, _lineValueType); } } }
public void SaveView() { GedcomSourceRecord source = _record as GedcomSourceRecord; if (source != null) { source.Title = TitleEntry.Text; source.Originator = OriginatorEntry.Text; source.FiledBy = FiledByEntry.Text; source.Agency = AgencyTextBox.Text; source.PublicationFacts = PublicationFactsTextView.Buffer.Text; if (_recordedEvent != null) { _recordedEvent.Types = _eventModel.IncludedEvents; if (!string.IsNullOrEmpty(DateRecordedEntry.Text)) { if (_recordedEvent.Date == null) { GedcomDate date = new GedcomDate(_database); date.Level = _record.Level + 3; // SOUR / DATA / EVEN / DATE _recordedEvent.Date = date; } _recordedEvent.Date.ParseDateString(DateRecordedEntry.Text); } else { _recordedEvent.Date = null; } if (!string.IsNullOrEmpty(PlaceRecordedEntry.Text)) { if (_recordedEvent.Place == null) { GedcomPlace place = new GedcomPlace(); place.Database = _database; place.Level = _record.Level + 3; // SOUR / DATA / EVEN / PLAC _recordedEvent.Place = place; } _recordedEvent.Place.Name = PlaceRecordedEntry.Text; } else { _recordedEvent.Place = null; } } source.Text = TextTextView.Buffer.Text; NotesView.Save(); // FIXME: repository citations RepoNotesView.Save(); } }