Beispiel #1
0
        public void Test_SearchTreeFragments_MergeTree()
        {
            List <List <GDMRecord> > treeFragments;
            Assembly assembly = typeof(CoreTests).Assembly;

            using (var ctx1 = new BaseContext(null)) {
                IBaseWindow baseWin = new BaseWindowStub(ctx1);

                using (Stream stmGed1 = assembly.GetManifestResourceStream("GKTests.Resources.test1.ged")) {
                    var gedcomProvider = new GEDCOMProvider(ctx1.Tree);
                    gedcomProvider.LoadFromStreamExt(stmGed1, stmGed1);
                }

                treeFragments = TreeTools.SearchTreeFragments(ctx1.Tree, null);
                Assert.AreEqual(2, treeFragments.Count);
                Assert.AreEqual(13, treeFragments[0].Count);
                Assert.AreEqual(1, treeFragments[1].Count);

                using (var ctx2 = new BaseContext(null)) {
                    using (Stream stmGed2 = assembly.GetManifestResourceStream("GKTests.Resources.test2.ged")) {
                        var gedcomProvider = new GEDCOMProvider(ctx2.Tree);
                        gedcomProvider.LoadFromStreamExt(stmGed2, stmGed2);
                    }

                    treeFragments = TreeTools.SearchTreeFragments(ctx2.Tree, null);
                    Assert.AreEqual(2, treeFragments.Count);
                    Assert.AreEqual(15, treeFragments[0].Count);
                    Assert.AreEqual(1, treeFragments[1].Count);

                    TreeTools.MergeTree(ctx1.Tree, ctx2.Tree, null);

                    treeFragments = TreeTools.SearchTreeFragments(ctx1.Tree, null);
                    Assert.AreEqual(4, treeFragments.Count);
                    Assert.AreEqual(13, treeFragments[0].Count);
                    Assert.AreEqual(1, treeFragments[1].Count);
                    Assert.AreEqual(15, treeFragments[2].Count);
                    Assert.AreEqual(1, treeFragments[3].Count);

                    GDMIndividualRecord iRec1 = ctx1.Tree.XRefIndex_Find("I1") as GDMIndividualRecord;
                    Assert.IsNotNull(iRec1);

                    GDMIndividualRecord iRec2 = ctx1.Tree.XRefIndex_Find("I3") as GDMIndividualRecord;
                    Assert.IsNotNull(iRec2);

                    TreeTools.MergeRecord(baseWin, iRec1, iRec2, true);

                    treeFragments = TreeTools.SearchTreeFragments(ctx1.Tree, null);
                    Assert.AreEqual(3, treeFragments.Count);
                    Assert.AreEqual(13, treeFragments[0].Count);
                    Assert.AreEqual(15, treeFragments[1].Count);
                    Assert.AreEqual(1, treeFragments[2].Count);
                }
            }
        }
        public void CheckGroups()
        {
            IProgressController      progress      = AppHost.Progress;
            List <List <GDMRecord> > treeFragments = TreeTools.SearchTreeFragments(fBase.Context.Tree, progress);

            fView.LogChart.Clear();
            fView.GroupsTree.BeginUpdate();
            try {
                fView.GroupsTree.Clear();

                int num = treeFragments.Count;
                for (int i = 0; i < num; i++)
                {
                    var groupRecords = treeFragments[i];

                    int     cnt       = groupRecords.Count;
                    int     groupNum  = (i + 1);
                    ITVNode groupItem = fView.GroupsTree.AddNode(null,
                                                                 groupNum.ToString() + " " + LangMan.LS(LSID.LSID_Group).ToLower() + " (" + cnt.ToString() + ")", null);

                    for (int j = 0; j < cnt; j++)
                    {
                        var iRec = (GDMIndividualRecord)groupRecords[j];

                        string pn = GKUtils.GetNameString(iRec, true, false);
                        if (iRec.Patriarch)
                        {
                            pn = "(*) " + pn;
                        }
                        pn = string.Join(" ", pn, "[", iRec.XRef, "]");

                        fView.GroupsTree.AddNode(groupItem, pn, iRec);
                    }

                    fView.GroupsTree.Expand(groupItem);
                    fView.LogChart.AddFragment(cnt);
                }
            } finally {
                treeFragments.Clear();
                fView.GroupsTree.EndUpdate();
            }
        }