public bool DeleteCommunicationRecord(GDMCommunicationRecord commRec) { if (commRec == null) { return(false); } int num = fRecords.Count; for (int i = 0; i < num; i++) { GDMRecord rec = fRecords[i]; if (rec.RecordType == GDMRecordType.rtResearch) { GDMResearchRecord resRec = (GDMResearchRecord)rec; for (int j = resRec.Communications.Count - 1; j >= 0; j--) { if (resRec.Communications[j].Value == commRec) { resRec.Communications.DeleteAt(j); } } } } DeleteRecord(commRec); return(true); }
public void RemoveCommunication(GDMCommunicationRecord commRecord) { if (commRecord == null) { return; } fCommunications.DeleteAt(IndexOfCommunication(commRecord)); }
public GDMCommunicationRecord CreateCommunication() { GDMCommunicationRecord result = new GDMCommunicationRecord(this); result.InitNew(); result.ChangeDate.ChangeDateTime = DateTime.Now; AddRecord(result); return(result); }
public bool AddCommunication(GDMCommunicationRecord commRecord) { bool result = false; if (commRecord != null) { GDMPointer ptr = new GDMPointer((int)GEDCOMTagType._COMM, string.Empty); ptr.XRef = commRecord.XRef; fCommunications.Add(ptr); result = true; } return(result); }
public override void Assign(GDMTag source) { GDMCommunicationRecord otherComm = (source as GDMCommunicationRecord); if (otherComm == null) { throw new ArgumentException(@"Argument is null or wrong type", "source"); } base.Assign(otherComm); fCommName = otherComm.fCommName; fCommunicationType = otherComm.fCommunicationType; fDate.Assign(otherComm.fDate); fCorresponder.Assign(otherComm.fCorresponder); }
public void Test_Common() { GDMIndividualRecord iRec = fContext.Tree.CreateIndividual(); Assert.IsNotNull(iRec); using (GDMCommunicationRecord comRec = fContext.Tree.CreateCommunication()) { comRec.CommName = "Test Communication"; Assert.AreEqual("Test Communication", comRec.CommName); comRec.CommunicationType = GDMCommunicationType.ctFax; Assert.AreEqual(GDMCommunicationType.ctFax, comRec.CommunicationType); comRec.Date.Date = TestUtils.ParseDT("23.01.2013"); Assert.AreEqual(TestUtils.ParseDT("23.01.2013"), comRec.Date.Date); comRec.SetCorresponder(GDMCommunicationDir.cdFrom, iRec); Assert.AreEqual(GDMCommunicationDir.cdFrom, comRec.CommDirection); Assert.AreEqual(iRec, fContext.Tree.GetPtrValue <GDMRecord>(comRec.Corresponder)); comRec.SetCorresponder(GDMCommunicationDir.cdTo, iRec); Assert.AreEqual(GDMCommunicationDir.cdTo, comRec.CommDirection); Assert.AreEqual(iRec, fContext.Tree.GetPtrValue <GDMRecord>(comRec.Corresponder)); using (GDMCommunicationRecord comm2 = fContext.Tree.CreateCommunication()) { Assert.Throws(typeof(ArgumentException), () => { comm2.Assign(null); }); comm2.Assign(comRec); string buf = TestUtils.GetTagStreamText(comm2, 0); Assert.AreEqual("0 @CM2@ _COMM\r\n" + "1 DATE 23 JAN 2013\r\n" + "1 NAME Test Communication\r\n" + "1 TYPE fax\r\n" + "1 TO @I1@\r\n", buf); } comRec.ReplaceXRefs(new GDMXRefReplacer()); Assert.IsFalse(comRec.IsEmpty()); comRec.Clear(); Assert.IsTrue(comRec.IsEmpty()); } }
public int IndexOfCommunication(GDMCommunicationRecord commRec) { int result = -1; if (commRec != null) { int num = fCommunications.Count; for (int i = 0; i < num; i++) { if (fCommunications[i].XRef == commRec.XRef) { result = i; break; } } } return(result); }
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); } }
public void Test_GEDCOMResearchRecord() { GDMCommunicationRecord commRec = fContext.Tree.CreateCommunication(); Assert.IsNotNull(commRec); GDMTaskRecord taskRec = fContext.Tree.CreateTask(); Assert.IsNotNull(taskRec); GDMGroupRecord groupRec = fContext.Tree.CreateGroup(); Assert.IsNotNull(groupRec); using (GDMResearchRecord resRec = fContext.Tree.CreateResearch()) { resRec.ResetOwner(fContext.Tree); Assert.AreEqual(fContext.Tree, resRec.GetTree()); Assert.IsNotNull(resRec.Communications); Assert.IsNotNull(resRec.Groups); Assert.IsNotNull(resRec.Tasks); resRec.ResearchName = "Test Research"; Assert.AreEqual("Test Research", resRec.ResearchName); resRec.Priority = GDMResearchPriority.rpNormal; Assert.AreEqual(GDMResearchPriority.rpNormal, resRec.Priority); resRec.Status = GDMResearchStatus.rsOnHold; Assert.AreEqual(GDMResearchStatus.rsOnHold, resRec.Status); resRec.StartDate.Date = TestUtils.ParseDT("20.01.2013"); Assert.AreEqual(TestUtils.ParseDT("20.01.2013"), resRec.StartDate.Date); resRec.StopDate.Date = TestUtils.ParseDT("21.01.2013"); Assert.AreEqual(TestUtils.ParseDT("21.01.2013"), resRec.StopDate.Date); resRec.Percent = 33; Assert.AreEqual(33, resRec.Percent); Assert.Throws(typeof(ArgumentException), () => { resRec.Assign(null); }); string buf = TestUtils.GetTagStreamText(resRec, 0); Assert.AreEqual("0 @RS2@ _RESEARCH\r\n" + "1 _STARTDATE 20 JAN 2013\r\n" + "1 _STOPDATE 21 JAN 2013\r\n" + "1 NAME Test Research\r\n" + "1 _PRIORITY normal\r\n" + "1 _STATUS onhold\r\n" + "1 _PERCENT 33\r\n", buf); Assert.AreEqual(-1, resRec.IndexOfCommunication(null)); resRec.AddCommunication(commRec); resRec.RemoveCommunication(commRec); resRec.RemoveCommunication(null); Assert.AreEqual(-1, resRec.IndexOfTask(null)); resRec.AddTask(taskRec); resRec.RemoveTask(taskRec); resRec.RemoveTask(null); Assert.AreEqual(-1, resRec.IndexOfGroup(null)); resRec.AddGroup(groupRec); resRec.RemoveGroup(groupRec); resRec.RemoveGroup(null); resRec.ReplaceXRefs(new GDMXRefReplacer()); Assert.IsFalse(resRec.IsEmpty()); resRec.Clear(); Assert.IsTrue(resRec.IsEmpty()); } }