コード例 #1
0
        /// <summary>
        /// Load the Information Model by reading all the .DCM and .RAW files
        /// present in the given directory. The data read is normalised into the
        /// Information Model.
        /// </summary>
        /// <param name="dataDirectory">Source data directory containing the .DCm and .RAW files.</param>
        public override void LoadInformationModel(System.String dataDirectory)
        {
            DataDirectory = dataDirectory;
            DirectoryInfo directoryInfo = new DirectoryInfo(DataDirectory);

            foreach (FileInfo fileInfo in directoryInfo.GetFiles())
            {
                if ((fileInfo.Extension.ToLower().Equals(".dcm")) ||
                    (fileInfo.Extension.ToLower().Equals(".raw")) ||
                    (fileInfo.Extension == "") || (fileInfo.Extension == null))
                {
                    try
                    {
                        // read the DCM file

                        Dvtk.Sessions.ScriptSession dvtkScriptSession = new Dvtk.Sessions.ScriptSession();

                        String tempPath = Path.GetTempPath();

                        dvtkScriptSession.StorageMode          = Dvtk.Sessions.StorageMode.AsMedia;
                        dvtkScriptSession.DataDirectory        = tempPath;
                        dvtkScriptSession.ResultsRootDirectory = tempPath;

                        DvtkData.Media.DicomFile dvtkDataDicomFile = dvtkScriptSession.ReadFile(fileInfo.FullName);

                        // Add DICOM file to Information Model - but do not re-save in file
                        AddToInformationModel(dvtkDataDicomFile, false);
                    }
                    catch (Exception)
                    {
                        //Invalid DICOM File - will be skiped from QR information model.
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Load the Information Model by reading all the .DCM and .RAW files
        /// present in the given directory. The data read is normalised into the
        /// Information Model.
        /// </summary>
        /// <param name="dataDirectory">Source data directory containing the .DCm and .RAW files.</param>
        public override void LoadInformationModel(System.String dataDirectory)
        {
            DataDirectory = dataDirectory;
            DirectoryInfo directoryInfo = new DirectoryInfo(DataDirectory);
            foreach (FileInfo fileInfo in directoryInfo.GetFiles())
            {
                if ((fileInfo.Extension.ToLower().Equals(".dcm")) ||
                    (fileInfo.Extension.ToLower().Equals(".raw")) ||
                    (fileInfo.Extension == "") || (fileInfo.Extension == null))
                {
                    try
                    {
                        // read the DCM file

                        Dvtk.Sessions.ScriptSession dvtkScriptSession = new Dvtk.Sessions.ScriptSession();

                        String tempPath = Path.GetTempPath();

                        dvtkScriptSession.StorageMode = Dvtk.Sessions.StorageMode.AsMedia;
                        dvtkScriptSession.DataDirectory = tempPath;
                        dvtkScriptSession.ResultsRootDirectory = tempPath;

                        DvtkData.Media.DicomFile dvtkDataDicomFile = dvtkScriptSession.ReadFile(fileInfo.FullName);

                        // Add DICOM file to Information Model - but do not re-save in file
                        AddToInformationModel(dvtkDataDicomFile, false);
                    }
                    catch (Exception)
                    {
                        //Invalid DICOM File - will be skiped from QR information model.
                    }
                }
            }
        }
コード例 #3
0
ファイル: DicomFile.cs プロジェクト: top501/DVTK-1
        /// <summary>
        /// Writes a Dicom file.
        /// </summary>
        /// <remarks>
        /// The group length attribute (0002,0000) will be set with the correct value
        /// automatically before writing to file begins.
        /// </remarks>
        /// <exception cref="HliException">
        ///	Writing to the file fails.
        /// </exception>
        /// <param name="fullFileName">The full file name.</param>
        /// <example>
        ///		<b>VB .NET</b>
        ///		<code>
        ///			' Example: Read a specified DICOM file and
        ///			'write it to back to a DICOM file
        ///
        ///			Dim myDicomFile As DvtkHighLevelInterface.Dicom.Files.DicomFile
        ///
        ///			If File.Exists("c:\somefile.dcm") Then
        ///				Try
        ///					myDicomFile.Read("c:\Somefile.dcm")
        ///                 Catch ex As DvtkHighLevelInterface.Common.Other.HliException
        ///					' Error reading the file, Maybe the file format is wrong?
        ///             End Try
        ///				'here is where you can manipulate the file
        ///				'write the dataset to a file
        ///				myDicomFile.Write("c:\newfile.dcm")
        ///			End If
        ///		</code>
        /// </example>
        public void Write(String fullFileName)
        {
            if (FileMetaInformation.TransferSyntax == "")
            {
                FileMetaInformation.TransferSyntax = "1.2.840.10008.1.2.1";
            }

            Dvtk.Sessions.ScriptSession dvtkScriptSession = CreateEmptyDvtkScriptSession();

            if (this.AddGroupLength)
            {
                dvtkScriptSession.AddGroupLength = true;
            }

            DvtkData.Media.DicomFile dvtkDataDicomFile = new DvtkData.Media.DicomFile();

            dvtkDataDicomFile.DataSet             = this.dataSet.DvtkDataDataSet;
            dvtkDataDicomFile.FileMetaInformation = this.fileMetaInformation.DvtkDataFileMetaInformation;
            dvtkDataDicomFile.FileHead            = this.fileMetaInformation.DvtkDataFileHead;

            if (!dvtkScriptSession.WriteFile(dvtkDataDicomFile, fullFileName))
            {
                throw new HliException("Error while writing file \"" + fullFileName + "\".");
            }
        }
コード例 #4
0
ファイル: DicomFile.cs プロジェクト: top501/DVTK-1
        public void Read(String fullFileName, params String[] definitionFilesFullName)
        {
            DvtkData.Media.DicomFile dvtkDataDicomFile = null;

            if (!File.Exists(fullFileName))
            {
                throw new HliException("Dicom file or raw file \"" + fullFileName + "\" not found.");
            }

            String tempPath = Path.GetTempPath();

            Dvtk.Sessions.ScriptSession dvtkScriptSession = new Dvtk.Sessions.ScriptSession();

            dvtkScriptSession.StorageMode          = Dvtk.Sessions.StorageMode.AsMedia;
            dvtkScriptSession.DataDirectory        = tempPath;
            dvtkScriptSession.ResultsRootDirectory = tempPath;

            foreach (String definitionFileFullName in definitionFilesFullName)
            {
                dvtkScriptSession.DefinitionManagement.LoadDefinitionFile(definitionFileFullName);
            }

            dvtkDataDicomFile = dvtkScriptSession.ReadFile(fullFileName);

            this.dataSet.DvtkDataDataSet = dvtkDataDicomFile.DataSet;
            this.FileMetaInformation.DvtkDataFileMetaInformation = dvtkDataDicomFile.FileMetaInformation;
            this.dvtkDataFileHead = dvtkDataDicomFile.FileHead;
        }
コード例 #5
0
ファイル: DicomFile.cs プロジェクト: top501/DVTK-1
        //
        // - Methods -
        //

        /// <summary>
        /// Creates an Dvtk.Sessions.ScriptSession instance in which no definiton files are loaded.
        /// </summary>
        /// <returns>An Dvtk.Sessions.ScriptSession instance.</returns>
        private Dvtk.Sessions.ScriptSession CreateEmptyDvtkScriptSession()
        {
            Dvtk.Sessions.ScriptSession dvtkScriptSession = new Dvtk.Sessions.ScriptSession();

            String tempPath = Path.GetTempPath();

            dvtkScriptSession.StorageMode          = Dvtk.Sessions.StorageMode.AsMedia;
            dvtkScriptSession.DataDirectory        = tempPath;
            dvtkScriptSession.ResultsRootDirectory = tempPath;

            return(dvtkScriptSession);
        }
コード例 #6
0
ファイル: DicomFile.cs プロジェクト: top501/DVTK-1
        public bool Write(String fullFileName)
        {
            Dvtk.Sessions.ScriptSession dvtkScriptSession = new Dvtk.Sessions.ScriptSession();

            DvtkData.Media.DicomFile dvtkDataDicomFile = new DvtkData.Media.DicomFile();

            dvtkDataDicomFile.DataSet             = this.dataSet.DvtkDataDataSet;
            dvtkDataDicomFile.FileMetaInformation = this.fileMetaInformation.DvtkDataFileMetaInformation;
            dvtkDataDicomFile.FileHead            = this.dvtkDataFileHead;

            return(dvtkScriptSession.WriteFile(dvtkDataDicomFile, fullFileName));
        }
コード例 #7
0
ファイル: DicomFile.cs プロジェクト: top501/DVTK-1
        /// <summary>
        /// Reads a file.
        /// </summary>
        /// <remarks>
        /// A new FileMetaInformation and DataSet object will be created inside this object. They will be
        /// filled with the content of the specified file.
        /// The FileMetaInformation and DataSet object previously used will not change (they will not be
        /// used anymore by this object) and can still be used outside this object if needed.
        ///
        /// Also see properties UnVrDefinitionLookUpWhenReading and StoreOBOFOWValuesWhenReading.
        ///
        /// If something goes wrong while reading the file, an exception is thrown.
        /// </remarks>
        /// <param name="fullFileName">The full file name.</param>
        /// <param name="dvtkScriptSession">The dvtk ScriptSession, from which the definition files to use for determining the attribute names are used.</param>
        private void Read(String fullFileName, Dvtk.Sessions.ScriptSession dvtkScriptSession)
        {
            // Create new FileMetaInformation and DataSet (depending on setting) objects.
            if (this.createNewDataSetObjectWhenReading)
            {
                this.dataSet = new DataSet();
            }

            // Throw an excpetion if the file doesn't exist.
            if (!File.Exists(fullFileName))
            {
                throw new HliException("File \"" + fullFileName + "\" not found.");
            }

            // Read the DicomFile using the supplied DicomThread.
            bool originalUnVrDefinitionLookUp = dvtkScriptSession.UnVrDefinitionLookUp;

            Dvtk.Sessions.StorageMode originalDvtkStorageMode = dvtkScriptSession.StorageMode;

            dvtkScriptSession.UnVrDefinitionLookUp = this.unVrDefinitionLookUpWhenReading;

            if (this.storeOBOFOWValuesWhenReading)
            {
                dvtkScriptSession.StorageMode = Dvtk.Sessions.StorageMode.AsDataSet;
            }
            else
            {
                dvtkScriptSession.StorageMode = Dvtk.Sessions.StorageMode.NoStorage;
            }

            DvtkData.Media.DicomFile dvtkDataDicomFile = dvtkScriptSession.ReadFile(fullFileName);

            if (dvtkDataDicomFile == null)
            {
                throw new HliException("Error while reading file \"" + fullFileName + "\".");
            }
            else
            {
                this.dataSet.DvtkDataDataSet = dvtkDataDicomFile.DataSet;
                this.FileMetaInformation     = new FileMetaInformation(dvtkDataDicomFile.FileMetaInformation, dvtkDataDicomFile.FileHead);
            }

            dvtkScriptSession.UnVrDefinitionLookUp = originalUnVrDefinitionLookUp;
            dvtkScriptSession.StorageMode          = originalDvtkStorageMode;
        }
コード例 #8
0
ファイル: DicomFile.cs プロジェクト: top501/DVTK-1
        /// <summary>
        /// Reads a file.
        /// </summary>
        /// <remarks>
        /// A new FileMetaInformation and DataSet object will be created inside this object. They will be
        /// filled with the content of the specified file.
        /// The FileMetaInformation and DataSet object previously used will not change (they will not be
        /// used anymore by this object) and can still be used outside this object if needed.
        /// <br></br><br></br>
        /// NOTE:
        /// The intention of this method is to use only the supplied definition files.
        /// The current implementation however uses all already loaded definition files outside this
        /// method and the supplied definition files!
        /// <br></br><br></br>
        /// Also see properties UnVrDefinitionLookUpWhenReading and StoreOBOFOWValuesWhenReading.
        /// <br></br><br></br>
        /// If something goes wrong while reading the file, an exception is thrown.
        /// </remarks>
        /// <param name="fullFileName">The full file name.</param>
        /// <param name="definitionFilesFullName">The definition files to use for determining the attribute names.</param>
        /// <example>
        ///		<b>VB .NET</b>
        ///		<code>
        ///			'Example: Read a specified DICOM file
        ///
        ///			Dim myDicomFile As DvtkHighLevelInterface.Dicom.Files.DicomFile
        ///
        ///			If File.Exists("") Then
        ///				Try
        ///					myDicomFile.Read("c:\Somefile.dcm")
        ///                 Catch ex As DvtkHighLevelInterface.Common.Other.HliException
        ///					' Error reading the file, Maybe the file format is wrong?
        ///             End Try
        ///			End If
        ///		</code>
        /// </example>
        public void Read(String fullFileName, params String[] definitionFilesFullName)
        {
            // Create a new dvtk session to read the DicomFile.
            Dvtk.Sessions.ScriptSession dvtkScriptSession = CreateEmptyDvtkScriptSession();

            // Add the definition files to this dvtk session.
            foreach (String definitionFileFullName in definitionFilesFullName)
            {
                dvtkScriptSession.DefinitionManagement.LoadDefinitionFile(definitionFileFullName);
            }

            Read(fullFileName, dvtkScriptSession);

            // Remove the definition files again to make sure the singleton doesn't keep them in memory.
            foreach (String definitionFileFullName in definitionFilesFullName)
            {
                dvtkScriptSession.DefinitionManagement.UnLoadDefinitionFile(definitionFileFullName);
            }
        }
コード例 #9
0
        /// <summary>
        /// Update the Specify SOP classes tab.
        /// </summary>
        public void UpdateDataGrid(Dvtk.Sessions.ScriptSession session)
        {
            theSession = session;

            Dvtk.Sessions.DefinitionFileDirectoryList theDefinitionFileDirectoryList = theSession.DefinitionManagement.DefinitionFileDirectoryList;

            // Update the definition file directories list box.
            ListBoxSpecifySopClassesDefinitionFileDirectories.Items.Clear();

            UpdateRemoveButton();

            foreach (string theDefinitionFileDirectory in theDefinitionFileDirectoryList)
            {
                ListBoxSpecifySopClassesDefinitionFileDirectories.Items.Add(theDefinitionFileDirectory);
            }

            // Update the SOP classes data grid.
            // For every definition file directory, use the .def files present in the directory.
            RichTextBoxSpecifySopClassesInfo.Clear();
            _DefinitionFilesInfoForDataGrid.Clear();

            // Add the correct information to the datagrid by inspecting the definition directory.
            // When doing this, also fill the combobox with available ae title - version combinations.
            AddSopClassesToDataGridFromDirectories();

            // Add the correct information to the datagrid by inspecting the loaded definitions.
            // When doing this, also fill the combobox with available ae title - version combinations.
            // Only add an entry if it does not already exist.
            AddSopClassesToDataGridFromLoadedDefinitions();

            // Workaround for following problem:
            // If the SOP classes tab has already been filled, and another session contains less
            // records for the datagrid, windows gets confused and thinks there are more records
            // then actually present in _DefinitionFilesInfoForDataGrid resulting in an assertion.
            DataGridSpecifySopClasses.SetDataBinding(null, "");

            // Actually refresh the data grid.
            DataGridSpecifySopClasses.SetDataBinding(_DefinitionFilesInfoForDataGrid, "");
            //DataGridSpecifySopClasses.DataSource = _DefinitionFilesInfoForDataGrid;

            DataGridSpecifySopClasses.Refresh();
        }
コード例 #10
0
ファイル: GenerateTriggers.cs プロジェクト: ewcasas/DVTK
        private static void AddQueryRetrieveKeys(TagValueCollection queryTags, DvtkData.Dimse.DataSet dataset)
        {
            // use script session to get to definition singleton
            Dvtk.Sessions.ScriptSession scriptSession = new Dvtk.Sessions.ScriptSession();

            // iterate over the query tags
            foreach(DicomTagValue queryTag in queryTags)
            {
                if (queryTag.ParentSequenceTag != DvtkData.Dimse.Tag.UNDEFINED)
                {
                    // try to get the sequence tag in the dataset
                    DvtkData.Dimse.Attribute sequenceAttribute = dataset.GetAttribute(queryTag.ParentSequenceTag);
                    if ((sequenceAttribute != null) &&
                        (sequenceAttribute.ValueRepresentation == DvtkData.Dimse.VR.SQ))
                    {
                        SequenceOfItems sequenceOfItems = (SequenceOfItems)sequenceAttribute.DicomValue;
                        if (sequenceOfItems.Sequence.Count == 1)
                        {
                            DvtkData.Dimse.SequenceItem item = sequenceOfItems.Sequence[0];

                            if (item != null)
                            {
                                VR vr = scriptSession.DefinitionManagement.GetAttributeVrFromDefinition(queryTag.Tag);

                                // add the query value
                                item.AddAttribute(queryTag.Tag.GroupNumber,
                                    queryTag.Tag.ElementNumber,
                                    vr,
                                    queryTag.Value);
                            }
                        }
                    }
                }
                else
                {
                    VR vr = scriptSession.DefinitionManagement.GetAttributeVrFromDefinition(queryTag.Tag);

                    // add the query value
                    dataset.AddAttribute(queryTag.Tag.GroupNumber,
                        queryTag.Tag.ElementNumber,
                        vr,
                        queryTag.Value);
                }
            }
        }
コード例 #11
0
ファイル: DicomThread.cs プロジェクト: ewcasas/DVTK
        /// <summary>
        /// Initializes this instance as a DicomThread with a parent thread.
        /// </summary>
        /// <param name="parent">The parent thread.</param>
        public new void Initialize(Thread parent)
        {
            // Initialize may only be called once, so check for this.
            if (this.isInitialized)
            {
                throw new HliException(alreadyInitializedErrorText);
            }

            base.Initialize(parent);
            this.dvtkScriptSession = new Dvtk.Sessions.ScriptSession();
            Initialize();
            this.isInitialized = true;
        }
コード例 #12
0
ファイル: DicomFile.cs プロジェクト: ewcasas/DVTK
        public void Read(String fullFileName, params String[] definitionFilesFullName)
        {
            DvtkData.Media.DicomFile dvtkDataDicomFile = null;

            if (!File.Exists(fullFileName))
            {
                throw new HliException("Dicom file or raw file \"" + fullFileName + "\" not found.");
            }

            String tempPath = Path.GetTempPath();

            Dvtk.Sessions.ScriptSession dvtkScriptSession = new Dvtk.Sessions.ScriptSession();

            dvtkScriptSession.StorageMode = Dvtk.Sessions.StorageMode.AsMedia;
            dvtkScriptSession.DataDirectory = tempPath;
            dvtkScriptSession.ResultsRootDirectory = tempPath;

            foreach(String definitionFileFullName in definitionFilesFullName)
            {
                dvtkScriptSession.DefinitionManagement.LoadDefinitionFile(definitionFileFullName);
            }

            dvtkDataDicomFile = dvtkScriptSession.ReadFile(fullFileName);

            this.dataSet.DvtkDataDataSet = dvtkDataDicomFile.DataSet;
            this.FileMetaInformation.DvtkDataFileMetaInformation = dvtkDataDicomFile.FileMetaInformation;
            this.dvtkDataFileHead = dvtkDataDicomFile.FileHead;
        }
コード例 #13
0
ファイル: DicomFile.cs プロジェクト: ewcasas/DVTK
        public bool Write(String fullFileName)
        {
            Dvtk.Sessions.ScriptSession dvtkScriptSession = new Dvtk.Sessions.ScriptSession();

            DvtkData.Media.DicomFile dvtkDataDicomFile = new DvtkData.Media.DicomFile();

            dvtkDataDicomFile.DataSet = this.dataSet.DvtkDataDataSet;
            dvtkDataDicomFile.FileMetaInformation = this.fileMetaInformation.DvtkDataFileMetaInformation;
            dvtkDataDicomFile.FileHead = this.dvtkDataFileHead;

            return dvtkScriptSession.WriteFile(dvtkDataDicomFile, fullFileName);
        }
コード例 #14
0
ファイル: ProjectForm.cs プロジェクト: ewcasas/DVTK
        private void ComboBoxSessionType_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if ((this.ComboBoxSessionType.SelectedItem.ToString() == "Script") &&
                !(this.selected_session is Dvtk.Sessions.ScriptSession))
            {
                // We only want to replace the selected session when the user
                // has changed the session type.
                Dvtk.Sessions.ScriptSession    session;
                session = new Dvtk.Sessions.ScriptSession();

                session.SessionFileName = this.selected_session.SessionFileName;

                session.SessionTitle = this.TextBoxSessionTitle.Text;
                session.SessionId = Convert.ToUInt16 (this.NumericSessonID.Value);
                session.TestedBy = this.TextBoxTestedBy.Text;
                session.Date = this.DateTested.Value;
                if (this.TextBoxResultsRoot.Text == "")
                    session.ResultsRootDirectory = ".";
                else
                    session.ResultsRootDirectory = this.TextBoxResultsRoot.Text;

                if (this.TextBoxScriptRoot.Text == "")
                    session.DicomScriptRootDirectory = ".";
                else
                    session.DicomScriptRootDirectory = this.TextBoxScriptRoot.Text;

                session.DvtSystemSettings.AeTitle = this.TextBoxDVTAETitle.Text;
                session.DvtSystemSettings.Port = (ushort)this.NumericDVTListenPort.Value;
                session.DvtSystemSettings.SocketTimeout = (ushort)this.NumericDVTTimeOut.Value;
                session.DvtSystemSettings.MaximumLengthReceived = (uint)this.NumericDVTMaxPDU.Value;

                session.SutSystemSettings.AeTitle = this.TextBoxSUTAETitle.Text;
                session.SutSystemSettings.Port = (ushort)this.NumericSUTListenPort.Value;
                session.SutSystemSettings.HostName = this.TextBoxSUTTCPIPAddress.Text;
                session.SutSystemSettings.MaximumLengthReceived = (uint)this.NumericSUTMaxPDU.Value;

                session.SecuritySettings.SecureSocketsEnabled = this.CheckBoxSecureConnection.Checked;
                if (this.CheckBoxSecureConnection.Checked)
                {
                    session.SecuritySettings.CacheTlsSessions = ((Dvtk.Sessions.ISecure)this.selected_session).SecuritySettings.CacheTlsSessions;
                    session.SecuritySettings.CertificateFileName = ((Dvtk.Sessions.ISecure)this.selected_session).SecuritySettings.CertificateFileName;
                    session.SecuritySettings.CheckRemoteCertificate = ((Dvtk.Sessions.ISecure)this.selected_session).SecuritySettings.CheckRemoteCertificate;
                    session.SecuritySettings.CipherFlags = ((Dvtk.Sessions.ISecure)this.selected_session).SecuritySettings.CipherFlags;
                    session.SecuritySettings.CredentialsFileName = ((Dvtk.Sessions.ISecure)this.selected_session).SecuritySettings.CredentialsFileName;
                    session.SecuritySettings.TlsCacheTimeout = ((Dvtk.Sessions.ISecure)this.selected_session).SecuritySettings.TlsCacheTimeout;
                    session.SecuritySettings.TlsPassword = ((Dvtk.Sessions.ISecure)this.selected_session).SecuritySettings.TlsPassword;
                    session.SecuritySettings.TlsVersionFlags = ((Dvtk.Sessions.ISecure)this.selected_session).SecuritySettings.TlsVersionFlags;
                }

                // Copy the definition settings (SOP Classes, AE title/version and definition dirs)
                session.DefinitionManagement.ApplicationEntityName = this.selected_session.DefinitionManagement.ApplicationEntityName;
                session.DefinitionManagement.ApplicationEntityVersion = this.selected_session.DefinitionManagement.ApplicationEntityVersion;
                session.DefinitionManagement.DefinitionFileDirectoryList.Clear ();
                foreach (string def_dir in this.selected_session.DefinitionManagement.DefinitionFileDirectoryList)
                    session.DefinitionManagement.DefinitionFileDirectoryList.Add (def_dir);
                session.DefinitionManagement.DefinitionFileRootDirectory = this.selected_session.DefinitionManagement.DefinitionFileRootDirectory;
                foreach (string def_file in this.selected_session.DefinitionManagement.LoadedDefinitionFileNames)
                    session.DefinitionManagement.LoadDefinitionFile (def_file);
                this.selected_session.DefinitionManagement.UnLoadDefinitionFiles ();

                //this.project.ReplaceSession (this.selected_session, session, this._activity_handler);
                foreach (TreeNode node in this.SessionBrowser.Nodes)
                {
                    // Clear the tree node representing the old session.
                    if (node.Text == session.SessionFileName)
                        node.Nodes.Clear ();
                }

                this.selected_session = session;
                this.UpdateSessionProperties ();
                ////////this.project.SetSessionChanged (session.SessionFileName, true);
                this.ResizeSessionPropertiesView ();
            }
            if ((this.ComboBoxSessionType.SelectedItem.ToString() == "Media") &&
                !(this.selected_session is Dvtk.Sessions.MediaSession))
            {
                // We only want to replace the selected session when the user
                // has changed the session type.
                Dvtk.Sessions.MediaSession  session;
                session = new Dvtk.Sessions.MediaSession ();

                session.SessionFileName = this.selected_session.SessionFileName;

                session.SessionTitle = this.TextBoxSessionTitle.Text;
                session.SessionId = Convert.ToUInt16 (this.NumericSessonID.Value);
                session.TestedBy = this.TextBoxTestedBy.Text;
                session.Date = this.DateTested.Value;
                if (this.TextBoxResultsRoot.Text == "")
                    session.ResultsRootDirectory = ".";
                else
                    session.ResultsRootDirectory = this.TextBoxResultsRoot.Text;

                // Copy the definition settings (SOP Classes, AE title/version and definition dirs)
                session.DefinitionManagement.ApplicationEntityName = this.selected_session.DefinitionManagement.ApplicationEntityName;
                session.DefinitionManagement.ApplicationEntityVersion = this.selected_session.DefinitionManagement.ApplicationEntityVersion;
                session.DefinitionManagement.DefinitionFileDirectoryList.Clear ();
                foreach (string def_dir in this.selected_session.DefinitionManagement.DefinitionFileDirectoryList)
                    session.DefinitionManagement.DefinitionFileDirectoryList.Add (def_dir);
                session.DefinitionManagement.DefinitionFileRootDirectory = this.selected_session.DefinitionManagement.DefinitionFileRootDirectory;
                foreach (string def_file in this.selected_session.DefinitionManagement.LoadedDefinitionFileNames)
                    session.DefinitionManagement.LoadDefinitionFile (def_file);
                this.selected_session.DefinitionManagement.UnLoadDefinitionFiles ();

                //this.project.ReplaceSession (this.selected_session, session, this._activity_handler);
                foreach (TreeNode node in this.SessionBrowser.Nodes)
                {
                    // Clear the tree node representing the old session.
                    if (node.Text == session.SessionFileName)
                        node.Nodes.Clear ();
                }

                this.selected_session = session;
                this.UpdateSessionProperties ();
                //////this.project.SetSessionChanged (session.SessionFileName, true);
                this.ResizeSessionPropertiesView ();
            }
            if ((this.ComboBoxSessionType.SelectedItem.ToString() == "Emulator") &&
                !(this.selected_session is Dvtk.Sessions.EmulatorSession))
            {
                // We only want to replace the selected session when the user
                // has changed the session type.
                Dvtk.Sessions.EmulatorSession   session;
                session = new Dvtk.Sessions.EmulatorSession ();

                session.SessionFileName = this.selected_session.SessionFileName;

                session.SessionTitle = this.TextBoxSessionTitle.Text;
                session.SessionId = Convert.ToUInt16 (this.NumericSessonID.Value);
                session.TestedBy = this.TextBoxTestedBy.Text;
                session.Date = this.DateTested.Value;
                if (this.TextBoxResultsRoot.Text == "")
                    session.ResultsRootDirectory = ".";
                else
                    session.ResultsRootDirectory = this.TextBoxResultsRoot.Text;

                session.DvtSystemSettings.AeTitle = this.TextBoxDVTAETitle.Text;
                session.DvtSystemSettings.Port = (ushort)this.NumericDVTListenPort.Value;
                session.DvtSystemSettings.SocketTimeout = (ushort)this.NumericDVTTimeOut.Value;
                session.DvtSystemSettings.MaximumLengthReceived = (uint)this.NumericDVTMaxPDU.Value;

                session.SutSystemSettings.AeTitle = this.TextBoxSUTAETitle.Text;
                session.SutSystemSettings.Port = (ushort)this.NumericSUTListenPort.Value;
                session.SutSystemSettings.HostName = this.TextBoxSUTTCPIPAddress.Text;
                session.SutSystemSettings.MaximumLengthReceived = (uint)this.NumericSUTMaxPDU.Value;

                session.SecuritySettings.SecureSocketsEnabled = this.CheckBoxSecureConnection.Checked;
                if (this.CheckBoxSecureConnection.Checked)
                {
                    session.SecuritySettings.CacheTlsSessions = ((Dvtk.Sessions.ISecure)this.selected_session).SecuritySettings.CacheTlsSessions;
                    session.SecuritySettings.CertificateFileName = ((Dvtk.Sessions.ISecure)this.selected_session).SecuritySettings.CertificateFileName;
                    session.SecuritySettings.CheckRemoteCertificate = ((Dvtk.Sessions.ISecure)this.selected_session).SecuritySettings.CheckRemoteCertificate;
                    session.SecuritySettings.CipherFlags = ((Dvtk.Sessions.ISecure)this.selected_session).SecuritySettings.CipherFlags;
                    session.SecuritySettings.CredentialsFileName = ((Dvtk.Sessions.ISecure)this.selected_session).SecuritySettings.CredentialsFileName;
                    session.SecuritySettings.TlsCacheTimeout = ((Dvtk.Sessions.ISecure)this.selected_session).SecuritySettings.TlsCacheTimeout;
                    session.SecuritySettings.TlsPassword = ((Dvtk.Sessions.ISecure)this.selected_session).SecuritySettings.TlsPassword;
                    session.SecuritySettings.TlsVersionFlags = ((Dvtk.Sessions.ISecure)this.selected_session).SecuritySettings.TlsVersionFlags;
                }

                // Copy the definition settings (SOP Classes, AE title/version and definition dirs)
                session.DefinitionManagement.ApplicationEntityName = this.selected_session.DefinitionManagement.ApplicationEntityName;
                session.DefinitionManagement.ApplicationEntityVersion = this.selected_session.DefinitionManagement.ApplicationEntityVersion;
                session.DefinitionManagement.DefinitionFileDirectoryList.Clear ();
                foreach (string def_dir in this.selected_session.DefinitionManagement.DefinitionFileDirectoryList)
                    session.DefinitionManagement.DefinitionFileDirectoryList.Add (def_dir);
                session.DefinitionManagement.DefinitionFileRootDirectory = this.selected_session.DefinitionManagement.DefinitionFileRootDirectory;
                foreach (string def_file in this.selected_session.DefinitionManagement.LoadedDefinitionFileNames)
                    session.DefinitionManagement.LoadDefinitionFile (def_file);
                this.selected_session.DefinitionManagement.UnLoadDefinitionFiles ();

                //this.project.ReplaceSession (this.selected_session, session, this._activity_handler);
                foreach (TreeNode node in this.SessionBrowser.Nodes)
                {
                    // Clear the tree node representing the old session.
                    if (node.Text == session.SessionFileName)
                        node.Nodes.Clear ();
                }

                this.selected_session = session;
                this.UpdateSessionProperties ();
                //////this.project.SetSessionChanged (session.SessionFileName, true);
                this.ResizeSessionPropertiesView ();
            }

            // Update the session tree browser
            this.UpdateSessionTreeView ();

            // Update the mainform controls (menu, toolbar, title)
            ((MainForm)this.ParentForm).UpdateUIControls ();
        }