/// <summary> /// Performs the business logic for adding the Parent relationship between the person and the parent. /// Once a person has a parent of a given gender, adding another /// parent of the same gender creates an adopted relationship. /// </summary> public static void AddParent(PeopleCollection family, Person person, Person parent) { // A person can only have 2 natural parents, so adding a 3rd or more indicates adoption // In this case, just add a simple child parent relationship and don't try to add // siblings etc, this should be done manually. Gender parentGender = parent.Gender; int i = 0; // number of parents of same gender foreach (Person p in person.Parents) { if (p.Gender == parentGender) { i++; } } if (i >= 1) //if a person already has a parent with the same gender, then add as an adopted parent (could be foster) { family.Add(parent); AddExistingParent(family, person, parent, ParentChildModifier.Adopted); return; } else //adding other parent and siblings, only when a person has one parent set. { // Add the parent to the main collection of people. family.Add(parent); if (person.Parents.Count == 0)// No exisiting parents { family.AddChild(parent, person, ParentChildModifier.Natural); } else { // One existing parent family.AddChild(parent, person, ParentChildModifier.Natural); family.AddSpouse(parent, person.Parents[0], SpouseModifier.Current); } // Handle siblings if (person.Siblings.Count > 0) { // Make siblings the child of the new parent foreach (Person sibling in person.Siblings) { family.AddChild(parent, sibling, ParentChildModifier.Natural); } } } //Setter for property change notification person.HasParents = true; }
/// <summary> /// Imports the individuals (INDI tags) from the GEDCOM XML file. /// </summary> private void ImportPeople() { // Get list of people. XmlNodeList list = doc.SelectNodes("/root/INDI"); foreach (XmlNode node in list) { // Create a new person that will be added to the collection. Person person = new Person(); // Import details about the person. person.FirstName = GetFirstName(node); person.LastName = GetLastName(node); person.NickName = GetNickName(node); person.Suffix = GetSuffix(node); person.MarriedName = GetMarriedName(node); person.Id = GetId(node); person.Gender = GetGender(node); ImportBirth(person, node); ImportDeath(person, node); ImportPhotos(person, node); ImportNote(person, node); people.Add(person); } }
public void LoadOPC() { // Loading, clear existing nodes PeopleCollection.Clear(); try { // Use the default path and filename if none were provided if (string.IsNullOrEmpty(FullyQualifiedFilename)) { FullyQualifiedFilename = DefaultFullyQualifiedFilename; } string tempFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), App.ApplicationFolderName); tempFolder = Path.Combine(tempFolder, App.AppDataFolderName + @"\"); OPCUtility.ExtractPackage(FullyQualifiedFilename, tempFolder); XmlSerializer xml = new XmlSerializer(typeof(People)); using (Stream stream = new FileStream(tempFolder + OPCContentFileName, FileMode.Open, FileAccess.Read, FileShare.Read)) { People people = (People)xml.Deserialize(stream); stream.Close(); foreach (Person person in people.PeopleCollection) { PeopleCollection.Add(person); } // To avoid circular references when serializing family data to xml, only the person Id // is seralized to express relationships. When family data is loaded, the correct // person object is found using the person Id and assigned to the appropriate relationship. foreach (Person person in PeopleCollection) { foreach (Relationship relationqhip in person.Relationships) { relationqhip.RelationTo = PeopleCollection.Find(relationqhip.PersonId); } } // Set the current person in the list CurrentPersonId = people.CurrentPersonId; CurrentPersonName = people.CurrentPersonName; PeopleCollection.Current = PeopleCollection.Find(CurrentPersonId); } PeopleCollection.IsDirty = false; return; } catch (Exception e) { // Could not load the file. Handle all exceptions // the same, ignore and continue. Debug.WriteLine(e.Message); fullyQualifiedFilename = string.Empty; } }
/// <summary> /// Performs the business logic for adding the Parent relationship between the person and the parent. /// </summary> public static void AddParent(PeopleCollection family, Person person, Person parent) { // A person can only have 2 parents, do nothing if (person.Parents.Count == 2) { return; } // Add the parent to the main collection of people. family.Add(parent); switch (person.Parents.Count) { // No exisitng parents case 0: family.AddChild(parent, person, ParentChildModifier.Natural); break; // An existing parent case 1: family.AddChild(parent, person, ParentChildModifier.Natural); family.AddSpouse(parent, person.Parents[0], SpouseModifier.Current); break; } // Handle siblings if (person.Siblings.Count > 0) { // Make siblings the child of the new parent foreach (Person sibling in person.Siblings) { family.AddChild(parent, sibling, ParentChildModifier.Natural); } } // Setter for property change notification person.HasParents = true; }
/// <summary> /// Imports the individuals (INDI tags) from the GEDCOM XML file. /// </summary> private void ImportPeople(XmlNodeList list) { foreach (XmlNode node in list) { // Create a new person that will be added to the collection. Person person = new Person(); // Import details about the person. person.FirstName = GetNames(node); person.LastName = GetSurname(node); // If no name or surname, call them unknown rather than an empty string if (string.IsNullOrEmpty(person.FirstName) && string.IsNullOrEmpty(person.LastName)) { person.FirstName = Properties.Resources.Unknown; } person.Suffix = GetSuffix(node); person.Id = GetId(node); person.Gender = GetGender(node); person.Restriction = GetRestriction(node); ImportBirth(person, node, doc); ImportDeath(person, node, doc); ImportBurial(person, node, doc); ImportCremation(person, node, doc); ImportOccupation(person, node, doc); ImportReligion(person, node, doc); ImportEducation(person, node, doc); ImportPhotosAttachments(person, node); ImportNote(person, node); people.Add(person); } }
public void LoadVersion2() { // Loading, clear existing nodes PeopleCollection.Clear(); try { // Use the default path and filename if none were provided if (string.IsNullOrEmpty(FullyQualifiedFilename)) { FullyQualifiedFilename = DefaultFullyQualifiedFilename; } XmlSerializer xml = new XmlSerializer(typeof(People)); using (Stream stream = new FileStream(FullyQualifiedFilename, FileMode.Open, FileAccess.Read, FileShare.Read)) { People people = (People)xml.Deserialize(stream); stream.Close(); foreach (Person person in people.PeopleCollection) { PeopleCollection.Add(person); } // Setup temp folders for this family to be packaged into OPC later string tempFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), App.ApplicationFolderName); tempFolder = Path.Combine(tempFolder, App.AppDataFolderName); RecreateDirectory(tempFolder); string photoFolder = Path.Combine(tempFolder, Photo.Const.PhotosFolderName); RecreateDirectory(photoFolder); string storyFolder = Path.Combine(tempFolder, Story.Const.StoriesFolderName); RecreateDirectory(storyFolder); foreach (Person person in PeopleCollection) { // To avoid circular references when serializing family data to xml, only the person Id // is seralized to express relationships. When family data is loaded, the correct // person object is found using the person Id and assigned to the appropriate relationship. foreach (Relationship relationship in person.Relationships) { relationship.RelationTo = PeopleCollection.Find(relationship.PersonId); } // store the stories into temp directory to be packaged into OPC later foreach (Photo photo in person.Photos) { string photoOldPath = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), App.ApplicationFolderName), photo.RelativePath); if (File.Exists(photoOldPath)) { string photoFile = Path.Combine(photoFolder, Path.GetFileName(photo.FullyQualifiedPath)); // Remove spaces since they'll be packaged as %20, breaking relative paths that expect spaces photoFile = photoFile.Replace(" ", ""); photo.RelativePath = photo.RelativePath.Replace(" ", ""); File.Copy(photoOldPath, photoFile, true); } } // store the person's story into temp directory to be packaged into OPC later if (person.Story != null) { string storyOldPath = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), App.ApplicationFolderName), person.Story.RelativePath); if (File.Exists(storyOldPath)) { string storyFile = Path.Combine(storyFolder, Path.GetFileName(person.Story.AbsolutePath)); // Remove spaces since they'll be packaged as %20, breaking relative paths that expect spaces storyFile = ReplaceEncodedCharacters(storyFile); person.Story.RelativePath = ReplaceEncodedCharacters(person.Story.RelativePath); File.Copy(storyOldPath, storyFile, true); } } } // Set the current person in the list CurrentPersonId = people.CurrentPersonId; CurrentPersonName = people.CurrentPersonName; PeopleCollection.Current = PeopleCollection.Find(CurrentPersonId); } PeopleCollection.IsDirty = false; return; } catch (Exception) { // Could not load the file. Handle all exceptions // the same, ignore and continue. fullyQualifiedFilename = string.Empty; } }