public void ReadWriteDIMSETest() { using (var stream = new MemoryStream()) { //Generate a DIMSE var dimse = CFind.CreateStudyQuery("123456"); var pContext = new PresentationContext() { AbstractSyntax = AbstractSyntax.STUDY_FIND, TransferSyntaxes = new List <string>() { TransferSyntaxHelper.IMPLICIT_VR_LITTLE_ENDIAN } }; PDataMessenger.WriteDimseToStream(dimse, stream, pContext); //Wrap stream in buffer to get to network stream using (var bs = new BufferedStream(stream)) { bs.Position = 0; var net = new NetworkBinaryReader(bs); var pdata = PDataProcessor.ReadPDataTFs(net); var dcm = PDataProcessor.GetCommandObject(pdata); AbstractDIMSE dimseRead; var success = DIMSEReader.TryReadDIMSE(dcm, out dimseRead); Assert.AreEqual(dimse.Elements.Count, dimseRead.Elements.Count); for (int i = 0; i < dimse.Elements.Count; i++) { var el1 = dimse.Elements[i]; var el2 = dimseRead.Elements[i]; Assert.AreEqual(el1.Tag, el2.Tag); Assert.AreEqual(el1.DData, el2.DData); } //Make sure this DIMSE was written with data Assert.IsTrue(dimse.HasData); //REad the data var dataPds = PDataProcessor.ReadPDataTFs(net); var data = PDataProcessor.GetDataObject(dataPds, TransferSyntax.IMPLICIT_VR_LITTLE_ENDIAN); DICOMAssert.AreEqual(data, dimse.Data); } } }
private static AbstractDIMSE ProcessCommand(List<PDataTF> pDatas, Association asc) { var dcm = GetCommandObject(pDatas); AbstractDIMSE dimse; var success = DIMSEReader.TryReadDIMSE(dcm, out dimse); if (!success) asc.Logger.Log("DIMSE could not be read!"); if (dimse.HasData) { var dr = asc.Reader; var dataPds = ReadPDataTFs(dr); int id; var txSyntax = GetTransferSyntax(asc, dataPds, out id); dimse.DataPresentationContextId = id; dimse.Data = GetDataObject(dataPds, txSyntax); } DIMSEProcessor.Process(dimse, asc); return dimse; }