コード例 #1
0
ファイル: RelationshipHelper.cs プロジェクト: karmicka/Source
        /// <summary>
        /// Performs the business logic for adding the Spousal relationship between the person and the spouse.
        /// In the case of existing people, do not hook up other siblings etc.  Allow the user to do this manually.
        /// </summary>
        public static void AddExistingSpouse(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)
            {
                // 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);
            }

            // Setter for property change notification
            person.HasSpouse = true;
        }
コード例 #2
0
ファイル: RelationshipHelper.cs プロジェクト: karmicka/Source
        /// <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, ParentChildModifier modifier)
        {
            if (person != child)
            {
                switch (person.Spouses.Count)
                {
                // Single parent, add the child to the person
                case 0:
                    family.AddChild(person, child, modifier);
                    break;

                // Has existing spouse, add the child to the person's spouse as well.
                case 1:
                    family.AddChild(person, child, modifier);
                    family.AddChild(person.Spouses[0], child, modifier);
                    break;
                }

                // Add the new child as a sibling to any existing natural children of the natural parents.
                foreach (Person existingSibling in person.NaturalChildren)
                {
                    if (existingSibling != child)
                    {
                        family.AddSibling(existingSibling, child);
                    }
                }
            }
        }
コード例 #3
0
        /// <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);
            }
        }
コード例 #4
0
ファイル: RelationshipHelper.cs プロジェクト: karmicka/Source
        /// <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)
                {
                    if (existingSibling != sibling)
                    {
                        family.AddSibling(existingSibling, sibling);
                    }
                }
            }

            if (person.NaturalParents != null)
            {
                foreach (Person parent in person.NaturalParents)
                {
                    family.AddChild(parent, sibling, ParentChildModifier.Natural);
                }

                family.AddSibling(person, sibling);
            }
            person.HasSiblings = true;
        }
コード例 #5
0
ファイル: RelationshipHelper.cs プロジェクト: karmicka/Source
 /// <summary>
 /// Performs the business logic for adding the Child relationship between the person and the child.
 /// In the case of existing people, do not hook up other siblings etc.  Allow the user to do this manually.
 /// </summary>
 public static void AddExistingChild(PeopleCollection family, Person person, Person child, ParentChildModifier modifier)
 {
     if (person != child)
     {
         family.AddChild(person, child, modifier);
     }
 }
コード例 #6
0
ファイル: RelationshipHelper.cs プロジェクト: karmicka/Source
 /// <summary>
 /// Performs the business logic for adding the Sibling relationship between the person and the sibling.
 /// In the case of existing people, do not hook up other siblings etc.  Allow the user to do this manually.
 /// </summary>
 public static void AddExistingSibling(PeopleCollection family, Person person, Person sibling)
 {
     if (person.Parents != null)
     {
         family.AddSibling(person, sibling);
     }
 }
コード例 #7
0
ファイル: RelationshipHelper.cs プロジェクト: karmicka/Source
        /// <summary>
        /// Performs the business logic for deleting a 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);
        }
コード例 #8
0
ファイル: People.cs プロジェクト: AndrewLang/FamilyShow
        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;
            }
        }
コード例 #9
0
ファイル: RelationshipHelper.cs プロジェクト: karmicka/Source
        /// <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;
        }
コード例 #10
0
        /// <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);
        }
コード例 #11
0
        /// <summary>
        /// Export the data from the People collection to the specified GEDCOM file.
        /// </summary>
        public void Export(PeopleCollection peopleCollection, string gedcomFilePath)
        {
            people = peopleCollection;

            using (writer = new StreamWriter(gedcomFilePath))
            {
                WriteLine(0, "HEAD", "");
                ExportPeople();
                ExportFamilies();
                WriteLine(0, "TRLR", "");
            }
        }
コード例 #12
0
ファイル: RelationshipHelper.cs プロジェクト: karmicka/Source
        /// <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
ファイル: RelationshipHelper.cs プロジェクト: karmicka/Source
 /// <summary>
 /// Performs the business logic for updating the natural siblings of a child.
 /// </summary>
 public static void UpdateSiblings(PeopleCollection family, Person child)
 {
     foreach (Person p in child.NaturalParents)
     {
         foreach (Person c in p.NaturalChildren)
         {
             if (c != child && !family.Current.Siblings.Contains(c))
             {
                 RelationshipHelper.AddExistingSibling(family, family.Current, c);
             }
         }
     }
 }
コード例 #14
0
        /// <summary>
        /// Organize the People collection into a list of families. A family consists of
        /// an wife, husband, children, and married / divorced information.
        /// </summary>
        public void Create(PeopleCollection people)
        {
            this.Clear();

            // First, iterate though the list and create parent groups.
            // A parent group is one or two parents that have one or
            // more children.
            foreach (Person person in people)
            {
                Collection <Person> parents = person.Parents;
                if (parents.Count > 0)
                {
                    // Only using the first two parents.
                    Person parentLeft  = parents[0];
                    Person parentRight = (parents.Count > 1) ? parents[1] : null;

                    // See if this parent group has been added to the list yet.
                    string key = GetKey(parentLeft, parentRight);
                    if (!this.ContainsKey(key))
                    {
                        // This parent group does not exist, add it to the list.
                        Family details = new Family(parentLeft, parentRight);
                        details.Relationship = parentLeft.GetSpouseRelationship(parentRight);
                        this[key]            = details;
                    }

                    // Add the child to the parent group.
                    this[key].Children.Add(person);
                }
            }

            // Next, iterate though the list and create marriage groups.
            // A marriage group is current or former marriages that
            // don't have any children.
            foreach (Person person in people)
            {
                Collection <Person> spouses = person.Spouses;
                foreach (Person spouse in spouses)
                {
                    // See if this marriage group is in the list.
                    string key = GetKey(person, spouse);
                    if (!this.ContainsKey(key))
                    {
                        // This marriage group is not in the list, add it to the list.
                        Family details = new Family(person, spouse);
                        details.Relationship = person.GetSpouseRelationship(spouse);
                        this[key]            = details;
                    }
                }
            }
        }
コード例 #15
0
ファイル: GedcomExport.cs プロジェクト: karmicka/Source
        /// <summary>
        /// Export the data from the People collection to the specified GEDCOM file.
        /// </summary>
        public void Export(PeopleCollection peopleCollection, SourceCollection sourceCollection, RepositoryCollection repositoryCollection, string gedcomFilePath, string familyxFilePath, string language)
        {
            this.people       = peopleCollection;
            this.sources      = sourceCollection;
            this.repositories = repositoryCollection;

            using (writer = new StreamWriter(gedcomFilePath))
            {
                WriteLine(0, "HEAD", "");
                ExportSummary(gedcomFilePath, familyxFilePath, language);
                ExportPeople();
                ExportFamilies();
                ExportSources();
                ExportRepositories();
                WriteLine(0, "TRLR", "");
            }
        }
コード例 #16
0
ファイル: RelationshipHelper.cs プロジェクト: karmicka/Source
        /// <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);
                }
            }
        }
コード例 #17
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;
                }
            }
        }
コード例 #18
0
ファイル: RelationshipHelper.cs プロジェクト: karmicka/Source
        /// <summary>
        /// Performs the business logic for updating the Parent relationship between the child and the parent.
        /// </summary>
        public static void UpdateParentChildStatus(PeopleCollection family, Person parent, Person child, ParentChildModifier modifier)
        {
            foreach (Relationship relationship in parent.Relationships)
            {
                if (relationship.RelationshipType == RelationshipType.Child && relationship.RelationTo.Equals(child))
                {
                    ((ChildRelationship)relationship).ParentChildModifier = modifier;
                    break;
                }
            }

            foreach (Relationship relationship in child.Relationships)
            {
                if (relationship.RelationshipType == RelationshipType.Parent && relationship.RelationTo.Equals(parent))
                {
                    ((ParentRelationship)relationship).ParentChildModifier = modifier;
                    break;
                }
            }
        }
コード例 #19
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;
        }
コード例 #20
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);
        }
コード例 #21
0
ファイル: People.cs プロジェクト: olachan/PostSharp-Toolkits
 public People()
 {
     peopleCollection = new PeopleCollection();
 }
コード例 #22
0
        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;
            }
        }
コード例 #23
0
        public string[] ExportPlaces(PeopleCollection peopleCollection, string fileName, bool hideliving, bool times, bool lifespans, bool places, bool burials, bool deaths, bool cremations, bool births, bool marriages)
        {
            string PlacesFileName = Path.GetFileNameWithoutExtension(fileName);

            TextWriter tw = new StreamWriter(fileName);

            #region styles

            // Write text necessary for kml file.
            // Uses Google Earths's male and female icons.
            tw.WriteLine("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
                         "<kml xmlns=\"http://www.opengis.net/kml/2.2\" xmlns:gx=\"http://www.google.com/kml/ext/2.2\" xmlns:kml=\"http://www.opengis.net/kml/2.2\" xmlns:atom=\"http://www.w3.org/2005/Atom\">\n" +
                         "<Document>\n" +
                         "<name>" + PlacesFileName + "</name>\n" +

                         "<Style id=\"sn_man2\">\n" +
                         "<IconStyle>\n" +
                         "<scale>0.9</scale>\n" +
                         "<Icon>\n" +
                         "<href>http://maps.google.com/mapfiles/kml/shapes/man.png</href>\n" +
                         "</Icon>\n" +
                         "</IconStyle>\n" +
                         "<LabelStyle>\n" +
                         "<scale>0.9</scale>\n" +
                         "</LabelStyle>\n" +
                         "</Style>\n" +

                         "<Style id=\"sh_man0\">\n" +
                         "<IconStyle>\n" +
                         "	<scale>0.9</scale>\n"+
                         "<Icon>\n" +
                         "	<href>http://maps.google.com/mapfiles/kml/shapes/man.png</href>\n"+
                         "</Icon>\n" +
                         "</IconStyle>\n" +
                         "<LabelStyle>\n" +
                         "	<scale>0.9</scale>\n"+
                         "</LabelStyle>\n" +
                         "</Style>\n" +

                         "<StyleMap id=\"msn_man\">\n" +
                         "<Pair>\n" +
                         "	<key>normal</key>\n"+
                         "	<styleUrl>#sn_man2</styleUrl>\n"+
                         "</Pair>\n" +
                         "<Pair>\n" +
                         "	<key>highlight</key>\n"+
                         "	<styleUrl>#sh_man0</styleUrl>\n"+
                         "</Pair>\n" +
                         "</StyleMap>\n" +


                         "<Style id=\"sn_woman1\">\n" +
                         "	<IconStyle>\n"+
                         "		<scale>0.9</scale>\n"+
                         "		<Icon>\n"+
                         "			<href>http://maps.google.com/mapfiles/kml/shapes/woman.png</href>\n"+
                         "		</Icon>\n"+
                         "	</IconStyle>\n"+
                         "  <LabelStyle>\n" +
                         "  	<scale>0.9</scale>\n"+
                         "  </LabelStyle>\n" +
                         "</Style>\n" +


                         "<Style id=\"sh_woman0\">\n" +
                         "	 <IconStyle>\n"+
                         "		<scale>0.9</scale>\n"+
                         "      <Icon>\n" +
                         "			<href>http://maps.google.com/mapfiles/kml/shapes/woman.png</href>\n"+
                         "		</Icon>\n"+
                         "	 </IconStyle>\n"+
                         "	 <LabelStyle>\n"+
                         "		<scale>0.9</scale>\n"+
                         "	 </LabelStyle>\n"+
                         "</Style>\n" +

                         "<StyleMap id=\"msn_woman\">\n" +
                         "<Pair>\n" +
                         "		<key>normal</key>\n"+
                         "		<styleUrl>#sn_woman1</styleUrl>\n"+
                         "</Pair>\n" +
                         "<Pair>\n" +
                         "		<key>highlight</key>\n"+
                         "		<styleUrl>#sh_woman0</styleUrl>\n"+
                         "</Pair>\n" +
                         "</StyleMap>");

            #endregion

            int i = 0;  // Counter for all the places exported.

            if (places)
            {
                #region places with no time information

                tw.WriteLine("<Folder>\n" +
                             "<name>" + Microsoft.FamilyShowLib.Properties.Resources.People + "</name>\n" +
                             "<open>0</open>\n" +
                             "<Folder>\n" +
                             "<name>" + Microsoft.FamilyShowLib.Properties.Resources.Births + "</name>\n" +
                             "<open>0</open>");

                if (births)
                {
                    foreach (Person p in peopleCollection)
                    {
                        if (!(hideliving && p.IsLiving))
                        {
                            if (!string.IsNullOrEmpty(p.BirthPlace) && p.Restriction != Restriction.Private)
                            {
                                string name = string.Empty;

                                tw.WriteLine("<Placemark>\n" +
                                             "	<name>"+ p.FullName + "</name>\n" +
                                             "	<address>"+ p.BirthPlace + "</address>\n" +
                                             "	<description>"+ p.BirthPlace + "</description>");

                                if (p.Gender == Gender.Male)
                                {
                                    tw.WriteLine("<styleUrl>#msn_man</styleUrl>\n</Placemark>");
                                }
                                else
                                {
                                    tw.WriteLine("<styleUrl>#msn_woman</styleUrl>\n</Placemark>");
                                }

                                i++;
                            }
                        }
                    }

                    tw.WriteLine("</Folder>");
                }

                if (deaths)
                {
                    tw.WriteLine("<Folder>\n<name>" + Microsoft.FamilyShowLib.Properties.Resources.Deaths + "</name>\n" +
                                 "<open>0</open>");

                    foreach (Person p in peopleCollection)
                    {
                        if (!(hideliving && p.IsLiving))
                        {
                            if (!string.IsNullOrEmpty(p.DeathPlace) && p.Restriction != Restriction.Private)
                            {
                                tw.WriteLine("<Placemark>\n" +
                                             "<name>" + p.FullName + "</name>\n" +
                                             "<address>" + p.DeathPlace + "</address>\n" +
                                             "<description>" + p.DeathPlace + "</description>");

                                if (p.Gender == Gender.Male)
                                {
                                    tw.WriteLine("<styleUrl>#msn_man</styleUrl>\n</Placemark>");
                                }
                                else
                                {
                                    tw.WriteLine("<styleUrl>#msn_woman</styleUrl>\n</Placemark>");
                                }

                                i++;
                            }
                        }
                    }

                    tw.WriteLine("</Folder>");
                }

                if (burials)
                {
                    tw.WriteLine("<Folder>\n" +
                                 "<name>" + Microsoft.FamilyShowLib.Properties.Resources.Burials + "</name>\n" +
                                 "<open>0</open>");

                    foreach (Person p in peopleCollection)
                    {
                        if (!(hideliving && p.IsLiving))
                        {
                            if (!string.IsNullOrEmpty(p.BurialPlace) && p.Restriction != Restriction.Private)
                            {
                                tw.WriteLine("<Placemark>\n" +
                                             "<name>" + p.FullName + "</name>\n" +
                                             "<address>" + p.BurialPlace + "</address>\n" +
                                             "<description>" + p.BurialPlace + "</description>");

                                if (p.Gender == Gender.Male)
                                {
                                    tw.WriteLine("<styleUrl>#msn_man</styleUrl>\n</Placemark>");
                                }
                                else
                                {
                                    tw.WriteLine("<styleUrl>#msn_woman</styleUrl>\n</Placemark>");
                                }

                                i++;
                            }
                        }
                    }

                    tw.WriteLine("</Folder>");
                }

                if (cremations)
                {
                    tw.WriteLine("<Folder>\n" +
                                 "<name>" + Microsoft.FamilyShowLib.Properties.Resources.Cremations + "</name>\n" +
                                 "<open>0</open>");

                    foreach (Person p in peopleCollection)
                    {
                        if (!(hideliving && p.IsLiving))
                        {
                            if (!string.IsNullOrEmpty(p.CremationPlace) && p.Restriction != Restriction.Private)
                            {
                                tw.WriteLine("<Placemark>\n" +
                                             "<name>" + p.FullName + "</name>\n" +
                                             "<address>" + p.CremationPlace + "</address>\n" +
                                             "<description>" + p.CremationPlace + "</description>");

                                if (p.Gender == Gender.Male)
                                {
                                    tw.WriteLine("<styleUrl>#msn_man</styleUrl>\n</Placemark>");
                                }
                                else
                                {
                                    tw.WriteLine("<styleUrl>#msn_woman</styleUrl>\n</Placemark>");
                                }

                                i++;
                            }
                        }
                    }

                    tw.WriteLine("</Folder>");
                }

                if (marriages)
                {
                    tw.WriteLine("<Folder>\n" +
                                 "<name>" + Microsoft.FamilyShowLib.Properties.Resources.Marriages + "</name>\n" +
                                 "<open>0</open>");

                    foreach (Person p in peopleCollection)
                    {
                        if (!(hideliving && p.IsLiving))
                        {
                            if (p.Restriction != Restriction.Private)
                            {
                                foreach (Relationship rel in p.Relationships)
                                {
                                    if (rel.RelationshipType == RelationshipType.Spouse)
                                    {
                                        SpouseRelationship spouseRel = ((SpouseRelationship)rel);

                                        if (!string.IsNullOrEmpty(spouseRel.MarriagePlace))
                                        {
                                            tw.WriteLine("<Placemark>\n" +
                                                         "<name>" + p.FullName + "</name>\n" +
                                                         "<address>" + spouseRel.MarriagePlace + "</address>\n" +
                                                         "<description>" + spouseRel.MarriagePlace + "</description>");


                                            if (p.Gender == Gender.Male)
                                            {
                                                tw.WriteLine("<styleUrl>#msn_man</styleUrl>\n</Placemark>");
                                            }
                                            else
                                            {
                                                tw.WriteLine("<styleUrl>#msn_woman</styleUrl>\n</Placemark>");
                                            }

                                            i++;
                                        }
                                    }
                                }
                            }
                        }
                    }

                    tw.WriteLine("</Folder>");
                }

                #endregion
            }
            else if (times)
            {
                #region place with time information

                tw.WriteLine("<Folder>\n" +
                             "<name>" + Microsoft.FamilyShowLib.Properties.Resources.Events + "</name>\n" +
                             "<open>0</open>");

                if (births)
                {
                    tw.WriteLine("<Folder>\n" +
                                 "<name>" + Microsoft.FamilyShowLib.Properties.Resources.Births + "</name>\n" +
                                 "<open>0</open>");

                    foreach (Person p in peopleCollection)
                    {
                        if (!(hideliving && p.IsLiving))
                        {
                            if (!string.IsNullOrEmpty(p.BirthPlace) && p.Restriction != Restriction.Private)
                            {
                                tw.WriteLine("<Placemark>\n" +
                                             "	<name>"+ p.FullName + "</name>\n" +
                                             "	<address>"+ p.BirthPlace + "</address>\n" +
                                             "	<description>"+ p.BirthPlace + "</description>\n" +
                                             "   <TimeStamp>\n<when>" + p.YearOfBirth + "</when>\n</TimeStamp>");

                                if (p.Gender == Gender.Male)
                                {
                                    tw.WriteLine("<styleUrl>#msn_man</styleUrl>\n</Placemark>");
                                }
                                else
                                {
                                    tw.WriteLine("<styleUrl>#msn_woman</styleUrl>\n</Placemark>");
                                }

                                i++;
                            }
                        }
                    }

                    tw.WriteLine("</Folder>");
                }

                if (deaths)
                {
                    tw.WriteLine("<Folder>\n" +
                                 "<name>" + Microsoft.FamilyShowLib.Properties.Resources.Deaths + "</name>\n" +
                                 "<open>0</open>");

                    foreach (Person p in peopleCollection)
                    {
                        if (!(hideliving && p.IsLiving))
                        {
                            if (!string.IsNullOrEmpty(p.DeathPlace) && p.Restriction != Restriction.Private)
                            {
                                tw.WriteLine("<Placemark>\n" +
                                             "<name>" + p.FullName + "</name>\n" +
                                             "<address>" + p.DeathPlace + "</address>\n" +
                                             "<description>" + p.DeathPlace + "</description>\n" +
                                             "<TimeStamp>\n<when>" + p.YearOfDeath + "</when>\n</TimeStamp>");

                                if (p.Gender == Gender.Male)
                                {
                                    tw.WriteLine("<styleUrl>#msn_man</styleUrl>\n</Placemark>");
                                }
                                else
                                {
                                    tw.WriteLine("<styleUrl>#msn_woman</styleUrl>\n</Placemark>");
                                }

                                i++;
                            }
                        }
                    }

                    tw.WriteLine("</Folder>");
                }

                if (deaths)
                {
                    tw.WriteLine("<Folder>\n" +
                                 "<name>" + Microsoft.FamilyShowLib.Properties.Resources.Burials + "</name>\n" +
                                 "<open>0</open>");

                    foreach (Person p in peopleCollection)
                    {
                        if (!(hideliving && p.IsLiving))
                        {
                            string year = string.Empty;

                            if (p.BurialDate != null)
                            {
                                year = p.BurialDate.Value.Year.ToString();
                            }

                            if (!string.IsNullOrEmpty(p.BurialPlace) && p.Restriction != Restriction.Private && !string.IsNullOrEmpty(year))
                            {
                                tw.WriteLine("<Placemark>\n" +
                                             "<name>" + p.FullName + "</name>\n" +
                                             "<address>" + p.BurialPlace + "</address>\n" +
                                             "<description>" + p.BurialPlace + "</description>\n" +
                                             "<TimeStamp>\n<when>" + year + "</when>\n</TimeStamp>");

                                if (p.Gender == Gender.Male)
                                {
                                    tw.WriteLine("<styleUrl>#msn_man</styleUrl>\n</Placemark>");
                                }
                                else
                                {
                                    tw.WriteLine("<styleUrl>#msn_woman</styleUrl>\n</Placemark>");
                                }

                                i++;
                            }
                        }
                    }

                    tw.WriteLine("</Folder>");
                }

                if (cremations)
                {
                    tw.WriteLine("<Folder>\n" +
                                 "<name>" + Microsoft.FamilyShowLib.Properties.Resources.Cremations + "</name>\n" +
                                 "<open>0</open>");

                    foreach (Person p in peopleCollection)
                    {
                        if (!(hideliving && p.IsLiving))
                        {
                            string year = string.Empty;

                            if (p.CremationDate != null)
                            {
                                year = p.CremationDate.Value.Year.ToString();
                            }

                            if (!string.IsNullOrEmpty(p.CremationPlace) && p.Restriction != Restriction.Private && !string.IsNullOrEmpty(year))
                            {
                                tw.WriteLine("<Placemark>\n" +
                                             "<name>" + p.FullName + "</name>\n" +
                                             "<address>" + p.CremationPlace + "</address>\n" +
                                             "<description>" + p.CremationPlace + "</description>\n" +
                                             "<TimeStamp>\n<when>" + year + "</when>\n</TimeStamp>");

                                if (p.Gender == Gender.Male)
                                {
                                    tw.WriteLine("<styleUrl>#msn_man</styleUrl>\n</Placemark>");
                                }
                                else
                                {
                                    tw.WriteLine("<styleUrl>#msn_woman</styleUrl>\n</Placemark>");
                                }

                                i++;
                            }
                        }
                    }

                    tw.WriteLine("</Folder>");
                }

                if (marriages)
                {
                    tw.WriteLine("<Folder>\n" +
                                 "<name>" + Microsoft.FamilyShowLib.Properties.Resources.Marriages + "</name>\n" +
                                 "<open>0</open>");

                    foreach (Person p in peopleCollection)
                    {
                        if (!(hideliving && p.IsLiving))
                        {
                            if (p.Restriction != Restriction.Private)
                            {
                                foreach (Relationship rel in p.Relationships)
                                {
                                    if (rel.RelationshipType == RelationshipType.Spouse)
                                    {
                                        SpouseRelationship spouseRel = ((SpouseRelationship)rel);

                                        if (!string.IsNullOrEmpty(spouseRel.MarriagePlace))
                                        {
                                            string date = string.Empty;

                                            if (spouseRel.MarriageDate != null)
                                            {
                                                date = spouseRel.MarriageDate.Value.Year.ToString();
                                            }

                                            tw.WriteLine("<Placemark>\n" +
                                                         "<name>" + p.FullName + "</name>\n" +
                                                         "<address>" + spouseRel.MarriagePlace + "</address>\n" +
                                                         "<description>" + spouseRel.MarriagePlace + "</description>\n" +
                                                         "<TimeStamp>\n<when>" + date + "</when>\n</TimeStamp>");


                                            if (p.Gender == Gender.Male)
                                            {
                                                tw.WriteLine("<styleUrl>#msn_man</styleUrl>\n</Placemark>");
                                            }
                                            else
                                            {
                                                tw.WriteLine("<styleUrl>#msn_woman</styleUrl>\n</Placemark>");
                                            }

                                            i++;
                                        }
                                    }
                                }
                            }
                        }
                    }

                    tw.WriteLine("</Folder>");
                }
                #endregion
            }
            else if (lifespans)
            {
                #region lifespans

                tw.WriteLine("<Folder>\n" +
                             "<name>" + Microsoft.FamilyShowLib.Properties.Resources.People + "</name>\n" +
                             "<open>0</open>");

                foreach (Person p in peopleCollection)
                {
                    if (!(hideliving && p.IsLiving))
                    {
                        if (p.Restriction != Restriction.Private)
                        {
                            string place = string.Empty;

                            if (!string.IsNullOrEmpty(p.BirthPlace) && string.IsNullOrEmpty(place))
                            {
                                place = p.BirthPlace;
                            }

                            if (!string.IsNullOrEmpty(p.DeathPlace) && string.IsNullOrEmpty(place))
                            {
                                place = p.DeathPlace;
                            }

                            tw.WriteLine("<Placemark>\n" +
                                         "<name>" + p.FullName + "</name>\n" +
                                         "<address>" + place + "</address>\n" +
                                         "<description>" + place + "</description>\n" +
                                         "<TimeSpan>");
                            if (!string.IsNullOrEmpty(p.YearOfBirth))
                            {
                                tw.WriteLine("<begin>" + p.YearOfBirth + "</begin>");
                            }
                            if (!string.IsNullOrEmpty(p.YearOfBirth))
                            {
                                tw.WriteLine("<end>" + p.YearOfDeath + "</end>");
                            }

                            tw.WriteLine("</TimeSpan>");

                            if (p.Gender == Gender.Male)
                            {
                                tw.WriteLine("<styleUrl>#msn_man</styleUrl>\n</Placemark>");
                            }
                            else
                            {
                                tw.WriteLine("<styleUrl>#msn_woman</styleUrl>\n</Placemark>");
                            }

                            i++;
                        }
                    }
                }

                #endregion
            }

            tw.WriteLine("</Folder>\n" +
                         "</Document>\n" +
                         "</kml>");

            tw.Close();

            string[] summary = new string[2];

            summary[0] = i.ToString() + " " + Microsoft.FamilyShowLib.Properties.Resources.PlacesExported;
            summary[1] = fileName.ToString();

            if (i == 0)
            {
                File.Delete(fileName);
                summary[0] = Microsoft.FamilyShowLib.Properties.Resources.NoPlaces;
                summary[1] = "No file";
            }

            return(summary);
        }
コード例 #24
0
ファイル: RelationshipHelper.cs プロジェクト: karmicka/Source
 /// <summary>
 /// Performs the business logic for adding the Parent relationship between the person and the parent.
 /// In the case of existing people, do not hook up other siblings etc.  Allow the user to do this manually.
 /// </summary>
 public static void AddExistingParent(PeopleCollection family, Person person, Person parent, ParentChildModifier modifier)
 {
     family.AddChild(parent, person, modifier);
     //Setter for property change notification
     person.HasParents = true;
 }