Ejemplo n.º 1
0
        /// <summary>
        /// This method is indirectly called by a MessageIterator to let this object try
        /// to handle the received DulMessage.
        /// </summary>
        /// <param name="dulMessage">The received DulMessage.</param>
        /// <returns>Returns true if this object has handled the DulMessage, otherwise false.</returns>
        private bool HandleDulMessage(DulMessage dulMessage)
        {
            bool handled = false;

            if (dulMessage is Abort)
            {
                handled = HandleAbort(dulMessage as Abort);
            }
            else if (dulMessage is AssociateAc)
            {
                handled = HandleAssociateAccept(dulMessage as AssociateAc);
            }
            else if (dulMessage is AssociateRj)
            {
                handled = HandleAssociateReject(dulMessage as AssociateRj);
            }
            else if (dulMessage is AssociateRq)
            {
                handled = HandleAssociateRequest(dulMessage as AssociateRq);
            }
            else if (dulMessage is ReleaseRp)
            {
                handled = HandleReleaseResponse(dulMessage as ReleaseRp);
            }
            else if (dulMessage is ReleaseRq)
            {
                handled = HandleReleaseRequest(dulMessage as ReleaseRq);
            }
            else
            {
                Debug.Assert(true, "Not implemented yet.");
            }

            return(handled);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// <see cref="ISniffer.Validate(DulMessage , ValidationControlFlags )"/>
        /// </summary>
        public bool Validate(
            DulMessage message,
            ValidationControlFlags validationControlFlags)
        {
            if (message == null)
            {
                throw new System.ArgumentNullException();
            }

            //Set the validation options
            Wrappers.ValidationControlFlags
                wrappersValidationControlFlags = Wrappers.ValidationControlFlags.None;
            if ((validationControlFlags & ValidationControlFlags.UseDefinitions) != 0)
            {
                wrappersValidationControlFlags |= Wrappers.ValidationControlFlags.UseDefinitions;
            }
            if ((validationControlFlags & ValidationControlFlags.UseValueRepresentations) != 0)
            {
                wrappersValidationControlFlags |= Wrappers.ValidationControlFlags.UseValueRepresentations;
            }

            return((this.m_adaptee as Wrappers.MSnifferSession).Validate(
                       message,
                       wrappersValidationControlFlags));
        }
Ejemplo n.º 3
0
 /// <summary>
 /// <see cref="IDulMessaging.Receive"/>
 /// </summary>
 public ReceiveReturnCode Receive(out DulMessage dulMessage)
 {
     dulMessage = null;
     Wrappers.ReceiveReturnCode wrappersReceiveReturnCode =
         (this.m_adaptee as Wrappers.MScriptSession).Receive(out dulMessage);
     return(_Convert(wrappersReceiveReturnCode));
 }
Ejemplo n.º 4
0
 /// <summary>
 /// This method is called after a DulMessage has been received but before it
 /// (possibly) will be handled by the (zero or more) MessageHandler objects that
 /// are attached to this object.
 /// </summary>
 /// <param name="dulMessage">The received DulMessage.</param>
 private void BeforeHandlingDulMessage(DulMessage dulMessage)
 {
     if (dulMessage is Abort)
     {
         BeforeHandlingAbort(dulMessage as Abort);
     }
     else if (dulMessage is AssociateAc)
     {
         BeforeHandlingAssociateAccept(dulMessage as AssociateAc);
     }
     else if (dulMessage is AssociateRj)
     {
         BeforeHandlingAssociateReject(dulMessage as AssociateRj);
     }
     else if (dulMessage is AssociateRq)
     {
         BeforeHandlingAssociateRequest(dulMessage as AssociateRq);
     }
     else if (dulMessage is ReleaseRq)
     {
         BeforeHandlingReleaseRequest(dulMessage as ReleaseRq);
     }
     else if (dulMessage is ReleaseRp)
     {
         BeforeHandlingReleaseResponse(dulMessage as ReleaseRp);
     }
     else
     {
         Debug.Assert(true, "Not implemented yet.");
     }
 }
Ejemplo n.º 5
0
        private bool SendAssociationAndWait(DicomMessageCollection dicomMessages, params PresentationContext[] presentationContexts)
        {
            bool isAssociationAccepted = true;

            // Send the associate request.
            SendAssociateRq(presentationContexts);

            // Receive the associate repsonse (may be an accept or reject).
            DulMessage associateRp = ReceiveAssociateRp();

            try
            {
                // If an associate accept was received, send the collection of DicomMessages, receive a response and
                // release the association.
                if (associateRp is AssociateAc)
                {
                    // send each message
                    foreach (DicomMessage dicomMessage in dicomMessages)
                    {
                        Send(dicomMessage);

                        DicomMessage responseMessage = ReceiveDicomMessage();

                        // use the common config option 1 to determine how the storage commitment should be handled
                        if (DicomClient.ConfigOption1.Equals("DO_STORAGE_COMMITMENT_ON_SINGLE_ASSOCIATION") == true)
                        {
                            DicomMessage dicomRequest = ReceiveDicomMessage();

                            // Validate the received message
                            //                        System.String iodName = GetIodNameFromDefinition(dicomRequest);
                            //                        Validate(dicomRequest, iodName);

                            // set up the default N-EVENT-REPORT-RSP with a successful status
                            responseMessage = new DicomMessage(DvtkData.Dimse.DimseCommand.NEVENTREPORTRSP);
                            responseMessage.Set("0x00000900", VR.US, 0);

                            // send the response
                            Send(responseMessage);
                        }
                    }

                    SendReleaseRq();

                    ReceiveReleaseRp();
                }
                else
                {
                    isAssociationAccepted = false;
                }
            }
            catch (Exception e)
            {
                SendReleaseRq();
                ReceiveReleaseRp();
                throw e;
            }

            return(isAssociationAccepted);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// <see cref="IDulValidation.Validate"/>
        /// </summary>
        public bool Validate(
            DulMessage message,
            DulMessage referenceMessage,
            ValidationControlFlags validationControlFlags)
        {
            if (message == null)
            {
                throw new System.ArgumentNullException();
            }
            //
            // referenceMessage may be null
            //
            if (referenceMessage != null)
            {
                //
                // Check runtime instance type equality of message and referenceMessage
                //
                if (referenceMessage.GetType() != message.GetType())
                {
                    throw new System.ArgumentException(
                              string.Concat(
                                  "message and referenceMessage should have the same type.\n",
                                  string.Format(
                                      "message type = {0}\n",
                                      message.GetType().ToString()
                                      ),
                                  string.Format(
                                      "referenceMessage type = {0}\n",
                                      referenceMessage.GetType().ToString()
                                      )
                                  ),
                              "referenceMessage");
                }
            }
            //
            // Remove obsolete flag ValidationControlFlags.UseValueRepresentations
            //
            Wrappers.ValidationControlFlags
                wrappersValidationControlFlags = Wrappers.ValidationControlFlags.None;
            if ((validationControlFlags & ValidationControlFlags.UseDefinitions) != 0)
            {
                wrappersValidationControlFlags |= Wrappers.ValidationControlFlags.UseDefinitions;
            }
            if ((validationControlFlags & ValidationControlFlags.UseReferences) != 0)
            {
                wrappersValidationControlFlags |= Wrappers.ValidationControlFlags.UseReferences;
            }
//            if ((validationControlFlags & ValidationControlFlags.UseValueRepresentations) != 0)
//                wrappersValidationControlFlags |= Wrappers.ValidationControlFlags.UseValueRepresentations;

            return((this.m_adaptee as Wrappers.MScriptSession).Validate(
                       message,
                       referenceMessage,
                       wrappersValidationControlFlags));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// <see cref="IDulMessaging.Send"/>
        /// </summary>
        public SendReturnCode Send(DulMessage message)
        {
            if (message == null)
            {
                throw new System.ArgumentNullException();
            }

            Wrappers.SendReturnCode wrappersSendReturnCode =
                (this.m_adaptee as Wrappers.MScriptSession).Send(message);
            return(_Convert(wrappersSendReturnCode));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Validate the Dul Message by inspecting the VR's and the definition.
        /// </summary>
        /// <param name="dulMessage">The Dul Message.</param>

        public void Validate(DicomThread dicomThread, DulMessage dulMessage)
        {
            this.thread.WriteInformationInternal("Validate Dul message...");

            if (!dulMessage.AreValueRepresentationsValidated)
            {
                dicomThread.DvtkScriptSession.Validate(dulMessage.DvtkDataDulMessage, null, Dvtk.Sessions.ValidationControlFlags.UseValueRepresentations);
                dulMessage.AreValueRepresentationsValidated = true;
            }
            else
            {
                dicomThread.WriteInformationInternal("VR's of DulMessage will not be validated again.\r\nNo validation performed.");
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// <see cref="IDulMessaging.Receive"/>
        /// </summary>
        public ReceiveReturnCode Receive(out A_RELEASE_RQ A_RELEASE_RQ_Message)
        {
            ReceiveReturnCode receiveReturnCode;
            DulMessage        dulMessage = null;

            receiveReturnCode    = Receive(out dulMessage);
            A_RELEASE_RQ_Message = dulMessage as A_RELEASE_RQ;
            if (
                receiveReturnCode == ReceiveReturnCode.Success &&
                A_RELEASE_RQ_Message == null
                )
            {
                receiveReturnCode = ReceiveReturnCode.Failure;
            }
            return(receiveReturnCode);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// <see cref="IDulMessaging.Receive"/>
        /// </summary>
        public ReceiveReturnCode Receive(out A_ASSOCIATE_RJ A_ASSOCIATE_RJ_Message)
        {
            ReceiveReturnCode receiveReturnCode;
            DulMessage        dulMessage = null;

            receiveReturnCode      = Receive(out dulMessage);
            A_ASSOCIATE_RJ_Message = dulMessage as A_ASSOCIATE_RJ;
            if (
                receiveReturnCode == ReceiveReturnCode.Success &&
                A_ASSOCIATE_RJ_Message == null
                )
            {
                receiveReturnCode = ReceiveReturnCode.Failure;
            }
            return(receiveReturnCode);
        }
Ejemplo n.º 11
0
        protected override void Execute()
        {
            SendAssociateRq(
                new PresentationContext(selectedQueryRootSop, explicitVRLittleEndian)
                );

            DulMessage dulMsg = ReceiveAssociateRp();

            if (dulMsg is AssociateAc)
            {
                if (selectedQueryRootSop == patientRootQRFindSOP)
                {
                    DoPatientLevelQuery();
                }
                else if (selectedQueryRootSop == studyRootQRFindSOP)
                {
                    DoStudyLevelQuery(patientId);
                }

                if ((this.ThreadState != ThreadState.Stopping) && (this.ThreadState != ThreadState.Stopped))
                {
                    SendReleaseRq();

                    ReceiveReleaseRp();
                }

                FilterQueryData();
            }
            else if (dulMsg is AssociateRj)
            {
                AssociateRj assocRj = (AssociateRj)dulMsg;
                string      msg     = string.Format("Association Rejected for proposed presentation contexts:\nResult - {0}({1})\nSource - {2}({3})\nReason - {4}({5})", assocRj.Result,
                                                    convertResult(assocRj.Result),
                                                    assocRj.Source,
                                                    convertSource(assocRj.Source),
                                                    assocRj.Reason,
                                                    convertReason(assocRj.Source, assocRj.Reason));
                WriteInformation(msg);
            }
            else
            {
                WriteInformation("Unknown message is received from SCP.");
            }
        }
Ejemplo n.º 12
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;
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Serialize DVT Detail Data to Xml.
        /// </summary>
        /// <param name="streamWriter">Stream writer to serialize to.</param>
        /// <param name="level">Recursion level. 0 = Top.</param>
        /// <returns>bool - success/failure</returns>
        public bool DvtDetailToXml(StreamWriter streamWriter, int level)
        {
            if (streamWriter == null)
            {
                return(true);
            }

            bool result = false;

            streamWriter.WriteLine("<Receive>");
            if (Item is DicomMessage)
            {
                DicomMessage dicomMessage = (DicomMessage)Item;
                result = dicomMessage.DvtDetailToXml(streamWriter, level);
            }
            else
            {
                DulMessage dulMessage = (DulMessage)Item;
                result = dulMessage.DvtDetailToXml(streamWriter, level);
            }
            streamWriter.WriteLine("</Receive>");

            return(result);
        }
Ejemplo n.º 14
0
        protected override void Execute()
        {
            if (_presentationContexts.Length != 0)
            {
                SendAssociateRq(_presentationContexts);
            }
            else
            {
                WriteError("There is no presentation context available for proposing.");
                return;
            }

            DulMessage dulMsg = ReceiveAssociateRp();

            if (dulMsg is AssociateAc)
            {
                AssociateAc assocAc = (AssociateAc)dulMsg;
                foreach (PresentationContext acceptedPC in assocAc.PresentationContexts)
                {
                    if (acceptedPC.Result == 0)
                    {
                        string msg = string.Format("Accepted Presentation Context: Abstract Syntax - {0}, Transfer Syntax - {1}", acceptedPC.AbstractSyntax, acceptedPC.TransferSyntax);
                        WriteInformation(msg);

                        string sopClassUid    = "";
                        string sopInstUid     = "";
                        string transferSyntax = "";
                        foreach (DicomFile dcmFile in _dicomFileCollection)
                        {
                            // Get the SOP Class UID
                            Values values = dcmFile.DataSet["0x00080016"].Values;
                            sopClassUid = values[0];

                            // Get the SOP Instance UID
                            Values sopClassUidvalues = dcmFile.DataSet["0x00080018"].Values;
                            sopInstUid = sopClassUidvalues[0];

                            Values transferSyntaxes = dcmFile.FileMetaInformation["0x00020010"].Values;
                            transferSyntax = transferSyntaxes[0];


                            // try for a match
                            if ((acceptedPC.Result == 0) &&
                                (acceptedPC.AbstractSyntax == sopClassUid) && acceptedPC.TransferSyntax == transferSyntax)
                            {
                                DicomMessage storeMsg = new DicomMessage(DvtkData.Dimse.DimseCommand.CSTORERQ, dcmFile.DataSet);


                                string message = string.Format("Sending DICOM object with PC ID - {0}", acceptedPC.ID);
                                WriteInformation(message);
                                System.Diagnostics.Debug.WriteLine(storeMsg.DataSet.Dump("set-"));

                                Send(storeMsg, acceptedPC.ID);

                                DicomMessage rspMsg    = ReceiveDicomMessage();
                                Int32        statusVal = Int32.Parse(rspMsg.CommandSet.GetValues("0x00000900")[0]);
                                if (statusVal == 0)
                                {
                                    string infoMsg = string.Format("Image with SOP Instance UID{0} stored successfully.", sopInstUid);
                                    WriteInformation(infoMsg);
                                }
                                else
                                {
                                    string warnMsg = string.Format("Non-zero status returned. Image with SOP Instance UID{0} storage failed.", sopInstUid);
                                    WriteWarning(warnMsg);
                                }
                            }
                        }
                    }
                    else
                    {
                        string resultStr = convertAccResult(acceptedPC.Result);
                        string message   = string.Format("Can't store DICOM object with Rejected Abstract Syntax - {0}, PC ID - {1}, Reason - {2}", acceptedPC.AbstractSyntax, acceptedPC.ID, resultStr);
                        WriteWarning(message);
                    }
                }

                SendReleaseRq();

                ReceiveReleaseRp();
            }
            else if (dulMsg is AssociateRj)
            {
                AssociateRj assocRj = (AssociateRj)dulMsg;
                string      msg     = string.Format("Association Rejected for proposed presentation contexts:\nResult - {0}({1})\nSource - {2}({3})\nReason - {4}({5})", assocRj.Result,
                                                    convertResult(assocRj.Result),
                                                    assocRj.Source,
                                                    convertSource(assocRj.Source),
                                                    assocRj.Reason,
                                                    convertReason(assocRj.Source, assocRj.Reason));
                WriteInformation(msg);
            }
            else
            {
                WriteInformation("Unknown message is received from SCP.");
            }
        }