private ISopDicomFileLoader ConvertLoader(IDicomFileLoader loader)
		{
			return new SopDicomFileLoader(loader.CanLoadCompleteHeader, loader.CanLoadPixelData, loader.CanLoadFramePixelData,
				args => loader.LoadDicomFile(new LoadDicomFileArgs(StudyInstanceUid, SeriesInstanceUid, SopInstanceUid, args.ForceCompleteHeader, args.IncludePixelData)),
				args => loader.LoadFramePixelData(new LoadFramePixelDataArgs(StudyInstanceUid, SeriesInstanceUid, SopInstanceUid, args.FrameNumber)));
		}
 private ISopDicomFileLoader ConvertLoader(IDicomFileLoader loader)
 {
     return(new SopDicomFileLoader(loader.CanLoadCompleteHeader, loader.CanLoadPixelData, loader.CanLoadFramePixelData,
                                   args => loader.LoadDicomFile(new LoadDicomFileArgs(StudyInstanceUid, SeriesInstanceUid, SopInstanceUid, args.ForceCompleteHeader, args.IncludePixelData)),
                                   args => loader.LoadFramePixelData(new LoadFramePixelDataArgs(StudyInstanceUid, SeriesInstanceUid, SopInstanceUid, args.FrameNumber))));
 }
            private IFramePixelData TryClientRetrievePixelData(out Exception lastRetrieveException)
            {
                // retry parameters
                const int maxRetryCount = 10;
                const int retryTimeout  = 1500;
                int       retryDelay    = 50;
                int       retryCounter  = 0;

                IFramePixelData result = null;

                lastRetrieveException = null;

                var 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 = _loader.LoadFramePixelData(new LoadFramePixelDataArgs(this._studyInstanceUid, this._seriesInstanceUid, this.SopInstanceUid, this._frameNumber));

                        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.BytesReceived, 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);
            }