Пример #1
0
        public DicomCommandStatusType OnGet(DicomClient client, byte presentationId, int messageId, string affectedClass, DicomCommandPriorityType priority, DicomDataSet request)
        {
            try
            {
                _messageId      = messageId;
                _presentationId = presentationId;
                _clientSession  = new ClientSession(client);

                CMoveClientSessionProxy sessionProxy = new CMoveClientSessionProxy(_clientSession, presentationId, messageId, affectedClass);
                DicomCommand            command      = new CustomCMoveCommand(sessionProxy, request);

                _clientSession.CMoveStoreSubOperation += new EventHandler <CMoveStoreSubOperationEventArgs>(_clientSession_CMoveStoreSubOperation);
                _clientSession.CMoveResponse          += new EventHandler <CMoveResponseEventArgs>(_clientSession_CMoveResponse);

                _clientSession.ProcessCMoveRequest(presentationId, messageId, affectedClass, priority, command).WaitOne( );

                return(_status);
            }
            finally
            {
                if (request != null)
                {
                    request.Dispose( );
                }
            }
        }
Пример #2
0
        protected override void OnReceiveCFindResponse(byte presentationID, int messageID, string affectedClass, DicomCommandStatusType status, DicomDataSet dataSet)
        {
            InvokeStatusEvent(StatusType.ReceiveCFindResponse, status);

            switch (status)
            {
            case DicomCommandStatusType.Success:
            case DicomCommandStatusType.Warning:
                Event.Set();
                break;

            case DicomCommandStatusType.Pending:
            case DicomCommandStatusType.PendingWarning:
                AddDS(dataSet);
                break;

            default:
                Event.Set();
                break;
            }

            if (null != dataSet)
            {
                dataSet.Dispose( );
            }
        }
Пример #3
0
        private void LoadDataset(string filename)
        {
            if (_DataView != null)
            {
                _DataView.Dispose();
            }

            _DataView = new DicomDataSet();
            try
            {
                RasterImage image = null;
                int         count = 0;

                _DataView.Load(filename, DicomDataSetLoadFlags.None);
                count = _DataView.GetImageCount(null);
                image = _DataView.GetImages(null, 0, count, 0, RasterByteOrder.Rgb | RasterByteOrder.Gray,
                                            DicomGetImageFlags.AutoApplyVoiLut | DicomGetImageFlags.AutoApplyModalityLut);
                if (image != null)
                {
                    Cell.Image          = image;
                    Cell.FitImageToCell = true;
                    if (image.GrayscaleMode != RasterGrayscaleMode.None)
                    {
                        Cell.SetTag(2, MedicalViewerTagAlignment.BottomLeft, MedicalViewerTagType.WindowLevelData);
                        Cell.SetTag(0, MedicalViewerTagAlignment.TopRight, MedicalViewerTagType.Frame);
                    }
                }
                tabControl.SelectedTab = tabPageViewer;
            }
            catch (Exception e)
            {
                Messager.ShowError(this, e);
            }
        }
Пример #4
0
        protected override void OnReceiveCMoveResponse(byte presentationID, int messageID, string affectedClass, DicomCommandStatusType status, int remaining, int completed, int failed, int warning, DicomDataSet dataSet)
        {
            InvokeStatusEvent(StatusType.ReceiveCMoveResponse, DicomExceptionCode.Success, completed, remaining, status);
            //Event.Set();
            switch (status)
            {
            case DicomCommandStatusType.Success:
            case DicomCommandStatusType.Warning:
                Event.Set();
                break;

            case DicomCommandStatusType.Pending:
                AddDS(dataSet);
                break;

            default:
                Event.Set();
                break;
            }

            if (null != dataSet)
            {
                dataSet.Dispose( );
            }
        }
Пример #5
0
 protected override void OnReceiveData(byte presentationID, DicomDataSet cs, DicomDataSet ds)
 {
     base.OnReceiveData(presentationID, cs, ds);
     if (null != cs)
     {
         cs.Dispose( );
     }
 }
Пример #6
0
        protected override void OnReceiveCFindRequest(byte presentationID, int messageID, string affectedClass, DicomCommandPriorityType priority, DicomDataSet dataSet)
        {
            action = server.InitAction("C-FIND-REQUEST", ProcessType.FindRequest, this, dataSet);

            action.PresentationID = presentationID;
            action.MessageID      = messageID;
            action.Class          = affectedClass;
            action.Priority       = priority;
            StartAction(action);
            dataSet.Dispose( );
        }
Пример #7
0
        public DicomCommandStatusType SendNActionRequest <TQuery>(DicomScp Scp, TQuery Query, int action, string instance)
        {
            DicomDataSet ds = null;

            if (Scp == null)
            {
                throw new ArgumentNullException("Scp");
            }

            if (Query == null)
            {
                throw new ArgumentNullException("Query");
            }

            _ErrorMessage = string.Empty;
            try
            {
                _CurrentInstance = GetFindAttribute(Query);
                if (_CurrentInstance == null)
                {
                    throw new InvalidOperationException();
                }

                ds = GetDataset(Query, null);
                Connect(Scp);
                if (parameters.Result == null)
                {
                    SendNAction(ds, action, instance);
                }
                else
                {
                    throw new ClientAssociationException(parameters.Reason);
                }
            }
            catch (Exception e)
            {
                _ErrorMessage = e.Message;
                _Status       = DicomCommandStatusType.Failure;
            }
            finally
            {
                if (IsConnected())
                {
                    Close();
                }
                if (ds != null)
                {
                    ds.Dispose();
                    ds = null;
                }
            }

            return(_Status);
        }
Пример #8
0
        protected override void OnReceiveCStoreRequest(byte presentationID, int messageID, string affectedClass, string instance, DicomCommandPriorityType priority, string moveAE, int moveMessageID, DicomDataSet dataSet)
        {
            action = server.InitAction("C-STORE-REQUEST", ProcessType.StoreRequest, this, dataSet);

            action.PresentationID = presentationID;
            action.MessageID      = messageID;
            action.Class          = affectedClass;
            action.Instance       = instance;
            action.Priority       = priority;
            action.MoveAETitle    = moveAE;
            action.MoveMessageID  = moveMessageID;
            StartAction(action);
            dataSet.Dispose( );
        }
Пример #9
0
        protected virtual void OnActionComplete()
        {
            if (ActionComplete != null)
            {
                // Invokes the delegates.
                ActionComplete(this, new EventArgs());
            }

            if (ds != null)
            {
                ds.Dispose();

                ds = null;
            }
        }
Пример #10
0
        protected override void OnReceiveData(byte presentationID, DicomDataSet cs, DicomDataSet ds)
        {
            if (Logger.DisableLogging == false)
            {
                if (server.SaveCSReceived && cs != null)
                {
                    server.LogCS(this, cs);
                }

                //if you don't need the CommandSet DataSet then dispose it here. Otherwise GC will take care if it.
                if (null != cs)
                {
                    cs.Dispose();
                }
            }
        }
Пример #11
0
        public DicomCommandStatusType OnFind
        (
            DicomClient client,
            byte presentationId,
            int messageId,
            string affectedClass,
            DicomCommandPriorityType priority,
            DicomDataSet request
        )
        {
            try
            {
                CFindClientSessionProxy sessionProxy;
                DicomCommand            command;


                _messageId      = messageId;
                _presentationId = presentationId;
                _clientSession  = new ClientSession(client);

                if (null == DicomCommandFactory.GetInitializationService(typeof(QueryCFindCommand)))
                {
                    DicomCommandFactory.RegisterCommandInitializationService(typeof(QueryCFindCommand),
                                                                             new FindCommandInitializationService( ));
                }

                sessionProxy = new CFindClientSessionProxy(_clientSession, presentationId, messageId, affectedClass);
                command      = DicomCommandFactory.GetInstance( ).CreateCFindCommand(sessionProxy, request);

                _clientSession.CFindResponse += new EventHandler <CFindResponseEventArgs> (clientSession_CFindResponse);

                _clientSession.ProcessCFindRequest(presentationId, messageId, affectedClass, priority, command).WaitOne( );;

                return(_status);
            }
            finally
            {
                if (null != request)
                {
                    request.Dispose( );
                }
            }
        }
Пример #12
0
        void QueueService_ActiveMediaItemChanged(object sender, EventArgs e)
        {
            try
            {
                DicomDataSet mediaDataSet = null;
                DicomDataSet oldDataSet   = null;


                if (QueueService.ActiveMediaItem != null)
                {
                    mediaDataSet = new DicomDataSet( );

                    mediaDataSet.Set(QueueService.ActiveMediaItem);
                }

                oldDataSet = View.DetailesDataSet;

                __SyncContext.Send(new SendOrPostCallback(delegate
                {
                    try
                    {
                        View.DetailesDataSet = mediaDataSet;
                        //View.SelectedMediaObject = QueueService.ActiveMediaItem ;
                    }
                    catch (Exception exception)
                    {
                        System.Diagnostics.Debug.Assert(false, exception.Message);
                    }
                }), null);

                if (null != oldDataSet)
                {
                    oldDataSet.Dispose( );
                }

                UpdateViewUI( );
            }
            catch (Exception exception)
            {
                System.Diagnostics.Debug.Assert(false, exception.Message);
            }
        }
Пример #13
0
        protected override void OnReceiveCStoreRequest(byte presentationID, int messageID, string affectedClass, string instance, DicomCommandPriorityType priority, string moveAE, int moveMessageID, DicomDataSet dataSet)
        {
            DicomDataSet ds = new DicomDataSet();

            server.cfind.ResetTimeoutEvent.Set();

            server.cfind.InvokeStatusEvent(StatusType.ReceiveCStoreRequest, DicomExceptionCode.Success);
            if (dataSet == null)
            {
                SendCStoreResponse(presentationID, messageID, affectedClass, instance, DicomCommandStatusType.ProcessingFailure);
                return;
            }

            ds.Copy(dataSet, null, null);
            server.dsCollection.Add(ds);

            server.cfind.InvokeStatusEvent(StatusType.SendCStoreResponse, DicomExceptionCode.Success);
            SendCStoreResponse(presentationID, messageID, affectedClass, instance, DicomCommandStatusType.Success);

            dataSet.Dispose( );
        }
Пример #14
0
        private void OnMatchFound(DicomDataSet response)
        {
            try
            {
                if (null != MatchFound)
                {
                    try
                    {
                        GatewaySession.Log(__Client, DicomCommandType.CFind, LogType.Debug, MessageDirection.Output, null,
                                           "[Gateway] Sending C-Find response to client \"" + (__Client.IsAssociated() ? __Client.Association.Calling : string.Empty) + "\"");

                        DicomElement element = response.FindFirstElement(null, DicomTag.RetrieveAETitle, true);

                        if (null != element)
                        {
                            response.DeleteElement(element);
                        }

                        response.InsertElementAndSetValue(DicomTag.InstanceAvailability, "NEARLINE");

                        MatchFound(this, new MatchFoundEventArgs(response));

                        GatewaySession.Log(__Client, DicomCommandType.CFind, LogType.Debug, MessageDirection.Output, null,
                                           "[Gateway] C-Find response sent successfully to client \"" + (__Client.IsAssociated() ? __Client.Association.Calling : string.Empty) + "\"");
                    }
                    catch (Exception exception)
                    {
                        GatewaySession.Log(__Client, DicomCommandType.CFind, LogType.Error, MessageDirection.Output, null,
                                           "[Gateway] Faild to send C-Find response to client \"" + (__Client.IsAssociated() ? __Client.Association.Calling : string.Empty) + "\"\n"
                                           + exception.Message);
                    }
                }
            }
            finally
            {
                response.Dispose();
            }
        }
Пример #15
0
        //[PresentationContext(DicomUidType.PatientRootQueryMove, new byte[] {1,0,1},DicomUidType.ImplicitVRLittleEndian)]
        //[PresentationContext(DicomUidType.PatientStudyQueryMove, DicomUidType.ImplicitVRLittleEndian)]
        //[PresentationContext(DicomUidType.StudyRootQueryMove, DicomUidType.ImplicitVRLittleEndian)]
        public DicomCommandStatusType OnMove
        (
            DicomClient client,
            byte presentationId,
            int messageId,
            string affectedClass,
            DicomCommandPriorityType priority,
            string moveAE,
            DicomDataSet request
        )
        {
            try
            {
                int countOfServersConnection;


                __Client   = client;
                __ClientAE = client.AETitle;

                if (null == __ServersManager)
                {
                    GatewaySession.Log(string.Empty, string.Empty, -1, DicomCommandType.CMove, LogType.Error, MessageDirection.None, null, "[Gateway] Gateway server not available");

                    return(DicomCommandStatusType.ProcessingFailure);
                }

                countOfServersConnection = 0;

                //make sure to break the loop on success or normal failure
                while (countOfServersConnection < __ServersManager.Servers.Count)
                {
                    AeInfo           currentRemoteServer;
                    DicomScp         remoteScp;
                    QueryRetrieveScu cMoveScu;


                    countOfServersConnection++;

                    currentRemoteServer = __ServersManager.GetRemoteServer( );
                    remoteScp           = GetScp(currentRemoteServer);

                    cMoveScu = GetScu(__ServersManager.Gateway.Server);

                    try
                    {
                        RegisterEvents(cMoveScu);

                        if (cMoveScu.SecurityMode == DicomNetSecurityMode.Tls)
                        {
                            // Set the TLS certificate
                            cMoveScu.SetTlsClientCertificate(
                                GatewaySession.DicomSecurityAgent.CertificateFileName,
                                GatewaySession.DicomSecurityAgent.CertificateType,
                                GatewaySession.DicomSecurityAgent.KeyFileName.Length > 0 ? GatewaySession.DicomSecurityAgent.KeyFileName : null);
                        }

                        __CMoveScu = cMoveScu;

                        __CurrentStatus = DicomCommandStatusType.Success;

                        __CurrentRequest     = new MoveRequestInformation(request);
                        __MovedInstances     = new List <string> ( );
                        __ForwardedInstances = new List <string> ( );

                        ServerEventBroker.Instance.Subscribe <CStoreRequestReceivedEventArgs> (OnReceiveCStoreRequest);
                        ServerEventBroker.Instance.Subscribe <CStoreResponseSentEventArgs>    (OnSendCStoreResponse);

                        try
                        {
                            GatewaySession.Log(client, DicomCommandType.CMove, LogType.Information, MessageDirection.Output, request,
                                               "[Gateway] Sending C-Move request to remote server \"" + currentRemoteServer.AETitle + "\"");

                            cMoveScu.Move(remoteScp, __ServersManager.Gateway.Server.AETitle, request);

                            GatewaySession.Log(client, DicomCommandType.CMove, LogType.Information, MessageDirection.Output, request,
                                               "[Gateway] C-Move request sent successfully \"" + currentRemoteServer.AETitle + "\"");
                        }
                        finally
                        {
                            ServerEventBroker.Instance.Unsubscribe <CStoreRequestReceivedEventArgs> (OnReceiveCStoreRequest);
                            ServerEventBroker.Instance.Unsubscribe <CStoreResponseSentEventArgs>    (OnSendCStoreResponse);
                        }

                        break;
                    }
                    catch (ClientConnectionException exception)
                    {
                        GatewaySession.Log(client, DicomCommandType.CMove, LogType.Warning, MessageDirection.None, null, "[Gateway] Connecting to server failed \"" + currentRemoteServer.AETitle + "\"\n" + exception.Message);

                        __ServersManager.SetRemoteServerConnectionFailure( );

                        if (countOfServersConnection >= __ServersManager.Servers.Count)
                        {
                            __CurrentStatus = DicomCommandStatusType.Failure;
                        }
                    }
                    catch (ClientCommunicationException exception)
                    {
                        //Don't update the status, just log a message here
                        //__CurrentStatus = exception.Status ;

                        GatewaySession.Log(client, DicomCommandType.CMove, LogType.Warning, MessageDirection.None, null, "[Gateway] Problem occured moving from server \"" + currentRemoteServer.AETitle + "\"\n" + exception.Message);

                        break;
                    }
                    catch (DicomException exception)
                    {
                        if (__CurrentStatus == DicomCommandStatusType.Success)
                        {
                            __CurrentStatus = DicomCommandStatusType.Failure;
                        }

                        GatewaySession.Log(client, DicomCommandType.CMove, LogType.Error, MessageDirection.None, null, "[Gateway] Sending to server failed \"" + currentRemoteServer.AETitle + "\"\n" + exception.Message);

                        break;
                    }
                    catch (Exception exception)
                    {
                        if (__CurrentStatus == DicomCommandStatusType.Success)
                        {
                            __CurrentStatus = DicomCommandStatusType.ProcessingFailure;
                        }

                        GatewaySession.Log(client, DicomCommandType.CMove, LogType.Error, MessageDirection.None, null, "[Gateway] Sending to server failed \"" + currentRemoteServer.AETitle + "\"\n" + exception.Message);

                        break;
                    }
                    finally
                    {
                        UnregisterEvents(cMoveScu);

                        cMoveScu.Dispose( );

                        __CMoveScu = null;
                    }
                }

                return(__CurrentStatus);
            }
            finally
            {
                request.Dispose( );
            }
        }
Пример #16
0
        public DicomCommandStatusType OnStore
        (
            DicomClient client,
            byte presentationId,
            int messageId,
            string affectedClass,
            string instance,
            DicomCommandPriorityType priority,
            string moveAE,
            int moveMessageId,
            DicomDataSet request
        )
        {
            try
            {
                CStoreClientSessionProxy sessionProxy;
                DicomCommand             command;


                if (request != null && !CanStore(client, instance))
                {
                    return(DicomCommandStatusType.DuplicateInstance);
                }

                if (!ValidateLicense(client, request))
                {
                    return(DicomCommandStatusType.ProcessingFailure);
                }

                _messageId      = messageId;
                _presentationId = presentationId;
                _clientSession  = new ClientSession(client);

                sessionProxy = new CStoreClientSessionProxy(_clientSession, presentationId, messageId, affectedClass, instance, moveAE, moveMessageId);

                if (AddInsSession.DataAccess == null)
                {
                    if (null == DicomCommandFactory.GetInitializationService(typeof(CStoreCommand)))
                    {
                        DicomCommandFactory.RegisterCommandInitializationService(typeof(CStoreCommand),
                                                                                 new StoreCommandInitializationService( ));
                    }

                    command = DicomCommandFactory.GetInstance( ).CreateCStoreCommand(sessionProxy, request);
                }
                else
                {
                    StoreCommandInitializationService service;


                    service = ServiceLocator.Retrieve <StoreCommandInitializationService> ( );
                    command = new InstanceCStoreCommand(sessionProxy, request, AddInsSession.DataAccess);

                    service.ConfigureCommand(command);
                }

                _clientSession.CStoreResponse += new EventHandler <CStoreResponseEventArgs> (_clientSession_CStoreResponse);

                byte[] value = new byte[] { 0x00, 0x01 };

                request.InsertElementAndSetValue(DicomTag.FileMetaInformationVersion, value);
                request.InsertElementAndSetValue(DicomTag.MediaStorageSOPClassUID, affectedClass);
                request.InsertElementAndSetValue(DicomTag.MediaStorageSOPInstanceUID, instance);

                if (request.FindFirstElement(null, DicomTag.ImplementationClassUID, true) == null)
                {
                    request.InsertElementAndSetValue(DicomTag.ImplementationClassUID, (string.IsNullOrEmpty(client.Server.ImplementationClass) ? "1.2.840.114257.1123456" : client.Server.ImplementationClass));
                }

                if (request.FindFirstElement(null, DicomTag.ImplementationVersionName, true) == null)
                {
                    request.InsertElementAndSetValue(DicomTag.ImplementationVersionName, (string.IsNullOrEmpty(client.Server.ImplementationVersionName) ? "LTPACSF V19" : client.Server.ImplementationVersionName));
                }

                _clientSession.ProcessCStoreRequestSync(presentationId, messageId, affectedClass, instance, priority, moveAE, moveMessageId, command);

                if (_status != DicomCommandStatusType.Success)
                {
                    SaveFailedStoreRequest(request, _status.ToString( ), client);
                }

                return(_status);
            }
            catch (Exception exception)
            {
                SaveFailedStoreRequest(request, exception.Message, client);

                throw;
            }
            finally
            {
                if (null != request)
                {
                    request.Dispose( );
                }
            }
        }
Пример #17
0
        //[PresentationContext(DicomUidType.PatientRootQueryFind, new byte[] {1,0,1},DicomUidType.ImplicitVRLittleEndian)]
        //[PresentationContext(DicomUidType.PatientStudyQueryFind, DicomUidType.ImplicitVRLittleEndian)]
        //[PresentationContext(DicomUidType.StudyRootQueryFind, DicomUidType.ImplicitVRLittleEndian)]
        public DicomCommandStatusType OnFind
        (
            DicomClient client,
            byte presentationId,
            int messageId,
            string affectedClass,
            DicomCommandPriorityType priority,
            DicomDataSet request
        )
        {
            int countOfServersConnection;


            try
            {
                __Client = client;

                if (null == __ServersManager)
                {
                    GatewaySession.Log(string.Empty, string.Empty, -1, DicomCommandType.CFind, LogType.Error, MessageDirection.None, null, "[Gateway] Gateway server not available");

                    return(DicomCommandStatusType.ProcessingFailure);
                }

                countOfServersConnection = 0;

                //make sure to break the loop on success or normal failure
                while (countOfServersConnection < __ServersManager.Servers.Count)
                {
                    AeInfo           currentRemoteServer;
                    DicomScp         remoteScp;
                    QueryRetrieveScu cFindScu;


                    countOfServersConnection++;

                    currentRemoteServer = __ServersManager.GetRemoteServer();

                    remoteScp = GetScp(currentRemoteServer);
                    cFindScu  = GetScu(__ServersManager.Gateway.Server);

                    try
                    {
                        RegisterEvents(cFindScu);

                        if (cFindScu.SecurityMode == DicomNetSecurityMode.Tls)
                        {
                            GatewaySession.InitializeDicomSecurity(false);
                            GatewaySession.SetCiphers(cFindScu);
                            GatewaySession.SetSecurityCertificates(cFindScu);
                        }

                        __CFindScu = cFindScu;

                        __CurrentStatus = DicomCommandStatusType.Success;

                        GatewaySession.Log(client, DicomCommandType.CFind, LogType.Information, MessageDirection.Output, request,
                                           "[Gateway] Sending C-Find request to remote server \"" + currentRemoteServer.AETitle + "\"");

                        cFindScu.Find(remoteScp, request);

                        GatewaySession.Log(client, DicomCommandType.CFind, LogType.Information, MessageDirection.None, null,
                                           "[Gateway] C-Find request sent successfully \"" + currentRemoteServer.AETitle + "\"");

                        break;
                    }
                    catch (ClientConnectionException exception)
                    {
                        GatewaySession.Log(client, DicomCommandType.CFind, LogType.Warning, MessageDirection.None, null, "[Gateway] Connecting to server failed \"" + currentRemoteServer.AETitle + "\"\n" + exception.Message);

                        __ServersManager.SetRemoteServerConnectionFailure();

                        __CurrentStatus = DicomCommandStatusType.Failure;
                    }
                    catch (ClientCommunicationException exception)
                    {
                        __CurrentStatus = exception.Status;

                        GatewaySession.Log(client, DicomCommandType.CFind, LogType.Error, MessageDirection.None, null, "[Gateway] Communicating with server failed \"" + currentRemoteServer.AETitle + "\"\n" + exception.Message);

                        break;
                    }
                    catch (DicomException exception)
                    {
                        if (__CurrentStatus == DicomCommandStatusType.Success)
                        {
                            __CurrentStatus = DicomCommandStatusType.Failure;
                        }

                        GatewaySession.Log(client, DicomCommandType.CFind, LogType.Error, MessageDirection.None, null, "[Gateway] Forwarding to server failed \"" + currentRemoteServer.AETitle + "\"\n" + exception.Message);

                        break;
                    }
                    catch (Exception exception)
                    {
                        if (__CurrentStatus == DicomCommandStatusType.Success)
                        {
                            __CurrentStatus = DicomCommandStatusType.ProcessingFailure;
                        }

                        GatewaySession.Log(client, DicomCommandType.CFind, LogType.Error, MessageDirection.None, null, "[Gateway] Forwarding to server failed \"" + currentRemoteServer.AETitle + "\"\n" + exception.Message);

                        break;
                    }
                    finally
                    {
                        UnregisterEvents(cFindScu);

                        cFindScu.Dispose();

                        __CFindScu = null;
                    }
                }

                return(__CurrentStatus);
            }
            finally
            {
                request.Dispose();
            }
        }