Exemple #1
0
        public GDMAssociation AddAssociation(string relation, GDMIndividualRecord relPerson)
        {
            GDMAssociation result = new GDMAssociation(this);

            result.Relation   = relation;
            result.Individual = relPerson;
            Associations.Add(result);
            return(result);
        }
        public GDMAssociation AddAssociation(string relation, GDMIndividualRecord relPerson)
        {
            GDMAssociation result = new GDMAssociation();

            result.Relation = relation;
            result.XRef     = (relPerson == null) ? string.Empty : relPerson.XRef;
            Associations.Add(result);
            return(result);
        }
        public void Test_GEDCOMAssociation()
        {
            using (GDMAssociation association = new GDMAssociation()) {
                Assert.IsNotNull(association);

                Assert.IsNotNull(association.SourceCitations);

                Assert.IsNotNull(association.Notes); // for GEDCOMPointerWithNotes

                association.Relation = "This is test relation";
                Assert.AreEqual("This is test relation", association.Relation);

                association.XRef = string.Empty;
                Assert.IsNull(fContext.Tree.GetPtrValue(association));

                GDMIndividualRecord iRec = fContext.Tree.XRefIndex_Find("I1") as GDMIndividualRecord;
                Assert.IsNotNull(iRec);

                association.XRef = iRec.XRef;
                Assert.AreEqual(iRec, fContext.Tree.GetPtrValue(association));

                using (GDMAssociation asso2 = new GDMAssociation()) {
                    Assert.IsNotNull(asso2);

                    Assert.Throws(typeof(ArgumentException), () => {
                        asso2.Assign(null);
                    });

                    var iRec2 = new GDMIndividualRecord(null);
                    asso2.Assign(association);
                    iRec2.Associations.Add(asso2);

                    string buf = TestUtils.GetTagStreamText(iRec2, 0);
                    Assert.AreEqual("0 INDI\r\n" +
                                    "1 SEX U\r\n" +
                                    "1 ASSO @I1@\r\n" +
                                    "2 RELA This is test relation\r\n", buf);
                }

                association.ReplaceXRefs(new GDMXRefReplacer());

                GDMTag tag = association.SourceCitations.Add(new GDMSourceCitation());
                Assert.IsNotNull(tag);
                Assert.IsTrue(tag is GDMSourceCitation);

                Assert.IsFalse(association.IsEmpty());
                association.Clear();
                Assert.IsTrue(association.IsEmpty());
            }
        }
Exemple #4
0
        public override void Assign(GDMTag source)
        {
            GDMAssociation sourceObj = (source as GDMAssociation);

            if (sourceObj == null)
            {
                throw new ArgumentException(@"Argument is null or wrong type", "source");
            }

            base.Assign(sourceObj);

            fRelation = sourceObj.fRelation;
            AssignList(sourceObj.fSourceCitations, fSourceCitations);
        }
Exemple #5
0
        public void Test_Common()
        {
            GDMIndividualRecord iRec = fContext.Tree.XRefIndex_Find("I1") as GDMIndividualRecord;
            GDMCustomEvent      evt, evtd;

            GEDCOMRecordTest(iRec);

            evt = iRec.FindEvent(GEDCOMTagType.BIRT);
            Assert.IsNotNull(evt);

            evtd = iRec.FindEvent(GEDCOMTagType.DEAT);
            Assert.IsNotNull(evtd);

            Assert.IsFalse(iRec.IsLive());

            GDMIndividualRecord ind3 = fContext.Tree.XRefIndex_Find("I3") as GDMIndividualRecord;

            Assert.IsNotNull(ind3.GetParentsFamily());

            GDMIndividualRecord ind2 = fContext.Tree.XRefIndex_Find("I2") as GDMIndividualRecord;

            Assert.IsNotNull(ind2.GetMarriageFamily());

            //
            GDMIndividualRecord indiRec = fContext.Tree.XRefIndex_Find("I4") as GDMIndividualRecord;

            Assert.IsNull(indiRec.GetMarriageFamily());
            Assert.IsNotNull(indiRec.GetMarriageFamily(true));

            //
            Assert.Throws(typeof(ArgumentException), () => { indiRec.Assign(null); });

            indiRec.AutomatedRecordID = "test11";
            Assert.AreEqual("test11", indiRec.AutomatedRecordID);

            Assert.AreEqual(GDMRecordType.rtIndividual, indiRec.RecordType);

            Assert.AreEqual(4, indiRec.GetId());
            Assert.AreEqual("4", indiRec.GetXRefNum());

            Assert.AreEqual(-1, indiRec.IndexOfSource(null));

            indiRec.AddUserRef("test userref");
            Assert.AreEqual("test userref", indiRec.UserReferences[0].StringValue);

            //
            Assert.IsNotNull(indiRec.Aliases);
            Assert.IsNotNull(indiRec.Associations);
            Assert.IsNotNull(indiRec.UserReferences); // for GEDCOMRecord

            Assert.Throws(typeof(ArgumentException), () => {
                indiRec.AddEvent(new GDMFamilyEvent(null));
            });

            GDMIndividualRecord father, mother;
            GDMFamilyRecord     fam = indiRec.GetParentsFamily();

            if (fam == null)
            {
                father = null;
                mother = null;
            }
            else
            {
                father = fam.Husband.Individual;
                mother = fam.Wife.Individual;
            }

            Assert.IsNull(father);
            Assert.IsNull(mother);

            indiRec.Sex = GDMSex.svMale;
            Assert.AreEqual(GDMSex.svMale, indiRec.Sex);

            indiRec.Restriction = GDMRestriction.rnLocked;
            Assert.AreEqual(GDMRestriction.rnLocked, indiRec.Restriction);

            indiRec.Patriarch = true;
            Assert.AreEqual(true, indiRec.Patriarch);
            indiRec.Patriarch = false;
            Assert.AreEqual(false, indiRec.Patriarch);

            indiRec.Bookmark = true;
            Assert.AreEqual(true, indiRec.Bookmark);
            indiRec.Bookmark = false;
            Assert.AreEqual(false, indiRec.Bookmark);

            Assert.Throws(typeof(ArgumentException), () => { indiRec.MoveTo(null, false); });

            using (GDMIndividualRecord copyIndi = new GDMIndividualRecord(null)) {
                Assert.IsNotNull(copyIndi);

                Assert.Throws(typeof(ArgumentException), () => { copyIndi.Assign(null); });

                copyIndi.Assign(indiRec);
                Assert.AreEqual(100.0f, indiRec.IsMatch(copyIndi, new MatchParams()));
            }


            Assert.IsFalse(indiRec.IsEmpty());
            indiRec.Clear();
            Assert.IsTrue(indiRec.IsEmpty());

            float ca = indiRec.GetCertaintyAssessment();

            Assert.AreEqual(0.0f, ca);


            Assert.IsNull(indiRec.GetPrimaryMultimediaLink());
            GDMMultimediaLink mmLink = indiRec.SetPrimaryMultimediaLink(null);

            Assert.IsNull(mmLink);
            GDMMultimediaRecord mmRec = fContext.Tree.CreateMultimedia();

            mmLink = indiRec.SetPrimaryMultimediaLink(mmRec);
            Assert.IsNotNull(mmLink);
            mmLink = indiRec.GetPrimaryMultimediaLink();
            Assert.AreEqual(mmRec, mmLink.Value);


            Assert.AreEqual(-1, indiRec.IndexOfGroup(null));
            Assert.AreEqual(-1, indiRec.IndexOfSpouse(null));


            GDMIndividualRecord indi2 = fContext.Tree.XRefIndex_Find("I2") as GDMIndividualRecord;
            GDMAssociation      asso  = indiRec.AddAssociation("test", indi2);

            Assert.IsNotNull(asso);

            using (GDMIndividualRecord indi = new GDMIndividualRecord(fContext.Tree)) {
                Assert.IsNotNull(indi);

                var parts = GKUtils.GetNameParts(indi); // test with empty PersonalNames
                Assert.AreEqual("", parts.Surname);
                Assert.AreEqual("", parts.Name);
                Assert.AreEqual("", parts.Patronymic);

                indi.AddPersonalName(new GDMPersonalName(indi)); // test with empty Name
                parts = GKUtils.GetNameParts(indi);
                Assert.AreEqual("", parts.Surname);
                Assert.AreEqual("", parts.Name);
                Assert.AreEqual("", parts.Patronymic);
                indi.PersonalNames.Clear();

                string st;
                Assert.AreEqual("", GKUtils.GetNameString(indi, true, false));
                Assert.AreEqual("", GKUtils.GetNickString(indi));

                GDMPersonalName pName = new GDMPersonalName(indi);
                indi.AddPersonalName(pName);
                pName.Pieces.Nickname = "BigHead";
                pName.SetNameParts("Ivan", "Petrov", "");

                st = GKUtils.GetNameString(indi, true, true);
                Assert.AreEqual("Petrov Ivan [BigHead]", st);
                st = GKUtils.GetNameString(indi, false, true);
                Assert.AreEqual("Ivan Petrov [BigHead]", st);
                Assert.AreEqual("BigHead", GKUtils.GetNickString(indi));

                Assert.IsNull(indi.GetParentsFamily());
                Assert.IsNotNull(indi.GetParentsFamily(true));

                // MoveTo test
                GDMIndividualRecord ind = fContext.Tree.XRefIndex_Find("I2") as GDMIndividualRecord;

                indi.AddAssociation("test", ind);
                indi.Aliases.Add(new GDMAlias(indi));

                using (GDMIndividualRecord indi3 = new GDMIndividualRecord(fContext.Tree)) {
                    indi.MoveTo(indi3, false);

                    st = GKUtils.GetNameString(indi3, true, true);
                    Assert.AreEqual("Petrov Ivan [BigHead]", st);
                }

                indi.ResetOwner(fContext.Tree);
                Assert.AreEqual(fContext.Tree, indi.GetTree());
            }

            indiRec.ReplaceXRefs(new GDMXRefReplacer());
        }
Exemple #6
0
        public override void MoveTo(GDMRecord targetRecord, bool clearDest)
        {
            GDMIndividualRecord targetIndi = targetRecord as GDMIndividualRecord;

            if (targetIndi == null)
            {
                throw new ArgumentException(@"Argument is null or wrong type", "targetRecord");
            }

            /*if (!clearDest) {
             *  DeleteTag(GEDCOMTagType.SEX);
             *  DeleteTag(GEDCOMTagType._UID);
             * }*/

            base.MoveTo(targetRecord, clearDest);

            targetIndi.Sex = fSex;

            while (fPersonalNames.Count > 0)
            {
                GDMPersonalName obj = fPersonalNames.Extract(0);
                obj.ResetOwner(targetIndi);
                targetIndi.AddPersonalName(obj);
            }

            string currentXRef = this.XRef;
            string targetXRef  = targetRecord.XRef;

            while (fChildToFamilyLinks.Count > 0)
            {
                GDMChildToFamilyLink ctfLink = fChildToFamilyLinks.Extract(0);
                GDMFamilyRecord      family  = ctfLink.Family;

                int num = family.Children.Count;
                for (int i = 0; i < num; i++)
                {
                    GDMIndividualLink childPtr = family.Children[i];

                    if (childPtr.XRef == currentXRef)
                    {
                        childPtr.XRef = targetXRef;
                    }
                }

                ctfLink.ResetOwner(targetIndi);
                targetIndi.ChildToFamilyLinks.Add(ctfLink);
            }

            while (fSpouseToFamilyLinks.Count > 0)
            {
                GDMSpouseToFamilyLink stfLink = fSpouseToFamilyLinks.Extract(0);
                GDMFamilyRecord       family  = stfLink.Family;

                if (family.Husband.XRef == currentXRef)
                {
                    family.Husband.XRef = targetXRef;
                }
                else if (family.Wife.XRef == currentXRef)
                {
                    family.Wife.XRef = targetXRef;
                }

                stfLink.ResetOwner(targetIndi);
                targetIndi.SpouseToFamilyLinks.Add(stfLink);
            }

            while (fAssociations.Count > 0)
            {
                GDMAssociation obj = fAssociations.Extract(0);
                obj.ResetOwner(targetIndi);
                targetIndi.Associations.Add(obj);
            }

            while (fAliases.Count > 0)
            {
                GDMAlias obj = fAliases.Extract(0);
                obj.ResetOwner(targetIndi);
                targetIndi.Aliases.Add(obj);
            }

            while (fGroups.Count > 0)
            {
                GDMPointer obj = fGroups.Extract(0);
                obj.ResetOwner(targetIndi);
                targetIndi.Groups.Add(obj);
            }
        }
        public override void MoveTo(GDMRecord targetRecord)
        {
            GDMIndividualRecord targetIndi = targetRecord as GDMIndividualRecord;

            if (targetIndi == null)
            {
                throw new ArgumentException(@"Argument is null or wrong type", "targetRecord");
            }

            base.MoveTo(targetRecord);

            targetIndi.Sex = fSex;

            while (fPersonalNames.Count > 0)
            {
                GDMPersonalName obj = fPersonalNames.Extract(0);
                targetIndi.AddPersonalName(obj);
            }

            string currentXRef = this.XRef;
            string targetXRef  = targetRecord.XRef;

            while (fChildToFamilyLinks.Count > 0)
            {
                GDMChildToFamilyLink ctfLink = fChildToFamilyLinks.Extract(0);
                var family = fTree.GetPtrValue <GDMFamilyRecord>(ctfLink);

                int num = family.Children.Count;
                for (int i = 0; i < num; i++)
                {
                    GDMIndividualLink childPtr = family.Children[i];

                    if (childPtr.XRef == currentXRef)
                    {
                        childPtr.XRef = targetXRef;
                    }
                }

                targetIndi.ChildToFamilyLinks.Add(ctfLink);
            }

            while (fSpouseToFamilyLinks.Count > 0)
            {
                GDMSpouseToFamilyLink stfLink = fSpouseToFamilyLinks.Extract(0);
                var family = fTree.GetPtrValue <GDMFamilyRecord>(stfLink);

                if (family.Husband.XRef == currentXRef)
                {
                    family.Husband.XRef = targetXRef;
                }
                else if (family.Wife.XRef == currentXRef)
                {
                    family.Wife.XRef = targetXRef;
                }

                targetIndi.SpouseToFamilyLinks.Add(stfLink);
            }

            while (fAssociations.Count > 0)
            {
                GDMAssociation obj = fAssociations.Extract(0);
                targetIndi.Associations.Add(obj);
            }

            while (fGroups.Count > 0)
            {
                GDMPointer obj = fGroups.Extract(0);
                targetIndi.Groups.Add(obj);
            }
        }