Exemplo n.º 1
0
        public bool DeleteRepositoryRecord(GDMRepositoryRecord repRec)
        {
            if (repRec == null)
            {
                return(false);
            }

            int num = fRecords.Count;

            for (int i = 0; i < num; i++)
            {
                GDMRecord rec = fRecords[i];
                if (rec.RecordType == GDMRecordType.rtSource)
                {
                    GDMSourceRecord srcRec = (GDMSourceRecord)rec;
                    for (int j = srcRec.RepositoryCitations.Count - 1; j >= 0; j--)
                    {
                        if (srcRec.RepositoryCitations[j].Value == repRec)
                        {
                            srcRec.RepositoryCitations.DeleteAt(j);
                        }
                    }
                }
            }

            DeleteRecord(repRec);
            return(true);
        }
Exemplo n.º 2
0
        public GDMRepositoryRecord CreateRepository()
        {
            GDMRepositoryRecord result = new GDMRepositoryRecord(this);

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

            AddRecord(result);
            return(result);
        }
Exemplo n.º 3
0
        public void Test_Common()
        {
            var tree = new GDMTree();

            using (GDMRepositoryRecord repoRec = new GDMRepositoryRecord(tree)) {
                Assert.IsNotNull(repoRec);

                repoRec.InitNew();
                repoRec.RepositoryName = "Test Repository";
                Assert.AreEqual("Test Repository", repoRec.RepositoryName);

                Assert.IsNotNull(repoRec.Address);
                repoRec.Address.AddressLine1 = "AdrLine1";

                using (GDMRepositoryRecord repo2 = new GDMRepositoryRecord(tree)) {
                    repo2.InitNew();

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

                    repo2.Assign(repoRec);

                    string buf = TestUtils.GetTagStreamText(repo2, 0);
                    Assert.AreEqual("0 @R2@ REPO\r\n" +
                                    "1 NAME Test Repository\r\n" +
                                    "1 ADDR\r\n" +
                                    "2 ADR1 AdrLine1\r\n", buf);
                }

                using (GDMRepositoryRecord repo3 = new GDMRepositoryRecord(tree)) {
                    repo3.InitNew();

                    var matchParams = new MatchParams();
                    matchParams.NamesIndistinctThreshold = 100.0f;

                    Assert.AreEqual(0.0f, repoRec.IsMatch(null, matchParams));

                    repo3.RepositoryName = "Test Repository";
                    Assert.AreEqual(100.0f, repoRec.IsMatch(repo3, matchParams));

                    repo3.RepositoryName = "test";
                    Assert.AreEqual(0.0f, repoRec.IsMatch(repo3, matchParams));
                }

                repoRec.ReplaceXRefs(new GDMXRefReplacer());

                Assert.IsFalse(repoRec.IsEmpty());
                repoRec.Clear();
                Assert.IsTrue(repoRec.IsEmpty());
            }
        }
Exemplo n.º 4
0
        // TODO: connect to use
        public override float IsMatch(GDMTag tag, MatchParams matchParams)
        {
            GDMRepositoryRecord otherRep = tag as GDMRepositoryRecord;

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

            float match = GetStrMatch(RepositoryName, otherRep.RepositoryName, matchParams);

            return(match);
        }
Exemplo n.º 5
0
        public GDMRepositoryCitation AddRepository(GDMRepositoryRecord repRec)
        {
            GDMRepositoryCitation cit = null;

            if (repRec != null)
            {
                cit       = new GDMRepositoryCitation(this);
                cit.Value = repRec;
                fRepositoryCitations.Add(cit);
            }

            return(cit);
        }
Exemplo n.º 6
0
        public GDMRepositoryCitation AddRepository(GDMRepositoryRecord repRec)
        {
            GDMRepositoryCitation cit = null;

            if (repRec != null)
            {
                cit      = new GDMRepositoryCitation();
                cit.XRef = repRec.XRef;
                fRepositoryCitations.Add(cit);
            }

            return(cit);
        }
Exemplo n.º 7
0
        public override void Assign(GDMTag source)
        {
            GDMRepositoryRecord otherRepo = (source as GDMRepositoryRecord);

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

            base.Assign(otherRepo);

            fAddress.Assign(otherRepo.fAddress);
            fRepositoryName = otherRepo.fRepositoryName;
        }
Exemplo n.º 8
0
        public void RemoveRepository(GDMRepositoryRecord repRec)
        {
            if (repRec == null)
            {
                throw new ArgumentNullException("repRec");
            }

            foreach (GDMRepositoryCitation repCit in fRepositoryCitations)
            {
                if (repCit.XRef == repRec.XRef)
                {
                    fRepositoryCitations.Delete(repCit);
                    break;
                }
            }
        }
Exemplo n.º 9
0
        public void Test_Common()
        {
            // check match
            using (GDMSourceRecord src1 = new GDMSourceRecord(fContext.Tree)) {
                Assert.IsNotNull(src1, "src1 != null");

                Assert.Throws(typeof(ArgumentNullException), () => {
                    src1.RemoveRepository(null);
                });

                using (GDMSourceRecord src2 = new GDMSourceRecord(fContext.Tree)) {
                    Assert.IsNotNull(src2, "src2 != null");

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

                    // empty records
                    Assert.AreEqual(100.0f, src1.IsMatch(src2, new MatchParams()));

                    // filled records
                    src1.ShortTitle = "test source";
                    src2.ShortTitle = "test source";
                    Assert.AreEqual(100.0f, src1.IsMatch(src2, new MatchParams()));
                }

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

            // check move
            using (GDMSourceRecord src1 = new GDMSourceRecord(fContext.Tree)) {
                Assert.Throws(typeof(ArgumentException), () => {
                    src1.MoveTo(null, false);
                });

                // fill the record
                src1.ShortTitle             = "test source";
                src1.Title.Lines.Text       = ("test title");
                src1.Originator.Lines.Text  = ("test author");
                src1.Publication.Lines.Text = ("test publ");
                src1.Text.Lines.Text        = ("test text");

                Assert.AreEqual("test source", src1.ShortTitle);
                Assert.AreEqual("test title", src1.Title.Lines.Text);
                Assert.AreEqual("test author", src1.Originator.Lines.Text);
                Assert.AreEqual("test publ", src1.Publication.Lines.Text);
                Assert.AreEqual("test text", src1.Text.Lines.Text);

                src1.ReplaceXRefs(new GDMXRefReplacer());

                GDMRepositoryRecord repRec = fContext.Tree.CreateRepository();
                repRec.RepositoryName = "test repository";
                src1.AddRepository(repRec);
                Assert.AreEqual(1, src1.RepositoryCitations.Count);

                using (GDMSourceRecord src2 = new GDMSourceRecord(fContext.Tree)) {
                    src2.ShortTitle = "test source 2"; // title isn't replaced

                    Assert.AreEqual(0, src2.RepositoryCitations.Count);

                    src1.MoveTo(src2, false);

                    Assert.AreEqual("test source 2", src2.ShortTitle);

                    Assert.AreEqual("test title", src2.Title.Lines.Text);
                    Assert.AreEqual("test author", src2.Originator.Lines.Text);
                    Assert.AreEqual("test publ", src2.Publication.Lines.Text);
                    Assert.AreEqual("test text", src2.Text.Lines.Text);

                    Assert.AreEqual(1, src2.RepositoryCitations.Count);
                }
            }
        }
Exemplo n.º 10
0
        private static void GEDCOMRepositoryCitationTest(GDMSourceRecord sourRec, GDMRepositoryRecord repRec)
        {
            GDMRepositoryCitation repCit = sourRec.AddRepository(repRec);

            Assert.IsFalse(repCit.IsEmpty(), "repCit.IsEmpty()"); // its pointer
        }
Exemplo n.º 11
0
        public void Test_Common2()
        {
            GDMSourceRecord     sourRec = fContext.Tree.CreateSource();
            GDMIndividualRecord indiv   = fContext.Tree.CreateIndividual();
            GDMRepositoryRecord repRec  = fContext.Tree.CreateRepository();

            Assert.IsNotNull(sourRec.Data);

            sourRec.ShortTitle = "This is test source";
            Assert.AreEqual("This is test source", sourRec.ShortTitle);

            //
            sourRec.Originator.Lines.Text = ("author");
            Assert.AreEqual("author", sourRec.Originator.Lines.Text);

            sourRec.Title.Lines.Text = ("title");
            Assert.AreEqual("title", sourRec.Title.Lines.Text);

            sourRec.Publication.Lines.Text = ("publication");
            Assert.AreEqual("publication", sourRec.Publication.Lines.Text);

            sourRec.Text.Lines.Text = ("sample");
            Assert.AreEqual("sample", sourRec.Text.Lines.Text);

            //
            sourRec.SetOriginatorArray(new string[] { "author1", "author2", "author3", "author4" });
            Assert.AreEqual("author1\r\nauthor2\r\nauthor3\r\nauthor4", sourRec.Originator.Lines.Text);

            sourRec.SetTitleArray(new string[] { "title" });
            Assert.AreEqual("title", sourRec.Title.Lines.Text);

            sourRec.SetPublicationArray(new string[] { "publication" });
            Assert.AreEqual("publication", sourRec.Publication.Lines.Text);

            sourRec.SetTextArray(new string[] { "sample" });
            Assert.AreEqual("sample", sourRec.Text.Lines.Text);

            //
            GEDCOMRepositoryCitationTest(sourRec, repRec);

            using (GDMSourceRecord sour2 = fContext.Tree.CreateSource()) {
                Assert.Throws(typeof(ArgumentException), () => {
                    sour2.Assign(null);
                });

                sour2.Assign(sourRec);

                string buf = TestUtils.GetTagStreamText(sour2, 0);
                Assert.AreEqual("0 @S2@ SOUR\r\n" +
                                "1 TITL title\r\n" +
                                "1 PUBL publication\r\n" +
                                "1 ABBR This is test source\r\n" +
                                "1 REPO @R2@\r\n" +
                                "1 AUTH author1\r\n" +
                                "2 CONT author2\r\n" +
                                "2 CONT author3\r\n" +
                                "2 CONT author4\r\n" +
                                "1 TEXT sample\r\n", buf);
            }

            sourRec.ReplaceXRefs(new GDMXRefReplacer());

            Assert.IsFalse(sourRec.IsEmpty());
            sourRec.Clear();
            Assert.IsTrue(sourRec.IsEmpty());
        }
Exemplo n.º 12
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);
            }
        }