public GDMMultimediaLink SetPrimaryMultimediaLink(GDMMultimediaRecord mediaRec) { if (mediaRec == null) { return(null); } GDMMultimediaLink mmLink = null; int num = MultimediaLinks.Count; for (int i = 0; i < num; i++) { GDMMultimediaLink lnk = MultimediaLinks[i]; if (lnk.Value == mediaRec) { mmLink = lnk; break; } } if (mmLink == null) { mmLink = this.AddMultimedia(mediaRec); } mmLink.IsPrimary = true; return(mmLink); }
public string GetUID() { string result = null; try { if (Value != null) { ExtRect cutoutArea; if (IsPrimaryCutout) { cutoutArea = CutoutPosition.Value; } else { cutoutArea = ExtRect.CreateEmpty(); } GDMMultimediaRecord mmRec = (GDMMultimediaRecord)Value; result = mmRec.UID + "-" + GKUtils.GetRectUID(cutoutArea.Left, cutoutArea.Top, cutoutArea.Right, cutoutArea.Bottom); } } catch (Exception ex) { Logger.WriteError("GDMMultimediaLink.GetUID()", ex); result = null; } return(result); }
public bool DeleteMediaRecord(GDMMultimediaRecord mRec) { if (mRec == null) { return(false); } int num = fRecords.Count; for (int i = 0; i < num; i++) { GDMRecord rec = fRecords[i]; if (!rec.HasMultimediaLinks) { continue; } for (int j = rec.MultimediaLinks.Count - 1; j >= 0; j--) { if (rec.MultimediaLinks[j].XRef == mRec.XRef) { rec.MultimediaLinks.DeleteAt(j); } } } DeleteRecord(mRec); return(true); }
private static void GEDCOMMultimediaLinkTest(GDMMultimediaRecord mediaRec, GDMIndividualRecord indiv) { GDMMultimediaLink mmLink = indiv.AddMultimedia(mediaRec); Assert.IsNotNull(mmLink.FileReferences); mmLink.Title = "Title1"; Assert.AreEqual("Title1", mmLink.Title); string buf = TestUtils.GetTagStreamText(mmLink, 1); Assert.AreEqual("1 OBJE @O2@\r\n" + "2 TITL Title1\r\n", buf); mmLink.ReplaceXRefs(new GDMXRefReplacer()); Assert.IsTrue(mmLink.IsPointer, "mmLink.IsPointer"); mmLink.IsPrimary = true; Assert.IsTrue(mmLink.IsPrimary, "mmLink.IsPrimary"); Assert.IsFalse(mmLink.IsEmpty(), "mmLink.IsEmpty()"); // its pointer mmLink.Clear(); }
public void Test_GEDCOMMultimediaLink() { var iRec = new GDMIndividualRecord(fContext.Tree); using (GDMMultimediaLink mmLink = new GDMMultimediaLink()) { Assert.IsNotNull(mmLink); Assert.IsTrue(mmLink.IsEmpty()); // extensions Assert.IsFalse(mmLink.IsPrimaryCutout); mmLink.IsPrimaryCutout = true; Assert.IsTrue(mmLink.IsPrimaryCutout); mmLink.CutoutPosition.Value = ExtRect.Create(10, 15, 500, 600); ExtRect rt = mmLink.CutoutPosition.Value; Assert.AreEqual(10, rt.Left); Assert.AreEqual(15, rt.Top); Assert.AreEqual(500, rt.Right); Assert.AreEqual(600, rt.Bottom); Assert.AreEqual(10, mmLink.CutoutPosition.X1); Assert.AreEqual(15, mmLink.CutoutPosition.Y1); Assert.AreEqual(500, mmLink.CutoutPosition.X2); Assert.AreEqual(600, mmLink.CutoutPosition.Y2); mmLink.CutoutPosition.X1 = 10; mmLink.CutoutPosition.Y1 = 10; mmLink.CutoutPosition.X2 = 300; mmLink.CutoutPosition.Y2 = 400; Assert.AreEqual(10, mmLink.CutoutPosition.X1); Assert.AreEqual(10, mmLink.CutoutPosition.Y1); Assert.AreEqual(300, mmLink.CutoutPosition.X2); Assert.AreEqual(400, mmLink.CutoutPosition.Y2); mmLink.CutoutPosition.ParseString("11 15 576 611"); Assert.IsFalse(mmLink.CutoutPosition.IsEmpty()); Assert.AreEqual("11 15 576 611", mmLink.CutoutPosition.StringValue); Assert.Throws(typeof(ArgumentException), () => { mmLink.Assign(null); }); using (var mmRec = new GDMMultimediaRecord(fContext.Tree)) { fContext.Tree.NewXRef(mmRec); Assert.IsNull(mmLink.GetUID(fContext.Tree)); mmLink.XRef = mmRec.XRef; Assert.IsNotNull(mmLink.GetUID(fContext.Tree)); } mmLink.CutoutPosition.Clear(); Assert.IsTrue(mmLink.CutoutPosition.IsEmpty()); Assert.AreEqual("", mmLink.CutoutPosition.StringValue); } }
public GDMMultimediaRecord CreateMultimedia() { GDMMultimediaRecord result = new GDMMultimediaRecord(this); result.InitNew(); result.ChangeDate.ChangeDateTime = DateTime.Now; AddRecord(result); return(result); }
public void Test_Common() { GDMIndividualRecord indiv = fContext.Tree.CreateIndividual(); using (GDMMultimediaRecord mediaRec = fContext.Tree.CreateMultimedia()) { Assert.IsNotNull(mediaRec); mediaRec.ResetOwner(fContext.Tree); Assert.AreEqual(fContext.Tree, mediaRec.GetTree()); Assert.AreEqual("", mediaRec.GetFileTitle()); mediaRec.FileReferences.Add(new GDMFileReferenceWithTitle(mediaRec)); GDMFileReferenceWithTitle fileRef = mediaRec.FileReferences[0]; Assert.IsNotNull(fileRef); fileRef.Title = "File Title 2"; Assert.AreEqual("File Title 2", fileRef.Title); fileRef.LinkFile("sample.png"); fileRef.MediaType = GDMMediaType.mtManuscript; Assert.AreEqual("sample.png", fileRef.StringValue); Assert.AreEqual(GDMMultimediaFormat.mfPNG, fileRef.MultimediaFormat); Assert.AreEqual(GDMMediaType.mtManuscript, fileRef.MediaType); string title = mediaRec.GetFileTitle(); Assert.AreEqual("File Title 2", title); using (GDMMultimediaRecord media2 = fContext.Tree.CreateMultimedia()) { Assert.Throws(typeof(ArgumentException), () => { media2.Assign(null); }); media2.Assign(mediaRec); string buf = TestUtils.GetTagStreamText(media2, 0); Assert.AreEqual("0 @O3@ OBJE\r\n" + "1 FILE sample.png\r\n" + "2 FORM png\r\n" + "3 TYPE manuscript\r\n" + "2 TITL File Title 2\r\n", buf); } mediaRec.ReplaceXRefs(new GDMXRefReplacer()); GEDCOMMultimediaLinkTest(mediaRec, indiv); Assert.IsFalse(mediaRec.IsEmpty()); mediaRec.Clear(); Assert.IsTrue(mediaRec.IsEmpty()); } }
public GDMMultimediaLink AddMultimedia(GDMMultimediaRecord mediaRec) { GDMMultimediaLink mmLink = null; if (mediaRec != null) { mmLink = new GDMMultimediaLink(this); mmLink.Value = mediaRec; fMultimediaLinks.Add(mmLink); } return(mmLink); }
public override void Assign(GDMTag source) { GDMMultimediaRecord sourceObj = source as GDMMultimediaRecord; if (sourceObj == null) { throw new ArgumentException(@"Argument is null or wrong type", "source"); } base.Assign(sourceObj); AssignList(sourceObj.fFileReferences, fFileReferences); }
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_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()); }