Exemplo n.º 1
0
        private void SendDICOMDataInSingleAssociation(string[] mediaFiles)
        {
            // Set the dicom messages to send
            List<DicomFile> dicomMessageCollection = new List<DicomFile>();
            PresentationContextCollection pcCollection = new PresentationContextCollection();

            StoreScu storageScuThread = new StoreScu();

            storageScuThread.Initialize(this.overviewThread);
            storageScuThread.Options.CopyFrom(this.storageOptions);

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

            storageScuThread.Options.LogThreadStartingAndStoppingInParent = false;
            storageScuThread.Options.LogWaitingForCompletionChildThreads = false;
            storageScuThread.Options.AutoValidate = false;

            //The Current Directory is being set to the Results Directory because
            // when DICOMDIRs(or DICOM Files)Media are exported, the Environment.CurrentDirectory
            //is set to the Directory in which the DCM objects are present and the export will fail
            // if the DICOMDIR is present on a Physical Media.
            Environment.CurrentDirectory = this.storageOptions.ResultsDirectory;

            foreach (string dcmFilename in mediaFiles)
            {
                string msg = string.Format("Reading the DICOM object - {0}", dcmFilename);
                storageScuThread.WriteInformation(msg);

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

                    dcmFile.Read(dcmFilename, storageScuThread);

                    FileMetaInformation fMI =  dcmFile.FileMetaInformation;

                    // Get the transfer syntax and SOP class UID
                    System.String transferSyntax = "1.2.840.10008.1.2.1";
                    System.String sopClassUid = "";
                    if ((fMI != null))
                    {
                        // Get the Transfer syntax
                        HLI.Attribute tranferSyntaxAttr = fMI["0x00020010"];
                        transferSyntax = tranferSyntaxAttr.Values[0];

                        // Get the SOP Class UID
                        Values values = fMI["0x00020002"].Values;
                        sopClassUid = values[0];
                    }
                    else
                    {
                        // Get the SOP Class UID
                        Values values =  dcmFile.DataSet["0x00080016"].Values;
                        sopClassUid = values[0];
                    }

                    //Check for DICOMDIR
                    if(sopClassUid == "")
                    {
                        storageScuThread.WriteError("Can't determine SOP Class UID for DCM file. \nSkipping the DCM File.");
                        continue;
                    }
                    else if (sopClassUid == "1.2.840.10008.1.3.10")
                    {

                            HLI.DataSet tempDataSet = new HLI.DataSet();

                            // Read the DICOMDIR dataset
                            dcmFile.DataSet.DvtkDataDataSet = Dvtk.DvtkDataHelper.ReadDataSetFromFile(dcmFilename);
                            Dvtk.Sessions.ScriptSession session = this.storageOptions.DvtkScriptSession;
                            ArrayList refFiles = ImportRefFilesFromDicomdir(dcmFilename, dcmFile.DataSet);

                            foreach (string refFilename in refFiles)
                            {
                                // Read the Reference File
                                DicomFile refFile = new DicomFile();
                                refFile.Read(refFilename, storageScuThread);

                                FileMetaInformation refFMI = refFile.FileMetaInformation;

                                // Get the transfer syntax and SOP class UID
                                System.String refTransferSyntax = "1.2.840.10008.1.2.1";
                                if ((refFMI != null) && refFMI.Exists("0x00020010"))
                                {
                                    // Get the Transfer syntax
                                    HLI.Attribute refTranferSyntaxAttr = refFMI["0x00020010"];
                                    refTransferSyntax = refTranferSyntaxAttr.Values[0];
                                }

                                Values sopValues = refFile.DataSet["0x00080016"].Values;
                                System.String refSopClassUid = sopValues[0];

                                PresentationContext refPresentationContext = new PresentationContext(refSopClassUid, // Abstract Syntax Name
                                                                                                     refTransferSyntax); // Transfer Syntax Name(s)
                                pcCollection.Add(refPresentationContext);

                                //DicomMessage refStorageMessage = new DicomMessage(DvtkData.Dimse.DimseCommand.CSTORERQ);
                                //refStorageMessage.DataSet.CloneFrom(refFile.DataSet);
                                dicomMessageCollection.Add(refFile);
                            }
                    }
                    else
                    {
                        PresentationContext presentationContext = new PresentationContext(sopClassUid, // Abstract Syntax Name
                                                                                          transferSyntax); // Transfer Syntax Name(s)
                        pcCollection.Add(presentationContext);

                        //DicomMessage storageMessage = new DicomMessage(DvtkData.Dimse.DimseCommand.CSTORERQ);
                        //storageMessage.DataSet.CloneFrom(dcmFile.DataSet);
                        dicomMessageCollection.Add(dcmFile);
                    }
                }
                catch (Exception e)
                {
                    storageScuThread.WriteError(e.Message + "\nSkipping the DCM File.");
                }
            }

            // set the presentation contexts for the association
            PresentationContext[] presentationContexts = SetPresentationContexts(pcCollection);

            storageScuThread.DICOMFileCollection = dicomMessageCollection;
            storageScuThread.PresentationContexts = presentationContexts;

            storageScuThread.Start();

            storageScuThread.WaitForCompletion();

            DicomMessageCollection cStoreResponses = storageScuThread.Messages.DicomMessages.CStoreResponses;

            //storageScuThread.Stop();

            HandleCStoreResponses(storageCommitItems, cStoreResponses);

            storageScuThread.Messages.DicomMessages.CStoreResponses.Clear();
        }
Exemplo n.º 2
0
        public StorageSCUEmulator()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            InitializeBackgoundWorker();

            this.dvtkWebBrowserSCUEmulator.XmlStyleSheetFullFileName = applDirectory + "\\DVT_RESULTS.xslt";
            this.dvtkWebBrowserSCUEmulator.BackwardFormwardEnabledStateChangeEvent +=new DvtkApplicationLayer.UserInterfaces.DvtkWebBrowserNew.BackwardFormwardEnabledStateChangeEventHandler(dvtkWebBrowserSCUEmulator_BackwardFormwardEnabledStateChangeEvent);
            this.dvtkWebBrowserSCUEmulator.ErrorWarningEnabledStateChangeEvent += new DvtkWebBrowserNew.ErrorWarningEnabledStateChangeEventHandler(dvtkWebBrowserSCUEmulator_ErrorWarningEnabledStateChangeEvent);

            selectedTS.Add("1.2.840.10008.1.2");
            selectedTS.Add("1.2.840.10008.1.2.1");
            selectedTS.Add("1.2.840.10008.1.2.2");

            //
            // Set the .Net thread name for debugging purposes.
            //
            System.Threading.Thread.CurrentThread.Name = "Storage SCU Emulator";

            this.threadsStateChangeEventHandler = new ThreadManager.ThreadsStateChangeEventHandler(this.HandleThreadsStateChangeEvent);

            updateUIControlsHandler = new UpdateUIControlsDelegate(UpdateUIControls);

            updateUIControlsFromBGThreadHandler = new UpdateUIControlsFromBGThreadDelegate(UpdateUIControlsFromBGThread);

            this.threadManager = new ThreadManager();
            this.threadManager.ThreadsStateChangeEvent += this.threadsStateChangeEventHandler;

            //
            // Stored files options.
            //
            this.fileGroups = new FileGroups("Storage SCU Emulator");

            this.validationResultsFileGroup = new ValidationResultsFileGroup();
            this.validationResultsFileGroup.DefaultFolder = "Results";
            this.fileGroups.Add(validationResultsFileGroup);

            this.fileGroups.CreateDirectories();

            this.fileGroups.CheckIsConfigured("\"Stored Files\\Options...\" menu item");

            // Set Storage thread
            StoreScu storageScu = new StoreScu();

            storageScu.Initialize(this.threadManager);
            this.storageOptions = storageScu.Options;
            this.storageOptions.LoadFromFile(Path.Combine(applDirectory, "StorageSCUEmulator.ses"));
            this.storageOptions.StorageMode = Dvtk.Sessions.StorageMode.AsMediaOnly;
            this.storageOptions.ResultsDirectory = validationResultsFileGroup.Directory;
            this.storageOptions.DataDirectory = validationResultsFileGroup.Directory;
            //Environment.CurrentDirectory = this.storageOptions.ResultsDirectory;
            //Set the Commit thread
            CommitScu commitScu = new CommitScu(this);

            commitScu.Initialize(this.threadManager);
            this.storageCommitSCUOptions = commitScu.Options;
            this.storageCommitSCUOptions.LoadFromFile(Path.Combine(applDirectory, "CommitSCUEmulator.ses"));
            this.storageCommitSCUOptions.ResultsDirectory = validationResultsFileGroup.Directory;
            this.storageCommitSCUOptions.DataDirectory = validationResultsFileGroup.Directory;

            // Make sure the session files contain the same information as the Stored Files user settings.
            SaveToSessionFiles(this.storageOptions, this.storageCommitSCUOptions);

            this.storageCommitItems = new ReferencedSopItemCollection();
        }