1
Vote

Import then save as crashes the app

description

Unfortunately, I don't have any more info that than. i imported a gedcom file then tried to save as a new file and it crashes. I guess it could be something within the gedcom.

comments

spyhunter99 wrote Jul 4, 2011 at 1:23 AM

Ok I think I've identified a number of bugs. I build my gedcom file from GenealogyJ and it looks like your import class makes some invalid assumptions (at least in reference to the way that GenealogyJ saves it). Fix: in GedcomImport.cs, function private static string[] GetPhotos(XmlNode node)

change code to this (explain inline)
string[] photos;
        XmlNodeList list = node.SelectNodes("OBJE");

        //AO added
        //this should be a list of OBJE references to xml nodes, siblings of node, that with matching values
        /*
         *    <INDI Value="@I54@">
                <NAME Value="name" />
                <SEX Value="F" />
                <OBJE Value="@M3@" />
              </INDI>
              <OBJE Value="@M3@">
                <FILE Value="D:/My Documents/Downloads/family tree/birth/name.jpg">
                  <FORM Value="jpg" />
                  <TITL Value="" />
                </FILE>
              </OBJE>
         * */
        photos = new string[list.Count];

        for (int i = 0; i < list.Count; i++)

            photos[i] = GetFile(list[i], node.ParentNode);

        return photos;


Problem #2. when importing dates, the gedcom format allows for qualifiers such as ABT, EST, BEF, AFT, etc... in the function, private static DateTime? GetValueDate(XmlNode node, string xpath)....I change the code this.
DateTime? result = null;
        try
        {
            string value = GetValue(node, xpath);
            if (!string.IsNullOrEmpty(value))
            {
                try
                {
                    return DateTime.Parse(value, CultureInfo.InvariantCulture);
                }
                catch { }
                //forgot about date qualifiers
                try
                {
                    if (value.StartsWith("ABT") || value.StartsWith("EST") || value.StartsWith("CAL") || value.StartsWith("BEF"))
                        return DateTime.Parse(value.Substring(4, value.Length - 4), CultureInfo.InvariantCulture);
                }
                catch { }
                //could be just a year
                if (value.Trim().Length == 4)
                    try
                    {
                        return new DateTime(Int32.Parse(value), 1, 1);
                    }
                    catch { }

                string[] stuff = value.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                if (stuff == null || stuff.Length == 0)
                    return null;
                else
                {
                    for (int i = 0; i < stuff.Length; i++)
                    {
                        if (stuff[i].Trim().Length == 4)
                        {
                            return new DateTime(Int32.Parse(stuff[i].Trim()), 1, 1);
                        }
                    }
                }
            }
        }
        catch
        {
            // The date is invalid, ignore and continue processing.
        }

        return result;

Problem #3. Gedcom does not require a date associate with a marriage. If no date is specified, Family.Show will not render it. I haven't found a solution yet

spyhunter99 wrote Jul 4, 2011 at 2:10 AM

Problem #3 turns out the root cause is GeneaologyJ. When you add a spouse, it doesn't automatically add the marriage date unless you fill out at least one element. So its not actually a problem with family.show

spyhunter99 wrote Jul 6, 2011 at 1:17 PM

In general, Family.Show is a great rendering engine, but it's general lack of compliance with gedcom makes it very frustrating. The best approach would have been to start with the gedcom format since it's so flexible and then build the data class structures to match it. This xml conversion process really isn't necessary. Changing to a gedcom style class structure would mean that the user interface would have to be rewritten to allow for inserting the data.

When importing, the current version ignores all data associated with marriages other than the dates. What about notes? Images?

I've also found another rendering bug which seems to happen when there are a large number of children by the same parent (that also had children of another spouse 10+). Lines are no longer drawn connecting them. I've also found an instance where children won't show up for a particular spouse (wife) when she is highlighted.

spyhunter99 wrote Jul 13, 2011 at 1:23 AM

Yet another problem. If a husband has multiple spouses, the child can be incorrectly associated or not associated at all with the correct parents, I believe the problem is in the following code snippet which is from RelationshipHelper.cs

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

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

The fix for this is simple, add an additional function to RelationShipHelper.cs

/// <summary>
    /// Performs the business logic for adding the Child relationship between two parents and the child.
    /// Added AO
    /// </summary>
    public static void AddChild(PeopleCollection family, Person husband, Person wife, Person child)
    {
        // Add the new child as a sibling to any existing children
        foreach (Person existingSibling in husband.Children)
        {
            //if (existingSibling.Parents.Contains(husband) && 
           //     !existingSibling.Parents.Contains(wife))

            family.AddSibling(existingSibling, child);
        }
        // Add the new child as a sibling to any existing children
        foreach (Person existingSibling in wife.Children)
        {
            //if (existingSibling.Parents.Contains(husband) && 
            //     !existingSibling.Parents.Contains(wife))

            family.AddSibling(existingSibling, child);
        }

        family.AddChild(husband, child, ParentChildModifier.Natural);
        family.AddChild(wife, child, ParentChildModifier.Natural);

    }

Then in GedcomImport.cs, edit ImportFamiles()

replace the child import code with the following

// Import the children.
            foreach (string child in children)
            {
                // Get the Person object for the child.
                Person childPerson = people.Find(child);
                //added AO
                if (childPerson != null)
                {
                    if (husbandPerson != null && wifePerson != null)
                        RelationshipHelper.AddChild(people, husbandPerson, wifePerson, childPerson);
                    else if (husbandPerson == null && wifePerson != null)
                        RelationshipHelper.AddChild(people, wifePerson, childPerson);
                    else
                        RelationshipHelper.AddChild(people, husbandPerson, childPerson);

                }
            }