コード例 #1
0
		private void Parser_TagFound(object sender, EventArgs e)
		{
			_level = _Parser.Level;
			_xrefID = _Parser.XrefID;
			_tag = TagMap(_Parser.Tag);
			_lineValue = _Parser.LineValue;
			_lineValueType = _Parser.LineValueType;
					
			GedcomRecord current = null;

			// pop previous levels from the stack
			
			current = PopStack(_level);
			
			if (current == null)
			{
				switch (_tag)
				{
					case "FAM":
						
						// must have an xref id to have a family record
						// otherwise it can't be referenced anywhere
						if (!string.IsNullOrEmpty(_xrefID))
						{
							current = new GedcomFamilyRecord();
						}
						break;
					case "INDI":
						
						// must have an xref id to have an individual record
						// otherwise it can't be referenced anywhere
						if (!string.IsNullOrEmpty(_xrefID))
						{
							current = new GedcomIndividualRecord();
						}
						break;
					case "OBJE":
						
						// must have an xref id to have a multimedia record
						// otherwise it can't be referenced anywhere
						if (!string.IsNullOrEmpty(_xrefID))
						{
							current = new GedcomMultimediaRecord();
						}
						break;
					case "NOTE":
						
						// must have an xref id to have a note record
						// otherwise it can't be referenced anywhere
						if (!string.IsNullOrEmpty(_xrefID))
						{
							GedcomNoteRecord note = new GedcomNoteRecord();
							current = note;
							
							// set initial note text if needed
							
							if (_lineValueType == GedcomLineValueType.DataType)
							{
								note.ParsedText.Append(_lineValue);
							}
							else if (_lineValue != string.Empty)
							{
								// pointer to a note, this should not occur
								// as we should be at level 0 here
								
								Debug.WriteLine("Spurious Note pointer: " + _xrefID + "\t at level: " + _level);
							}
						}
						break;
					case "REPO":
						
						// must have an xref id to have a repository record
						// otherwise it can't be referenced anywhere
						if (!string.IsNullOrEmpty(_xrefID))
						{
							current = new GedcomRepositoryRecord();
						}
						break;
					case "SOUR":
						
						// must have an xref id to have a source record
						// otherwise it can't be referenced anywhere
						if (!string.IsNullOrEmpty(_xrefID))
						{
							current = new GedcomSourceRecord();
						}
						break;
					case "SUBM":
						
						// must have an xref id to have a submitter record
						// otherwise it can't be referenced anywhere
						if (!string.IsNullOrEmpty(_xrefID))
						{
							current = new GedcomSubmitterRecord();
						}
						break;
					case "HEAD":
						
						// header record
						current = new GedcomHeader();
					
						break;

					case "SUBN":

						// Submission record
						if (!string.IsNullOrEmpty(_xrefID))
						{
							current = new GedcomSubmissionRecord();
						}
						break;
						
					case "TRLR":
						
						break;
					default:
						
						// Unknown tag
						
						Debug.WriteLine("Unknown: " + _tag + " at level: " + _level);
						break;
				}
				
				// if we created a new record push it onto the stack
				if (current != null)
				{
					if (!string.IsNullOrEmpty(_xrefID))
					{
						current.XRefID = _xrefID;
					}
					current.Database = _ParseState.Database;
					current.Level = _level;
					_ParseState.Records.Push(current);
				}
			}
			else
			{
				switch (current.RecordType)
				{
					case GedcomRecordType.Header:
						ReadHeaderRecord();
						break;
					case GedcomRecordType.Family:
						ReadFamilyRecord();
						break;
					case GedcomRecordType.Individual:
						ReadIndividualRecord();
						break;
					case GedcomRecordType.Multimedia:
						ReadMultimediaRecord();
						break;
					case GedcomRecordType.Note:
						ReadNoteRecord();
						break;
					case GedcomRecordType.Repository:
						ReadRepositoryRecord();
						break;
					case GedcomRecordType.Source:
						ReadSourceRecord();
						break;
					case GedcomRecordType.Submitter:
						ReadSubmitterRecord();
						break;
					case GedcomRecordType.Submission:
						ReadSubmissionRecord();						
						break;
					
					// Non top level records
					case GedcomRecordType.Event:
						ReadEventRecord();
						break;
					case GedcomRecordType.FamilyEvent:
						ReadEventRecord();
						break;
					case GedcomRecordType.IndividualEvent:
						ReadEventRecord();
						break;
					
					case GedcomRecordType.Place:
						ReadPlaceRecord();
						break;
					case GedcomRecordType.SourceCitation:
						ReadSourceCitationRecord();
						break;
					case GedcomRecordType.FamilyLink:
						ReadFamilyLinkRecord();
						break;
					case GedcomRecordType.Association:
						ReadAssociationRecord();
						break;
					case GedcomRecordType.Name:
						ReadNameRecord();
						break;
					case GedcomRecordType.Date:
						ReadDateRecord();
						break;
					case GedcomRecordType.RepositoryCitation:
						ReadRepositoryCitation();
						break;
					case GedcomRecordType.CustomRecord:
						ReadEventRecord();
						break;
				}
			}
			
			_ParseState.AddPreviousTag(_tag, _level);
		}
コード例 #2
0
ファイル: GedMatch.cs プロジェクト: Bert6623/Gedcom.Net
        private void GetGedMatch(string nKitNbr, string html, string pre, string sex, int attempt = 0)
        {
            if (!html.Equals("&nbsp;") && !html.Equals(String.Empty) && (html.IndexOf("<a href") >= 0))
            {
                Console.WriteLine("Loading GED Kit number " + nKitNbr);
                _gd1 = new GedcomDatabase();
                GedcomHeader gh = new GedcomHeader();
                string GedName = String.Empty;
                gh.Filename = "GM_" + nKitNbr + ".ged";
                _gd1.Header = gh;

                htIndi = new System.Collections.Hashtable(50);

                html = html.Replace("&nbsp;", " ");
                html = html.Replace("<a href='", "");
                string geds = String.Empty;
                try { geds = html.Trim().Substring(0, html.IndexOf(" title") - 2); }
                catch { }

                int ifam = html.IndexOf("id_family=");
                int ifame = html.IndexOf("' title");
                string nfamily = html.Substring(ifam + 10,ifame-ifam-10);
                GetHTML(geds, WorkDir + "\\GM_SURNAME" + nKitNbr + ".html", pre);

                StreamReader reader = new StreamReader(WorkDir + "\\GM_SURNAME" + nKitNbr + ".html");
                string line = reader.ReadLine();
                bool found = false;
                while (line != null)
                {
                    if (line.StartsWith("ANCESTORS OF: "))
                    {
                        int ig = line.IndexOf("&id_ged");
                        int ige = line.IndexOf("'>");
                        int ine = line.IndexOf("</a>");
                        try
                        {
                            GedName = line.Substring(ige + 2, ine - ige - 2).Replace("&nbsp;", " ").Replace("<b>", "").Replace("</b>", "");
                        }
                        catch { }
                        try
                        {
                            string nindi = line.Substring(ig + 8, ige - ig - 8);

                            if (!Directory.Exists(WorkIndiDir + nfamily))
                                Directory.CreateDirectory(WorkIndiDir + nfamily);

                            GedcomIndividualRecord gir = GetGedIndi(nindi, nfamily, nKitNbr, geds, sex);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message + " - " + ex.StackTrace);
                        }
                        found = true;
                        break;
                    }
                    line = reader.ReadLine();
                }
                reader.Close();

                if (!found && attempt++ < 2)
                {
                    GetHTML("http://www.gedmatch.com/surname.php?id_family=" + nfamily, WorkDir + "\\GM_SURNAME_LIST_" + nKitNbr + ".html", geds);
                    StreamReader freader = new StreamReader(WorkDir + "\\GM_SURNAME_LIST_" + nKitNbr + ".html");
                    string fline = freader.ReadLine();
                    {
                        //Try http://www.gedmatch.com/surname_detail.php?id_familyname=243182&id_family=5884506
                        try
                        {
                            GetHTML("http://www.gedmatch.com/surname.php?initial=A&id_family=" + nfamily, WorkDir + "\\GM_SURNAME_LIST_A_" + nKitNbr + ".html", geds);

                            StreamReader f1reader = new StreamReader(WorkDir + "\\GM_SURNAME_LIST_A_" + nKitNbr + ".html");
                            string f1line = f1reader.ReadLine();
                            while (f1line != null)
                            {
                                if (f1line.IndexOf("id_familyname=") > 0)
                                {
                                    int ifamname = f1line.IndexOf("id_familyname=");
                                    int ige = f1line.IndexOf("&");
                                    string nfamilyname = f1line.Substring(ifamname + 14, ige - ifamname - 14);
                                    //Get http://www.gedmatch.com/surname_detail.php?id_familyname=243182&id_family=5884506
                                    GetHTML("http://www.gedmatch.com/surname_detail.php?id_familyname=" + nfamilyname + "&id_family=" + nfamily, WorkDir + "\\GM_SURNAME_DETAIL_" + nKitNbr + ".html", geds);

                                    StreamReader dreader = new StreamReader(WorkDir + "\\GM_SURNAME_DETAIL_" + nKitNbr + ".html");
                                    string dline = dreader.ReadLine();
                                    while (dline != null)
                                    {
                                        if (dline.IndexOf("id_ged=") > 0)
                                        {
                                            int iged = dline.IndexOf("id_ged=");
                                            int ie = dline.IndexOf("'>");
                                            string nindi = dline.Substring(iged + 7,ie-7-iged);
                                            html = dline.Substring(iged, ie + 4 - iged);
                                            //Call 
                                            if (!Directory.Exists(WorkIndiDir + nfamily))
                                                Directory.CreateDirectory(WorkIndiDir + nfamily);
                                            GetGedIndi(nindi, nfamily, nKitNbr, geds, sex);
                                            found = true;
                                        }
                                        dline = dreader.ReadLine();
                                    }
                                }
                                f1line = f1reader.ReadLine();
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message + " - " + ex.StackTrace);
                        }

                    }
                    reader.Close();

                }

                if (found)
                lock (gedfile)
                {
                    gedfile = WorkDir + "\\GM_" + GedName + nKitNbr + ".ged";
                    Console.WriteLine("Writting " + gedfile);
                    GedcomParser.GedcomRecordWriter grw = new GedcomParser.GedcomRecordWriter();
                    try
                    {
                        grw.WriteGedcom(_gd1, gedfile);
                    }
                    catch
                    {   
                        try
                        {
                            gedfile = WorkDir + "\\GM_" + nKitNbr + ".ged";
                            grw.WriteGedcom(_gd1, gedfile);
                        }
                        catch (Exception ex) { Console.WriteLine("Couldn't write out " + gedfile + ": " + ex.Message + " - " + ex.StackTrace); }
                    }
                    gedfile = string.Empty;
                }

            }
        }