示例#1
0
        public bool DeleteLocationRecord(GDMLocationRecord locRec)
        {
            if (locRec == null)
            {
                return(false);
            }

            int num = fRecords.Count;

            for (int i = 0; i < num; i++)
            {
                var evsRec = fRecords[i] as GDMRecordWithEvents;
                if (evsRec != null)
                {
                    for (int j = evsRec.Events.Count - 1; j >= 0; j--)
                    {
                        GDMCustomEvent ev = evsRec.Events[j];

                        if (ev.Place.Location.Value == locRec)
                        {
                            ev.Place.DeleteTag(GEDCOMTagName._LOC);
                        }
                    }
                }
            }

            DeleteRecord(locRec);
            return(true);
        }
示例#2
0
        public void RenameLocationRecord(GDMLocationRecord locRec)
        {
            if (locRec == null)
            {
                return;
            }

            int num = fRecords.Count;

            for (int i = 0; i < num; i++)
            {
                var evsRec = fRecords[i] as GDMRecordWithEvents;
                if (evsRec == null || !evsRec.HasEvents)
                {
                    continue;
                }

                for (int j = evsRec.Events.Count - 1; j >= 0; j--)
                {
                    var evt = evsRec.Events[j];
                    if (!evt.HasPlace)
                    {
                        continue;
                    }

                    GDMPlace evPlace = evt.Place;
                    if (evPlace.Location.XRef == locRec.XRef)
                    {
                        evPlace.StringValue = locRec.LocationName;
                    }
                }
            }
        }
示例#3
0
        public bool DeleteLocationRecord(GDMLocationRecord locRec)
        {
            if (locRec == null)
            {
                return(false);
            }

            int num = fRecords.Count;

            for (int i = 0; i < num; i++)
            {
                var evsRec = fRecords[i] as GDMRecordWithEvents;
                if (evsRec != null)
                {
                    for (int j = evsRec.Events.Count - 1; j >= 0; j--)
                    {
                        GDMPointer evLocation = evsRec.Events[j].Place.Location;

                        if (evLocation.XRef == locRec.XRef)
                        {
                            evLocation.XRef = string.Empty;
                        }
                    }
                }
            }

            DeleteRecord(locRec);
            return(true);
        }
示例#4
0
        public void RenameLocationRecord(GDMLocationRecord locRec)
        {
            if (locRec == null)
            {
                return;
            }

            int num = fRecords.Count;

            for (int i = 0; i < num; i++)
            {
                var evsRec = fRecords[i] as GDMRecordWithEvents;
                if (evsRec != null)
                {
                    for (int j = evsRec.Events.Count - 1; j >= 0; j--)
                    {
                        GDMPlace evPlace = evsRec.Events[j].Place;

                        if (evPlace.Location.Value == locRec)
                        {
                            evPlace.StringValue = locRec.LocationName;
                        }
                    }
                }
            }
        }
示例#5
0
        public void Test_MoveTo1()
        {
            GDMRecord     other    = new GDMLocationRecord(null);
            GDMNoteRecord instance = new GDMNoteRecord(null);

            Assert.Throws(typeof(ArgumentException), () => {
                instance.MoveTo(other);
            });
        }
示例#6
0
        public GDMLocationRecord CreateLocation()
        {
            GDMLocationRecord result = new GDMLocationRecord(this);

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

            AddRecord(result);
            return(result);
        }
示例#7
0
        // TODO: connect to use
        public override float IsMatch(GDMTag tag, MatchParams matchParams)
        {
            GDMLocationRecord otherLoc = tag as GDMLocationRecord;

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

            float match = GetStrMatch(LocationName, otherLoc.LocationName, matchParams);

            return(match);
        }
示例#8
0
        public override void Assign(GDMTag source)
        {
            GDMLocationRecord otherLoc = (source as GDMLocationRecord);

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

            base.Assign(otherLoc);

            fLocationName = otherLoc.fLocationName;
            fMap.Assign(otherLoc.fMap);
        }
        public void Test_Common()
        {
            using (GDMLocationRecord locRec = fContext.Tree.CreateLocation()) {
                locRec.LocationName = "Test Location";
                Assert.AreEqual("Test Location", locRec.LocationName);

                Assert.IsNotNull(locRec.Map);
                locRec.Map.Lati = 5.111111;
                locRec.Map.Long = 7.999999;

                using (GDMLocationRecord loc3 = fContext.Tree.CreateLocation()) {
                    var matchParams = new MatchParams();
                    matchParams.NamesIndistinctThreshold = 100.0f;

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

                    loc3.LocationName = "Test Location";
                    Assert.AreEqual(100.0f, locRec.IsMatch(loc3, matchParams));

                    loc3.LocationName = "test";
                    Assert.AreEqual(0.0f, locRec.IsMatch(loc3, matchParams));
                }

                using (GDMLocationRecord loc2 = fContext.Tree.CreateLocation()) {
                    Assert.Throws(typeof(ArgumentException), () => {
                        loc2.Assign(null);
                    });

                    loc2.Assign(locRec);

                    string buf = TestUtils.GetTagStreamText(loc2, 0);
                    Assert.AreEqual("0 @L3@ _LOC\r\n" +
                                    "1 MAP\r\n" +
                                    "2 LATI 5.111111\r\n" +
                                    "2 LONG 7.999999\r\n" +
                                    "1 NAME Test Location\r\n", buf);
                }

                locRec.ReplaceXRefs(new GDMXRefReplacer());

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

                string buf1 = TestUtils.GetTagStreamText(locRec, 0);
                Assert.AreEqual("0 @L1@ _LOC\r\n", buf1);
            }
        }
示例#10
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);
            }
        }