Esempio n. 1
0
        private void Ticket1283_1()
        {
            if (ticket1283_1_ReceivedAssociateRq == null)
            {
                ThreadManager threadManager = new ThreadManager();

                DicomThread_NUnit.ScpAssociationOnly scpAssociationOnly = new DicomThread_NUnit.ScpAssociationOnly("1.2.840.10008.5.1.4.1.1.7", "1.2.840.10008.1.2.1");

                scpAssociationOnly.Initialize(threadManager);

                Config.SetOptions(scpAssociationOnly, "ticket1283_1", "scp");

                DicomThread_NUnit.ScuAssociationOnly scuAssociationOnly = new DicomThread_NUnit.ScuAssociationOnly("1.2.840.10008.5.1.4.1.1.7", "1.2.840.10008.1.2.1");

                scuAssociationOnly.Initialize(threadManager);

                Config.SetOptions(scuAssociationOnly, "ticket1283_1", "scu");
                scuAssociationOnly.Options.LocalAeTitle  = "CALLINGAETITLE1";
                scuAssociationOnly.Options.RemoteAeTitle = "CALLEDAETITLE1";

                scpAssociationOnly.Start();
                scuAssociationOnly.Start(250);

                scpAssociationOnly.WaitForCompletion();
                scuAssociationOnly.WaitForCompletion();

                ticket1283_1_ReceivedAssociateRq = scpAssociationOnly.Messages.DulMessages[0] as AssociateRq;
            }
        }
Esempio n. 2
0
File: SCP.cs Progetto: ewcasas/DVTK
 /// <summary>
 /// This class was only intended as an example of a MessageIterator derived class. Please use the MessageIterator class instead.
 /// </summary>
 /// <param name="associateRq">-</param>
 public override void AfterHandlingAssociateRequest(AssociateRq associateRq)
 {
     if (!IsMessageHandled)
     {
         SendAssociateAc(new TransferSyntaxes("1.2.840.10008.1.2", "1.2.840.10008.1.2.1", "1.2.840.10008.1.2.2"));
         IsMessageHandled = true;
     }
 }
Esempio n. 3
0
 /// <summary>
 /// Handle Association Req
 /// </summary>
 /// <param name="associateRq"></param>
 public override void AfterHandlingAssociateRequest(AssociateRq associateRq)
 {
     if (!IsMessageHandled)
     {
         string [] tsList = (System.String[])supportedTS.ToArray(typeof(System.String));
         SendAssociateRp(new TransferSyntaxes(tsList));
         IsMessageHandled = true;
     }
 }
Esempio n. 4
0
        private void Ticket1283_1()
        {
            if (ticket1283_1_ReceivedAssociateRq == null)
            {
                ThreadManager threadManager = new ThreadManager();

                DicomThread_NUnit.ScpAssociationOnly scpAssociationOnly = new DicomThread_NUnit.ScpAssociationOnly("1.2.840.10008.5.1.4.1.1.7", "1.2.840.10008.1.2.1");

                scpAssociationOnly.Initialize(threadManager);

                Config.SetOptions(scpAssociationOnly, "ticket1283_1", "scp");

                DicomThread_NUnit.ScuAssociationOnly scuAssociationOnly = new DicomThread_NUnit.ScuAssociationOnly("1.2.840.10008.5.1.4.1.1.7", "1.2.840.10008.1.2.1");

                scuAssociationOnly.Initialize(threadManager);

                Config.SetOptions(scuAssociationOnly, "ticket1283_1", "scu");
                scuAssociationOnly.Options.LocalAeTitle = "CALLINGAETITLE1";
                scuAssociationOnly.Options.RemoteAeTitle = "CALLEDAETITLE1";

                scpAssociationOnly.Start();
                scuAssociationOnly.Start(250);

                scpAssociationOnly.WaitForCompletion();
                scuAssociationOnly.WaitForCompletion();

                ticket1283_1_ReceivedAssociateRq = scpAssociationOnly.Messages.DulMessages[0] as AssociateRq;
            }
        }
Esempio n. 5
0
 /// <summary>
 /// Override this method to handle an A-ASSOCIATE-RQ.
 /// </summary>
 /// <param name="associateRq">The received A-ASSOCIATE-RQ.</param>
 /// <returns>Return true when this methods has handled the received A-ASSOCIATE-RQ, otherwise false.</returns>
 public virtual bool HandleAssociateRequest(AssociateRq associateRq)
 {
     return false;
 }
Esempio n. 6
0
        /// <summary>
        /// Method to handle the workflow after receiving an Associate Request.
        /// </summary>
        /// <param name="associateRq">Associate Request message.</param>
        public override void AfterHandlingAssociateRequest(AssociateRq associateRq)
        {
            if (IsMessageHandled == false)
            {
                // determine which workflow to follow
                switch(_scpRespondToAssociateRequest)
                {
                    case ScpRespondToAssociateRequestEnum.WithAssociateAccept:
                        // send an associate accept with the supported transfer syntaxes.
                        SendAssociateAc(_sopClasses,_transferSyntaxes);
                        break;
                    case ScpRespondToAssociateRequestEnum.WithAssociateReject:
                        // send an associate reject with the given parameters
                        SendAssociateRj(_rejectResult, _rejectSource, _rejectReason);

                        // handle results files
                        if (_resultsFilePerAssociation == true)
                        {
                            StopResultsGathering();
                            StartResultsGathering();
                        }
                        break;
                    case ScpRespondToAssociateRequestEnum.WithAbort:
                    default:
                        // send an abort request with the given parameters
                        SendAbort(_abortSource, _abortReason);

                        // handle results files
                        if (_resultsFilePerAssociation == true)
                        {
                            StopResultsGathering();
                            StartResultsGathering();
                        }
                        break;
                }

                // message has now been handled
                IsMessageHandled = true;
            }
        }
Esempio n. 7
0
 /// <summary>
 /// This method is called after an A-ASSOCIATE-RQ has been received but before it
 /// (possibly) will be handled by the (zero or more) MessageHandler objects that
 /// are attached to this object.
 /// 
 /// Default, nothing is done in this method. Override if needed.
 /// </summary>
 /// <param name="associateRq">The received A-ASSOCIATE-RQ</param>
 public virtual void BeforeHandlingAssociateRequest(AssociateRq associateRq)
 {
     // Do nothing.
 }
Esempio n. 8
0
 /// <summary>
 /// This method is called after an A-ASSOCIATE-RQ has been received and has 
 /// (possibly) been handled by the (zero or more) MessageHandler objects that
 /// are attached to this object.
 /// 
 /// Default, nothing is done in this method. Override if needed.
 /// </summary>
 /// <param name="associateRq">The received A-ASSOCIATE-RQ.</param>
 public virtual void AfterHandlingAssociateRequest(AssociateRq associateRq)
 {
     // Do nothing.
 }
 public override void AfterHandlingAssociateRequest(AssociateRq associateRq)
 {
     if (!IsMessageHandled)
     {
         SendAssociateRp();
         IsMessageHandled = true;
     }
 }
Esempio n. 10
0
        /// <summary>
        /// Sends an A-ASSOCIATE-RQ.The A-ASSOCIATE-RQ being passed must have the Presentation Contexts also.
        /// </summary>
        /// <param name="associateRequest">The A-Associate-Rq</param>
        /// <returns>The sent A-ASSOCIATE-RQ</returns>
        /// <exception cref="System.Exception">
        ///	The A-Associate-Rq message does not have any presentation contexts. 
        /// 
        /// </exception> 
        /// <example>
        ///		<b>VB.NET</b>
        ///		<code>
        /// 			<include file='Doc\VisualBasicExamples.xml' path='Examples/Example[@name="IncludesDicomThreadScu"]' />
        /// 			<include file='Doc\VisualBasicExamples.xml' path='Examples/Example[@name="DicomThreadScu"]' />
        /// 			<include file='Doc\VisualBasicExamples.xml' path='Examples/Example[@name="Main"]' />		
        ///		</code>
        /// </example>		
        protected internal AssociateRq SendAssociateRq(DvtkData.Dul.A_ASSOCIATE_RQ associateRequest)
        {
            AssociateRq associateRq= null;

            // Create the DvtkData ASSOCIATE request and set default values.
            associateRequest.CallingAETitle = Options.LocalAeTitle;
            associateRequest.CalledAETitle = Options.RemoteAeTitle;
            associateRequest.UserInformation.MaximumLength.MaximumLengthReceived = Options.LocalMaximumLength;
            associateRequest.UserInformation.ImplementationClassUid.UID = Options.LocalImplementationClassUid;
            associateRequest.UserInformation.ImplementationVersionName.Name = Options.LocalImplementationVersionName;

            if (associateRequest.PresentationContexts == null)
            {
                throw new System.Exception("The association Request Message does not have any Presentation Contexts to propose. ");
            }

            associateRq = new AssociateRq(associateRequest);

            SendMessage(associateRq);

            hasOpenConnection = true;

            return (associateRq);
        }
Esempio n. 11
0
        /// <summary>
        /// Sends an A-ASSOCIATE-RQ.
        /// </summary>
        /// <param name="presentationContexts">One or more PresentationContext objects.</param>
        /// <returns>The sent A-ASSOCIATE-RQ</returns>
        /// <exception cref="System.Exception">
        ///	One or more of the supplied presentation contexts is an A_ASSOCIATE_AC presentation 
        /// context or sending of the A-ASSOCIATE-RQ fails.
        /// </exception> 
        /// <example>
        ///		<b>VB.NET</b>
        ///		<code>
        /// 			<include file='Doc\VisualBasicExamples.xml' path='Examples/Example[@name="IncludesDicomThreadScu"]' />
        /// 			<include file='Doc\VisualBasicExamples.xml' path='Examples/Example[@name="DicomThreadScu"]' />
        /// 			<include file='Doc\VisualBasicExamples.xml' path='Examples/Example[@name="Main"]' />		
        ///		</code>
        /// </example>		
        protected internal AssociateRq SendAssociateRq(params PresentationContext[] presentationContexts)
        {
            AssociateRq associateRq = null;

            // Create a DvtkData ASSOCIATE request and set default values.
            DvtkData.Dul.A_ASSOCIATE_RQ dvtkDataAssociateRq = new DvtkData.Dul.A_ASSOCIATE_RQ();
            dvtkDataAssociateRq.CallingAETitle = Options.LocalAeTitle;
            dvtkDataAssociateRq.CalledAETitle = Options.RemoteAeTitle;
            dvtkDataAssociateRq.UserInformation.MaximumLength.MaximumLengthReceived = Options.LocalMaximumLength;
            dvtkDataAssociateRq.UserInformation.ImplementationClassUid.UID = Options.LocalImplementationClassUid;
            dvtkDataAssociateRq.UserInformation.ImplementationVersionName.Name = Options.LocalImplementationVersionName;

            // Parse all parameters.
            foreach (PresentationContext presentationContext in presentationContexts)
            {
                if (!presentationContext.IsForAssociateRequest)
                {
                    throw new System.Exception("Error while interpreting parameters for PresentationContext");
                }

                DvtkData.Dul.RequestedPresentationContext requestedPresentationContext = new DvtkData.Dul.RequestedPresentationContext();

                requestedPresentationContext.AbstractSyntax = new DvtkData.Dul.AbstractSyntax(presentationContext.AbstractSyntax);

                foreach (String transferSyntax in presentationContext.TransferSyntaxes)
                {
                    requestedPresentationContext.AddTransferSyntaxes(new DvtkData.Dul.TransferSyntax(transferSyntax));
                }

                dvtkDataAssociateRq.AddPresentationContexts(requestedPresentationContext);
            }

            associateRq = new AssociateRq(dvtkDataAssociateRq);

            SendMessage(associateRq);

            hasOpenConnection = true;

            return (associateRq);
        }
Esempio n. 12
0
 public override void BeforeHandlingAssociateRequest(AssociateRq associateRq)
 {
     this.SendingMessageEvent += new SendingMessageEventHandler(QRScp_SendingMessageEvent);
     this.MessageReceivedEvent += new MessageReceivedEventHandler(QRScp_MessageReceivedEvent);
     base.BeforeHandlingAssociateRequest(associateRq);
 }
Esempio n. 13
0
 /// <summary>
 /// Handle Association Req
 /// </summary>
 /// <param name="associateRq"></param>
 public override void AfterHandlingAssociateRequest(AssociateRq associateRq)
 {
     if (!IsMessageHandled)
     {
         this.Options.LocalAeTitle = associateRq.CalledAETitle;
         this.Options.RemoteAeTitle = associateRq.CallingAETitle;
         SendAssociateRp(sopClasses, new TransferSyntaxes(tsList));
         IsMessageHandled = true;
     }
 }
Esempio n. 14
0
        /// <summary>
        /// Method to handle the workflow after receiving an Associate Request.
        /// </summary>
        /// <param name="associateRq">Associate Request message.</param>
        public override void AfterHandlingAssociateRequest(AssociateRq associateRq)
        {
            if (IsMessageHandled == false)
            {
                // determine which workflow to follow
                switch(_scpRespondToAssociateRequest)
                {
                    case ScpRespondToAssociateRequestEnum.WithAssociateAccept:
                        {
                            // send an associate accept with the supported transfer syntaxes.
                            PresentationContextCollection presentationContextsForAssociateAc = new PresentationContextCollection();
                            foreach (PresentationContext reqtedPC in associateRq.PresentationContexts)
                            {
                                String abstractSyntaxInAssociateRq = reqtedPC.AbstractSyntax;

                                PresentationContext presentationContextForAssociateAc = null;

                                if (sopList.Contains(abstractSyntaxInAssociateRq))
                                {
                                    String transferSyntaxForAssociateAc = null;
                                    this.Options.LocalAeTitle = associateRq.CalledAETitle;
                                    this.Options.RemoteAeTitle = associateRq.CallingAETitle;
                                    if (reqtedPC.AbstractSyntax == "1.2.840.10008.1.20.1")
                                    {
                                        transferSyntaxForAssociateAc = DetermineTransferSyntaxToAccept
                                            (reqtedPC.TransferSyntaxes, tsCommitList);
                                    }
                                    else
                                    {
                                        transferSyntaxForAssociateAc = DetermineTransferSyntaxToAccept
                                            (reqtedPC.TransferSyntaxes, tsStoreList);
                                    }

                                    if (transferSyntaxForAssociateAc.Length == 0)
                                    {
                                        presentationContextForAssociateAc = new PresentationContext
                                            (reqtedPC.AbstractSyntax,
                                            4,
                                            "");
                                    }
                                    else
                                    {
                                        presentationContextForAssociateAc = new PresentationContext
                                            (reqtedPC.AbstractSyntax,
                                            0,
                                            transferSyntaxForAssociateAc);
                                    }
                                }
                                else
                                {
                                    presentationContextForAssociateAc = new PresentationContext
                                        (reqtedPC.AbstractSyntax,
                                        3,
                                        "");
                                }

                                presentationContextsForAssociateAc.Add(presentationContextForAssociateAc);
                            }

                            SendAssociateAc(presentationContextsForAssociateAc);
                            isAssociated = true;
                            break;
                        }
                    case ScpRespondToAssociateRequestEnum.WithAssociateReject:
                        // send an associate reject with the given parameters
                        SendAssociateRj(_rejectResult, _rejectSource, _rejectReason);
                        break;
                    case ScpRespondToAssociateRequestEnum.WithAbort:
                    default:
                        // send an abort request with the given parameters
                        SendAbort(_abortSource, _abortReason);
                        break;
                }

                // message has now been handled
                IsMessageHandled = true;
            }
        }
Esempio n. 15
0
        /// <summary>
        /// Method to handle the workflow after receiving an Associate Request.
        /// </summary>
        /// <param name="associateRq">Associate Request message.</param>
        public override void AfterHandlingAssociateRequest(AssociateRq associateRq)
        {
            if (IsMessageHandled == false)
            {
                // determine which workflow to follow
                switch (_scpRespondToAssociateRequest)
                {
                    case ScpRespondToAssociateRequestEnum.WithAssociateAccept:
                        {
                            // send an associate accept with the supported transfer syntaxes.
                            this.Options.LocalAeTitle = associateRq.CalledAETitle;
                            this.Options.RemoteAeTitle = associateRq.CallingAETitle;
                            AssociateAc associateAc = SendAssociateAc(new SopClasses(sopList), new TransferSyntaxes(tsStoreList));
                            break;
                        }
                    case ScpRespondToAssociateRequestEnum.WithAssociateReject:
                        // send an associate reject with the given parameters
                        SendAssociateRj(_rejectResult, _rejectSource, _rejectReason);
                        break;
                    case ScpRespondToAssociateRequestEnum.WithAbort:
                    default:
                        // send an abort request with the given parameters
                        SendAbort(_abortSource, _abortReason);
                        break;
                }

                // message has now been handled
                IsMessageHandled = true;
            }
        }
Esempio n. 16
0
 //
 // - Methods -
 //
 /// <summary>
 /// This method is called after an A-ASSOCIATE-RQ has been received but before it
 /// (possibly) will be handled by the (zero or more) MessageHandler instances that
 /// are attached to this object.
 /// 
 /// This implementation makes sure that before the A-ASSOCIATE-RQ is handled, a new
 /// child DicomThread is started that listens to the same port as the current instance.
 /// This method will only be called by a child DicomThread.
 /// </summary>
 /// <param name="associateRq">The received A-ASSOCIATE-RQ</param>
 public override void BeforeHandlingAssociateRequest(AssociateRq associateRq)
 {
     CreateAndStartChildDicomThread(this.overviewThread);
 }
Esempio n. 17
0
        /// <summary>
        /// Method to handle an Associate Request.
        /// </summary>
        /// <param name="associateRq">Associate Request message.</param>
        public override void AfterHandlingAssociateRequest(AssociateRq associateRq)
        {
            if (IsMessageHandled == false)
            {
                this.Options.LocalAeTitle = associateRq.CalledAETitle;
                this.Options.RemoteAeTitle = associateRq.CallingAETitle;

                // send an associate accept/reject with the supported transfer syntaxes.
                DulMessage dulMsg = SendAssociateRp(new SopClasses("1.2.840.10008.1.20.1"), new TransferSyntaxes(tsList));

                if (dulMsg is AssociateRj)
                    this.receiveMessages = false;

                // message has now been handled
                IsMessageHandled = true;
            }
        }
Esempio n. 18
0
        /// <summary>
        /// Receives a messages (can be a Dicom or Dul message).
        /// </summary>
        /// <param name="messageToExpect">Message to expect that is written in the results.</param>
        /// <returns>The received message.</returns>
        /// <exception cref="DicomProtocolMessageReceiveException">
        ///	Receiving of a message fails.
        /// </exception> 
        private DicomProtocolMessage ReceiveMessage(String messageToExpect)
        {
            DicomProtocolMessage receivedMessage = null;

            DvtkData.Message dvtkDataMessage = null;

            if (this.hasOpenConnection)
            {
                if (messageToExpect == "")
                {
                    WriteInformation("Receiving message...");
                }
                else
                {
                    WriteInformation("Receiving message (expecting " +  messageToExpect + ")...");
                }
            }
            else
            {
                WriteInformation(String.Format("Listening for incoming Dicom connection on port {0}...", Options.LocalPort));
            }

            Dvtk.Sessions.ReceiveReturnCode receiveReturnCode = DvtkScriptSession.Receive(out dvtkDataMessage);

            if (receiveReturnCode != Dvtk.Sessions.ReceiveReturnCode.Success)
            {
                throw new DicomProtocolMessageReceiveException("Error while trying to receive a Message. Error code " + receiveReturnCode.ToString() + ".", receiveReturnCode);
            }
            else
            {
                if (dvtkDataMessage is DvtkData.Dimse.DicomMessage)
                {
                    DicomMessage receivedDicomMessage = new DicomMessage(dvtkDataMessage as DvtkData.Dimse.DicomMessage);

                    // Apply the inbound DicomMessage filters if this is a DicomMessage.
                    foreach (InboundDicomMessageFilter inboundDicomMessageFilter in this.inboundDicomMessageFilters)
                    {
                        inboundDicomMessageFilter.Apply(receivedDicomMessage);
                    }

                    receivedMessage = receivedDicomMessage;
                }
                else if (dvtkDataMessage is DvtkData.Dul.A_ASSOCIATE_RQ)
                {
                    receivedMessage = new AssociateRq(dvtkDataMessage as DvtkData.Dul.A_ASSOCIATE_RQ);
                    hasOpenConnection = true;
                }
                else if (dvtkDataMessage is DvtkData.Dul.A_ASSOCIATE_AC)
                {
                    receivedMessage = new AssociateAc(dvtkDataMessage as DvtkData.Dul.A_ASSOCIATE_AC);
                    this.lastAssociateAc = receivedMessage as AssociateAc;
                }
                else if (dvtkDataMessage is DvtkData.Dul.A_ASSOCIATE_RJ)
                {
                    receivedMessage = new AssociateRj(dvtkDataMessage as DvtkData.Dul.A_ASSOCIATE_RJ);
                    hasOpenConnection = false;
                }
                else if (dvtkDataMessage is DvtkData.Dul.A_RELEASE_RQ)
                {
                    receivedMessage = new ReleaseRq(dvtkDataMessage as DvtkData.Dul.A_RELEASE_RQ);
                }
                else if (dvtkDataMessage is DvtkData.Dul.A_RELEASE_RP)
                {
                    receivedMessage = new ReleaseRp(dvtkDataMessage as DvtkData.Dul.A_RELEASE_RP);
                    hasOpenConnection = false;
                }
                else if (dvtkDataMessage is DvtkData.Dul.A_ABORT)
                {
                    receivedMessage = new Abort(dvtkDataMessage as DvtkData.Dul.A_ABORT);
                    hasOpenConnection = false;
                }
                else
                {
                    Debug.Assert(true, "Unexpected DvtkData Message descendant type.");
                }

                WriteInformation("... " + receivedMessage.ToString() + " received.");

                // If the options AutoValidate is true, try to validate as much
                // as possible for the received message.
                if (Options.AutoValidate)
                {
                    Validate(receivedMessage);
                }

                MessageReceived(receivedMessage);

                if (receivedMessage is ReleaseRq)
                {
                    if (AssociationReleasedEvent != null)
                    {
                        AssociationReleasedEvent(this);
                    }
                }
            }

            return (receivedMessage);
        }