Ejemplo n.º 1
0
        /// <summary>
        /// Overridden N-ACTION-RQ message handler. Return an N-EVENT-REPORT-RQ
        /// after the N-ACTION-RSP.
        /// </summary>
        /// <param name="queryMessage">N-ACTION-RQ and Dataset.</param>
        /// <returns>Boolean - true if dicomMessage handled here.</returns>
        protected override void AfterHandlingNActionRequest(DicomMessage dicomMessage)
        {
            isEventSent = false;

            // set up the default N-ACTION-RSP with a successful status
            DicomMessage responseMessage = new DicomMessage(DvtkData.Dimse.DimseCommand.NACTIONRSP);

            responseMessage.Set("0x00000900", DvtkData.Dimse.VR.US, 0);

            // send the response
            this.Send(responseMessage);

            IsMessageHandled = true;

            // creating information model
            QueryRetrieveInformationModels qrInfoModels = CreateQueryRetrieveInformationModels(true, _dataDirectory);

            // delay before generating the N-EVENT-REPORT-RQ
            WriteInformation(string.Format("Delaying the N-EVENT-REPORT by {0} secs", _eventDelay / 1000));

            isAssociated = true;
            int waitedTime = 0;

            if (WaitForPendingDataInNetworkInputBuffer(_eventDelay, ref waitedTime))
            {
                ReleaseRq releaseRq = ReceiveReleaseRq();

                if (releaseRq != null)
                {
                    SendReleaseRp();

                    isAssociated = false;
                }
            }

            if (!isAssociated)
            {
                string info = "Sending the N-Event-Report asynchronously.";
                WriteInformation(info);

                SCU commitScu = new SCU();

                commitScu.Initialize(this.Parent);

                // Set the correct settings for the overview DicomThread.
                //
                commitScu.Options.Identifier = "Storage_Commitment_SCU_association_" + storageCommitmentScuIndex.ToString();
                commitScu.Options.ResultsFileNameOnlyWithoutExtension = (this.overviewThread as StoreCommitScp).startDateTime + "_Storage_Commitment_SCU_association_" + storageCommitmentScuIndex.ToString();
                storageCommitmentScuIndex++;
                commitScu.Options.LocalAeTitle     = this.Options.LocalAeTitle;
                commitScu.Options.RemoteAeTitle    = _remoteAETitle;
                commitScu.Options.RemotePort       = _port;
                commitScu.Options.RemoteHostName   = _remoteHostName;
                commitScu.Options.RemoteRole       = Dvtk.Sessions.SutRole.Requestor;
                commitScu.Options.ResultsDirectory = this.Options.ResultsDirectory;
                commitScu.Options.DataDirectory    = this.Options.DataDirectory;
                commitScu.Options.StorageMode      = Dvtk.Sessions.StorageMode.NoStorage;
                commitScu.Options.LogThreadStartingAndStoppingInParent = false;
                commitScu.Options.LogWaitingForCompletionChildThreads  = false;
                commitScu.Options.AutoValidate = false;

                PresentationContext presentationContext = new PresentationContext("1.2.840.10008.1.20.1", // Abstract Syntax Name
                                                                                  "1.2.840.10008.1.2");   // Transfer Syntax Name(s)
                PresentationContext[] presentationContexts = new PresentationContext[1];
                presentationContexts[0] = presentationContext;

                // create the N-EVENT-REPORT-RQ based in the contents of the N-ACTION-RQ
                DicomMessage requestMessage = GenerateTriggers.MakeStorageCommitEvent(qrInfoModels, dicomMessage);

                if (waitedTime < _eventDelay)
                {
                    Sleep(_eventDelay - waitedTime);
                }

                commitScu.Start();

                isEventSent = commitScu.TriggerSendAssociationAndWait(requestMessage, presentationContexts);
            }
            else
            {
                string info = "Sending the N-Event-Report synchronously.";
                WriteInformation(info);

                if (!isEventSent)
                {
                    SendNEventReport(qrInfoModels, dicomMessage);
                }
            }
        }
Ejemplo n.º 2
0
        private bool HandleSubOperation(System.String moveDestinationAE, System.String dcmFilename, int subOperationIndex)
        {
            SCU storageScu = new SCU();

            storageScu.Initialize(DicomThread.ThreadManager);
            storageScu.Options.DeepCopyFrom(DicomThread.Options);

            storageScu.Options.Identifier = "StorageSubOperationAsScu";

            ////Check for Secure connection
            //if (DicomThread.Options.SecureConnection)
            //{
            //    storageScu.Options.SecureConnection = true;
            //    storageScu.Options.CertificateFilename = DicomThread.Options.CertificateFilename;
            //    storageScu.Options.CredentialsFilename = DicomThread.Options.CredentialsFilename;
            //}

            storageScu.Options.ResultsFileNameOnlyWithoutExtension = "StorageSubOperationAsScu" + subOperationIndex.ToString();
            storageScu.Options.ResultsDirectory = DicomThread.Options.ResultsDirectory;

            storageScu.Options.LocalAeTitle = DicomThread.Options.LocalAeTitle;
            storageScu.Options.LocalPort    = DicomThread.Options.LocalPort;
            if (IsHaveMoveDestinations)
            {
                storageScu.Options.RemoteAeTitle  = moveDestinationAE;
                storageScu.Options.RemotePort     = MoveDestiantions[MoveAEdetailsIndex].Port;
                storageScu.Options.RemoteHostName = MoveDestiantions[MoveAEdetailsIndex].IP;
            }
            else
            {
                storageScu.Options.RemoteAeTitle  = moveDestinationAE;
                storageScu.Options.RemotePort     = DicomThread.Options.RemotePort;
                storageScu.Options.RemoteHostName = DicomThread.Options.RemoteHostName;
            }

            storageScu.Options.DataDirectory = DicomThread.Options.DataDirectory;
            storageScu.Options.StorageMode   = Dvtk.Sessions.StorageMode.AsDataSet;

            // Read the DCM File
            DicomFile dcmFile = new DicomFile();

            dcmFile.Read(dcmFilename, storageScu);

            FileMetaInformation fMI = dcmFile.FileMetaInformation;

            // Get the transfer syntax and SOP class UID
            System.String transferSyntax = "1.2.840.10008.1.2";
            if ((fMI != null) && fMI.Exists("0x00020010"))
            {
                // Get the Transfer syntax
                DvtkHighLevelInterface.Dicom.Other.Attribute tranferSyntaxAttr = fMI["0x00020010"];
                transferSyntax = tranferSyntaxAttr.Values[0];
            }

            Values values = dcmFile.DataSet["0x00080016"].Values;

            System.String sopClassUid = values[0];

            PresentationContext presentationContext = new PresentationContext(sopClassUid,             // Abstract Syntax Name
                                                                              transferSyntax);         // Transfer Syntax Name(s)

            PresentationContext[] presentationContexts = new PresentationContext[1];
            presentationContexts[0] = presentationContext;

            DicomMessage storageMessage = new DicomMessage(DvtkData.Dimse.DimseCommand.CSTORERQ);

            storageMessage.DataSet.CloneFrom(dcmFile.DataSet);

            storageScu.Start();

            bool sendResult = storageScu.TriggerSendAssociationAndWait(storageMessage, presentationContexts);

            if (!sendResult)
            {
                WriteWarning("Association to move destination for Storage Sub-Operation is rejected.");
            }

            if (storageScu.HasExceptionOccured)
            {
                WriteError("Storage Sub-Operation As SCU Failed");
            }
            storageScu.Stop();

            DicomMessageCollection cStoreResponses = storageScu.Messages.DicomMessages.CStoreResponses;

            // Obtain the value of the C-STORE RSP.The value of this variable is used to determine the attributes of the C-MOVE RSP.
            foreach (DicomMessage cStoreRsp in cStoreResponses)
            {
                cStoreStatusVal = Int32.Parse(cStoreRsp.CommandSet.GetValues("0x00000900")[0]);
            }

            // Transform the sub results
            Xslt.StyleSheetFullFileName = DicomThread.Options.StyleSheetFullFileName;
            System.String htmlResultsFilename = Xslt.Transform(storageScu.Options.ResultsDirectory, storageScu.Options.ResultsFileNameOnly);

            // Make link to the sub-operation results file
            System.String message = System.String.Format("<a href=\"{0}\">Storage sub-operation {1} to AE Title \"{2}\"</a><br/>",
                                                         htmlResultsFilename,
                                                         subOperationIndex,
                                                         moveDestinationAE);
            DicomThread.WriteHtmlInformation(message);

            return(sendResult);
        }
Ejemplo n.º 3
0
        private bool HandleSubOperation(System.String moveDestinationAE, System.String dcmFilename, int subOperationIndex)
        {
            SCU storageScu = new SCU(true);

            storageScu.Initialize(DicomThread.ThreadManager);

            storageScu.Options.Identifier = "StorageSubOperationAsScu";

            if (DicomThread.Options.StartAndEndResultsGathering == true)
            {
                storageScu.Options.StartAndEndResultsGathering = true;
                storageScu.Options.ResultsFilePerAssociation   = false;

                System.String filenameFormat  = DicomThread.Options.ResultsFileName.Replace("_res", "_StorageSubOperationAsScu{0}_res");
                System.String resultsFilename = String.Format(filenameFormat, subOperationIndex);
                storageScu.Options.ResultsFileName  = resultsFilename;
                storageScu.Options.ResultsDirectory = DicomThread.Options.ResultsDirectory;

                System.String message = String.Format("StorageSubOperation filename: {0}", storageScu.Options.ResultsDirectory + "Detail_" + storageScu.Options.ResultsFileName);
                DicomThread.WriteInformation(message);
            }
            else
            {
                storageScu.Options.StartAndEndResultsGathering = false;
            }

            storageScu.Options.DvtAeTitle = DicomThread.Options.DvtAeTitle;
            storageScu.Options.DvtPort    = DicomThread.Options.DvtPort;

            storageScu.Options.SutAeTitle   = moveDestinationAE;
            storageScu.Options.SutPort      = DicomThread.Options.SutPort;
            storageScu.Options.SutIpAddress = DicomThread.Options.SutIpAddress;

            storageScu.Options.DataDirectory = DicomThread.Options.DataDirectory;
            storageScu.Options.StorageMode   = Dvtk.Sessions.StorageMode.AsDataSet;

//			foreach (System.String filename in config.DefinitionFiles)
//			{
//				storageScu.Options.LoadDefinitionFile(filename);
//			}

            System.String       sopClassUid = "1.2.840.10008.5.1.4.1.1.7";
            PresentationContext presentationContext
                = new PresentationContext(sopClassUid,                 // Abstract Syntax Name
                                          "1.2.840.10008.1.2");        // Transfer Syntax Name(s)

            PresentationContext[] presentationContexts = new PresentationContext[1];
            presentationContexts[0] = presentationContext;

            DicomMessage storageMessage = new DicomMessage(DvtkData.Dimse.DimseCommand.CSTORERQ);

            storageMessage.DataSet.Read(dcmFilename, storageScu);

            storageScu.NonThreadedStart();

            bool sendResult = false;

            try
            {
                sendResult = storageScu.SendAssociation(storageMessage, presentationContexts);
            }
            catch (System.Exception)
            {
                DicomThread.WriteError("Storage Sub-Operation As SCU Failed");
            }
            finally
            {
                storageScu.NonThreadedStop();
            }

            return(sendResult);
        }
Ejemplo n.º 4
0
        private void dICOMEchoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string detailedEchoFileName = "";

            if (registeredPeersGrid.SelectedIndices.Count > 0)
            {
                int selectedIndex = registeredPeersGrid.SelectedIndices[0];

                //isStorageEcho = true;
                allThreadsFinished = false;
                if ((peers[selectedIndex].IP == null) || (peers[selectedIndex].IP.Length == 0))
                {
                    MessageBox.Show("Pl Specify SCP IP Address.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                //Update DVT & SUT settings
                OverviewThread overviewThread = new OverviewThread();
                overviewThread.Initialize(threadManager);
                overviewThread.Options.DeepCopyFrom(options);
                overviewThread.Options.Identifier = "Move_Destinations";
                overviewThread.Options.AttachChildsToUserInterfaces         = true;
                overviewThread.Options.LogThreadStartingAndStoppingInParent = false;
                overviewThread.Options.LogWaitingForCompletionChildThreads  = false;
                String resultsFileName = "MoveDestinations_" + System.DateTime.Now.ToString("yyyyMMddHHmmss", System.Globalization.CultureInfo.InvariantCulture);
                overviewThread.Options.ResultsFileNameOnlyWithoutExtension = resultsFileName;


                SCU echoScu = new SCU();
                echoScu.Initialize(overviewThread);
                echoScu.Options.DeepCopyFrom(options);

                String resultsFileBaseName = "MoveDestinationsEcho_" + System.DateTime.Now.ToString("yyyyMMddHHmmss", System.Globalization.CultureInfo.InvariantCulture);
                echoScu.Options.ResultsFileNameOnlyWithoutExtension = resultsFileBaseName;
                echoScu.Options.Identifier = resultsFileBaseName;

                echoScu.Options.LogThreadStartingAndStoppingInParent = false;
                echoScu.Options.LogWaitingForCompletionChildThreads  = false;
                echoScu.Options.AutoValidate     = false;
                echoScu.Options.ResultsDirectory = options.ResultsDirectory;

                //echoScu.Options.LocalAeTitle ="SCU";
                echoScu.Options.RemoteAeTitle  = peers[selectedIndex].AE;
                echoScu.Options.RemotePort     = peers[selectedIndex].Port;
                echoScu.Options.RemoteHostName = peers[selectedIndex].IP;
                //this.userControlActivityLogging.Attach(echoScu);

                detailedEchoFileName = echoScu.Options.DetailResultsFullFileName;
                PresentationContext presentationContext = new PresentationContext("1.2.840.10008.1.1",  // Abstract Syntax Name
                                                                                  "1.2.840.10008.1.2"); // Transfer Syntax Name(s)
                PresentationContext[] presentationContexts = new PresentationContext[1];
                presentationContexts[0] = presentationContext;

                DvtkHighLevelInterface.Dicom.Messages.DicomMessage echoMessage = new DvtkHighLevelInterface.Dicom.Messages.DicomMessage(DvtkData.Dimse.DimseCommand.CECHORQ);

                echoScu.Start();

                bool sendResult = echoScu.TriggerSendAssociationAndWait(echoMessage, presentationContexts);

                if (!sendResult)
                {
                    MessageBox.Show("DICOM Echo failed ", "Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    MessageBox.Show("DICOM Echo successful", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }

                echoScu.Stop();
                if (OnShowEchoResults != null)
                {
                    OnShowEchoResults.Invoke(detailedEchoFileName, sendResult);
                }
                allThreadsFinished = false;
            }
        }