Exemplo n.º 1
0
		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);	
				}
			}
		}
Exemplo n.º 2
0
		private void ReadSubmitterRecord()
		{
			GedcomSubmitterRecord submitterRecord;
									
			submitterRecord = _ParseState.Records.Peek() as GedcomSubmitterRecord;

			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;
				}
			}

			if (_level == submitterRecord.ParsingLevel + 1)
			{
				switch (_tag)
				{
					case "NAME":
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							submitterRecord.Name = _lineValue;	
						}
						break;
					case "ADDR":
						if (submitterRecord.Address == null)
						{
							submitterRecord.Address = new GedcomAddress();
							submitterRecord.Address.Database = Database;
						}
						
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							submitterRecord.Address.AddressLine = _lineValue;	
						}
						
						break;
					case "PHON":
						if (submitterRecord.Address == null)
						{
							submitterRecord.Address = new GedcomAddress();	
							submitterRecord.Address.Database = Database;
						}
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							if (string.IsNullOrEmpty(submitterRecord.Address.Phone1))
							{
								submitterRecord.Address.Phone1 = _lineValue;	
							}
							else if (string.IsNullOrEmpty(submitterRecord.Address.Phone2))
							{
								submitterRecord.Address.Phone2 = _lineValue;	
							}
							else if (string.IsNullOrEmpty(submitterRecord.Address.Phone3))
							{
								submitterRecord.Address.Phone3 = _lineValue;	
							}
							else
							{
								// should never occur only 3 phone numbers are allowed	
							}
						}
						break;
					case "EMAIL":
						if (submitterRecord.Address == null)
						{
							submitterRecord.Address = new GedcomAddress();	
							submitterRecord.Address.Database = Database;
						}
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							if (string.IsNullOrEmpty(submitterRecord.Address.Email1))
							{
								submitterRecord.Address.Email1 = _lineValue;	
							}
							else if (string.IsNullOrEmpty(submitterRecord.Address.Email2))
							{
								submitterRecord.Address.Email2 = _lineValue;	
							}
							else if (string.IsNullOrEmpty(submitterRecord.Address.Email3))
							{
								submitterRecord.Address.Email3 = _lineValue;	
							}
							else
							{
								// should never occur only 3 emails are allowed	
							}
						}
						break;
					case "FAX":
						if (submitterRecord.Address == null)
						{
							submitterRecord.Address = new GedcomAddress();	
							submitterRecord.Address.Database = Database;
						}
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							if (string.IsNullOrEmpty(submitterRecord.Address.Fax1))
							{
								submitterRecord.Address.Fax1 = _lineValue;	
							}
							else if (string.IsNullOrEmpty(submitterRecord.Address.Fax2))
							{
								submitterRecord.Address.Fax2 = _lineValue;	
							}
							else if (string.IsNullOrEmpty(submitterRecord.Address.Fax3))
							{
								submitterRecord.Address.Fax3 = _lineValue;	
							}
							else
							{
								// should never occur only 3 fax numbers are allowed	
							}
						}
						break;
					case "WWW":
						if (submitterRecord.Address == null)
						{
							submitterRecord.Address = new GedcomAddress();	
							submitterRecord.Address.Database = Database;
						}
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							if (string.IsNullOrEmpty(submitterRecord.Address.Www1))
							{
								submitterRecord.Address.Www1 = _lineValue;	
							}
							else if (string.IsNullOrEmpty(submitterRecord.Address.Www2))
							{
								submitterRecord.Address.Www2 = _lineValue;	
							}
							else if (string.IsNullOrEmpty(submitterRecord.Address.Www3))
							{
								submitterRecord.Address.Www3 = _lineValue;	
							}
							else
							{
								// should never occur only 3 urls are allowed	
							}
						}
						break;
					case "OBJE":
						AddMultimediaRecord(submitterRecord);
						break;
					case "LANG":
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							// only 3 lang are allowed
							for (int i = 0; i < 3; i ++)
							{
								if (string.IsNullOrEmpty(submitterRecord.LanguagePreferences[i]))
								{
									submitterRecord.LanguagePreferences[i] = _lineValue;	
								}
							}
						}
						break;
					case "RFN":
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							submitterRecord.RegisteredRFN = _lineValue;
						}
						break;
					case "RIN":
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							submitterRecord.AutomatedRecordID = _lineValue;	
						}
						break;
					case "CHAN":
						GedcomChangeDate date = new GedcomChangeDate(Database);
						date.Level = _level;
						_ParseState.Records.Push(date);
						break;
					case "NOTE":
					    AddNoteRecord(submitterRecord);
						break;
				}
			}
			else if ( (!string.IsNullOrEmpty(_ParseState.PreviousTag)) &&
			            _level == submitterRecord.Level + 2) //_ParseState.PreviousLevel + 2)
			{
				AddressParse(submitterRecord.Address, _tag, _lineValue, _lineValueType);
			}
			else
			{
				// shouldn't be here
				Debug.WriteLine("Unknown state / tag parsing submitter node: " + _tag + "\t at level: " + _level);
			}
		}
Exemplo n.º 3
0
		private void ReadFamilyRecord()
		{
			GedcomFamilyRecord familyRecord;
			
			// allowed sub records
			GedcomFamilyEvent familyEvent;
						
			familyRecord = _ParseState.Records.Peek() as GedcomFamilyRecord;
			
			if (_tag.StartsWith("_"))
			{
				switch (_tag)
				{
					case "_MSTAT":
						try
						{
							familyRecord.StartStatus = EnumHelper.Parse<MarriageStartStatus>(_lineValue, true);
						}
						catch
						{
							System.Diagnostics.Debug.WriteLine("Unknown marriage start state: " + _lineValue);
						}
						break;
					case "_FREL":
					case "_MREL":
						if ( (!string.IsNullOrEmpty(_ParseState.PreviousTag)) &&
						    _ParseState.PreviousTag == "CHIL" &&
						    _level == _ParseState.PreviousLevel + 1)
						{
							string childID = familyRecord.Children[familyRecord.Children.Count - 1];
							Gedcom.PedegreeLinkageType currentType = familyRecord.GetLinkageType(childID);
							
							Gedcom.GedcomAdoptionType linkTo = Gedcom.GedcomAdoptionType.Husband;
							if (_tag == "_MREL")
							{
								linkTo = Gedcom.GedcomAdoptionType.Wife;
							}
							
							switch (_lineValue)
							{
								case "Natural":
									familyRecord.SetLinkageType(childID, Gedcom.PedegreeLinkageType.Birth, linkTo);
									break;
								case "Adopted":
									familyRecord.SetLinkageType(childID, Gedcom.PedegreeLinkageType.Adopted, linkTo);
									break;
								default:
									System.Diagnostics.Debug.WriteLine("Unsupported value for " + _tag + ": " + _lineValue);
									break;
							}
							break;
						}
						
						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
						//familyRecord.Events.Add(custom);
						
						_ParseState.Records.Push(custom);
						break;
				}
			}
			else if (_level == familyRecord.ParsingLevel + 1)
			{
				switch (_tag)
				{
					case "RESN":
						
						// restriction notice
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							try
							{
								familyRecord.RestrictionNotice = EnumHelper.Parse<GedcomRestrictionNotice>(_lineValue,true);
							}
							catch
							{
								Debug.WriteLine("Invalid restriction type: " + _lineValue);
								
								// default to confidential to protect privacy
								familyRecord.RestrictionNotice = GedcomRestrictionNotice.Confidential;
							}
						}
						break;
					case "ANUL":
						
						// event
						familyEvent = familyRecord.AddNewEvent(GedcomEvent.GedcomEventType.ANUL);
						_ParseState.Records.Push(familyEvent);
					
						break;
					case "CENS":
						
						// event
						familyEvent = familyRecord.AddNewEvent(GedcomEvent.GedcomEventType.CENS_FAM);				
						_ParseState.Records.Push(familyEvent);
					
						break;
					case "DIV":
						
						// event
						familyEvent = familyRecord.AddNewEvent(GedcomEvent.GedcomEventType.DIV);				
						_ParseState.Records.Push(familyEvent);
					
						break;
					case "DIVF":
						
						// event
						familyEvent = familyRecord.AddNewEvent(GedcomEvent.GedcomEventType.DIVF);
						_ParseState.Records.Push(familyEvent);
					
						break;
					case "ENGA":
						
						// event
						familyEvent = familyRecord.AddNewEvent(GedcomEvent.GedcomEventType.ENGA);				
						_ParseState.Records.Push(familyEvent);
					
						break;
					case "MARB":
						
						// event
						familyEvent = familyRecord.AddNewEvent(GedcomEvent.GedcomEventType.MARB);
						_ParseState.Records.Push(familyEvent);
					
						break;
					case "MARC":
						
						// event
						familyEvent = familyRecord.AddNewEvent(GedcomEvent.GedcomEventType.MARC);
						_ParseState.Records.Push(familyEvent);
					
						break;
					case "MARR":
						
						// event
						familyEvent = familyRecord.AddNewEvent(GedcomEvent.GedcomEventType.MARR);
						_ParseState.Records.Push(familyEvent);
					
						break;
					case "MARL":
						
						// event
						familyEvent = familyRecord.AddNewEvent(GedcomEvent.GedcomEventType.MARL);
						_ParseState.Records.Push(familyEvent);
					
						break;
					case "MARS":
						
						// event
						familyEvent = familyRecord.AddNewEvent(GedcomEvent.GedcomEventType.MARS);
						_ParseState.Records.Push(familyEvent);
					
						break;	
					case "RESI":
						
						// event
						familyEvent = familyRecord.AddNewEvent(GedcomEvent.GedcomEventType.RESI);
						_ParseState.Records.Push(familyEvent);
					
						break;
					case "EVEN":
						
						// event
						familyEvent = familyRecord.AddNewEvent(GedcomEvent.GedcomEventType.GenericEvent);
					
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							familyEvent.EventName = _lineValue;
						}
										
						_ParseState.Records.Push(familyEvent);
					
						break;
					
					case "HUSB":
						if (_lineValueType == GedcomLineValueType.PointerType)
						{
							familyRecord.Husband = _lineValue;
							_missingReferences.Add(_lineValue);
						}
						break;
					case "WIFE":
						if (_lineValueType == GedcomLineValueType.PointerType)
						{
							familyRecord.Wife = _lineValue;
							_missingReferences.Add(_lineValue);
						}
						break;
					case "CHIL":
						if (_lineValueType == GedcomLineValueType.PointerType)
						{
							familyRecord.Children.Add(_lineValue);
							_missingReferences.Add(_lineValue);
						}
						break;
					case "NCHI":
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							try
							{
								familyRecord.NumberOfChildren = Convert.ToInt32(_lineValue);
							}
							catch
							{
								Debug.WriteLine("Invalid number for Number of children tag");
							}
						}
						break;
					case "SUBM":
						if (_lineValueType == GedcomLineValueType.PointerType)
						{
							familyRecord.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);
							
							familyRecord.SubmitterRecords.Add(submitter.XRefID);
						}
						
						break;
					case "FIXME?????":
						// lds spouse sealing
						break;
					case "REFN":
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							familyRecord.UserReferenceNumber = _lineValue;
						}
						break;
					case "RIN":
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							familyRecord.AutomatedRecordID = _lineValue;	
						}
						break;
					case "CHAN":
						GedcomChangeDate date = new GedcomChangeDate(Database);
						date.Level = _level;
						_ParseState.Records.Push(date);
						break;
					case "NOTE":
					    AddNoteRecord(familyRecord);
						break;
					case "SOUR":
					    AddSourceCitation(familyRecord);				
						break;
					case "OBJE":
						AddMultimediaRecord(familyRecord);
						break;
				}
			}
			else if ( (!string.IsNullOrEmpty(_ParseState.PreviousTag)) &&
			            _ParseState.PreviousTag == "REFN" &&
			            _level == _ParseState.PreviousLevel + 1)
			{
				if (_tag == "TYPE")
				{
					if (_lineValueType == GedcomLineValueType.DataType)
					{
						familyRecord.UserReferenceType = _lineValue;
					}
				}
			}
			// not valid GEDCOM, but Family Tree Maker adds ADOP/FOST tags
			// to CHIL in a FAM, this is apparently valid in GEDCOM < 5.5
			else if ( (!string.IsNullOrEmpty(_ParseState.PreviousTag)) &&
			         _ParseState.PreviousTag == "CHIL" &&
			         _level == _ParseState.PreviousLevel + 1)
			{
				string childID = familyRecord.Children[familyRecord.Children.Count - 1];
				switch (_tag)
				{
					case "ADOP":
						switch (_lineValue)
						{
							case "HUSB":
								familyRecord.SetLinkageType(childID, Gedcom.PedegreeLinkageType.Adopted, Gedcom.GedcomAdoptionType.Husband);
								break;
							case "WIFE":
								familyRecord.SetLinkageType(childID, Gedcom.PedegreeLinkageType.Adopted, Gedcom.GedcomAdoptionType.Wife);
								break;
							case "BOTH":
							default:
								familyRecord.SetLinkageType(childID, Gedcom.PedegreeLinkageType.Adopted);
								break;
						}
						break;
					case "FOST":
						switch (_lineValue)
						{
							case "HUSB":
								familyRecord.SetLinkageType(childID, Gedcom.PedegreeLinkageType.Foster, Gedcom.GedcomAdoptionType.Husband);
								break;
							case "WIFE":
								familyRecord.SetLinkageType(childID, Gedcom.PedegreeLinkageType.Foster, Gedcom.GedcomAdoptionType.Wife);
								break;
							case "BOTH":
							default:
								familyRecord.SetLinkageType(childID, Gedcom.PedegreeLinkageType.Foster);
								break;
						}
						break;
				}
			}
			else
			{
				// shouldn't be here
				Debug.WriteLine("Unknown state / tag parsing family node: " + _tag + "\t at level: " + _level);
			}
		}
Exemplo n.º 4
0
		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);
			}
		}
Exemplo n.º 5
0
		private void ReadHeaderRecord()
		{
			GedcomHeader headerRecord;
			
			headerRecord = _ParseState.Records.Peek() as GedcomHeader;
			
			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;
				}
			}
			
			if (_level == headerRecord.ParsingLevel + 1)
			{
				switch (_tag)
				{
					case "CHAR":
						// special case to get the character set we should be using
						// only do if charset is unknown or we will get in a nice loop
						if (_Parser.Charset == GedcomCharset.Unknown)
						{
							Encoding enc = null;
							GedcomCharset charset = GedcomCharset.UnSupported;
							switch (_lineValue)
							{
								case "ANSEL":
									charset = GedcomCharset.Ansel;
									enc = new AnselEncoding();
									break;
								case "ANSI":
									charset = GedcomCharset.Ansi;
									// default to windows codepage, wrong but best guess
									// or should it be 436 (DOS)
									enc = Encoding.GetEncoding(1252);
									break;
								case "IBMPC":
									enc = Encoding.GetEncoding(437);
									break;
								case "UTF8":
									// this is correct, we will already have converted from utf8
									charset = GedcomCharset.UTF16LE;
									break;
								case "ASCII":
									// yes, ASCII is the same as UTF8 but extended ascii spoils that
									// which is probably in use
									charset = GedcomCharset.Ascii;
									enc = Encoding.ASCII;
									break;
								default:
									break;
							}
							if (enc != null)
							{
								_stream.Close();
								_stream.Dispose();
								_stream = new StreamReader(_gedcomFile, enc);
												
								ResetParse();
							}
						    _Parser.Charset = charset;
						}
						break;
					case "SOUR":
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							headerRecord.ApplicationSystemID = _lineValue;
						}
						break;
					case "DEST":
						break;
					case "SUBM":
						string submXref = AddSubmitterRecord(headerRecord);
						headerRecord.SubmitterXRefID = submXref;
						break;
					case "SUBN":
						if (_lineValueType == GedcomLineValueType.PointerType)
						{

						}
						else
						{

						}
						break;
					case "COPR":
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							headerRecord.Copyright = _lineValue;
						}
						break;
					case "LANG":
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							headerRecord.Language = _lineValue;
						}
						break;
					case "PLAC":
						break;
					case "DATE":
						GedcomDate date = new GedcomDate(Database);
						date.Level = _level;
						_ParseState.Records.Push(date);
						headerRecord.TransmissionDate = date;
						_level ++;
						ReadDateRecord();
						_level --;
						_ParseState.Records.Pop();
						break;
					case "NOTE":
					    AddNoteRecord(headerRecord);
						break;
				}
			}
			else if (_level == headerRecord.ParsingLevel + 2)
			{
				switch (_tag)
				{
					case "NAME":
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							headerRecord.ApplicationName = _lineValue;	
						}
						break;
					case "VERS":
						switch (_ParseState.ParentTag(_level))
						{
							case "SOUR":
								if (_lineValueType == GedcomLineValueType.DataType)
								{
									headerRecord.ApplicationVersion = _lineValue;	
								}
								break;
							case "CHAR":
								break;
							case "GEDC":
								break;
						}
						break;
					case "CORP":
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							headerRecord.Corporation = _lineValue;	
						}
						break;
				
					case "DATA":
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							headerRecord.SourceName = _lineValue;
						}
						break;
				}
			}
			else if (_level == headerRecord.ParsingLevel + 3)
			{
				switch (_tag)
				{
					case "TIME":
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							if (headerRecord.TransmissionDate != null)
							{
								headerRecord.TransmissionDate.Time = _lineValue;
							}
						}
						break;
					case "DATE":
						GedcomDate date = new GedcomDate(Database);
						date.Level = _level;
						_ParseState.Records.Push(date);
						headerRecord.SourceDate = date;
						_level ++;
						ReadDateRecord();
						_level --;
						_ParseState.Records.Pop();
						break;
					case "COPR":
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							headerRecord.SourceCopyright = _lineValue;
						}
						break;
					case "ADDR":
						if (headerRecord.CorporationAddress == null)
						{
							headerRecord.CorporationAddress = new GedcomAddress();
							headerRecord.CorporationAddress.Database = Database;
						}
						
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							headerRecord.CorporationAddress.AddressLine = _lineValue;	
						}
						
						break;
					case "PHON":
						if (headerRecord.CorporationAddress == null)
						{
							headerRecord.CorporationAddress = new GedcomAddress();	
							headerRecord.CorporationAddress.Database = Database;
						}
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							if (string.IsNullOrEmpty(headerRecord.CorporationAddress.Phone1))
							{
								headerRecord.CorporationAddress.Phone1 = _lineValue;	
							}
							else if (string.IsNullOrEmpty(headerRecord.CorporationAddress.Phone2))
							{
								headerRecord.CorporationAddress.Phone2 = _lineValue;	
							}
							else if (string.IsNullOrEmpty(headerRecord.CorporationAddress.Phone3))
							{
								headerRecord.CorporationAddress.Phone3 = _lineValue;	
							}
							else
							{
								// should never occur only 3 phone numbers are allowed	
							}
						}
						break;
					case "EMAIL":
						if (headerRecord.CorporationAddress == null)
						{
							headerRecord.CorporationAddress = new GedcomAddress();	
							headerRecord.CorporationAddress.Database = Database;
						}
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							if (string.IsNullOrEmpty(headerRecord.CorporationAddress.Email1))
							{
								headerRecord.CorporationAddress.Email1 = _lineValue;	
							}
							else if (string.IsNullOrEmpty(headerRecord.CorporationAddress.Email2))
							{
								headerRecord.CorporationAddress.Email2 = _lineValue;	
							}
							else if (string.IsNullOrEmpty(headerRecord.CorporationAddress.Email3))
							{
								headerRecord.CorporationAddress.Email3 = _lineValue;	
							}
							else
							{
								// should never occur only 3 emails are allowed	
							}
						}
						break;
					case "FAX":
						if (headerRecord.CorporationAddress == null)
						{
							headerRecord.CorporationAddress = new GedcomAddress();	
							headerRecord.CorporationAddress.Database = Database;
						}
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							if (string.IsNullOrEmpty(headerRecord.CorporationAddress.Fax1))
							{
								headerRecord.CorporationAddress.Fax1 = _lineValue;	
							}
							else if (string.IsNullOrEmpty(headerRecord.CorporationAddress.Fax2))
							{
								headerRecord.CorporationAddress.Fax2 = _lineValue;	
							}
							else if (string.IsNullOrEmpty(headerRecord.CorporationAddress.Fax3))
							{
								headerRecord.CorporationAddress.Fax3 = _lineValue;	
							}
							else
							{
								// should never occur only 3 fax numbers are allowed	
							}
						}
						break;
					case "WWW":
						if (headerRecord.CorporationAddress == null)
						{
							headerRecord.CorporationAddress = new GedcomAddress();	
							headerRecord.CorporationAddress.Database = Database;
						}
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							if (string.IsNullOrEmpty(headerRecord.CorporationAddress.Www1))
							{
								headerRecord.CorporationAddress.Www1 = _lineValue;	
							}
							else if (string.IsNullOrEmpty(headerRecord.CorporationAddress.Www2))
							{
								headerRecord.CorporationAddress.Www2 = _lineValue;	
							}
							else if (string.IsNullOrEmpty(headerRecord.CorporationAddress.Www3))
							{
								headerRecord.CorporationAddress.Www3 = _lineValue;	
							}
							else
							{
								// should never occur only 3 urls are allowed	
							}
						}
						break;
				}
			}
			else if (_level == headerRecord.ParsingLevel + 4)
			{
				AddressParse(headerRecord.CorporationAddress, _tag, _lineValue, _lineValueType);
			}
		}