private void button1_Click(object sender, EventArgs e) { for (int i = 0; i < 100; i++) { Thread t = new Thread(delegate(object parm) { StreamingClient client = new StreamingClient(new Uri("http://localhost:1000/wado")); do { Stream image = client.RetrieveImage("ImageServer", "1.2.840.113619.2.5.1762583153.215519.978957063.78", "1.2.840.113619.2.5.1762583153.215519.978957063.79", "1.2.840.113619.2.5.1762583153.215519.978957063.89" ); } while (true); }); t.Start(); } }
public void GetStudy(string studyInstanceUid, Uri baseUri, string serverAE, bool singleImage) { Console.WriteLine("[{0}] : Loading {1}", _id, studyInstanceUid); string uri = String.Format("http://{0}:{1}/HeaderStreaming/HeaderStreaming", "localhost", 50221); EndpointAddress endpoint = new EndpointAddress(uri); BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.None); binding.TransferMode = TransferMode.Streamed; binding.MessageEncoding = WSMessageEncoding.Mtom; binding.MaxReceivedMessageSize = Int32.MaxValue; binding.TextEncoding = Encoding.UTF8; HeaderStreamingServiceClient headerClient = new HeaderStreamingServiceClient(binding, endpoint); using (headerClient) { HeaderStreamingParameters parms = new HeaderStreamingParameters(); parms.StudyInstanceUID = studyInstanceUid; parms.ReferenceID = Guid.NewGuid().ToString(); parms.ServerAETitle = "ImageServer"; Stream stream = headerClient.GetStudyHeader("TEST", parms); XmlDocument doc = new XmlDocument(); StudyXmlIo.ReadGzip(doc, stream); _studyXml = new StudyXml(studyInstanceUid); _studyXml.SetMemento(doc); stream.Close(); headerClient.Close(); } if (singleImage) { ulong size = 0; StreamingClient client = new StreamingClient(baseUri); foreach (SeriesXml series in _studyXml) { foreach (InstanceXml instance in series) { do { Stream image = client.RetrieveImage(serverAE, studyInstanceUid, series.SeriesInstanceUid, instance.SopInstanceUid); byte[] buffer = new byte[image.Length]; image.Read(buffer, 0, buffer.Length); image.Close(); Console.Write("."); } while (true); } Console.WriteLine("\n[{0}] : Finish Loading {1} [{2}]", _id, studyInstanceUid, ByteCountFormatter.Format(size)); } } else { Random ran = new Random(); do { ulong size = 0; StreamingClient client = new StreamingClient(baseUri); foreach (SeriesXml series in _studyXml) { foreach (InstanceXml instance in series) { Stream image = client.RetrieveImage(serverAE, studyInstanceUid, series.SeriesInstanceUid, instance.SopInstanceUid); byte[] buffer = new byte[image.Length]; image.Read(buffer, 0, buffer.Length); image.Close(); size += (ulong)buffer.Length; Console.Write("."); } Console.WriteLine("\n[{0}] : Finish Loading {1} [{2}]", _id, studyInstanceUid, ByteCountFormatter.Format(size)); } Thread.Sleep(ran.Next(1000, 5000)); } while (true); } }
private static void RetrieveImages(string serverAE, string studyPath) { Console.WriteLine("server={0}", serverAE); string baseUri = String.Format("http://{0}:{1}", serverHost, serverPort); StreamingClient client = new StreamingClient(new Uri(baseUri)); int totalFrameCount = 0; DirectoryInfo directoryInfo = new DirectoryInfo(studyPath); string studyUid = directoryInfo.Name; RateStatistics frameRate = new RateStatistics("Speed", "frame"); RateStatistics speed = new RateStatistics("Speed", RateType.BYTES); AverageRateStatistics averageSpeed = new AverageRateStatistics(RateType.BYTES); ByteCountStatistics totalSize = new ByteCountStatistics("Size"); frameRate.Start(); speed.Start(); Console.WriteLine("\n------------------------------------------------------------------------------------------------------------------------"); string[] seriesDirs = Directory.GetDirectories(studyPath); foreach (string seriesPath in seriesDirs) { DirectoryInfo dirInfo = new DirectoryInfo(seriesPath); string seriesUid = dirInfo.Name; string[] objectUidPath = Directory.GetFiles(seriesPath, "*.dcm"); foreach (string uidPath in objectUidPath) { FileInfo fileInfo = new FileInfo(uidPath); string uid = fileInfo.Name.Replace(".dcm", ""); Console.Write("{0,-64}... ", uid); try { Stream imageStream; StreamingResultMetaData imageMetaData; FrameStreamingResultMetaData frameMetaData; switch (type) { case ContentTypes.Dicom: imageStream = client.RetrieveImage(serverAE, studyUid, seriesUid, uid, out imageMetaData); totalFrameCount++; averageSpeed.AddSample(imageMetaData.Speed); totalSize.Value += (ulong)imageMetaData.ContentLength; Console.WriteLine("1 dicom sop [{0,10}] in {1,12}\t[mime={2}]", ByteCountFormatter.Format((ulong)imageStream.Length), TimeSpanFormatter.Format(imageMetaData.Speed.ElapsedTime), imageMetaData.ResponseMimeType); break; case ContentTypes.RawPixel: TimeSpanStatistics elapsedTime = new TimeSpanStatistics(); elapsedTime.Start(); ulong instanceSize = 0; int frameCount = 0; do { RetrievePixelDataResult result = client.RetrievePixelData(serverAE, studyUid, seriesUid, uid, frameCount); frameMetaData = result.MetaData; totalFrameCount++; frameCount++; averageSpeed.AddSample(frameMetaData.Speed); totalSize.Value += (ulong)frameMetaData.ContentLength; instanceSize += (ulong)frameMetaData.ContentLength; } while (!frameMetaData.IsLast); elapsedTime.End(); Console.WriteLine("{0,3} frame(s) [{1,10}] in {2,12}\t[mime={3}]", frameCount, ByteCountFormatter.Format(instanceSize), elapsedTime.FormattedValue, frameMetaData.ResponseMimeType); break; default: imageStream = client.RetrieveImage(serverAE, studyUid, seriesUid, uid, out imageMetaData); totalFrameCount++; averageSpeed.AddSample(imageMetaData.Speed); totalSize.Value += (ulong)imageMetaData.ContentLength; Console.WriteLine("1 object [{0,10}] in {1,12}\t[mime={2}]", ByteCountFormatter.Format((ulong)imageStream.Length), TimeSpanFormatter.Format(imageMetaData.Speed.ElapsedTime), imageMetaData.ResponseMimeType); break; } } catch (Exception ex) { if (ex is WebException) { HttpWebResponse rsp = ((ex as WebException).Response as HttpWebResponse); string msg = String.Format("Error: {0} : {1}", rsp.StatusCode, HttpUtility.HtmlDecode(rsp.StatusDescription) ); Console.WriteLine(msg); } else { Console.WriteLine(ex.Message); } } } } frameRate.SetData(totalFrameCount); frameRate.End(); speed.SetData(totalSize.Value); speed.End(); Console.WriteLine("\nTotal {0,3} image(s)/frame(s) [{1,10}] in {2,12} ==> [ Speed: {3,12} or {4,12}]", totalFrameCount, totalSize.FormattedValue, TimeSpanFormatter.Format(frameRate.ElapsedTime), frameRate.FormattedValue, speed.FormattedValue ); }