Beispiel #1
0
        public static bool VerifyAssociation(IDicomServerContext context, AssociationParameters assocParms, out DicomRejectResult result, out DicomRejectReason reason)
        {
            string calledTitle = (assocParms.CalledAE ?? "").Trim();
            string callingAE   = (assocParms.CallingAE ?? "").Trim();

            result = DicomRejectResult.Permanent;
            reason = DicomRejectReason.NoReasonGiven;

            var extendedConfiguration = LocalDicomServer.GetExtendedConfiguration();

            if (!extendedConfiguration.AllowUnknownCaller && ServerDirectory.GetRemoteServersByAETitle(callingAE).Count == 0)
            {
                reason = DicomRejectReason.CallingAENotRecognized;
            }
            else if (calledTitle != context.AETitle)
            {
                reason = DicomRejectReason.CalledAENotRecognized;
            }
            else
            {
                return(true);
            }

            return(false);
        }
Beispiel #2
0
        private static IImageViewer LaunchViewer(OpenStudiesRequest request, string primaryStudyInstanceUid)
        {
            try
            {
                CompleteOpenStudyInfo(request.StudiesToOpen);
            }
            catch (Exception ex)
            {
                if (request.ReportFaultToUser)
                {
                    SynchronizationContext.Current.Post(ReportLoadFailures, ex);
                }
                throw;
            }

            ImageViewerComponent viewer;

            if (!request.LoadPriors.HasValue || request.LoadPriors.Value)
            {
                viewer = new ImageViewerComponent(LayoutManagerCreationParameters.Extended);
            }
            else
            {
                viewer = new ImageViewerComponent(LayoutManagerCreationParameters.Extended, PriorStudyFinder.Null);
            }

            var loadStudyArgs = (from info in request.StudiesToOpen
                                 let server = ServerDirectory.GetRemoteServersByAETitle(info.SourceAETitle).FirstOrDefault() ?? ServerDirectory.GetLocalServer()
                                              select new LoadStudyArgs(info.StudyInstanceUid, server)).ToList();

            try
            {
                viewer.LoadStudies(loadStudyArgs);
            }
            catch (Exception e)
            {
                bool faultThrown = false;
                try
                {
                    HandleLoadStudiesException(e, primaryStudyInstanceUid, viewer);
                }
                catch
                {
                    faultThrown = true;
                    viewer.Dispose();
                    throw;
                }
                finally
                {
                    if (!faultThrown || request.ReportFaultToUser)
                    {
                        SynchronizationContext.Current.Post(ReportLoadFailures, e);
                    }
                }
            }

            ImageViewerComponent.Launch(viewer, new LaunchImageViewerArgs(ViewerLaunchSettings.WindowBehaviour));
            return(viewer);
        }
            public StudyInfo(IImageSopProvider provider, NextSeriesNumberDelegate nextSeriesNumberDelegate)
            {
                _provider = provider;
                _nextSeriesNumberDelegate = nextSeriesNumberDelegate;
                _studyInstanceUid         = provider.Sop.StudyInstanceUid;
                _originServer             = ServerDirectory.GetRemoteServersByAETitle(provider.Sop[DicomTags.SourceApplicationEntityTitle].ToString()).FirstOrDefault();
                _sourceServer             = provider.Sop.DataSource.Server;

                KeyObjectSeriesUid         = DicomUid.GenerateUid().UID;
                KeyObjectSeriesDateTime    = Platform.Time;
                PresentationSeriesUid      = DicomUid.GenerateUid().UID;
                PresentationSeriesDateTime = Platform.Time;
            }
Beispiel #4
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="sourceAE">The AE title of the remote application sending the SOP Instances.</param>
        /// <param name="configuration">Storage configuration. </param>
        /// <param name="hostname">The IP Address the remote app is connecting with.</param>
        /// <param name="auditSource">The source of the request for auditing purposes </param>
        public DicomReceiveImportContext(string sourceAE, string hostname, StorageConfiguration configuration, EventSource auditSource) : base(sourceAE, configuration, auditSource)
        {
            // TODO (CR Jun 2012 - Med): This object is disposable and should be cleaned up.

            _monitor = WorkItemActivityMonitor.Create(false);
            _monitor.WorkItemsChanged += WorkItemsChanged;

            var serverList = ServerDirectory.GetRemoteServersByAETitle(sourceAE);
            if (serverList.Count == 1)
                _dicomServerNode = CollectionUtils.FirstElement(serverList);

            _hostname = hostname;
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="sourceAE">The AE title of the remote application sending the SOP Instances.</param>
        /// <param name="configuration">Storage configuration. </param>
        /// <param name="hostname">The IP Address the remote app is connecting with.</param>
        /// <param name="auditSource">The source of the request for auditing purposes </param>
        public DicomReceiveImportContext(string sourceAE, string hostname, StorageConfiguration configuration, EventSource auditSource) : base(sourceAE, configuration, auditSource)
        {
            _monitor = WorkItemActivityMonitor.Create(false);
            _monitor.WorkItemsChanged += WorkItemsChanged;

            var serverList = ServerDirectory.GetRemoteServersByAETitle(sourceAE);

            if (serverList.Count == 1)
            {
                _dicomServerNode = CollectionUtils.FirstElement(serverList);
            }

            _hostname = hostname;
        }
Beispiel #6
0
        public void TestGetServersByAE()
        {
            Initialize1();

            var all = ServerDirectory.GetRemoteServers();

            Assert.AreEqual(2, all.Count);

            var ae1 = ServerDirectory.GetRemoteServersByAETitle("AE1");

            Assert.AreEqual(1, ae1.Count);
            var ae2 = ServerDirectory.GetRemoteServersByAETitle("AE2");

            Assert.AreEqual(1, ae2.Count);
            Assert.AreEqual(0, ServerDirectory.GetRemoteServersByAETitle(null).Count);
            Assert.AreEqual(0, ServerDirectory.GetRemoteServersByAETitle(String.Empty).Count);
            Assert.AreEqual(0, ServerDirectory.GetRemoteServersByAETitle("abc").Count);
        }
Beispiel #7
0
        public void Publish()
        {
            if (_sourceInformation.ClipboardItems.Count == 0)
            {
                return;
            }

            var service = Platform.GetService <IPublishFiles>();

            while (!service.CanPublish())
            {
                // ActiveDesktopWindow may be null when the study is opened from Webstation
                // By the time viewer closes, there is no browser window to display the error
                if (Application.ActiveDesktopWindow == null)
                {
                    // Log to file only and return immediately
                    Platform.Log(LogLevel.Error, SR.MessageKeyImagePublishingFailed);
                    return;
                }
                else
                {
                    // TODO CR (Sep 12): convert this to a desktop alert
                    DialogBoxAction result = Application.ActiveDesktopWindow.ShowMessageBox(
                        SR.MessageCannotPublishKeyImagesServersNotRunning, MessageBoxActions.OkCancel);

                    if (result == DialogBoxAction.Cancel)
                    {
                        return;
                    }
                }
            }

            var anyFailed = false;

            try
            {
                CreateKeyObjectDocuments();

                var publishers = new Dictionary <string, DicomPublishingHelper>();

                // add each KO document to a publisher by study
                foreach (var koDocument in _keyObjectDocuments)
                {
                    var publisher = GetValue(publishers, koDocument.DataSet[DicomTags.StudyInstanceUid].ToString());
                    publisher.Files.Add(koDocument);
                }

                // add each PR state to a publisher by study
                foreach (var presentationFrame in SourceFrames)
                {
                    var sourceFrame = presentationFrame.Key;
                    var publisher   = GetValue(publishers, sourceFrame.StudyInstanceUid);

                    if (presentationFrame.Value != null)
                    {
                        publisher.Files.Add(presentationFrame.Value.DicomFile);
                    }

                    var sopDataSource = sourceFrame.ParentImageSop.DataSource;
                    publisher.OriginServer = ServerDirectory.GetRemoteServersByAETitle(sopDataSource[DicomTags.SourceApplicationEntityTitle].ToString()).FirstOrDefault();
                    publisher.SourceServer = sopDataSource.Server;
                }

                // publish all files now
                foreach (var publisher in publishers.Values)
                {
                    if (!publisher.Publish())
                    {
                        anyFailed = true;
                    }
                }
            }
            catch (Exception e)
            {
                anyFailed = true;
                Platform.Log(LogLevel.Error, e, "An unexpected error occurred while trying to publish key images.");
            }

            // TODO CR (Sep 12): convert this to a desktop alert
            if (anyFailed)
            {
                // ActiveDesktopWindow may be null when the study is opened from Webstation
                // By the time viewer closes, there is no browser window to display the error, so log to file only.
                if (Application.ActiveDesktopWindow == null)
                {
                    Platform.Log(LogLevel.Error, SR.MessageKeyImagePublishingFailed);
                }
                else
                {
                    Application.ActiveDesktopWindow.ShowMessageBox(SR.MessageKeyImagePublishingFailed, MessageBoxActions.Ok);
                }
            }
        }
        public override bool OnReceiveRequest(ClearCanvas.Dicom.Network.DicomServer server, ServerAssociationParameters association, byte presentationID, DicomMessage message)
        {
            //// Check for a Cancel message, and cancel the SCU.
            if (message.CommandField == DicomCommandField.CCancelRequest)
            {
                OnReceiveCancelRequest(message);
                return(true);
            }

            // TODO (CR Jun 2012): Log when there's more than 1.

            var remoteAE = ServerDirectory.GetRemoteServersByAETitle(message.MoveDestination).FirstOrDefault();

            if (remoteAE == null)
            {
                server.SendCMoveResponse(presentationID, message.MessageId, new DicomMessage(),
                                         DicomStatuses.QueryRetrieveMoveDestinationUnknown);
                return(true);
            }

            String level = message.DataSet[DicomTags.QueryRetrieveLevel].GetString(0, string.Empty);

            try
            {
                if (level.Equals("STUDY"))
                {
                    OnReceiveMoveStudiesRequest(server, presentationID, message, remoteAE);
                }
                else if (level.Equals("SERIES"))
                {
                    OnReceiveMoveSeriesRequest(server, presentationID, message, remoteAE);
                }
                else if (level.Equals("IMAGE"))
                {
                    OnReceiveMoveImageRequest(server, presentationID, message, remoteAE);
                }
                else
                {
                    Platform.Log(LogLevel.Error, "Unexpected Study Root Move Query/Retrieve level: {0}", level);

                    server.SendCMoveResponse(presentationID, message.MessageId, new DicomMessage(),
                                             DicomStatuses.QueryRetrieveIdentifierDoesNotMatchSOPClass);
                    return(true);
                }
            }
            catch (Exception e)
            {
                Platform.Log(LogLevel.Error, e, "Unexpected exception when processing C-MOVE-RQ");
                try
                {
                    server.SendCMoveResponse(presentationID, message.MessageId, new DicomMessage(),
                                             DicomStatuses.QueryRetrieveUnableToProcess, e.Message);
                }
                catch (Exception ex)
                {
                    Platform.Log(LogLevel.Error, ex,
                                 "Unable to send final C-MOVE-RSP message on association from {0} to {1}",
                                 association.CallingAE, association.CalledAE);
                }
            }

            return(true);
        }
Beispiel #9
0
        public void Publish()
        {
            if (_sourceInformation.ClipboardItems.Count == 0)
            {
                return;
            }

            while (!WorkItemActivityMonitor.IsRunning)
            {
                // TODO CR (Sep 12): convert this to a desktop alert
                DialogBoxAction result = Application.ActiveDesktopWindow.ShowMessageBox(
                    SR.MessageCannotPublishKeyImagesServersNotRunning, MessageBoxActions.OkCancel);

                if (result == DialogBoxAction.Cancel)
                {
                    return;
                }
            }

            var anyFailed = false;

            try
            {
                CreateKeyObjectDocuments();

                var publishers = new Dictionary <string, DicomPublishingHelper>();

                // add each KO document to a publisher by study
                foreach (var koDocument in _keyObjectDocuments)
                {
                    var publisher = GetValue(publishers, koDocument.DataSet[DicomTags.StudyInstanceUid].ToString());
                    publisher.Files.Add(koDocument);
                }

                // add each PR state to a publisher by study
                foreach (var presentationFrame in SourceFrames)
                {
                    var sourceFrame = presentationFrame.Key;
                    var publisher   = GetValue(publishers, sourceFrame.StudyInstanceUid);

                    if (presentationFrame.Value != null)
                    {
                        publisher.Files.Add(presentationFrame.Value.DicomFile);
                    }

                    var sopDataSource = sourceFrame.ParentImageSop.DataSource;
                    publisher.OriginServer = ServerDirectory.GetRemoteServersByAETitle(sopDataSource[DicomTags.SourceApplicationEntityTitle].ToString()).FirstOrDefault();
                    publisher.SourceServer = sopDataSource.Server;
                }

                // publish all files now
                foreach (var publisher in publishers.Values)
                {
                    if (!publisher.Publish())
                    {
                        anyFailed = true;
                    }
                }
            }
            catch (Exception e)
            {
                anyFailed = true;
                Platform.Log(LogLevel.Error, e, "An unexpected error occurred while trying to publish key images.");
            }

            // TODO CR (Sep 12): convert this to a desktop alert
            if (anyFailed)
            {
                Application.ActiveDesktopWindow.ShowMessageBox(SR.MessageKeyImagePublishingFailed, MessageBoxActions.Ok);
            }
        }