Ejemplo n.º 1
0
            /// <summary>
            /// Determines if the first received DicomMessage in a DicomThread instance has an explicit transfer syntax.
            /// </summary>
            /// <param name="dicomThread">The DicomThread.</param>
            /// <returns>Boolean indicating if the first received DicomMessage has an explicit transfer syntax.</returns>
            private bool IsDataTransferExplicit(DicomThread dicomThread)
            {
                bool isDataTransferExplicit = true;

                if ((dicomThread.Messages.ReceivedMessages.DicomMessages.Count > 0))
                {
                    DicomMessage firstReceivedDicomMessage = dicomThread.Messages.ReceivedMessages.DicomMessages[0];

                    byte presentationContextIdFirstReceivedDicomMessage = firstReceivedDicomMessage.EncodedPresentationContextID;

                    AssociateAc firstReceivedAssociateAc = null;

                    foreach (DulMessage dulMessage in dicomThread.Messages.SendMessages.DulMessages)
                    {
                        if (dulMessage is AssociateAc)
                        {
                            firstReceivedAssociateAc = dulMessage as AssociateAc;

                            break;
                        }
                    }

                    if (firstReceivedAssociateAc != null)
                    {
                        foreach (PresentationContext presentationContext in firstReceivedAssociateAc.PresentationContexts)
                        {
                            if (presentationContext.ID == presentationContextIdFirstReceivedDicomMessage)
                            {
                                String transferSyntax = presentationContext.TransferSyntax;

                                if (transferSyntax == "1.2.840.10008.1.2")
                                {
                                    isDataTransferExplicit = false;
                                }
                                else
                                {
                                    isDataTransferExplicit = true;
                                }
                            }
                        }
                    }
                }

                return(isDataTransferExplicit);
            }
Ejemplo n.º 2
0
 /// <summary>
 /// Override this method to handle an A-ASSOCIATE-AC.
 /// </summary>
 /// <param name="associateAc">The received A-ASSOCIATE-AC.</param>
 /// <returns>Return true when this methods has handled the received A-ASSOCIATE-AC, otherwise false.</returns>
 public virtual bool HandleAssociateAccept(AssociateAc associateAc)
 {
     return false;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// This method is called after an A-ASSOCIATE-AC 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="associateAc">The received A-ASSOCIATE-AC</param>
 public virtual void BeforeHandlingAssociateAccept(AssociateAc associateAc)
 {
     // Do nothing.
 }
Ejemplo n.º 4
0
 /// <summary>
 /// This method is called after an A-ASSOCIATE-AC 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="associateAc">The received A-ASSOCIATE-AC.</param>
 public virtual void AfterHandlingAssociateAccept(AssociateAc associateAc)
 {
     // Do nothing.
 }
Ejemplo n.º 5
0
        private void SendMessage(DulMessage dulMessage)
        {
            //
            // Administration.
            //

            dulMessage.IsSend = true;

            AddMessage(dulMessage);

            if (SendingMessageEvent != null)
            {
                SendingMessageEvent(dulMessage);
            }

            //
            // Perform the actual sending.
            //

            Dvtk.Sessions.SendReturnCode sendReturnCode = Dvtk.Sessions.SendReturnCode.Failure;

            sendReturnCode = DvtkScriptSession.Send(dulMessage.DvtkDataDulMessage);

            //
            // If an error is encountered while sending, throw an exception.
            //

            if (sendReturnCode != Dvtk.Sessions.SendReturnCode.Success)
            {
                throw new DicomProtocolMessageSendException("Error while trying to send a " + dulMessage.ToString() + " (" + sendReturnCode.ToString() + ")", sendReturnCode);
            }

            if (dulMessage is AssociateAc)
            {
                this.lastAssociateAc = dulMessage as AssociateAc;
            }
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Sends an A-ASSOCIATE-AC based on the supplied presentation contexts.
        /// </summary>
        /// <remarks>
        /// Any requested presentation context that has no counterpart in the supplied presentation
        /// contexts will automaticaly be added to the A-ASSOCIATE-AC with the presentation context rejected.<br></br><br></br>
        /// 
        /// If an A-ASSOCIATE-RJ should be sent when none of the requested presentation contexts is accepted,
        /// use the <see cref="SendAssociateRp(PresentationContextCollection)"/> method instead.	
        /// </remarks>
        /// <param name="presentationContextCollection">The presentation contexts.</param>
        /// <returns>The sent AssociateAc.</returns>
        protected internal AssociateAc SendAssociateAc(PresentationContextCollection presentationContextCollection)
        {
            //
            // Check the parameter(s).
            //

            foreach(PresentationContext presentationContext in presentationContextCollection)
            {
                if (!presentationContext.IsForAssociateAccept)
                {
                    throw new System.Exception("PresentationContext instance supplied that is not suitable for an A-ASSOCIATE-AC.");
                }
            }

            //
            // Construct the AssociateAc instance.
            //

            AssociateAc associateAc = new AssociateAc
                (Options.RemoteAeTitle,
                Options.LocalAeTitle,
                Options.LocalMaximumLength,
                Options.LocalImplementationClassUid,
                Options.LocalImplementationVersionName);

            foreach(PresentationContext presentationContext in presentationContextCollection)
            {
                associateAc.DvtkDataAssociateAc.AddPresentationContexts(presentationContext.DvtkDataAcceptedPresentationContext);
            }

            //
            // Send the A-ASSOCIATE-AC.
            //

            SendMessage(associateAc);

            return(associateAc);
        }