Example #1
0
 /// <summary>
 /// Override this method to handle an A-RELEASE-RP.
 /// </summary>
 /// <param name="releaseRp">The received A-RELEASE-RP.</param>
 /// <returns>Return true when this methods has handled the received A-RELEASE-RP, otherwise false.</returns>
 public virtual bool HandleReleaseResponse(ReleaseRp releaseRp)
 {
     return false;
 }
Example #2
0
 /// <summary>
 /// This method is called after an A-RELEASE-RP 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="releaseRp">The received A-RELEASE-RP.</param>
 public virtual void BeforeHandlingReleaseResponse(ReleaseRp releaseRp)
 {
     // Do nothing.
 }
Example #3
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);
        }
Example #4
0
 /// <summary>
 /// This method is called after an A-RELEASE-RP 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="releaseRp">The received A-RELEASE-RP.</param>
 public virtual void AfterHandlingReleaseResponse(ReleaseRp releaseRp)
 {
     // Do nothing.
 }
Example #5
0
        /// <summary>
        /// Sends a Dicom A_RELEASE_RP.
        /// </summary>
        /// <returns>The sent A_RELEASE_RP.</returns>
        /// <exception cref="System.Exception">
        ///	Sending of the A_RELEASE_RP fails.
        /// </exception> 		
        protected internal ReleaseRp SendReleaseRp()
        {
            ReleaseRp releaseRp = new ReleaseRp();

            SendMessage(releaseRp);

            hasOpenConnection = false;

            return (releaseRp);
        }