Exemplo n.º 1
0
        private void CreateSiblingEdges(GraphNode <GedcomIndividualRecord> node, GedcomFamilyRecord family)
        {
            GedcomIndividualRecord indi = node.Data;

            foreach (string childID in family.Children)
            {
                if (childID != indi.XRefID)
                {
                    GedcomIndividualRecord child = Database[childID] as GedcomIndividualRecord;
                    if (child != null)
                    {
                        GraphNode <GedcomIndividualRecord> sibling = new GraphNode <GedcomIndividualRecord>();
                        sibling.Data = child;
                        node.Edges.Add(sibling);
                    }
                    else
                    {
                        System.Diagnostics.Debug.WriteLine("child in family points to non individual record");
                    }
                }
            }

            foreach (GraphNode <GedcomIndividualRecord> sibling in node.Edges)
            {
                sibling.Edges.Add(node);
                foreach (GraphNode <GedcomIndividualRecord> sibling2 in node.Edges)
                {
                    if (sibling2 != sibling)
                    {
                        sibling.Edges.Add(sibling2);
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create an individual with a specific name.
        /// </summary>
        /// <param name="gedcomDb">The gedcom database to attach the name and individual to.</param>
        /// <param name="givenName">The given name (first name) to attach to the new individual.</param>
        /// <param name="surname">The surname (last name) to attach to the new individual.</param>
        /// <returns>The constructed individual.</returns>
        public static GedcomIndividualRecord NamedPerson(this GedcomDatabase gedcomDb, string givenName, string surname)
        {
            var person = new GedcomIndividualRecord(gedcomDb);

            person.Names.Clear();
            if (!string.IsNullOrWhiteSpace(givenName) || !string.IsNullOrWhiteSpace(surname))
            {
                var personName = new GedcomName();
                personName.Level    = 1;
                personName.Database = gedcomDb;
                if (!string.IsNullOrWhiteSpace(givenName))
                {
                    personName.Given = givenName;
                }

                personName.PreferredName = true;
                if (!string.IsNullOrWhiteSpace(surname))
                {
                    personName.Surname = surname;
                }

                person.Names.Add(personName);
            }

            return(person);
        }
Exemplo n.º 3
0
        private void CreateAncestorEdges(GraphNode <GedcomIndividualRecord> node, GedcomFamilyRecord family)
        {
            GedcomIndividualRecord husb = null;
            GedcomIndividualRecord wife = null;

            if (!string.IsNullOrEmpty(family.Husband))
            {
                husb = Database[family.Husband] as GedcomIndividualRecord;
                if (husb == null)
                {
                    System.Diagnostics.Debug.WriteLine("Husband points to non individual record");
                }
            }

            if (!string.IsNullOrEmpty(family.Wife))
            {
                wife = Database[family.Wife] as GedcomIndividualRecord;
                if (wife == null)
                {
                    System.Diagnostics.Debug.WriteLine("Wife points to non individual record");
                }
            }

            if (husb != null)
            {
                GraphNode <GedcomIndividualRecord> father = CreateNode(husb, GraphType.Ancestors);
                node.Edges.Add(father);
            }

            if (wife != null)
            {
                GraphNode <GedcomIndividualRecord> mother = CreateNode(wife, GraphType.Ancestors);
                node.Edges.Add(mother);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Add a child.
        /// </summary>
        /// <param name="indi">The child.</param>
        /// <returns>
        /// Returns True if a new child record is added; otherwise False.
        /// </returns>
        public bool AddChild(GedcomIndividualRecord indi)
        {
            bool added = false;

            if (indi != null && !Children.Contains(indi.XRefID))
            {
                if (string.IsNullOrEmpty(XRefID))
                {
                    XRefID = Database.GenerateXref("FAM");
                    Database.Add(XRefID, this);
                }

                if (!indi.ChildInFamily(XRefID))
                {
                    GedcomFamilyLink link = new GedcomFamilyLink();
                    link.Database   = Database;
                    link.Family     = XRefID;
                    link.Individual = indi.XRefID;
                    link.Level      = 1;
                    indi.ChildIn.Add(link);
                }

                Children.Add(indi.XRefID);

                added = true;
            }

            return(added);
        }
Exemplo n.º 5
0
        private void AppendIndividualDetails(GedcomIndividualRecord indi, XmlNode root, int generation)
        {
            if (!processed.Contains(indi.XRefID))
            {
                processed.Add(indi.XRefID);

                foreach (GedcomIndividualEvent indiEvent in indi.Events)
                {
                    indiEvent.EventXRefID = Database.GenerateXref("EVENT");
                    AppendEvent(indiEvent, root);
                    AppendSources(indiEvent, root);
                }

                AppendIndividual(indi, root);

                if (generation < AncestorGenerations)
                {
                    foreach (GedcomFamilyLink link in indi.ChildIn)
                    {
                        AppendFamilyDetails(link, root, generation + 1);
                    }
                }

                if (generation > DecendantGenerations)
                {
                    foreach (GedcomFamilyLink link in indi.SpouseIn)
                    {
                        AppendFamilyDetails(link, root, generation);
                    }
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Gets the type of the linkage.
        /// </summary>
        /// <param name="childXrefID">The child xref identifier.</param>
        /// <returns>
        /// Pedigree linkage type.
        /// </returns>
        public PedigreeLinkageType GetLinkageType(string childXrefID)
        {
            PedigreeLinkageType ret = PedigreeLinkageType.Unknown;

            if (linkageTypes != null && linkageTypes.ContainsKey(childXrefID))
            {
                ret = linkageTypes[childXrefID];
            }
            else
            {
                GedcomIndividualRecord child = (GedcomIndividualRecord)Database[childXrefID];
                if (child != null)
                {
                    GedcomFamilyLink link = null;
                    if (child.ChildInFamily(XrefId, out link))
                    {
                        ret = link.Pedigree;
                    }
                    else
                    {
                        System.Diagnostics.Debug.WriteLine("Child " + childXrefID + " is not in family " +
                                                           XrefId + " in GetLinkageType");
                    }
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine("Attempt to GetLinkageType of unknown child " +
                                                       childXrefID + " in " + XrefId);
                }
            }

            return(ret);
        }
        private void Test1()
        {
            Read("test1.ged");

            GedcomGraph graph = new GedcomGraph();

            graph.Database = reader.Database;

            System.Console.WriteLine("Check 1");

            string id = reader.Parser.XrefCollection["I0115"];

            graph.Record = graph.Database[id];
            GedcomIndividualRecord relative = graph.Database[id] as GedcomIndividualRecord;

            Assert.True(graph.IsRelated(relative), "Expected Relationship not found");

            System.Console.WriteLine("Check 2");
            id           = reader.Parser.XrefCollection["I0684"];
            graph.Record = graph.Database[id];

            Assert.True(!graph.IsRelated(relative), "Unexpected Relationship found");

            System.Console.WriteLine("Check 3");
            id           = reader.Parser.XrefCollection["I0668"];
            graph.Record = graph.Database[id];

            Assert.True(graph.IsRelated(relative), "Expected Relationship not found");
        }
Exemplo n.º 8
0
        /// <summary>
        /// Add the given record to the database with the given XRef
        /// </summary>
        /// <param name="xrefID">
        /// A <see cref="string"/>
        /// </param>
        /// <param name="record">
        /// A <see cref="GedcomRecord"/>
        /// </param>
        public virtual void Add(string xrefID, GedcomRecord record)
        {
            Table.Add(xrefID, record);

            if (record is GedcomIndividualRecord)
            {
                GedcomIndividualRecord indi = (GedcomIndividualRecord)record;

                int pos = individuals.BinarySearch(indi);
                if (pos < 0)
                {
                    pos = ~pos;
                }

                individuals.Insert(pos, indi);
            }
            else if (record is GedcomFamilyRecord)
            {
                families.Add((GedcomFamilyRecord)record);
            }
            else if (record is GedcomSourceRecord)
            {
                GedcomSourceRecord source = (GedcomSourceRecord)record;

                int pos = sources.BinarySearch(source);
                if (pos < 0)
                {
                    pos = ~pos;
                }

                sources.Insert(pos, source);
            }
            else if (record is GedcomRepositoryRecord)
            {
                GedcomRepositoryRecord repo = (GedcomRepositoryRecord)record;

                int pos = repositories.BinarySearch(repo);
                if (pos < 0)
                {
                    pos = ~pos;
                }

                repositories.Insert(pos, repo);
            }
            else if (record is GedcomMultimediaRecord)
            {
                media.Add((GedcomMultimediaRecord)record);
            }
            else if (record is GedcomNoteRecord)
            {
                notes.Add((GedcomNoteRecord)record);
            }
            else if (record is GedcomSubmitterRecord)
            {
                submitters.Add((GedcomSubmitterRecord)record);
            }

            record.Database = this;
        }
        private void Individuals_without_data_do_not_match_at_all()
        {
            var individual1 = new GedcomIndividualRecord();
            var individual2 = new GedcomIndividualRecord();

            var match = individual1.CalculateSimilarityScore(individual2);

            Assert.Equal(decimal.Zero, match);
        }
        public void GedComComparison_GedcomIndividualRecord_IsEquivalentTo_ExpectAreEqual()
        {
            // Arrange
            var object1 = new GedcomIndividualRecord();
            var object2 = new GedcomIndividualRecord();

            // Act and Assert
            Assert.True(object1.IsEquivalentTo(object2));
            Assert.True(object2.IsEquivalentTo(object1));
        }
Exemplo n.º 11
0
        private void Time_when_output_is_24_hour_format()
        {
            SystemTime.SetDateTime(new System.DateTime(2020, 12, 13, 18, 30, 59));
            var gedcom = new GedcomDatabase {
                Header = new GedcomHeader(),
            };

            var individual = new GedcomIndividualRecord(gedcom, "O'Neill");

            Assert.Equal("18:30:59", individual.Names.Single().ChangeDate.Time);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Remove a child.
        /// </summary>
        /// <param name="child">The child.</param>
        public void RemoveChild(GedcomIndividualRecord child)
        {
            Children.Remove(child.XRefID);

            GedcomFamilyLink link;

            if (child.ChildInFamily(XRefID, out link))
            {
                child.ChildIn.Remove(link);
            }
        }
Exemplo n.º 13
0
        private void Date_when_output_is_in_english_and_not_the_culture_of_the_current_thread()
        {
            SystemTime.SetDateTime(new System.DateTime(2020, 12, 13));
            System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("de-DE");
            var gedcom = new GedcomDatabase {
                Header = new GedcomHeader(),
            };

            var individual = new GedcomIndividualRecord(gedcom, "O'Neill");

            Assert.Equal("13 Dec 2020", individual.Names.Single().ChangeDate.Date1);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Determines whether the passed person is related to this instance.
        /// </summary>
        /// <param name="relation">The relation.</param>
        /// <returns>
        ///   <c>true</c> if the specified relation is related; otherwise, <c>false</c>.
        /// </returns>
        public bool IsRelated(GedcomIndividualRecord relation)
        {
            bool ret = false;

            List <GraphNode <GedcomIndividualRecord> > visited = new List <GraphNode <GedcomIndividualRecord> >();

            if (Root != null)
            {
                ret = IsRelated(Root, visited, relation);
            }

            return(ret);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Removes the wife.
        /// </summary>
        /// <param name="indi">The wife.</param>
        public void RemoveWife(GedcomIndividualRecord indi)
        {
            GedcomFamilyLink link;

            if (wife == indi.XRefID)
            {
                wife = string.Empty;
            }

            if (indi.SpouseInFamily(XRefID, out link))
            {
                indi.SpouseIn.Remove(link);
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GedcomFamilyRecord" /> class.
        /// </summary>
        /// <param name="database">The database to associate with this record.</param>
        /// <param name="indi1">The first individual.</param>
        /// <param name="indi2">The second individual.</param>
        public GedcomFamilyRecord(GedcomDatabase database, GedcomIndividualRecord indi1, GedcomIndividualRecord indi2)
            : this()
        {
            Level    = 0;
            Database = database;
            XRefID   = database.GenerateXref("FAM");

            if (indi1 != null)
            {
                GedcomFamilyLink link = new GedcomFamilyLink();
                link.Database   = database;
                link.Family     = XRefID;
                link.Individual = indi1.XRefID;
                indi1.SpouseIn.Add(link);

                if (indi2 != null)
                {
                    link            = new GedcomFamilyLink();
                    link.Database   = database;
                    link.Family     = XRefID;
                    link.Individual = indi2.XRefID;
                    indi2.SpouseIn.Add(link);
                }

                switch (indi1.Sex)
                {
                case GedcomSex.Female:
                    Wife = indi1.XRefID;
                    if (indi2 != null)
                    {
                        Husband = indi2.XRefID;
                    }

                    break;

                default:
                    // got to put some where if not male or female,
                    // go with same as male
                    Husband = indi1.XRefID;
                    if (indi2 != null)
                    {
                        Wife = indi2.XRefID;
                    }

                    break;
                }
            }

            database.Add(XRefID, this);
        }
Exemplo n.º 17
0
        /// <summary>
        /// Removes the husband.
        /// </summary>
        /// <param name="indi">The husband.</param>
        public void RemoveHusband(GedcomIndividualRecord indi)
        {
            GedcomFamilyLink link;

            if (husband == indi.XRefID)
            {
                husband = string.Empty;
            }

            if (indi.SpouseInFamily(XRefID, out link))
            {
                indi.SpouseIn.Remove(link);
            }
        }
Exemplo n.º 18
0
        /// <summary>
        /// Create an individual with a specific name.
        /// </summary>
        /// <param name="gedcomDb">The gedcom database to attach the name and individual to.</param>
        /// <param name="name">The name to place directly into the name field.</param>
        /// <returns>The constructed individual.</returns>
        public static GedcomIndividualRecord NamedPerson(this GedcomDatabase gedcomDb, string name)
        {
            var personName = new GedcomName();

            personName.Level         = 1;
            personName.Database      = gedcomDb;
            personName.Name          = name;
            personName.PreferredName = true;

            var person = new GedcomIndividualRecord(gedcomDb);

            person.Names.Clear();
            person.Names.Add(personName);
            return(person);
        }
Exemplo n.º 19
0
        /// <summary>
        /// Add the given individual to the surnames list
        /// </summary>
        /// <param name="indi">
        /// A <see cref="GedcomIndividualRecord"/>
        /// </param>
        protected virtual void BuildSurnameList(GedcomIndividualRecord indi)
        {
            foreach (GedcomName name in indi.Names)
            {
                // TODO: not right, need to include prefix + suffix
                string surname = name.Surname;

                if (!surnames.ContainsKey(surname))
                {
                    surnames[surname] = 1;
                }
                else
                {
                    surnames[surname] = 1 + surnames[surname];
                }
            }
        }
Exemplo n.º 20
0
        /// <summary>
        /// Add a new child.
        /// </summary>
        /// <returns>
        /// The child's record.
        /// </returns>
        public GedcomIndividualRecord AddNewChild()
        {
            GedcomIndividualRecord husband = null;
            GedcomIndividualRecord wife    = null;

            if (!string.IsNullOrEmpty(this.husband))
            {
                husband = Database[this.husband] as GedcomIndividualRecord;
            }

            if (!string.IsNullOrEmpty(this.wife))
            {
                wife = Database[this.wife] as GedcomIndividualRecord;
            }

            string surname = "unknown";

            if (husband != null)
            {
                GedcomName husbandName = husband.GetName();
                if (husbandName != null)
                {
                    surname = husbandName.Surname;
                }
            }
            else if (wife != null)
            {
                GedcomName wifeName = wife.GetName();
                if (wifeName != null)
                {
                    surname = wifeName.Surname;
                }
            }

            GedcomIndividualRecord indi = new GedcomIndividualRecord(Database, surname);

            // don't care about failure here, won't happen as indi isn't null
            // and they aren't already in the family
            AddChild(indi);

            return(indi);
        }
Exemplo n.º 21
0
        private void CreateDecendantEdges(GraphNode <GedcomIndividualRecord> node, GedcomFamilyRecord family)
        {
            GedcomIndividualRecord indi = node.Data;

            foreach (string childID in family.Children)
            {
                // should never happen, best to check anyway
                if (childID != indi.XRefID)
                {
                    GedcomIndividualRecord child = Database[childID] as GedcomIndividualRecord;
                    if (child != null)
                    {
                        GraphNode <GedcomIndividualRecord> decendant = CreateNode(child, GraphType.Decendants);
                        node.Edges.Add(decendant);
                    }
                    else
                    {
                        System.Diagnostics.Debug.WriteLine("child in family points to non individual record");
                    }
                }
            }
        }
Exemplo n.º 22
0
        /// <summary>
        /// Finds the duplicates.
        /// </summary>
        /// <param name="indi">The indi.</param>
        /// <param name="databaseB">The database b.</param>
        /// <param name="matchThreshold">The match threshold.</param>
        /// <returns>A list of duplicate records.</returns>
        public static List <GedcomIndividualRecord> FindDuplicates(GedcomIndividualRecord indi, GedcomDatabase databaseB, decimal matchThreshold)
        {
            List <GedcomIndividualRecord> matches = new List <GedcomIndividualRecord>();

            foreach (GedcomIndividualRecord matchIndi in databaseB.Individuals)
            {
                // can't match self, databaseB could be the same database as indi.Database
                // so we can check this
                if (matchIndi != indi)
                {
                    var match = indi.CalculateSimilarityScore(matchIndi);

                    if (match > matchThreshold)
                    {
                        matches.Add(matchIndi);

                        // System.Console.WriteLine(indi.Names[0].Name + " matches " + matchIndi.Names[0].Name + " at " + match + "%");
                    }
                }
            }

            return(matches);
        }
Exemplo n.º 23
0
        /// <summary>
        /// Adds a sample person (well, a cartoon mouse) to the presidents file. The mouse may do a better job if elected president.
        /// </summary>
        /// <param name="db">The database to add the individual to.</param>
        public static void AddPerson(GedcomDatabase db)
        {
            var individual = new GedcomIndividualRecord(db);

            var name = individual.Names[0];

            name.Given   = "Michael";
            name.Surname = "Mouse";
            name.Nick    = "Mickey";

            individual.Names.Add(name);

            var birthDate = new GedcomDate(db);

            birthDate.ParseDateString("24 Jan 1933");
            individual.Events.Add(new GedcomIndividualEvent
            {
                Database  = db,
                Date      = birthDate,
                EventType = Enums.GedcomEventType.Birth
            });

            Console.WriteLine($"Added record for '{individual.GetName().Name}' with birth date {individual.Birth.Date.Date1}.");
        }
Exemplo n.º 24
0
        /// <summary>
        /// Changes the wife.
        /// </summary>
        /// <param name="indi">The wife.</param>
        public void ChangeWife(GedcomIndividualRecord indi)
        {
            GedcomIndividualRecord husband = null;
            GedcomIndividualRecord wife    = null;

            if (!string.IsNullOrEmpty(this.husband))
            {
                husband = Database[this.husband] as GedcomIndividualRecord;
            }

            if (!string.IsNullOrEmpty(this.wife))
            {
                wife = Database[this.wife] as GedcomIndividualRecord;
            }

            if (string.IsNullOrEmpty(XRefID))
            {
                XRefID = Database.GenerateXref("FAM");
                Database.Add(XRefID, this);
            }

            if (wife != null)
            {
                GedcomFamilyLink link;
                if (wife.SpouseInFamily(XRefID, out link))
                {
                    wife.SpouseIn.Remove(link);
                }
            }

            wife      = indi;
            this.wife = string.Empty;

            if (husband != null)
            {
                this.husband = husband.XRefID;

                if (!husband.SpouseInFamily(XRefID))
                {
                    GedcomFamilyLink link = new GedcomFamilyLink();
                    link.Database   = Database;
                    link.Family     = XRefID;
                    link.Individual = this.husband;
                    husband.SpouseIn.Add(link);
                }
            }

            if (wife != null)
            {
                this.wife = wife.XRefID;

                if (!wife.SpouseInFamily(XRefID))
                {
                    GedcomFamilyLink link = new GedcomFamilyLink();
                    link.Database   = Database;
                    link.Family     = XRefID;
                    link.Individual = this.wife;
                    wife.SpouseIn.Add(link);
                }
            }
        }
Exemplo n.º 25
0
        /// <summary>
        /// Generates the XML.
        /// </summary>
        /// <param name="root">The root.</param>
        public override void GenerateXML(XmlNode root)
        {
            XmlDocument doc = root.OwnerDocument;

            XmlNode      node;
            XmlAttribute attr;

            XmlNode eventNode = doc.CreateElement("EventRec");

            attr       = doc.CreateAttribute("Id");
            attr.Value = EventXRefID;
            eventNode.Attributes.Append(attr);

            attr       = doc.CreateAttribute("Type");
            attr.Value = GedcomEvent.TypeToReadable(EventType);
            eventNode.Attributes.Append(attr);

            // TODO: VitalType attribute
            // (marriage | befmarriage | aftmarriage |
            // birth | befbirth | aftbirth |
            // death | befdeath | aftdeath)
            if (RecordType == GedcomRecordType.FamilyEvent)
            {
                GedcomFamilyEvent  famEvent = this as GedcomFamilyEvent;
                GedcomFamilyRecord family   = famEvent.FamRecord;

                // TODO: <Participant>s
                // probably not right, but always stick husband/wife in as
                // participants
                bool added = false;

                if (!string.IsNullOrEmpty(family.Husband))
                {
                    GedcomIndividualRecord husb = Database[family.Husband] as GedcomIndividualRecord;
                    if (husb != null)
                    {
                        node = doc.CreateElement("Participant");

                        XmlNode linkNode = doc.CreateElement("Link");

                        attr       = doc.CreateAttribute("Target");
                        attr.Value = "IndividualRec";
                        linkNode.Attributes.Append(attr);

                        attr       = doc.CreateAttribute("Ref");
                        attr.Value = family.Husband;
                        linkNode.Attributes.Append(attr);

                        node.AppendChild(linkNode);

                        eventNode.AppendChild(node);
                        added = true;
                    }
                    else
                    {
                        System.Diagnostics.Debug.WriteLine("Pointer to non existant husband");
                    }
                }

                if (!string.IsNullOrEmpty(family.Wife))
                {
                    GedcomIndividualRecord wife = Database[family.Wife] as GedcomIndividualRecord;
                    if (wife != null)
                    {
                        node = doc.CreateElement("Participant");

                        XmlNode linkNode = doc.CreateElement("Link");

                        attr       = doc.CreateAttribute("Target");
                        attr.Value = "IndividualRec";
                        linkNode.Attributes.Append(attr);

                        attr       = doc.CreateAttribute("Ref");
                        attr.Value = family.Wife;
                        linkNode.Attributes.Append(attr);

                        node.AppendChild(linkNode);

                        eventNode.AppendChild(node);
                        added = true;
                    }
                    else
                    {
                        System.Diagnostics.Debug.WriteLine("Pointer to non existant wife");
                    }
                }

                if (!added)
                {
                    // TODO: no husband or wife now what?  XML will be invalid
                    // without a participant
                }
            }
            else
            {
                GedcomIndividualRecord indi = (this as GedcomIndividualEvent).IndiRecord;

                node = doc.CreateElement("Participant");

                XmlNode linkNode = doc.CreateElement("Link");

                attr       = doc.CreateAttribute("Target");
                attr.Value = "IndividualRec";
                linkNode.Attributes.Append(attr);

                attr       = doc.CreateAttribute("Ref");
                attr.Value = indi.XRefID;
                linkNode.Attributes.Append(attr);

                XmlNode roleNode = doc.CreateElement("Role");
                if (this == indi.Birth)
                {
                    roleNode.AppendChild(doc.CreateTextNode("child"));
                }
                else
                {
                    roleNode.AppendChild(doc.CreateTextNode("principle"));
                }

                linkNode.AppendChild(roleNode);

                node.AppendChild(linkNode);

                eventNode.AppendChild(node);
            }

            if (Date != null)
            {
                node = doc.CreateElement("Date");
                node.AppendChild(doc.CreateTextNode(Date.DateString));
                eventNode.AppendChild(node);
            }

            if (Place != null)
            {
                node = doc.CreateElement("Place");
                node.AppendChild(doc.CreateTextNode(Place.Name));
                eventNode.AppendChild(node);
            }

            GenerateNoteXML(eventNode);
            GenerateCitationsXML(eventNode);
            GenerateMultimediaXML(eventNode);

            GenerateChangeDateXML(eventNode);

            root.AppendChild(eventNode);
        }
Exemplo n.º 26
0
        private void AppendFamilyDetails(GedcomFamilyLink link, XmlNode root, int generation)
        {
            string famID = link.Family;

            if (!processed.Contains(famID))
            {
                processed.Add(famID);

                GedcomFamilyRecord fam = Database[famID] as GedcomFamilyRecord;

                if (fam != null)
                {
                    foreach (GedcomFamilyEvent famEvent in fam.Events)
                    {
                        famEvent.EventXRefID = Database.GenerateXref("EVENT");
                        AppendEvent(famEvent, root);

                        AppendSources(famEvent, root);
                    }

                    AppendFamily(fam, root);

                    if (!string.IsNullOrEmpty(fam.Husband))
                    {
                        GedcomIndividualRecord husb = Database[fam.Husband] as GedcomIndividualRecord;
                        if (husb != null)
                        {
                            AppendIndividualDetails(husb, root, generation);
                        }
                        else
                        {
                            throw new Exception("Husband points to non individual record");
                        }
                    }

                    if (!string.IsNullOrEmpty(fam.Wife))
                    {
                        GedcomIndividualRecord wife = Database[fam.Wife] as GedcomIndividualRecord;
                        if (wife != null)
                        {
                            AppendIndividualDetails(wife, root, generation);
                        }
                        else
                        {
                            throw new Exception("Husband points to non individual record");
                        }
                    }

                    foreach (string childID in fam.Children)
                    {
                        GedcomIndividualRecord child = Database[childID] as GedcomIndividualRecord;
                        if (child != null)
                        {
                            int childGeneration = generation - 1;
                            AppendIndividualDetails(child, root, childGeneration);
                        }
                        else
                        {
                            throw new Exception("Child points to non individual record");
                        }
                    }
                }
                else
                {
                    throw new Exception("Family link points to non family record");
                }
            }
        }
 /// <summary>
 /// Appends the individual.
 /// </summary>
 /// <param name="indi">The indi.</param>
 /// <param name="root">The root.</param>
 protected void AppendIndividual(GedcomIndividualRecord indi, XmlNode root)
 {
     indi.GenerateXML(root);
 }
Exemplo n.º 28
0
		private void FillView()
		{
			GedcomFamilyRecord fam = _famRecord;
			
			GedcomIndividualRecord husb = null;
			GedcomIndividualRecord wife = null;
		
			GedcomFamilyEvent marriage = fam.Marriage as GedcomFamilyEvent;

			if (marriage != null)
			{
				GedcomPlace place = marriage.Place;
				if (place != null)
				{
					MarriageLocationEntry.Text = place.Name;	
				}
				
				GedcomDate date = marriage.Date;
				if (date != null)
				{
					MarriageDateEntry.Text = date.DateString;
				}
			}

			BeginingStatusComboBox.Active = (int)fam.StartStatus;
			
			_husband = husb;
			_wife = wife;	
			
			Marriage_Changed(this, EventArgs.Empty);
		}
Exemplo n.º 29
0
        /// <summary>
        /// Remove the given record with the given XRef from the database
        /// </summary>
        /// <param name="xrefID">
        /// A <see cref="string"/>
        /// </param>
        /// <param name="record">
        /// A <see cref="GedcomRecord"/>
        /// </param>
        public virtual void Remove(string xrefID, GedcomRecord record)
        {
            if (Table.Contains(xrefID))
            {
                Table.Remove(xrefID);

                if (record is GedcomIndividualRecord)
                {
                    GedcomIndividualRecord indi = (GedcomIndividualRecord)record;

                    individuals.Remove(indi);

                    // remove names from surname cache
                    foreach (GedcomName name in indi.Names)
                    {
                        // TODO: not right, need to include prefix + suffix
                        string surname = name.Surname;

                        if (surnames.ContainsKey(surname))
                        {
                            int count = surnames[surname];
                            count--;
                            if (count > 0)
                            {
                                surnames[surname] = count;
                            }
                            else
                            {
                                surnames.Remove(surname);
                            }
                        }
                    }
                }
                else if (record is GedcomFamilyRecord)
                {
                    families.Remove((GedcomFamilyRecord)record);
                }
                else if (record is GedcomSourceRecord)
                {
                    sources.Remove((GedcomSourceRecord)record);
                }
                else if (record is GedcomRepositoryRecord)
                {
                    repositories.Remove((GedcomRepositoryRecord)record);
                }
                else if (record is GedcomMultimediaRecord)
                {
                    media.Remove((GedcomMultimediaRecord)record);
                }
                else if (record is GedcomNoteRecord)
                {
                    notes.Remove((GedcomNoteRecord)record);
                }
                else if (record is GedcomSubmitterRecord)
                {
                    submitters.Remove((GedcomSubmitterRecord)record);
                }

                // TODO: should we set this to null? part of the deletion
                // methods may still want to access the database
                // record.Database = null;
            }
        }
Exemplo n.º 30
0
        /// <summary>
        /// Generates the XML.
        /// </summary>
        /// <param name="root">The root node.</param>
        public override void GenerateXML(XmlNode root)
        {
            XmlDocument doc = root.OwnerDocument;

            XmlNode      node;
            XmlAttribute attr;

            XmlNode famNode = doc.CreateElement("FamilyRec");

            attr       = doc.CreateAttribute("Id");
            attr.Value = XRefID;
            famNode.Attributes.Append(attr);

            if (!string.IsNullOrEmpty(Husband))
            {
                GedcomIndividualRecord husb = Database[Husband] as GedcomIndividualRecord;
                if (husb != null)
                {
                    node = doc.CreateElement("HusbFath");

                    XmlNode linkNode = doc.CreateElement("Link");

                    attr       = doc.CreateAttribute("Target");
                    attr.Value = "IndividualRec";
                    linkNode.Attributes.Append(attr);

                    attr       = doc.CreateAttribute("Ref");
                    attr.Value = Husband;
                    linkNode.Attributes.Append(attr);

                    node.AppendChild(linkNode);

                    famNode.AppendChild(node);
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine("Pointer to non existant husband");
                }
            }

            if (!string.IsNullOrEmpty(Wife))
            {
                GedcomIndividualRecord wife = Database[Wife] as GedcomIndividualRecord;
                if (wife != null)
                {
                    node = doc.CreateElement("WifeMoth");

                    XmlNode linkNode = doc.CreateElement("Link");

                    attr       = doc.CreateAttribute("Target");
                    attr.Value = "IndividualRec";
                    linkNode.Attributes.Append(attr);

                    attr       = doc.CreateAttribute("Ref");
                    attr.Value = Wife;
                    linkNode.Attributes.Append(attr);

                    node.AppendChild(linkNode);

                    famNode.AppendChild(node);
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine("Pointer to non existant wife");
                }
            }

            foreach (string child in Children)
            {
                GedcomIndividualRecord indi = Database[child] as GedcomIndividualRecord;
                if (indi != null)
                {
                    node = doc.CreateElement("Child");

                    XmlNode linkNode = doc.CreateElement("Link");

                    attr       = doc.CreateAttribute("Target");
                    attr.Value = "IndividualRec";
                    linkNode.Attributes.Append(attr);

                    attr       = doc.CreateAttribute("Ref");
                    attr.Value = child;
                    linkNode.Attributes.Append(attr);

                    node.AppendChild(linkNode);

                    // TODO: add in <ChildNbr>
                    GedcomFamilyLink link = null;

                    if (indi.ChildInFamily(XRefID, out link))
                    {
                        XmlNode relNode = doc.CreateElement("RelToFath");
                        string  relType = string.Empty;
                        switch (link.FatherPedigree)
                        {
                        case PedigreeLinkageType.Adopted:
                            relType = "adopted";
                            break;

                        case PedigreeLinkageType.Birth:
                            relType = "birth";
                            break;

                        case PedigreeLinkageType.Foster:
                            relType = "foster";
                            break;

                        case PedigreeLinkageType.Sealing:
                            relType = "sealing";
                            break;

                        default:
                            relType = "unknown";
                            break;
                        }

                        relNode.AppendChild(doc.CreateTextNode(relType));

                        relNode = doc.CreateElement("RelToMoth");
                        relType = string.Empty;
                        switch (link.MotherPedigree)
                        {
                        case PedigreeLinkageType.Adopted:
                            relType = "adopted";
                            break;

                        case PedigreeLinkageType.Birth:
                            relType = "birth";
                            break;

                        case PedigreeLinkageType.Foster:
                            relType = "foster";
                            break;

                        case PedigreeLinkageType.Sealing:
                            relType = "sealing";
                            break;

                        default:
                            relType = "unknown";
                            break;
                        }

                        relNode.AppendChild(doc.CreateTextNode(relType));
                    }

                    famNode.AppendChild(node);
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine("Pointer to non existant child");
                }
            }

            XmlNode basedOnNode = doc.CreateElement("BasedOn");

            foreach (GedcomFamilyEvent famEvent in Events)
            {
                node = doc.CreateElement("Event");

                XmlNode linkNode = doc.CreateElement("Link");

                attr       = doc.CreateAttribute("Target");
                attr.Value = "EventRec";
                linkNode.Attributes.Append(attr);

                attr       = doc.CreateAttribute("Ref");
                attr.Value = famEvent.EventXRefID;
                linkNode.Attributes.Append(attr);

                node.AppendChild(linkNode);

                basedOnNode.AppendChild(node);
            }

            famNode.AppendChild(basedOnNode);

            GenerateNoteXML(famNode);
            GenerateCitationsXML(famNode);
            GenerateMultimediaXML(famNode);

            GenerateChangeDateXML(famNode);

            root.AppendChild(famNode);
        }
Exemplo n.º 31
0
        /// <summary>
        /// Output GEDCOM format for this instance.
        /// </summary>
        /// <param name="sw">Where to output the data to.</param>
        public override void Output(TextWriter sw)
        {
            base.Output(sw);

            string levelPlusOne = Util.IntToString(Level + 1);

            if (RestrictionNotice != GedcomRestrictionNotice.None)
            {
                sw.Write(Environment.NewLine);
                sw.Write(levelPlusOne);
                sw.Write(" RESN ");
                sw.Write(RestrictionNotice.ToString().ToLower());
            }

            foreach (GedcomFamilyEvent familyEvent in events)
            {
                familyEvent.Output(sw);
            }

            if (!string.IsNullOrEmpty(husband))
            {
                sw.Write(Environment.NewLine);
                sw.Write(levelPlusOne);
                sw.Write(" HUSB ");
                sw.Write("@");
                sw.Write(husband);
                sw.Write("@");
            }

            if (!string.IsNullOrEmpty(wife))
            {
                sw.Write(Environment.NewLine);
                sw.Write(levelPlusOne);
                sw.Write(" WIFE ");
                sw.Write("@");
                sw.Write(wife);
                sw.Write("@");
            }

            string levelPlusTwo = Util.IntToString(Level + 2);

            foreach (string childID in children)
            {
                sw.Write(Environment.NewLine);
                sw.Write(levelPlusOne);
                sw.Write(" CHIL ");
                sw.Write("@");
                sw.Write(childID);
                sw.Write("@");

                GedcomIndividualRecord child = (GedcomIndividualRecord)Database[childID];
                if (child != null)
                {
                    // only output _FREL / _MREL value here,
                    // real PEDI goes on the FAMC on the INDI tag
                    GedcomFamilyLink link = null;
                    if (child.ChildInFamily(XrefId, out link))
                    {
                        switch (link.Pedigree)
                        {
                        case PedigreeLinkageType.FatherAdopted:
                            sw.Write(Environment.NewLine);
                            sw.Write(levelPlusTwo);
                            sw.Write("_FREL Adopted");
                            break;

                        case PedigreeLinkageType.MotherAdopted:
                            sw.Write(Environment.NewLine);
                            sw.Write(levelPlusTwo);
                            sw.Write("_MREL Adopted");
                            break;
                        }
                    }
                    else
                    {
                        System.Diagnostics.Debug.WriteLine("Missing child linkage for " + childID + " to family " + XrefId);
                    }
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine("Missing child " + childID + " when outputting family " + XrefId);
                }
            }

            if (numberOfChildren != 0)
            {
                sw.Write(Environment.NewLine);
                sw.Write(levelPlusOne);
                sw.Write(" NCHI ");
                sw.Write("@");
                sw.Write(Util.IntToString(numberOfChildren));
                sw.Write("@");
            }

            if (submitterRecords != null)
            {
                foreach (string submitter in SubmitterRecords)
                {
                    sw.Write(Environment.NewLine);
                    sw.Write(levelPlusOne);
                    sw.Write(" SUBM ");
                    sw.Write("@");
                    sw.Write(submitter);
                    sw.Write("@");
                }
            }

            if (StartStatus != MarriageStartStatus.Unknown)
            {
                sw.Write(Environment.NewLine);
                sw.Write(levelPlusOne);
                sw.Write(" _MSTAT ");
                sw.Write(StartStatus.ToString());
            }
        }