/// <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; } }
public override void AfterHandlingAssociateRequest(AssociateRq associateRq) { if (!IsMessageHandled) { SendAssociateRp(); IsMessageHandled = true; } }
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; } }
/// <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; } }
/// <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; } }
/// <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; } }
/// <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; } }
/// <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. }
/// <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; }
public override void BeforeHandlingAssociateRequest(AssociateRq associateRq) { this.SendingMessageEvent += new SendingMessageEventHandler(QRScp_SendingMessageEvent); this.MessageReceivedEvent += new MessageReceivedEventHandler(QRScp_MessageReceivedEvent); base.BeforeHandlingAssociateRequest(associateRq); }
/// <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. /// /// This implementation makes sure that before the A-ASSOCIATE-RQ is handled, a new /// sub DicomThread is started that listens to the same port as the current object. /// This method will only be called by a sub DicomThread. /// </summary> /// <param name="associateRq">The received A-ASSOCIATE-RQ</param> public override void BeforeHandlingAssociateRequest(AssociateRq associateRq) { CreateAndStartChildDicomThread(this.overviewThread); }
/// <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. }
/// <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; } }
/// <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); }
/// <summary> /// Send a A-ASSOCIATE-RQ. /// </summary> /// <param name="presentationContexts">One or more PresentationContext objects.</param> /// <returns>The A-ASSOCIATE-RQ</returns> public AssociateRq SendAssociateRq(params PresentationContext[] presentationContexts) { // Start Interface logging. // InterfaceLogging.Start(this); 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 = DvtkScriptSession.DvtSystemSettings.AeTitle; dvtkDataAssociateRq.CalledAETitle = DvtkScriptSession.SutSystemSettings.AeTitle; dvtkDataAssociateRq.UserInformation.MaximumLength.MaximumLengthReceived = Convert.ToUInt32(16384); dvtkDataAssociateRq.UserInformation.ImplementationClassUid.UID = "100.118.116.2003.1.4"; // Parse all parameters. foreach(PresentationContext presentationContext in presentationContexts) { if (!presentationContext.InterpretAsPcForAssociateRq()) { DvtkHighLevelInterfaceException.Throw("Error while interpreting parameters for PresentationContext"); } DvtkData.Dul.RequestedPresentationContext requestedPresentationContext = new DvtkData.Dul.RequestedPresentationContext(); requestedPresentationContext.AbstractSyntax = new DvtkData.Dul.AbstractSyntax(presentationContext.SopClass); foreach (String transferSyntax in presentationContext.TransferSyntaxes) { requestedPresentationContext.AddTransferSyntaxes(new DvtkData.Dul.TransferSyntax(transferSyntax)); } dvtkDataAssociateRq.AddPresentationContexts(requestedPresentationContext); } Dvtk.Sessions.SendReturnCode sendReturnCode = DvtkScriptSession.Send(dvtkDataAssociateRq); if (sendReturnCode != Dvtk.Sessions.SendReturnCode.Success) { DvtkHighLevelInterfaceException.Throw("Error sending associate request (" + sendReturnCode.ToString() + ")"); } else { associateRq = new AssociateRq(dvtkDataAssociateRq); associateRq.IsSend = true; ThreadManager.DataWarehouse.AddMessage(this, associateRq); } // End Interface logging. // InterfaceLogging.End(associateRq); return(associateRq); }
/// <summary> /// Receive a message (can be a Dicom or Dul message). /// /// An exception is thrown when receiving of a message fails. /// </summary> /// <returns>The received message.</returns> public Message ReceiveMessage() { // Start Interface logging. // InterfaceLogging.Start(this); DicomProtocolMessage receivedMessage = null; DvtkData.Message dvtkDataMessage = null; WriteInformation("Receive message..."); Dvtk.Sessions.ReceiveReturnCode receiveReturnCode = DvtkScriptSession.Receive(out dvtkDataMessage); if (receiveReturnCode != Dvtk.Sessions.ReceiveReturnCode.Success) { DvtkHighLevelInterfaceException.Throw("Error while trying to receive a Message. Error code " + receiveReturnCode.ToString() + "."); } else { if (dvtkDataMessage is DvtkData.Dimse.DicomMessage) { receivedMessage = new DicomMessage(dvtkDataMessage as DvtkData.Dimse.DicomMessage); } else if (dvtkDataMessage is DvtkData.Dul.A_ASSOCIATE_RQ) { lastAssociateRq = new AssociateRq(dvtkDataMessage as DvtkData.Dul.A_ASSOCIATE_RQ); receivedMessage = lastAssociateRq; } else if (dvtkDataMessage is DvtkData.Dul.A_ASSOCIATE_AC) { receivedMessage = new AssociateAc(dvtkDataMessage as DvtkData.Dul.A_ASSOCIATE_AC); } else if (dvtkDataMessage is DvtkData.Dul.A_ASSOCIATE_RJ) { receivedMessage = new AssociateRj(dvtkDataMessage as DvtkData.Dul.A_ASSOCIATE_RJ); } 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); } else if (dvtkDataMessage is DvtkData.Dul.A_ABORT) { receivedMessage = new Abort(dvtkDataMessage as DvtkData.Dul.A_ABORT); } else { Debug.Assert(true, "Unexpected DvtkData Message descendant type."); } // If the options AutoValidate is true, try to validate as much // as possible for the received message. if (Options.AutoValidate) { Validate(receivedMessage); } receivedMessage.IsReceived = true; ThreadManager.DataWarehouse.AddMessage(this, receivedMessage); if (receivedMessage is ReleaseRq) { if (AssociationReleasedEvent != null) { AssociationReleasedEvent(this); } } } // End Interface logging. // InterfaceLogging.End(receivedMessage); return(receivedMessage); }
private void SetAcceptedPresentationContexts(AssociateRq associateRq, AssociateAc associateAc, params Object[] parameters) { TransferSyntaxes transferSyntaxes = null; SopClasses sopClasses = null; if (parameters.Length == 1) { transferSyntaxes = parameters[0] as TransferSyntaxes; if (transferSyntaxes == null) { DvtkHighLevelInterfaceException.Throw("Error while interpreting parameters."); } } else if (parameters.Length == 2) { transferSyntaxes = parameters[0] as TransferSyntaxes; if (transferSyntaxes == null) { sopClasses = parameters[0] as SopClasses; if (sopClasses == null) { DvtkHighLevelInterfaceException.Throw("Error while interpreting parameters."); } else { transferSyntaxes = parameters[1] as TransferSyntaxes; if (transferSyntaxes == null) { DvtkHighLevelInterfaceException.Throw("Error while interpreting parameters."); } } } else { sopClasses = parameters[1] as SopClasses; if (sopClasses == null) { DvtkHighLevelInterfaceException.Throw("Error while interpreting parameters."); } } } else { DvtkHighLevelInterfaceException.Throw("Error while interpreting parameters."); } foreach(DvtkData.Dul.RequestedPresentationContext dvtkDataRequestedPresentationContext in associateRq.DvtkDataAssociateRq.PresentationContexts) { String sopClassToAccept = null; String transferSyntaxToAccept = null; if (sopClasses == null) { sopClassToAccept = dvtkDataRequestedPresentationContext.AbstractSyntax.UID; } else { foreach(String acceptedSopClass in sopClasses.list) { if (acceptedSopClass == dvtkDataRequestedPresentationContext.AbstractSyntax.UID) { sopClassToAccept = dvtkDataRequestedPresentationContext.AbstractSyntax.UID; break; } } } if (sopClassToAccept != null) { foreach(String acceptedTransferSyntax in transferSyntaxes.list) { foreach(DvtkData.Dul.TransferSyntax requestedDvtkDataTransferSyntax in dvtkDataRequestedPresentationContext.TransferSyntaxes) { if (acceptedTransferSyntax == requestedDvtkDataTransferSyntax.UID) { transferSyntaxToAccept = requestedDvtkDataTransferSyntax.UID; break; } } if (transferSyntaxToAccept != null) { break; } } if (transferSyntaxToAccept != null) { DvtkData.Dul.AcceptedPresentationContext dvtkDataAcceptedPresentationContext = new DvtkData.Dul.AcceptedPresentationContext(); dvtkDataAcceptedPresentationContext.AbstractSyntax = new DvtkData.Dul.AbstractSyntax(sopClassToAccept); dvtkDataAcceptedPresentationContext.TransferSyntax = new DvtkData.Dul.TransferSyntax(transferSyntaxToAccept); dvtkDataAcceptedPresentationContext.Result = 0; associateAc.DvtkDataAssociateAc.AddPresentationContexts(dvtkDataAcceptedPresentationContext); } } } }