/// <summary> /// Populate the people collection with information from the GEDCOM file. /// </summary> public void Import(PeopleCollection peopleCollection, string gedcomFilePath) { // Clear current content. peopleCollection.Clear(); // First convert the GEDCOM file to an XML file so it's easier to parse, // the temp XML file is deleted when importing is complete. string xmlFilePath = Path.GetTempFileName(); try { this.people = peopleCollection; // Convert the GEDCOM file to a temp XML file. GedcomConverter.ConvertToXml(gedcomFilePath, xmlFilePath, true); doc = new XmlDocument(); doc.Load(xmlFilePath); // Import data from the temp XML file to the people collection. ImportPeople(); ImportFamilies(); // The collection requires a primary-person, use the first // person added to the collection as the primary-person. if (peopleCollection.Count > 0) { peopleCollection.Current = peopleCollection[0]; } } finally { // Delete the temp XML file. File.Delete(xmlFilePath); } }
/// <summary> /// Populate the people collection with information from the GEDCOM file. /// </summary> public bool Import(PeopleCollection peopleCollection, SourceCollection sourceCollection, RepositoryCollection repositoryCollection, string gedcomFilePath, bool disableCharacterCheck) { // Clear current content. peopleCollection.Clear(); sourceCollection.Clear(); repositoryCollection.Clear(); // First convert the GEDCOM file to an XML file so it's easier to parse, // the temp XML file is deleted when importing is complete. string xmlFilePath = Path.GetTempFileName(); bool loaded = false; // if user canceled the load try { this.people = peopleCollection; this.sources = sourceCollection; this.repositories = repositoryCollection; // Convert the GEDCOM file to a temp XML file. GedcomConverter.ConvertToXml(gedcomFilePath, xmlFilePath, true, disableCharacterCheck); doc = new XmlDocument(); doc.Load(xmlFilePath); // Get list of people. XmlNodeList list = doc.SelectNodes("/root/INDI"); // Import data from the temp XML file to the people collection. ImportPeople(list); ImportFamilies(); ImportSources(); ImportRepositories(); // The collection requires a primary-person, use the first // person added to the collection as the primary-person. if (peopleCollection.Count > 0) { peopleCollection.Current = peopleCollection[0]; } // Update IDs to match Family.Show standards UpdatePeopleIDs(); UpdateSourceIDs(); UpdateRepositoryIDs(); loaded = true; } finally { //Delete the temp XML file. File.Delete(xmlFilePath); } return(loaded); }