예제 #1
0
        public override void Process()
        {
            EnsureMaxUsedSpaceNotExceeded();

            DicomServerConfiguration configuration = GetServerConfiguration();
            var remoteAE = ServerDirectory.GetRemoteServerByName(Request.ServerName);

            if (remoteAE == null)
            {
                if (!string.IsNullOrEmpty(Request.ServerAETitle) && !string.IsNullOrEmpty(Request.ServerHostname) && Request.ServerPort > 0)
                {
                    var device = new ApplicationEntity
                    {
                        Name          = string.Format("{0}/{1}", Request.ServerAETitle, Request.ServerHostname),
                        AETitle       = Request.ServerAETitle,
                        ScpParameters = new ScpParameters(Request.ServerHostname, Request.ServerPort)
                    };
                    remoteAE = new DicomServiceNode(new ServerDirectoryEntry(device));
                }
                else
                {
                    Proxy.Fail(string.Format("Unknown remote device: {0}", Request.ServerName), WorkItemFailureType.Fatal);
                    return;
                }
            }

            if (RetrieveStudy != null)
            {
                _scu = new ImageViewerMoveScu(configuration.AETitle, remoteAE, RetrieveStudy.Patient, RetrieveStudy.Study);
            }
            else if (RetrieveSeries != null)
            {
                _scu = new ImageViewerMoveScu(configuration.AETitle, remoteAE, RetrieveSeries.Patient, RetrieveSeries.Study, RetrieveSeries.SeriesInstanceUids);
            }
            else
            {
                Proxy.Fail("Invalid request type.", WorkItemFailureType.Fatal);
                return;
            }

            Progress.ImagesToRetrieve     = _scu.TotalSubOperations;
            Progress.FailureSubOperations = 0;
            Progress.WarningSubOperations = 0;
            Progress.SuccessSubOperations = 0;
            Progress.IsCancelable         = false;
            Proxy.UpdateProgress();

            _scu.ImageMoveCompleted += OnMoveImage;

            _scu.Retrieve();

            Progress.ImagesToRetrieve     = _scu.TotalSubOperations;
            Progress.SuccessSubOperations = _scu.SuccessSubOperations;
            Progress.FailureSubOperations = _scu.FailureSubOperations;
            Progress.WarningSubOperations = _scu.WarningSubOperations;
            Progress.StatusDetails        = !string.IsNullOrEmpty(_scu.ErrorDescriptionDetails) ? _scu.ErrorDescriptionDetails : _scu.FailureDescription;

            if (_scu.Canceled)
            {
                if (_cancelDueToDiskSpace)
                {
                    var study = RetrieveStudy.Study ?? RetrieveSeries.Study;

                    Platform.Log(LogLevel.Info, "Dicom Retrieve for {0} from {1} was cancelled because disk space has been exceeded", study, remoteAE.AETitle);
                    Progress.IsCancelable = true;
                    throw new NotEnoughStorageException();                     // item will be failed
                }
                else if (StopPending)
                {
                    Progress.IsCancelable = true;
                    Proxy.Postpone();
                }
                else
                {
                    Proxy.Cancel();
                }
            }
            else if (_scu.FailureSubOperations > 0 || _scu.Failed)
            {
                Progress.IsCancelable = true;
                Proxy.Fail(!string.IsNullOrEmpty(_scu.ErrorDescriptionDetails) ? _scu.ErrorDescriptionDetails : _scu.FailureDescription, WorkItemFailureType.NonFatal);
            }
            else
            {
                Proxy.Complete();
            }
        }
        public override void Process()
        {
            DicomServerConfiguration configuration = GetServerConfiguration();
            var remoteAE = ServerDirectory.GetRemoteServerByName(Request.DestinationServerName);

            if (remoteAE == null)
            {
                if (!string.IsNullOrEmpty(Request.DestinationServerAETitle) && !string.IsNullOrEmpty(Request.DestinationServerHostname) && Request.DestinationServerPort > 0)
                {
                    var device = new ApplicationEntity
                    {
                        Name          = string.Format("{0}/{1}", Request.DestinationServerAETitle, Request.DestinationServerHostname),
                        AETitle       = Request.DestinationServerAETitle,
                        ScpParameters = new ScpParameters(Request.DestinationServerHostname, Request.DestinationServerPort)
                    };
                    remoteAE = new DicomServiceNode(new ServerDirectoryEntry(device));
                }
                else
                {
                    Proxy.Fail(string.Format("Unknown destination: {0}", Request.DestinationServerName), WorkItemFailureType.Fatal);
                    return;
                }
            }

            if (AutoRoute != null && Proxy.Item.Priority != WorkItemPriorityEnum.Stat)
            {
                DateTime now           = Platform.Time;
                DateTime scheduledTime = AutoRoute.GetScheduledTime(now, 0);
                if (now != scheduledTime)
                {
                    Proxy.Postpone();
                    Platform.Log(LogLevel.Info, "Rescheduling AutoRoute WorkItem {0} back into the scheduled time window: {1}", Proxy.Item.Oid, Proxy.Item.ProcessTime);
                    return;
                }
            }

            _scu = new ImageViewerStorageScu(configuration.AETitle, remoteAE);

            LoadImagesToSend();

            if (Request.CompressionType != CompressionType.None)
            {
                _scu.LoadPreferredSyntaxes(Request);
            }

            Progress.TotalImagesToSend    = _scu.TotalSubOperations;
            Progress.FailureSubOperations = 0;
            Progress.WarningSubOperations = 0;
            Progress.SuccessSubOperations = 0;
            Progress.IsCancelable         = true;
            Proxy.UpdateProgress();

            _scu.ImageStoreCompleted += OnImageSent;

            _scu.DoSend();

            if (_scu.Canceled)
            {
                if (StopPending)
                {
                    Proxy.Postpone();
                }
                else
                {
                    Proxy.Cancel();
                }
            }
            else if (_scu.Failed || _scu.FailureSubOperations > 0)
            {
                var      settings = new DicomSendSettings();
                TimeSpan delay    = settings.RetryDelayUnits == RetryDelayTimeUnit.Seconds
                                                        ? TimeSpan.FromSeconds(settings.RetryDelay)
                                                        : TimeSpan.FromMinutes(settings.RetryDelay);

                Proxy.Fail(_scu.FailureDescription, WorkItemFailureType.NonFatal,
                           AutoRoute != null
                                                ? AutoRoute.GetScheduledTime(Platform.Time, (int)delay.TotalSeconds)
                                                : Platform.Time.Add(delay), settings.RetryCount);
            }
            else
            {
                Proxy.Complete();
            }
        }