public IFramePixelData LoadFramePixelData(LoadFramePixelDataArgs args) { try { var client = new StreamingClient(_wadoUri); var result = client.RetrievePixelData(_aeTitle, args.StudyInstanceUid, args.SeriesInstanceUid, args.SopInstanceUid, args.FrameNumber - 1); return new ImageServerFramePixelData(result); } catch (Exception e) { throw TranslateStreamingException(e); } }
public DicomFile LoadDicomFile(LoadDicomFileArgs args) { try { var client = new StreamingClient(_wadoUri); var file = new DicomFile(); using (var stream = client.RetrieveImageHeader(_aeTitle, args.StudyInstanceUid, args.SeriesInstanceUid, args.SopInstanceUid)) { file.Load(stream); } return file; } catch (Exception e) { throw TranslateStreamingException(e); } }
public DicomFile LoadDicomFile(LoadDicomFileArgs args) { try { Uri uri = new Uri(string.Format(StreamingSettings.Default.FormatWadoUriPrefix, _hostName, _wadoServicePort)); var client = new StreamingClient(uri); var file = new DicomFile(); using (var stream = client.RetrieveImageHeader(_aeTitle, args.StudyInstanceUid, args.SeriesInstanceUid, args.SopInstanceUid)) { file.Load(stream); } return file; } catch (Exception e) { throw TranslateStreamingException(e); } }
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(); } }
private RetrievePixelDataResult TryClientRetrievePixelData(out Exception lastRetrieveException) { // retry parameters const int maxRetryCount = 10; const int retryTimeout = 1500; int retryDelay = 50; int retryCounter = 0; StreamingClient client = new StreamingClient(this.BaseUrl); RetrievePixelDataResult result = null; lastRetrieveException = null; CodeClock timeoutClock = new CodeClock(); timeoutClock.Start(); while (true) { try { if (retryCounter > 0) Platform.Log(LogLevel.Info, "Retrying retrieve pixel data for Sop '{0}' (Attempt #{1})", this.SopInstanceUid, retryCounter); CodeClock statsClock = new CodeClock(); statsClock.Start(); result = client.RetrievePixelData(this.AETitle, this.StudyInstanceUid, this.SeriesInstanceUid, this.SopInstanceUid, this.FrameNumber - 1); statsClock.Stop(); Platform.Log(LogLevel.Debug, "[Retrieve Info] Sop/Frame: {0}/{1}, Transfer Syntax: {2}, Bytes transferred: {3}, Elapsed (s): {4}, Retries: {5}", this.SopInstanceUid, this.FrameNumber, this.TransferSyntaxUid, result.MetaData.ContentLength, statsClock.Seconds, retryCounter); break; } catch (Exception ex) { lastRetrieveException = ex; timeoutClock.Stop(); if (timeoutClock.Seconds * 1000 >= retryTimeout || retryCounter>=maxRetryCount) { // log an alert that we are aborting (exception trace at debug level only) int elapsed = (int)(1000*timeoutClock.Seconds); Platform.Log(LogLevel.Warn, "Failed to retrieve pixel data for Sop '{0}'; Aborting after {1} attempts in {2} ms", this.SopInstanceUid, retryCounter, elapsed); Platform.Log(LogLevel.Debug, ex, "[Retrieve Fail-Abort] Sop/Frame: {0}/{1}, Retry Attempts: {2}, Elapsed: {3} ms", this.SopInstanceUid, this.FrameNumber - 1, retryCounter, elapsed); break; } timeoutClock.Start(); retryCounter++; // log the retry (exception trace at debug level only) Platform.Log(LogLevel.Warn, "Failed to retrieve pixel data for Sop '{0}'; Retrying in {1} ms", this.SopInstanceUid, retryDelay); Platform.Log(LogLevel.Debug, ex, "[Retrieve Fail-Retry] Sop/Frame: {0}/{1}, Retry in: {2} ms", this.SopInstanceUid, this.FrameNumber - 1, retryDelay); MemoryManager.Collect(retryDelay); retryDelay *= 2; if (retryDelay > MaxRetryDelay) retryDelay = MaxRetryDelay; // cap it to avoid overflow, which will cause exception when calling MemoryManager.Collect() } } return result; }
public IFramePixelData LoadFramePixelData(LoadFramePixelDataArgs args) { try { var uri = new Uri(string.Format(StreamingSettings.Default.FormatWadoUriPrefix, _hostName, _wadoServicePort)); var client = new StreamingClient(uri); var result = client.RetrievePixelData(_aeTitle, args.StudyInstanceUid, args.SeriesInstanceUid, args.SopInstanceUid, args.FrameNumber - 1); return new ImageServerFramePixelData(result); } catch (Exception e) { throw TranslateStreamingException(e); } }
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 ); }
private DicomFile TryClientRetrieveImageHeader(out Exception lastRetrieveException) { // retry parameters const int retryTimeout = 1500; int retryDelay = 50; int retryCounter = 0; Uri uri = new Uri(string.Format(StreamingSettings.Default.FormatWadoUriPrefix, _host, _wadoServicePort)); StreamingClient client = new StreamingClient(uri); DicomFile result = null; lastRetrieveException = null; CodeClock timeoutClock = new CodeClock(); timeoutClock.Start(); while (true) { try { if (retryCounter > 0) Platform.Log(LogLevel.Info, "Retrying retrieve headers for Sop '{0}' (Attempt #{1})", this.SopInstanceUid, retryCounter); using (Stream imageHeaderStream = client.RetrieveImageHeader(_aeTitle, this.StudyInstanceUid, this.SeriesInstanceUid, this.SopInstanceUid)) { DicomFile imageHeader = new DicomFile(); imageHeader.Load(imageHeaderStream); result = imageHeader; } break; } catch (Exception ex) { lastRetrieveException = ex; timeoutClock.Stop(); if (timeoutClock.Seconds*1000 >= retryTimeout) { // log an alert that we are aborting (exception trace at debug level only) int elapsed = (int) (1000*timeoutClock.Seconds); Platform.Log(LogLevel.Warn, "Failed to retrieve headers for Sop '{0}'; Aborting after {1} attempts in {2} ms", this.SopInstanceUid, retryCounter, elapsed); Platform.Log(LogLevel.Debug, ex, "[GetHeaders Fail-Abort] Sop: {0}, Retry Attempts: {1}, Elapsed: {2} ms", this.SopInstanceUid, retryCounter, elapsed); break; } timeoutClock.Start(); retryCounter++; // log the retry (exception trace at debug level only) Platform.Log(LogLevel.Warn, "Failed to retrieve headers for Sop '{0}'; Retrying in {1} ms", this.SopInstanceUid, retryDelay); Platform.Log(LogLevel.Debug, ex, "[GetHeaders Fail-Retry] Sop: {0}, Retry in: {1} ms", this.SopInstanceUid, retryDelay); MemoryManager.Collect(retryDelay); retryDelay *= 2; } } return result; }