コード例 #1
0
ファイル: GedcomImport.cs プロジェクト: ssickles/archive
        /// <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);
            }
        }
コード例 #2
0
        public DiagramLogic()
        {
            // The list of people, this is a global list shared by the application.
            family = App.Family;

            Clear();
        }
コード例 #3
0
        public static void PeopleCollectionEnumerationExample()
        {
            PeopleCollection people = new PeopleCollection();
            people.AddPerson(new Person()
            {
                Name = "Mike",
                Age = 22
            });

            people.AddPerson(new Person()
            {
                Name = "Kate",
                Age = 17
            });

            people.AddPerson(new Person()
            {
                Name = "John",
                Age = 20
            });

            Console.WriteLine("All people");
            foreach (Person person in people)
                Console.WriteLine(person);

            Console.WriteLine("\r\nUnder age people");
            foreach (Person person in people.GetUnderAgePeople())
                Console.WriteLine(person);

            Console.WriteLine("\r\nTake people until under aged");
            foreach(Person person in people.GetPeopleUntilUnderAged())
                Console.WriteLine(person);
        }
コード例 #4
0
        public void Add_Person_WithIncorrectAge_ThrownExceptionShouldHaveMessage()
        {
            try
            {
                // Arrange
                PeopleCollection people = new PeopleCollection();

                // Act
                people.AddPerson(new Person() { Name = "Jack", Age = -1 });

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.InnerException);

                Assert.AreNotEqual<string>(string.Empty, ex.Message);
                Assert.IsNull(ex.InnerException);

                Assert.IsTrue(true);
                return;
            }

            Assert.IsTrue(false);
        }
コード例 #5
0
        public void Add_Person_WithAgeBelowZero_ThrowsInvalidAgeException()
        {
            // Arrange
            PeopleCollection people = new PeopleCollection();

            // Act
            people.AddPerson(new Person() { Name = "Jack", Age = -1 });
        }
コード例 #6
0
 /// <summary>
 /// Performs the business logic for adding the Parent relationship between the person and the parents.
 /// </summary>
 public static void AddParent(PeopleCollection family, Person person, ParentSet parentSet)
 {
     // First add child to parents.
     family.AddChild(parentSet.FirstParent, person, ParentChildModifier.Natural);
     family.AddChild(parentSet.SecondParent, person, ParentChildModifier.Natural);
     
     // Next update the siblings. Get the list of full siblings for the person. 
     // A full sibling is a sibling that has both parents in common. 
     List<Person> siblings = GetChildren(parentSet);
     foreach (Person sibling in siblings)
     {
         if (sibling != person)
             family.AddSibling(person, sibling);
     }
 }
コード例 #7
0
        /// <summary>
        /// Performs the business logic for adding the Child relationship between the person and the child.
        /// </summary>
        public static void AddChild(PeopleCollection family, Person person, Person child)
        {
            // Add the new child as a sibling to any existing children
            foreach (Person existingSibling in person.Children)
            {
                family.AddSibling(existingSibling, child);
            }

            switch (person.Spouses.Count)
            {
                // Single parent, add the child to the person
                case 0:
                    family.AddChild(person, child, ParentChildModifier.Natural);
                    break;

                // Has existing spouse, add the child to the person's spouse as well.
                case 1:
                    family.AddChild(person, child, ParentChildModifier.Natural);
                    family.AddChild(person.Spouses[0], child, ParentChildModifier.Natural);
                    break;
            }
        }
コード例 #8
0
        /// <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;
        }
コード例 #9
0
        /// <summary>
        /// Performs the business logic for changing the deleting the person
        /// </summary>
        public static void DeletePerson(PeopleCollection family, Person personToDelete)
        {
            if (!personToDelete.IsDeletable)
                return;

            // Remove the personToDelete from the relationships that contains the personToDelete.
            foreach (Relationship relationship in personToDelete.Relationships)
            {
                foreach (Relationship rel in relationship.RelationTo.Relationships)
                {
                    if (rel.RelationTo.Equals(personToDelete))
                    {
                        relationship.RelationTo.Relationships.Remove(rel);
                        break;
                    }                    
                } 
            }

            // Delete the person's photos and story
            personToDelete.DeletePhotos();
            personToDelete.DeleteStory();

            family.Remove(personToDelete);
        }
コード例 #10
0
        /// <summary>
        /// Performs the business logic for changing the person parents
        /// </summary>
        public static void ChangeParents(PeopleCollection family, Person person, ParentSet newParentSet)
        {
            // Don't do anything if there is nothing to change or if the parents are the same
            if (person.ParentSet == null || newParentSet == null || person.ParentSet.Equals(newParentSet))
                return;

            // store the current parent set which will be removed
            ParentSet formerParentSet = person.ParentSet;

            // Remove the first parent
            RemoveParentChildRelationship(person, formerParentSet.FirstParent);

            // Remove the person as a child of the second parent
            RemoveParentChildRelationship(person, formerParentSet.SecondParent);

            // Remove the sibling relationships
            RemoveSiblingRelationships(person);

            // Add the new parents
            AddParent(family, person, newParentSet);
        }
コード例 #11
0
        /// <summary>
        /// Performs the business logic for adding the Sibling relationship between the person and the sibling.
        /// </summary>
        public static void AddSibling(PeopleCollection family, Person person, Person sibling)
        {
            // Handle siblings
            if (person.Siblings.Count > 0)
            {
                // Make the siblings siblings to each other.
                foreach (Person existingSibling in person.Siblings)
                {
                    family.AddSibling(existingSibling, sibling);
                }
            }

            if (person.Parents != null)
            {
                switch (person.Parents.Count)
                {
                    // No parents
                    case 0:
                        family.AddSibling(person, sibling);
                        break;

                    // Single parent
                    case 1:
                        family.AddSibling(person, sibling);
                        family.AddChild(person.Parents[0], sibling, ParentChildModifier.Natural);
                        break;

                    // 2 parents
                    case 2:
                        // Add the sibling as a child of the same parents
                        foreach (Person parent in person.Parents)
                        {
                            family.AddChild(parent, sibling, ParentChildModifier.Natural);
                        }

                        family.AddSibling(person, sibling);
                        break;

                    default:
                        family.AddSibling(person, sibling);
                        break;
                }
            }
        }
コード例 #12
0
        /// <summary>
        /// Performs the business logic for adding the Spousal relationship between the person and the spouse.
        /// </summary>
        public static void AddSpouse(PeopleCollection family, Person person, Person spouse, SpouseModifier modifier)
        {
            // Assume the spouse's gender based on the counterpart of the person's gender
            if (person.Gender == Gender.Male)
                spouse.Gender = Gender.Female;
            else
                spouse.Gender = Gender.Male;

            if (person.Spouses != null)
            {
                switch (person.Spouses.Count)
                {
                    // No existing spouse	
                    case 0:
                        family.AddSpouse(person, spouse, modifier);

                        // Add any of the children as the child of the spouse.
                        if (person.Children != null || person.Children.Count > 0)
                        {
                            foreach (Person child in person.Children)
                            {
                                family.AddChild(spouse, child, ParentChildModifier.Natural);
                            }
                        }
                        break;

                    // Existing spouse(s)
                    default:
                        // If specifying a new married spouse, make existing spouses former.
                        if (modifier == SpouseModifier.Current)
                        {
                            foreach (Relationship relationship in person.Relationships)
                            {
                                if (relationship.RelationshipType == RelationshipType.Spouse)
                                    ((SpouseRelationship)relationship).SpouseModifier = SpouseModifier.Former;
                            }
                        }
                        
                        family.AddSpouse(person, spouse, modifier);
                        break;
                }

                // Setter for property change notification
                person.HasSpouse = true;
            }
        }
コード例 #13
0
		private async static Task LoadPeople()
		{
			People = new PeopleCollection(ApplicationData.Current.LocalFolder);
			//await People.LoadState();
			await People.LoadStateMock();
		}