Esempio n. 1
0
		private void DateCheck(GedcomDate date)
		{
			if (date != null)
			{
				if (!string.IsNullOrEmpty(date.Date1))
				{
					if (date.DateTime1 != null && date.DateTime1.HasValue)
					{
						_parsedDates ++;
					}
					else
					{
						_notParsedDates ++;
						System.Console.WriteLine("Unparsed: " + date.Date1);
					}
				}
				if (!string.IsNullOrEmpty(date.Date2))
				{
					if (date.DateTime2 != null && date.DateTime2.HasValue)
					{
						_parsedDates ++;
					}
					else
					{
						_notParsedDates ++;
						System.Console.WriteLine("Unparsed: " + date.Date2);
					}
				}
			}
		}
Esempio n. 2
0
 public static int CompareByDate(GedcomDate datea, GedcomDate dateb)
 {
     int ret = CompareNullableDateTime(datea.DateTime1, dateb.DateTime1);
     
     if (ret == 0)
     {
         ret = CompareNullableDateTime(datea.DateTime2, dateb.DateTime2);
         
         if (ret == 0)
         {
             ret = string.Compare(datea.Date1, dateb.Date1, true);
             if (ret == 0)
             {
                 ret = string.Compare(datea.Date2, dateb.Date2, true);
             }
         }
     }			
     
     return ret;
 }
Esempio n. 3
0
        public float IsMatch(GedcomDate date)
        {
            float match = 0F;

            if (date.Period.Equals("AFT"))// edcomDatePeriod.After)// && date.Date1.Equals("1905"))
            {
                Console.WriteLine("After" + date.Date1);
                return match;
            }

            if (Date1 == date.Date1 && Date2 == date.Date2 && DatePeriod == date.DatePeriod)
            {
                match = 100.0F;			
            }
            else
            {
                // compare date components in DateTime if present
                
                float matches = 0;
                int parts = 0;
                
                DateTime? dateDate1 = date.DateTime1;
                DateTime? dateDate2 = date.DateTime2;
                
                // same type, nice and simple,
                // range is the same as between as far as we are concerned
                // for instance an Occupation could have been FROM a TO B
                // or BETWEEN a AND b
                // logic doesn't hold for one off events such a birth, but
                // then a Range doesn't make sense for those anyway so if
                // we have one should be safe to assume it is Between
                if (DateType == date.DateType && 
                    (DatePeriod == date.DatePeriod||
                    (DatePeriod == GedcomDatePeriod.Range && date.DatePeriod == GedcomDatePeriod.Between) ||
                    (DatePeriod == GedcomDatePeriod.Between && date.DatePeriod == GedcomDatePeriod.Range)))
                {
                    matches ++;
                    
                    // checked 1 value
                    parts ++;
                    
                    parts += 3;
                    float date1Match = Utility.DateHelper.MatchDateTimes(DateTime1, dateDate1);
                    
                    // correct for number of date parts parsed
                    date1Match *= (_partsParsed1 / 3.0F);
                    
                    matches += date1Match;
                    
                    parts += 3;
                    float date2Match= Utility.DateHelper.MatchDateTimes(DateTime2, dateDate2);
                    
                    // correct for number of date parts parsed
                    date2Match *= (_partsParsed2 / 3.0F);
                    
                    matches += date2Match;
                                        
                    match = (matches / parts) * 100.0F;
                }
            }
            
            
            
            return match;
        }
Esempio n. 4
0
		private void ReadSourceCitationRecord()
		{
			GedcomSourceCitation sourceCitation;
			
			sourceCitation = _ParseState.Records.Peek() as GedcomSourceCitation;
			
			GedcomSourceRecord sourceRecord = null;
			
			if (_ParseState.Database.Contains(sourceCitation.Source))
			{
				sourceRecord = _ParseState.Database[sourceCitation.Source] as GedcomSourceRecord;	
			}
						
			if (_level == sourceCitation.ParsingLevel + 1)
			{
				switch (_tag)
				{
					case "PAGE":
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							sourceCitation.Page = _lineValue;	
						}
						break;
					case "CONT":
						if (sourceRecord != null)
						{
							sourceRecord.Title += Environment.NewLine;
							sourceRecord.Title += _lineValue;
						}
						break;
					case "CONC":
						if (sourceRecord != null)
						{
							sourceRecord.Title += _lineValue;
						}
						break;
					case "TEXT":
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							if (sourceCitation.ParsedText == null)
							{
								int capacity = _lineValue.Length;
								if (!string.IsNullOrEmpty(sourceCitation.Text))
								{
									capacity += sourceCitation.Text.Length;
									capacity += Environment.NewLine.Length;
								}
								sourceCitation.ParsedText = new StringBuilder(capacity);
							}
							
							if (!string.IsNullOrEmpty(sourceCitation.Text))
							{
								sourceCitation.ParsedText.Append(Environment.NewLine);
							}
							sourceCitation.ParsedText.Append(_lineValue);
						}
						break;
					case "DATA":
						// data tag, just contains child tags
						break;
					case "EVEN":
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							sourceCitation.EventType = _lineValue;	
						}
						break;
					case "OBJE":
						AddMultimediaRecord(sourceCitation);
						break;
					case "NOTE":
					    AddNoteRecord(sourceCitation);
						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;           	
							}
							sourceCitation.Certainty = (GedcomCertainty)certainty;
						}
						break;
				}
			}
			else if (_ParseState.PreviousTag != string.Empty && _level == sourceCitation.ParsingLevel + 2)
			{
				if (_ParseState.PreviousTag == "EVEN" && _tag == "ROLE") 
				{
					if (_lineValueType == GedcomLineValueType.DataType)
					{
						sourceCitation.Role = _lineValue;	
					}
				}
				else  //if (_ParseState.PreviousTag == "DATA")
				{
					if (_tag == "DATE") 
					{
						GedcomDate date = new GedcomDate(Database);
						date.Level = _level;
						_ParseState.Records.Push(date);
						sourceCitation.Date = date;
						_level ++;
						ReadDateRecord();
						_level --;
						_ParseState.Records.Pop();
					}
					else if (_tag == "TEXT")
					{
						if (_lineValueType == GedcomLineValueType.DataType)
						{
							if (sourceCitation.ParsedText == null)
							{
								int capacity = _lineValue.Length;
								if (!string.IsNullOrEmpty(sourceCitation.Text))
								{
									capacity += sourceCitation.Text.Length;
									capacity += Environment.NewLine.Length;
								}
								sourceCitation.ParsedText = new StringBuilder(capacity);
							}
							
							if (!string.IsNullOrEmpty(sourceCitation.Text))
							{
								sourceCitation.ParsedText.Append(Environment.NewLine);
							}
							sourceCitation.ParsedText.Append(_lineValue);
						}
					}
				//}
				//else if (_ParseState.PreviousTag == "TEXT")
				//{
					else if (_tag == "CONC")
					{
						if (sourceCitation.ParsedText == null)
						{
							sourceCitation.ParsedText = new StringBuilder(_lineValue.Length);
						}
						sourceCitation.ParsedText.Append(_lineValue);
					}
					else if (_tag == "CONT")
					{
						if (sourceCitation.ParsedText == null)
						{
							int capacity = _lineValue.Length + Environment.NewLine.Length;
							sourceCitation.ParsedText = new StringBuilder(capacity);
						}
						sourceCitation.ParsedText.Append(Environment.NewLine);
						sourceCitation.ParsedText.Append(_lineValue);
					}
				}
			}
			else if (_ParseState.PreviousTag != string.Empty && _level == sourceCitation.ParsingLevel + 3)
			{
				if (_ParseState.PreviousTag == "TEXT" || _ParseState.PreviousTag == "CONC" || _ParseState.PreviousTag == "CONT")
				{
					if (_tag == "CONC")
					{
						if (sourceCitation.ParsedText == null)
						{
							sourceCitation.ParsedText = new StringBuilder(_lineValue.Length);
						}
						sourceCitation.ParsedText.Append(_lineValue);
					}
					else if (_tag == "CONT")
					{
						if (sourceCitation.ParsedText == null)
						{
							int capacity = _lineValue.Length + Environment.NewLine.Length;
							sourceCitation.ParsedText = new StringBuilder(capacity);
						}
						sourceCitation.ParsedText.Append(Environment.NewLine);
						sourceCitation.ParsedText.Append(_lineValue);
					}
				}
			}
			else
			{
				// shouldn't be here
				Debug.WriteLine("Unknown state / tag parsing source citation node: " + _tag + "\t at level: " + _level);
			}
		}
Esempio n. 5
0
		private void DateParse(GedcomDate date, string lineValue)
		{			
			date.ParseDateString(lineValue);
			
			// no parsed date, perhaps it was an age?
			if (date.DateTime1 == null)
			{
				// date handling is severly broken in genealogy applications,
				// with many not taking any notice of the mandated formats when
				// outputting gedcom, and some such as Family Tree Maker
				// inserting what belongs in AGE as the date, e.g. INFANT

				// this is the date record
				GedcomRecord record = _ParseState.Records.Pop();
				
				// this is the one we are interested in
				record = _ParseState.Records.Peek();
				
				// put the date record back
				_ParseState.Records.Push(date);


				GedcomIndividualEvent ev = record as GedcomIndividualEvent;
				if (ev != null)
				{
					GedcomAge age = GedcomAge.Parse(lineValue, Database);
					if (age != null)
					{
						// we have a valid age, could calc a date at some point
						// based off birth of individual, don't do that here though
						
						// don't clear lineValue, we need something to keep
						// the event active!
						
						ev.Age = age;
					}
				}
			}
		}
Esempio n. 6
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);	
				}
			}
		}
Esempio n. 7
0
		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);
			}
		}
Esempio n. 8
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);
			}
		}
Esempio n. 9
0
        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("&nbsp;", " ").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("&nbsp;", " ").Trim();
                        string death = string.Empty;
                        if (ideath > 0)
                        {
                            born = line.Substring(iborn + 11, ideath - iborn - 11).Replace("<br>", "").Replace("&nbsp;", " ").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("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='./individual")||line.StartsWith("&nbsp;&nbsp;&nbsp;&nbsp;+<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;
        }
Esempio n. 10
0
		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();
			}
		}