public void BulkDataRead() { File.WriteAllText("test.txt", "xxx!"); var path = Path.GetFullPath("test.txt"); var bulkData = new BulkDataUriByteBuffer("file:" + path); Assert.Throws <InvalidOperationException>(() => bulkData.Data); Assert.Throws <InvalidOperationException>(() => bulkData.Size); var target = new DicomDataset { new DicomOtherWord(DicomTag.PixelData, bulkData) }; var json = JsonConvert.SerializeObject(target, Formatting.Indented, new JsonDicomConverter()); var reconstituated = JsonConvert.DeserializeObject <DicomDataset>(json, new JsonDicomConverter()); var json2 = JsonConvert.SerializeObject(reconstituated, Formatting.Indented, new JsonDicomConverter()); Assert.Equal(json, json2); DownloadBulkData(reconstituated.Get <BulkDataUriByteBuffer>(DicomTag.PixelData)); DownloadBulkData(bulkData); Assert.True(ValueEquals(target, reconstituated)); byte[] expectedPixelData = File.ReadAllBytes("test.txt"); File.Delete("test.txt"); Assert.Equal(target.Get <IByteBuffer>(DicomTag.PixelData).Size, (uint)expectedPixelData.Length); Assert.True(target.Get <byte[]>(DicomTag.PixelData).SequenceEqual(expectedPixelData)); Assert.Equal(reconstituated.Get <IByteBuffer>(DicomTag.PixelData).Size, (uint)expectedPixelData.Length); Assert.True(reconstituated.Get <byte[]>(DicomTag.PixelData).SequenceEqual(expectedPixelData)); }
private void DownloadBulkData(BulkDataUriByteBuffer bulkData) { var request = WebRequest.Create(bulkData.BulkDataUri); using (var response = request.GetResponse()) using (var responseStream = response.GetResponseStream()) { bulkData.Data = new byte[response.ContentLength]; responseStream.Read(bulkData.Data, 0, (int)response.ContentLength); } }
private static IBulkDataUriByteBuffer ReadJsonBulkDataUri(JsonReader reader) { reader.Read(); if (reader.TokenType != JsonToken.String) { throw new JsonReaderException("Malformed DICOM json"); } var data = new BulkDataUriByteBuffer((string)reader.Value); reader.Read(); return(data); }
public static IEnumerable <FileToStore> FillDataWithBlobDataUris(DicomDataset dataset, IEnumerable <string> files) { var result = new List <FileToStore>(); foreach (var enumerateFile in files) { var uri = $"urn:uuid:{Guid.NewGuid()}"; var bulkDataUri = new BulkDataUriByteBuffer(uri); var pixelData = new DicomOtherWord(DicomTag.PixelData, bulkDataUri); dataset.AddOrUpdate(pixelData); result.Add(new FileToStore { ContentLocaltionHeader = uri, FilePath = enumerateFile, Metadata = new DicomDataset(dataset) }); } return(result); }
public void BulkDataRead() { File.WriteAllText("test.txt", "xxx!"); var path = Path.GetFullPath("test.txt"); var bulkData = new BulkDataUriByteBuffer("file:" + path); Assert.Throws<InvalidOperationException>(() => bulkData.Data); Assert.Throws<InvalidOperationException>(() => bulkData.Size); var target = new DicomDataset { new DicomOtherWord(DicomTag.PixelData, bulkData) }; var json = JsonConvert.SerializeObject(target, Formatting.Indented, new JsonDicomConverter()); var reconstituated = JsonConvert.DeserializeObject<DicomDataset>(json, new JsonDicomConverter()); Console.WriteLine(json); var json2 = JsonConvert.SerializeObject(reconstituated, Formatting.Indented, new JsonDicomConverter()); Assert.Equal(json, json2); DownloadBulkData(reconstituated.Get<BulkDataUriByteBuffer>(DicomTag.PixelData)); DownloadBulkData(bulkData); Assert.True(ValueEquals(target, reconstituated)); byte[] expectedPixelData = File.ReadAllBytes("test.txt"); File.Delete("test.txt"); Assert.Equal(target.Get<IByteBuffer>(DicomTag.PixelData).Size, (uint)expectedPixelData.Length); Assert.True(target.Get<byte[]>(DicomTag.PixelData).SequenceEqual(expectedPixelData)); Assert.Equal(reconstituated.Get<IByteBuffer>(DicomTag.PixelData).Size, (uint)expectedPixelData.Length); Assert.True(reconstituated.Get<byte[]>(DicomTag.PixelData).SequenceEqual(expectedPixelData)); }