Beispiel #1
0
 public void SortChilds(GDMFamilyRecord famRec)
 {
     if (famRec != null)
     {
         famRec.Children.Sort(ChildrenEventsCompare);
     }
 }
Beispiel #2
0
        public override void MoveTo(GDMRecord targetRecord, bool clearDest)
        {
            GDMFamilyRecord targetFamily = targetRecord as GDMFamilyRecord;

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

            base.MoveTo(targetRecord, clearDest);

            targetFamily.RemoveSpouse(targetFamily.Husband.Individual);
            targetFamily.Husband.XRef = fHusband.XRef;

            targetFamily.RemoveSpouse(targetFamily.Wife.Individual);
            targetFamily.Wife.XRef = fWife.XRef;

            targetFamily.Status = fStatus;

            while (fChildren.Count > 0)
            {
                GDMIndividualLink obj = fChildren.Extract(0);
                obj.ResetOwner(targetFamily);
                targetFamily.Children.Add(obj);
            }
        }
Beispiel #3
0
        public override void Clear()
        {
            base.Clear();

            fSex = GDMSex.svUnknown;

            for (int i = fChildToFamilyLinks.Count - 1; i >= 0; i--)
            {
                GDMFamilyRecord family = fChildToFamilyLinks[i].Family;
                family.DeleteChild(this);
            }
            fChildToFamilyLinks.Clear();

            for (int i = fSpouseToFamilyLinks.Count - 1; i >= 0; i--)
            {
                GDMFamilyRecord family = fSpouseToFamilyLinks[i].Family;
                family.RemoveSpouse(this);
            }
            fSpouseToFamilyLinks.Clear();

            for (int i = fGroups.Count - 1; i >= 0; i--)
            {
                GDMGroupRecord group = (GDMGroupRecord)fGroups[i].Value;
                group.RemoveMember(this);
            }
            fGroups.Clear();

            fAliases.Clear();
            fAssociations.Clear();
            fPersonalNames.Clear();
        }
Beispiel #4
0
        public override void MoveTo(GDMRecord targetRecord)
        {
            GDMFamilyRecord targetFamily = targetRecord as GDMFamilyRecord;

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

            base.MoveTo(targetRecord);

            targetFamily.RemoveSpouse(fTree.GetPtrValue <GDMIndividualRecord>(targetFamily.Husband));
            targetFamily.Husband.XRef = fHusband.XRef;

            targetFamily.RemoveSpouse(fTree.GetPtrValue <GDMIndividualRecord>(targetFamily.Wife));
            targetFamily.Wife.XRef = fWife.XRef;

            targetFamily.Status = fStatus;

            while (fChildren.Count > 0)
            {
                GDMIndividualLink obj = fChildren.Extract(0);
                targetFamily.Children.Add(obj);
            }
        }
Beispiel #5
0
        public GDMIndividualRecord GetSpouseBy(GDMFamilyRecord family, GDMIndividualRecord spouse)
        {
            GDMIndividualRecord husb = GetPtrValue <GDMIndividualRecord>(family.Husband);
            GDMIndividualRecord wife = GetPtrValue <GDMIndividualRecord>(family.Wife);

            return((spouse == husb) ? wife : husb);
        }
Beispiel #6
0
        public GDMFamilyRecord CreateFamily()
        {
            GDMFamilyRecord result = new GDMFamilyRecord(this);

            result.InitNew();
            result.ChangeDate.ChangeDateTime = DateTime.Now;

            AddRecord(result);
            return(result);
        }
Beispiel #7
0
        public bool DeleteFamilyRecord(GDMFamilyRecord famRec)
        {
            if (famRec == null)
            {
                return(false);
            }

            famRec.Clear();
            DeleteRecord(famRec);
            return(true);
        }
        public void Test_Common2()
        {
            GDMTree tree = new GDMTree();

            using (GDMFamilyRecord famRec = new GDMFamilyRecord(tree)) {
                Assert.IsNotNull(famRec);

                GDMIndividualRecord unkInd = new GDMIndividualRecord(null);
                unkInd.Sex = GDMSex.svUnknown;
                Assert.IsFalse(famRec.AddSpouse(unkInd));

                GDMIndividualRecord child1 = tree.CreateIndividual(); // for pointer need a proper object
                Assert.IsTrue(famRec.AddChild(child1));

                GDMIndividualRecord child2 = tree.CreateIndividual(); // for pointer need a proper object
                Assert.IsTrue(famRec.AddChild(child2));
                Assert.AreEqual(1, famRec.IndexOfChild(child2));

                famRec.DeleteChild(child1);
                Assert.AreEqual(-1, famRec.IndexOfChild(child1));

                string str = GKUtils.GetFamilyString(famRec, null, null);
                Assert.AreEqual("? - ?", str);

                str = GKUtils.GetFamilyString(famRec, "x", "x");
                Assert.AreEqual("x - x", str);

                Assert.AreEqual(0.0f, famRec.IsMatch(null, new MatchParams()));
                Assert.AreEqual(100.0f, famRec.IsMatch(famRec, new MatchParams()));

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

                GDMCustomEvent evt = famRec.AddEvent(new GDMFamilyEvent(famRec, (int)GEDCOMTagType.MARR, "01 SEP 1981"));
                Assert.AreEqual(1, famRec.Events.Count);
                Assert.AreEqual(evt, famRec.FindEvent(GEDCOMTagType.MARR));

                using (GDMFamilyRecord famRec2 = new GDMFamilyRecord(tree)) {
                    Assert.AreEqual(0, famRec2.Events.Count);
                    Assert.AreEqual(null, famRec2.FindEvent(GEDCOMTagType.MARR));

                    famRec.MoveTo(famRec2, false);

                    Assert.AreEqual(1, famRec2.Events.Count);
                    Assert.AreEqual(evt, famRec2.FindEvent(GEDCOMTagType.MARR));
                }

                famRec.ResetOwner(tree);
                Assert.AreEqual(tree, famRec.GetTree());
            }
        }
Beispiel #9
0
        /// <summary>
        /// Attention: returns or creates only the first parents family!
        /// </summary>
        /// <param name="canCreate">can create if does not exist</param>
        /// <returns></returns>
        public GDMFamilyRecord GetParentsFamily(bool canCreate = false)
        {
            GDMFamilyRecord result = (fChildToFamilyLinks.Count < 1) ? null : fChildToFamilyLinks[0].Family;

            if (result == null && canCreate)
            {
                result = GetTree().CreateFamily();
                result.AddChild(this);
            }

            return(result);
        }
Beispiel #10
0
        /// <summary>
        /// Attention: returns or creates only the first marriage!
        /// </summary>
        /// <param name="canCreate">can create if does not exist</param>
        /// <returns></returns>
        public GDMFamilyRecord GetMarriageFamily(bool canCreate = false)
        {
            GDMFamilyRecord result = (fSpouseToFamilyLinks.Count < 1) ? null : fSpouseToFamilyLinks[0].Family;

            if (result == null && canCreate)
            {
                result = GetTree().CreateFamily();
                result.AddSpouse(this);
            }

            return(result);
        }
Beispiel #11
0
 public GDMChildToFamilyLink FindChildToFamilyLink(GDMFamilyRecord familyRec)
 {
     for (int i = 0, num = fChildToFamilyLinks.Count; i < num; i++)
     {
         var childLink = fChildToFamilyLinks[i];
         if (childLink.Family == familyRec)
         {
             return(childLink);
         }
     }
     return(null);
 }
Beispiel #12
0
        public void DeleteChildToFamilyLink(GDMFamilyRecord familyRec)
        {
            int num = fChildToFamilyLinks.Count;

            for (int i = 0; i < num; i++)
            {
                if (fChildToFamilyLinks[i].Family == familyRec)
                {
                    fChildToFamilyLinks.DeleteAt(i);
                    break;
                }
            }
        }
Beispiel #13
0
        public override float IsMatch(GDMTag tag, MatchParams matchParams)
        {
            GDMFamilyRecord otherFam = tag as GDMFamilyRecord;

            if (otherFam == null)
            {
                return(0.0f);
            }

            float match = GetStrMatch(GetFamilyString(), otherFam.GetFamilyString(), matchParams);

            return(match);
        }
Beispiel #14
0
        public int GetTotalChildsCount()
        {
            int result = 0;

            int num = SpouseToFamilyLinks.Count;

            for (int i = 0; i < num; i++)
            {
                GDMFamilyRecord family = SpouseToFamilyLinks[i].Family;
                result += family.Children.Count;
            }

            return(result);
        }
Beispiel #15
0
        public override void Assign(GDMTag source)
        {
            GDMFamilyRecord sourceRec = source as GDMFamilyRecord;

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

            base.Assign(source);

            fHusband.Assign(sourceRec.fHusband);
            fWife.Assign(sourceRec.fWife);
            fStatus = sourceRec.fStatus;
            AssignList(sourceRec.fChildren, fChildren);
        }
Beispiel #16
0
        public int IndexOfSpouse(GDMFamilyRecord familyRec)
        {
            if (familyRec != null)
            {
                int num = fSpouseToFamilyLinks.Count;
                for (int i = 0; i < num; i++)
                {
                    if (fSpouseToFamilyLinks[i].Family == familyRec)
                    {
                        return(i);
                    }
                }
            }

            return(-1);
        }
Beispiel #17
0
        public void DeleteChildToFamilyLink(GDMFamilyRecord familyRec)
        {
            if (familyRec == null)
            {
                return;
            }

            int num = fChildToFamilyLinks.Count;

            for (int i = 0; i < num; i++)
            {
                if (fChildToFamilyLinks[i].XRef == familyRec.XRef)
                {
                    fChildToFamilyLinks.DeleteAt(i);
                    break;
                }
            }
        }
Beispiel #18
0
        public void Test_Common()
        {
            GDMTree tree = new GDMTree();

            Assert.IsNotNull(tree);

            Assert.IsNotNull(tree.GetSubmitter());

            // Tests of event handlers
            tree.OnChange   += OnTreeChange;
            tree.OnChanging += OnTreeChanging;
            tree.OnProgress += OnTreeProgress;

            tree.BeginUpdate();
            Assert.IsTrue(tree.IsUpdated());

            GDMRecord rec;

            GDMIndividualRecord iRec = tree.CreateIndividual();

            Assert.IsNotNull(iRec, "CreateIndividual() != null");

            string xref = iRec.XRef;

            rec = tree.XRefIndex_Find(xref);
            Assert.IsNotNull(rec);
            Assert.AreEqual(xref, rec.XRef);

            string uid = iRec.UID;

            rec = tree.FindUID(uid);
            Assert.IsNotNull(rec);
            Assert.AreEqual(uid, rec.UID);
            Assert.IsNull(tree.FindUID(""));

            //
            GDMFamilyRecord famRec = tree.CreateFamily();

            Assert.IsNotNull(famRec, "CreateFamily() != null");

            //
            GDMNoteRecord noteRec = tree.CreateNote();

            Assert.IsNotNull(noteRec, "CreateNote() != null");

            //
            GDMRepositoryRecord repRec = tree.CreateRepository();

            Assert.IsNotNull(repRec, "CreateRepository() != null");

            //
            GDMSourceRecord srcRec = tree.CreateSource();

            Assert.IsNotNull(srcRec, "CreateSource() != null");

            //
            GDMMultimediaRecord mmRec = tree.CreateMultimedia();

            Assert.IsNotNull(mmRec, "CreateMultimedia() != null");

            //

            GDMRecord sbmrRec = tree.AddRecord(new GDMSubmitterRecord(tree));

            Assert.IsNotNull(sbmrRec, "sbmrRec != null");
            tree.NewXRef(sbmrRec);
            string submXRef = sbmrRec.XRef;

            //

            GDMSubmissionRecord submRec = tree.AddRecord(new GDMSubmissionRecord(tree)) as GDMSubmissionRecord;

            Assert.IsNotNull(submRec, "rec1 != null");
            tree.NewXRef(submRec);

            //
            GDMGroupRecord groupRec = tree.CreateGroup();

            Assert.IsNotNull(groupRec, "CreateGroup() != null");

            //
            GDMTaskRecord taskRec = tree.CreateTask();

            Assert.IsNotNull(taskRec, "CreateTask() != null");

            //
            GDMCommunicationRecord commRec = tree.CreateCommunication();

            Assert.IsNotNull(commRec, "CreateCommunication() != null");

            //
            GDMResearchRecord resRec = tree.CreateResearch();

            Assert.IsNotNull(resRec, "CreateResearch() != null");

            //
            GDMLocationRecord locRec = tree.CreateLocation();

            Assert.IsNotNull(locRec, "CreateLocation() != null");

            tree.EndUpdate();
            Assert.IsFalse(tree.IsUpdated());

            tree.OnChange   -= OnTreeChange;
            tree.OnChanging -= OnTreeChanging;
            tree.OnProgress -= OnTreeProgress;

            int       size  = 0;
            var       enum1 = tree.GetEnumerator(GDMRecordType.rtNone);
            GDMRecord rec1;

            enum1.Reset();
            while (enum1.MoveNext(out rec1))
            {
                size++;
            }
            Assert.AreEqual(14, size);

            for (int i = 0; i < tree.RecordsCount; i++)
            {
                GDMRecord rec2 = tree[i];
                Assert.IsNotNull(rec2);

                string    xref2 = rec2.XRef;
                GDMRecord rec3  = tree.XRefIndex_Find(xref2);
                Assert.IsNotNull(rec3);
                Assert.AreEqual(rec2, rec3);

                /*string uid = rec2.UID;
                 * GEDCOMRecord rec4 = tree.FindUID(uid);
                 * Assert.IsNotNull(rec4);
                 * Assert.AreEqual(rec2, rec4);*/

                int idx = tree.IndexOf(rec2);
                Assert.AreEqual(i, idx);
            }

            var recordsX = tree.GetRecords <GDMIndividualRecord>();

            Assert.IsNotNull(recordsX);
            Assert.AreEqual(1, recordsX.Count);

            int[] stats = tree.GetRecordStats();
            Assert.IsNotNull(stats);
            Assert.AreEqual(14, stats.Length);

            Assert.IsFalse(tree.IsEmpty);

            Assert.IsFalse(tree.DeleteFamilyRecord(null));
            Assert.IsTrue(tree.DeleteFamilyRecord(famRec));

            Assert.IsFalse(tree.DeleteNoteRecord(null));
            Assert.IsTrue(tree.DeleteNoteRecord(noteRec));

            Assert.IsFalse(tree.DeleteSourceRecord(null));
            Assert.IsTrue(tree.DeleteSourceRecord(srcRec));

            Assert.IsFalse(tree.DeleteGroupRecord(null));
            Assert.IsTrue(tree.DeleteGroupRecord(groupRec));

            Assert.IsFalse(tree.DeleteLocationRecord(null));
            Assert.IsTrue(tree.DeleteLocationRecord(locRec));

            Assert.IsFalse(tree.DeleteResearchRecord(null));
            Assert.IsTrue(tree.DeleteResearchRecord(resRec));

            Assert.IsFalse(tree.DeleteCommunicationRecord(null));
            Assert.IsTrue(tree.DeleteCommunicationRecord(commRec));

            Assert.IsFalse(tree.DeleteTaskRecord(null));
            Assert.IsTrue(tree.DeleteTaskRecord(taskRec));

            Assert.IsFalse(tree.DeleteMediaRecord(null));
            Assert.IsTrue(tree.DeleteMediaRecord(mmRec));

            Assert.IsFalse(tree.DeleteIndividualRecord(null));
            Assert.IsTrue(tree.DeleteIndividualRecord(iRec));

            Assert.IsFalse(tree.DeleteRepositoryRecord(null));
            Assert.IsTrue(tree.DeleteRepositoryRecord(repRec));

            tree.Clear();
            Assert.AreEqual(0, tree.RecordsCount);
            Assert.IsTrue(tree.IsEmpty);

            tree.State = GDMTreeState.osReady;
            Assert.AreEqual(GDMTreeState.osReady, tree.State);


            // Tests of GEDCOMTree.Extract()
            using (GDMTree tree2 = new GDMTree()) {
                GDMIndividualRecord iRec2 = tree.AddRecord(new GDMIndividualRecord(tree2)) as GDMIndividualRecord;
                Assert.IsNotNull(iRec2);
                tree2.NewXRef(iRec2);

                tree2.AddRecord(iRec2);
                int rIdx = tree2.IndexOf(iRec2);
                Assert.IsTrue(rIdx >= 0);
                GDMRecord extractedRec = tree2.Extract(rIdx);
                Assert.AreEqual(iRec2, extractedRec);
                Assert.IsTrue(tree2.IndexOf(iRec2) < 0);
            }
        }
Beispiel #19
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());
        }
Beispiel #20
0
        public void Test_Common()
        {
            GDMIndividualRecord iRec = fContext.Tree.XRefIndex_Find("I1") as GDMIndividualRecord;

            Assert.IsNotNull(iRec);

            GDMFamilyRecord famRec = fContext.Tree.XRefIndex_Find("F1") as GDMFamilyRecord;

            Assert.IsNotNull(famRec);

            GDMSourceRecord srcRec = fContext.Tree.XRefIndex_Find("S1") as GDMSourceRecord;

            Assert.IsNotNull(srcRec);

            using (GDMTaskRecord taskRec = new GDMTaskRecord(fContext.Tree)) {
                Assert.IsNotNull(taskRec);

                taskRec.Priority = GDMResearchPriority.rpNormal;
                Assert.AreEqual(GDMResearchPriority.rpNormal, taskRec.Priority);

                taskRec.StartDate.Date = TestUtils.ParseDT("20.01.2013");
                Assert.AreEqual(TestUtils.ParseDT("20.01.2013"), taskRec.StartDate.Date);

                taskRec.StopDate.Date = TestUtils.ParseDT("21.01.2013");
                Assert.AreEqual(TestUtils.ParseDT("21.01.2013"), taskRec.StopDate.Date);

                taskRec.Goal = "Test Goal";
                Assert.AreEqual("Test Goal", taskRec.Goal);
                var goal = GKUtils.GetTaskGoal(fContext.Tree, taskRec);
                Assert.AreEqual(GDMGoalType.gtOther, goal.GoalType);
                Assert.AreEqual(null, goal.GoalRec);

                taskRec.Goal = iRec.XRef;
                goal         = GKUtils.GetTaskGoal(fContext.Tree, taskRec);
                Assert.AreEqual(GDMGoalType.gtIndividual, goal.GoalType);
                Assert.AreEqual(iRec, goal.GoalRec);

                taskRec.Goal = famRec.XRef;
                goal         = GKUtils.GetTaskGoal(fContext.Tree, taskRec);
                Assert.AreEqual(GDMGoalType.gtFamily, goal.GoalType);
                Assert.AreEqual(famRec, goal.GoalRec);

                taskRec.Goal = srcRec.XRef;
                goal         = GKUtils.GetTaskGoal(fContext.Tree, taskRec);
                Assert.AreEqual(GDMGoalType.gtSource, goal.GoalType);
                Assert.AreEqual(srcRec, goal.GoalRec);

                using (GDMTaskRecord task2 = fContext.Tree.CreateTask()) {
                    Assert.Throws(typeof(ArgumentException), () => {
                        task2.Assign(null);
                    });

                    task2.Assign(taskRec);

                    // FIXME: goal format invalid!
                    string buf = TestUtils.GetTagStreamText(task2, 0);
                    Assert.AreEqual("0 @TK2@ _TASK\r\n" +
                                    "1 _STARTDATE 20 JAN 2013\r\n" +
                                    "1 _STOPDATE 21 JAN 2013\r\n" +
                                    "1 _PRIORITY normal\r\n" +
                                    "1 _GOAL S1\r\n", buf);
                }

                taskRec.ReplaceXRefs(new GDMXRefReplacer());

                Assert.IsFalse(taskRec.IsEmpty());
                taskRec.Clear();
                Assert.IsTrue(taskRec.IsEmpty());
            }
        }
Beispiel #21
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 void Test_Common()
        {
            GDMTree tree = new GDMTree();

            Assert.IsNotNull(tree);

            GDMIndividualRecord indiv = tree.CreateIndividual();

            Assert.IsNotNull(indiv);

            GDMFamilyRecord famRec = tree.CreateFamily();

            Assert.IsNotNull(famRec);

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

            famRec.AddChild(indiv);
            Assert.AreEqual(0, famRec.IndexOfChild(indiv));

            famRec.Husband.Value = tree.CreateIndividual();
            famRec.Wife.Value    = tree.CreateIndividual();

            using (GDMFamilyRecord fam2 = tree.CreateFamily()) {
                Assert.Throws(typeof(ArgumentException), () => {
                    fam2.Assign(null);
                });

                fam2.Assign(famRec);

                string buf = TestUtils.GetTagStreamText(fam2, 0);
                Assert.AreEqual("0 @F2@ FAM\r\n" +
                                "1 RESN locked\r\n" +
                                "1 HUSB @I2@\r\n" +
                                "1 WIFE @I3@\r\n" +
                                "1 CHIL @I1@\r\n", buf);
            }

            // Integrity test
            GDMChildToFamilyLink childLink = indiv.ChildToFamilyLinks[0];

            Assert.IsNotNull(childLink.Family);

            famRec.RemoveChild(indiv);
            Assert.AreEqual(-1, famRec.IndexOfChild(indiv));

            //

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

            famRec.ReplaceXRefs(new GDMXRefReplacer());

            //

            famRec.Husband.Value = indiv;
            Assert.AreEqual(indiv, famRec.Husband.Individual);
            famRec.Husband.Value = null;

            //

            famRec.Wife.Value = indiv;
            Assert.AreEqual(indiv, famRec.Wife.Individual);
            famRec.Wife.Value = null;

            //

            indiv.Sex = GDMSex.svMale;
            famRec.AddSpouse(indiv);
            Assert.AreEqual(0, indiv.IndexOfSpouse(famRec));
            Test_GDMSpouseToFamilyLink(indiv.SpouseToFamilyLinks[0]);
            Assert.IsNull(famRec.GetSpouseBy(indiv));
            famRec.RemoveSpouse(indiv);

            indiv.Sex = GDMSex.svFemale;
            famRec.AddSpouse(indiv);
            Assert.AreEqual(0, indiv.IndexOfSpouse(famRec));
            Test_GDMSpouseToFamilyLink(indiv.SpouseToFamilyLinks[0]);
            Assert.IsNull(famRec.GetSpouseBy(indiv));
            famRec.RemoveSpouse(indiv);

            //

            famRec.SortChilds();

            //

            famRec.AddChild(null);
            famRec.RemoveChild(null);
            famRec.AddSpouse(null);
            famRec.RemoveSpouse(null);

            //
            famRec.AddSpouse(indiv);

            famRec.AddChild(tree.CreateIndividual());
            famRec.AddChild(tree.CreateIndividual());
            famRec.AddChild(tree.CreateIndividual());
            Assert.AreEqual(3, famRec.Children.Count);

            Assert.IsFalse(famRec.IsEmpty());
            famRec.Clear();
            Assert.IsTrue(famRec.IsEmpty());
        }