Пример #1
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;
            }
        }
Пример #2
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.");
            }
        }
Пример #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.
 }
Пример #4
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);
 }
Пример #5
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.
 }