public void ResultsFromValidateMediaFilesAsynchronously(IAsyncResult theIAsyncResult) { Dvtk.Sessions.MediaSession theMediaSession = (Dvtk.Sessions.MediaSession)GetExecutingSession(); try { // Obligated to call the following method according to the asynchronous design pattern. theMediaSession.EndValidateMediaFiles(theIAsyncResult); } catch (Exception ex) { // // Problem: // Errors thrown from a workerthread are eaten by the .NET 1.x CLR. // Workaround: // Directly call the global (untrapped) exception handler callback. // Do NOT rely on // either // - System.AppDomain.CurrentDomain.UnhandledException // or // - System.Windows.Forms.Application.ThreadException // These events will only be triggered for the main thread not for worker threads. // CustomExceptionHandler eh = new CustomExceptionHandler(); System.Threading.ThreadExceptionEventArgs args = new ThreadExceptionEventArgs(ex); eh.OnThreadException(this, args); // // Rethrow. This rethrow may work in the future .NET 2.x CLR. // Currently eaten. // throw ex; } theMediaSession.EndResultsGathering(); if (mediaFilesToBeValidated.Count > 0) { ValidateMediaFiles(); } else { // Update the UI. Do this with an invoke, because the thread that is calling this // method is NOT the thread that created all controls used! _EndExecution = new EndExecution(_TagThatIsBeingExecuted); _TagThatIsBeingExecuted = null; _NotifyDelegate = new NotifyDelegate(_ParentForm.Notify); _ParentForm.Invoke(_NotifyDelegate, new object[]{_EndExecution}); } }
public void ExecuteSelectedScript() { ScriptFileTag theScriptFileTag = GetSelectedTreeNodeTag() as ScriptFileTag; if (theScriptFileTag == null) // Sanity check. { Debug.Assert(false); } else { bool isExecutionCancelled = false; // Remove the current results files for this script file. // If results files exists that will be removed, ask the user what to do with them. ArrayList theResultsFilesToRemove = ResultsFile.GetAllNamesForSession(theScriptFileTag._Session); theResultsFilesToRemove = ResultsFile.GetNamesForScriptFile(theScriptFileTag._ScriptFileName, theResultsFilesToRemove); theResultsFilesToRemove = ResultsFile.GetNamesForCurrentSessionId(theScriptFileTag._Session, theResultsFilesToRemove); if (theResultsFilesToRemove.Count != 0) { string theWarningMessage = string.Format("Results files exist that will be removed before execution of script file {0}.\nCopy these results files to backup files?", theScriptFileTag._ScriptFileName); DialogResult theDialogResult = DialogResult.No; // Only ask to backup the results file if this is configured. if (_MainForm._UserSettings.AskForBackupResultsFile) { theDialogResult = MessageBox.Show(theWarningMessage, "Warning", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); } if (theDialogResult == DialogResult.Yes) { ResultsFile.BackupFiles(theScriptFileTag._Session, theResultsFilesToRemove); ResultsFile.Remove(theScriptFileTag._Session, theResultsFilesToRemove); } else if (theDialogResult == DialogResult.No) { ResultsFile.Remove(theScriptFileTag._Session, theResultsFilesToRemove); } else { _TagThatIsBeingExecuted = null; // Update the UI. EndExecution theEndExecution = new EndExecution(GetSelectedTreeNodeTag()); Notify(theEndExecution); isExecutionCancelled = true; } } if (!isExecutionCancelled) { if ( (System.IO.Path.GetExtension(theScriptFileTag._ScriptFileName).ToLower() == ".dss") || (System.IO.Path.GetExtension(theScriptFileTag._ScriptFileName).ToLower() == ".ds") ) { ExecuteDicomScriptInThread(theScriptFileTag); } else if (System.IO.Path.GetExtension(theScriptFileTag._ScriptFileName).ToLower() == ".vbs") { ExecuteVisualBasicScriptInThread(theScriptFileTag); } else { MessageBox.Show("Execution of this type of file not supported (yet)"); _TagThatIsBeingExecuted = null; // Update the UI. EndExecution theEndExecution = new EndExecution(GetSelectedTreeNodeTag()); Notify(theEndExecution); } } } }
public void GenerateDICOMDIR() { OpenFileDialog theOpenFileDialog = new OpenFileDialog(); theOpenFileDialog.Filter = "DICOM media files (*.dcm)|*.dcm|All files (*.*)|*.*"; theOpenFileDialog.Title = "Select DCM files to create DICOMDIR"; theOpenFileDialog.Multiselect = true; theOpenFileDialog.ReadOnlyChecked = true; // Show the file dialog. // If the user pressed the OK button... if (theOpenFileDialog.ShowDialog() == DialogResult.OK) { // Add all DCM files selected. string [] dcmFiles = new string [theOpenFileDialog.FileNames.Length]; Dvtk.Sessions.MediaSession theMediaSession = GetSelectedSession() as Dvtk.Sessions.MediaSession; if (theMediaSession == null) { // Sanity check. Debug.Assert(false); } // Move all selected DCM files to directory "DICOM" in result root directory. int i = 0; DirectoryInfo theDirectoryInfo = null; theDirectoryInfo = new DirectoryInfo(theMediaSession.ResultsRootDirectory + "DICOM\\"); // Create "DICOM" directory if it doesn't exist if(!theDirectoryInfo.Exists) { theDirectoryInfo.Create(); } else // Remove existing DCM files from "DICOM" directory { FileInfo[] files = theDirectoryInfo.GetFiles(); foreach(FileInfo file in files) { file.Delete(); } } foreach(string dcmFile in theOpenFileDialog.FileNames) { FileInfo theFileInfo = new FileInfo(dcmFile); string destFileName = theDirectoryInfo.FullName + string.Format("IM{0:D4}",i);//theFileInfo.Name; theFileInfo.CopyTo(destFileName,true); dcmFiles.SetValue(destFileName,i); i++; } theMediaSession.StartResultsGathering("DICOMDIR_res.xml"); theMediaSession.GenerateDICOMDIR(dcmFiles); theMediaSession.EndResultsGathering(); // Update the UI. _TagThatIsBeingExecuted = null; EndExecution theEndExecution = new EndExecution(GetSelectedTreeNodeTag()); Notify(theEndExecution); } }
private void ExecuteSelectedMediaSession() { ArrayList theMediaFilesToBeValidatedLocalList = new ArrayList(); Dvtk.Sessions.MediaSession theMediaSession = GetSelectedSession() as Dvtk.Sessions.MediaSession; if (theMediaSession == null) { // Sanity check. Debug.Assert(false); } else { mediaFilesToBeValidated.Clear(); OpenFileDialog theOpenFileDialog = new OpenFileDialog(); theOpenFileDialog.Filter = "All files (*.*)|*.*"; theOpenFileDialog.Multiselect = true; theOpenFileDialog.ReadOnlyChecked = true; theOpenFileDialog.Title = "Select media files to validate"; // Show the file dialog. // If the user pressed the OK button... if (theOpenFileDialog.ShowDialog() == DialogResult.OK) { // Validate all files selected. foreach (string theFullFileName in theOpenFileDialog.FileNames) { mediaFilesToBeValidated.Enqueue(theFullFileName); theMediaFilesToBeValidatedLocalList.Add(theFullFileName); } } if (mediaFilesToBeValidated.Count == 0) // No files selected, so no media validation to perform. // Update UI. { _TagThatIsBeingExecuted = null; EndExecution theEndExecution = new EndExecution(GetSelectedTreeNodeTag()); Notify(theEndExecution); } else { bool isExecutionCancelled = false; // Remove the current results files for the selected media files. // If results files exists that will be removed, ask the user what to do with them. ArrayList theResultsFilesForSession = ResultsFile.GetAllNamesForSession(theMediaSession); ArrayList theResultsFilesToRemove = new ArrayList(); foreach(string theMediaFullFileName in theMediaFilesToBeValidatedLocalList) { string theMediaFileBaseName = ResultsFile.GetBaseNameForMediaFile(theMediaFullFileName); ArrayList theResultsFilesToRemoveForMediaFile = ResultsFile.GetNamesForBaseName(theMediaFileBaseName, theResultsFilesForSession); theResultsFilesToRemoveForMediaFile = ResultsFile.GetNamesForCurrentSessionId(theMediaSession, theResultsFilesToRemoveForMediaFile); theResultsFilesToRemove.AddRange(theResultsFilesToRemoveForMediaFile); } if (theResultsFilesToRemove.Count != 0) { string theWarningMessage = string.Format("Results files exist that will be removed before media validation.\nCopy these results files to backup files?"); DialogResult theDialogResult = DialogResult.No; // Only ask to backup the results file if this is configured. if (_MainForm._UserSettings.AskForBackupResultsFile) { theDialogResult = MessageBox.Show(theWarningMessage, "Warning", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); } if (theDialogResult == DialogResult.Yes) { ResultsFile.BackupFiles(theMediaSession, theResultsFilesToRemove); ResultsFile.Remove(theMediaSession, theResultsFilesToRemove); } else if (theDialogResult == DialogResult.No) { ResultsFile.Remove(theMediaSession, theResultsFilesToRemove); } else { _TagThatIsBeingExecuted = null; // Update the UI. EndExecution theEndExecution = new EndExecution(GetSelectedTreeNodeTag()); Notify(theEndExecution); isExecutionCancelled = true; } } if (!isExecutionCancelled) { _FirstMediaFileToValidate = (string)mediaFilesToBeValidated.Peek(); ValidateMediaFiles(); } } } }
private void ExecuteVisualBasicScript() { try { ScriptFileTag theScriptFileTag = _TagThatIsBeingExecuted as ScriptFileTag; if (theScriptFileTag == null) // Sanity check. { Debug.Assert(false); } else { // TODO!!!!! // The following code should be removed when the business layer is completely implemented! // For now, construct a business layer object that does the execution of the VBS. // BEGIN DvtkApplicationLayer.VisualBasicScript applicationLayerVisualBasicScript = new DvtkApplicationLayer.VisualBasicScript(theScriptFileTag._Session as ScriptSession, theScriptFileTag._ScriptFileName); // END String[] emptyArray = {}; ArrayList listContainingExmptyArray = new ArrayList(); listContainingExmptyArray.Add(emptyArray); applicationLayerVisualBasicScript.Execute(listContainingExmptyArray.ToArray()); } // Update the UI. Do this with an invoke, because the thread that is calling this // method is NOT the thread that created all controls used! _EndExecution = new EndExecution(_TagThatIsBeingExecuted); _TagThatIsBeingExecuted = null; _NotifyDelegate = new NotifyDelegate(_ParentForm.Notify); _ParentForm.Invoke(_NotifyDelegate, new object[]{_EndExecution}); } catch (Exception ex) { // // Problem: // Errors thrown from a workerthread are eaten by the .NET 1.x CLR. // Workaround: // Directly call the global (untrapped) exception handler callback. // Do NOT rely on // either // - System.AppDomain.CurrentDomain.UnhandledException // or // - System.Windows.Forms.Application.ThreadException // These events will only be triggered for the main thread not for worker threads. // CustomExceptionHandler eh = new CustomExceptionHandler(); System.Threading.ThreadExceptionEventArgs args = new ThreadExceptionEventArgs(ex); eh.OnThreadException(this, args); // // Rethrow. This rethrow may work in the future .NET 2.x CLR. // Currently eaten. // throw ex; } }
private void ExecuteVisualBasicScript() { try { Script theScriptFileTag = _TagThatIsBeingExecuted as Script; if (theScriptFileTag == null) { // Sanity check. Debug.Assert(false); } else { DvtkApplicationLayer.VisualBasicScript applicationLayerVisualBasicScript = new DvtkApplicationLayer.VisualBasicScript(((DvtkApplicationLayer.ScriptSession)theScriptFileTag.ParentSession).ScriptSessionImplementation , theScriptFileTag.ScriptFileName); // END String[] emptyArray = {}; ArrayList listContainingExmptyArray = new ArrayList(); listContainingExmptyArray.Add(emptyArray); applicationLayerVisualBasicScript.Execute(listContainingExmptyArray.ToArray()); } // Update the UI. Do this with an invoke, because the thread that is calling this // method is NOT the thread that created all controls used! theScriptFileTag.ParentSession.IsExecute = false; Script script = (Script)_TagThatIsBeingExecuted ; ((ScriptSession)script.ParentSession).CreateScriptFiles(); _EndExecution = new EndExecution(_TagThatIsBeingExecuted); _TagThatIsBeingExecuted = null; _NotifyDelegate = new NotifyDelegate(parentForm.Notify); parentForm.Invoke(_NotifyDelegate, new object[]{_EndExecution}); } catch (Exception ex) { // // Problem: // Errors thrown from a workerthread are eaten by the .NET 1.x CLR. // Workaround: // Directly call the global (untrapped) exception handler callback. // Do NOT rely on // either // - System.AppDomain.CurrentDomain.UnhandledException // or // - System.Windows.Forms.Application.ThreadException // These events will only be triggered for the main thread not for worker threads. // CustomExceptionHandler eh = new CustomExceptionHandler(); System.Threading.ThreadExceptionEventArgs args = new ThreadExceptionEventArgs(ex); eh.OnThreadException(this, args); // // Rethrow. This rethrow may work in the future .NET 2.x CLR. // Currently eaten. // throw ex; } }
private void ExecuteSelectedEmulator() { Dvtk.Sessions.EmulatorSession theEmulatorSession = GetSelectedSession() as Dvtk.Sessions.EmulatorSession; if (theEmulatorSession == null) { // Sanity check. Debug.Assert(false); } else { EmulatorTag theEmulatorTag = (EmulatorTag)GetSelectedTreeNodeTag(); string theResultsFileName = null; bool isExecutionCancelled = false; // Remove the current results files for the emulator. // If results files exists that will be removed, ask the user what to do with them. ArrayList theResultsFilesToRemove = ResultsFile.GetAllNamesForSession(theEmulatorSession); string theEmulatorBaseName = ResultsFile.GetBaseNameForEmulator(theEmulatorTag._EmulatorType); theResultsFilesToRemove = ResultsFile.GetNamesForBaseName(theEmulatorBaseName, theResultsFilesToRemove); theResultsFilesToRemove = ResultsFile.GetNamesForCurrentSessionId(theEmulatorSession, theResultsFilesToRemove); if (theResultsFilesToRemove.Count != 0) { string theWarningMessage = string.Format("Results files exist that will be removed before execution of the emulator.\nCopy these results files to backup files?"); DialogResult theDialogResult = DialogResult.No; // Only ask to backup the results file if this is configured. if (_MainForm._UserSettings.AskForBackupResultsFile) { theDialogResult = MessageBox.Show(theWarningMessage, "Warning", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); } if (theDialogResult == DialogResult.Yes) { ResultsFile.BackupFiles(theEmulatorSession, theResultsFilesToRemove); ResultsFile.Remove(theEmulatorSession, theResultsFilesToRemove); } else if (theDialogResult == DialogResult.No) { ResultsFile.Remove(theEmulatorSession, theResultsFilesToRemove); } else { _TagThatIsBeingExecuted = null; // Update the UI. EndExecution theEndExecution = new EndExecution(GetSelectedTreeNodeTag()); Notify(theEndExecution); isExecutionCancelled = true; } } if (!isExecutionCancelled) { // Determine the results file name. theResultsFileName = ResultsFile.GetExpandedNameForEmulator(theEmulatorSession, theEmulatorTag._EmulatorType); // Set the correct SCP type. if (theEmulatorTag._EmulatorType == EmulatorTag.EmulatorType.PRINT_SCP) { theEmulatorSession.ScpEmulatorType = DvtkData.Results.ScpEmulatorType.Printing; } if (theEmulatorTag._EmulatorType == EmulatorTag.EmulatorType.STORAGE_SCP) { theEmulatorSession.ScpEmulatorType = DvtkData.Results.ScpEmulatorType.Storage; } // Start the results gathering. theEmulatorSession.StartResultsGathering(theResultsFileName); // If this is the print SCP emulator or the storage SCP emulator... if ( (theEmulatorTag._EmulatorType == EmulatorTag.EmulatorType.PRINT_SCP) || (theEmulatorTag._EmulatorType == EmulatorTag.EmulatorType.STORAGE_SCP) ) { // Perform the actual execution of the script. AsyncCallback theAsyncCallback = new AsyncCallback(this.ResultsFromExecutingEmulatorScpAsynchronously); theEmulatorSession.BeginEmulateSCP(theAsyncCallback); } // If this is the storage SCU emulator... if (theEmulatorTag._EmulatorType == EmulatorTag.EmulatorType.STORAGE_SCU) { DialogResult theDialogResult = _StorageSCUEmulatorForm.ShowDialog(_ParentForm, theEmulatorSession); if (theDialogResult == DialogResult.Cancel) { // No sending of Dicom files is happening now. // Save the results. GetSelectedSession().EndResultsGathering(); _TagThatIsBeingExecuted = null; // Update the UI. EndExecution theEndExecution= new EndExecution(GetSelectedTreeNodeTag()); Notify(theEndExecution); } else { // Dicom files are being send in another thread. // Do nothing, let the call back method handle the enabling of the session in the UI. } } } } }
public void GenerateDICOMDIRWithDirectory() { FolderBrowserDialog mediaDirectoryBrowserDialog = new FolderBrowserDialog(); mediaDirectoryBrowserDialog.Description = "Select the directory contains media files:"; if (mediaDirectoryBrowserDialog.ShowDialog (this) == DialogResult.OK) { DirectoryInfo theDirectoryInfo = new DirectoryInfo(mediaDirectoryBrowserDialog.SelectedPath); FileInfo[] dcmFiles = null; if (theDirectoryInfo != null) { // Get all the subdirectories FileSystemInfo[] infos = theDirectoryInfo.GetFileSystemInfos(); ArrayList allDCMFiles = new ArrayList(); foreach (FileSystemInfo f in infos) { if (f is DirectoryInfo) { // Get all the files in a specific directory FileInfo[] dcmFilesInSubDir = ((DirectoryInfo)f).GetFiles(); if(dcmFilesInSubDir.Length != 0) { foreach (FileInfo fileNext in dcmFilesInSubDir) { allDCMFiles.Add(fileNext); } } } else if (f is FileInfo) { allDCMFiles.Add((FileInfo)f); } } dcmFiles = (FileInfo[])allDCMFiles.ToArray(typeof(FileInfo)); allDCMFiles.Clear(); } if(dcmFiles.Length != 0) { DvtkApplicationLayer.MediaSession theMediaSession = GetSelectedSessionNew() as DvtkApplicationLayer.MediaSession; if (theMediaSession == null) { // Sanity check. Debug.Assert(false); } theMediaSession.IsExecute = true; _TagThatIsBeingExecuted = GetSelectedTag(); // Move all selected DCM files to directory "DICOM" in result root directory. int i = 0; DirectoryInfo theDICOOMDirInfo = null; string resultsDir = theMediaSession.ResultsRootDirectory; if(!resultsDir.EndsWith("\\")) resultsDir += "\\"; theDICOOMDirInfo = new DirectoryInfo(resultsDir + "DICOM\\"); // Create "DICOM" directory if it doesn't exist if(!theDICOOMDirInfo.Exists) { theDICOOMDirInfo.Create(); } else { // Remove existing DCM files from "DICOM" directory FileInfo[] files = theDICOOMDirInfo.GetFiles(); foreach(FileInfo file in files) { file.Delete(); } } string[] filesToSend = new string[dcmFiles.Length]; foreach(FileInfo theFileInfo in dcmFiles) { string newFileName = string.Format("I{0:00000}",i); string destFileName = theDICOOMDirInfo.FullName + "\\" + newFileName; //string destFileName = theDICOOMDirInfo.FullName + theFileInfo.Name; theFileInfo.CopyTo(destFileName,true); filesToSend.SetValue(destFileName,i); i++; } _MainForm = (MainForm)_ParentForm._MainForm; if(_MainForm != null) { _MainForm.MainStatusBar.Text = "Please wait, DICOMDIR creation is in progress..."; } string theExpandedResultsFileName = theMediaSession.SessionId.ToString("000") + "_" + "dicomdir_creation_logging" + "_res.xml"; theMediaSession.Implementation.StartResultsGathering(theExpandedResultsFileName); AsyncCallback createDicomdirAsyncCallback = new AsyncCallback(this.ResultsFromCreationDicomdirAsynchronously); theMediaSession.MediaSessionImplementation.BeginGenerationDICOMDIR(filesToSend,createDicomdirAsyncCallback); } else { // No files selected, so no media validation to perform. // Update UI. _TagThatIsBeingExecuted = null; EndExecution theEndExecution = new EndExecution(GetSelectedTag()); Notify(theEndExecution); } } }
public void GenerateDICOMDIR() { OpenFileDialog theOpenFileDialog = new OpenFileDialog(); theOpenFileDialog.Filter = "DICOM media files (*.dcm)|*.dcm|All files (*.*)|*.*"; theOpenFileDialog.Title = "Select DCM files to create DICOMDIR"; theOpenFileDialog.Multiselect = true; theOpenFileDialog.ReadOnlyChecked = true; // Show the file dialog. // If the user pressed the OK button... if (theOpenFileDialog.ShowDialog() == DialogResult.OK) { // Add all DCM files selected. string [] dcmFiles = new string [theOpenFileDialog.FileNames.Length]; DvtkApplicationLayer.MediaSession theMediaSession = GetSelectedSessionNew() as DvtkApplicationLayer.MediaSession; if (theMediaSession == null) { // Sanity check. Debug.Assert(false); } theMediaSession.IsExecute = true; _TagThatIsBeingExecuted = GetSelectedTag(); if (theOpenFileDialog.FileNames.Length == 0) { // No files selected, so no media validation to perform. // Update UI. _TagThatIsBeingExecuted = null; EndExecution theEndExecution = new EndExecution(GetSelectedTag()); Notify(theEndExecution); } // Move all selected DCM files to directory "DICOM" in result root directory. int i = 0; DirectoryInfo theDirectoryInfo = null; try { string resultsDir = theMediaSession.ResultsRootDirectory; if(!resultsDir.EndsWith("\\")) resultsDir += "\\"; theDirectoryInfo = new DirectoryInfo(resultsDir + "DICOM\\"); // Create "DICOM" directory if it doesn't exist if(!theDirectoryInfo.Exists) { theDirectoryInfo.Create(); } else { // Remove existing DCM files from "DICOM" directory FileInfo[] files = theDirectoryInfo.GetFiles(); foreach(FileInfo file in files) { file.Delete(); } } foreach(string dcmFile in theOpenFileDialog.FileNames) { FileInfo theFileInfo = new FileInfo(dcmFile); string newFileName = string.Format("I{0:00000}",i); string destFileName = theDirectoryInfo.FullName + "\\" + newFileName; //string destFileName = theDirectoryInfo.FullName + theFileInfo.Name; theFileInfo.CopyTo(destFileName,true); dcmFiles.SetValue(destFileName,i); i++; } } catch(IOException exception) { MessageBox.Show(exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } _MainForm = (MainForm)_ParentForm._MainForm; if(_MainForm != null) { _MainForm.MainStatusBar.Text = "Please wait, DICOMDIR creation is in progress..."; } string theExpandedResultsFileName = theMediaSession.SessionId.ToString("000") + "_" + "dicomdir_creation_logging" + "_res.xml"; theMediaSession.Implementation.StartResultsGathering(theExpandedResultsFileName); AsyncCallback createDicomdirAsyncCallback = new AsyncCallback(this.ResultsFromCreationDicomdirAsynchronously); theMediaSession.MediaSessionImplementation.BeginGenerationDICOMDIR(dcmFiles,createDicomdirAsyncCallback); } }
/// <summary> /// This method performs the validation of a media direcetory /// </summary> /// <param name="MediaDirectoryInfo"></param> public void Execute(DirectoryInfo MediaDirectoryInfo) { _ISMediaDirectoryValidation = true; string errorTextFromIsFileInUse; DvtkApplicationLayer.Session session = GetSession(); session.IsExecute = true; if (!Directory.Exists(session.ResultsRootDirectory)) { MessageBox.Show("The results directory specified for this session is not valid.\nExecution is cancelled.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); session.IsExecute = false; } else if (IsFileInUse(GetSelectedTag(), out errorTextFromIsFileInUse)) { string firstPartWarningText = ""; if (GetSelectedTag() is Script) { firstPartWarningText = "Unable to execute script.\n\n"; } else if (GetSelectedTag() is Emulator) { firstPartWarningText = "Unable to execute emulator.\n\n"; } MessageBox.Show(firstPartWarningText + errorTextFromIsFileInUse + "\n\n(hint: change the session ID to obtain a different results file name)", "Warning"); } else { _TagThatIsBeingExecuted = GetSelectedTag(); /* if session is an emulator session or a script session . * Since media session do not require any connection to have * secured connection*/ if ((_TagThatIsBeingExecuted is DvtkApplicationLayer.Emulator) || (_TagThatIsBeingExecuted is DvtkApplicationLayer.DicomScript)) { bool bDisplayPwdMsg = false; bool bPwdMsg = true; int certIndex = 0; int credIndex = 0; Dvtk.Sessions.ISecuritySettings theISecuritySettings = null; theISecuritySettings = (GetSelectedSessionNew().Implementation as Dvtk.Sessions.ISecure).SecuritySettings; /* If the session selected has security settings enabled */ if (theISecuritySettings.SecureSocketsEnabled == true) { certIndex = theISecuritySettings.CertificateFileName.LastIndexOf("\\"); credIndex = theISecuritySettings.CredentialsFileName.LastIndexOf("\\"); /* if Certificate file name not specified */ if ((certIndex + 1) == theISecuritySettings.CertificateFileName.Length) { MessageBox.Show("Session cannot be executed as the certificate name is not specified "); _TagThatIsBeingExecuted = null; bDisplayPwdMsg = true; } /* if Certificate file donot exist */ else if (!File.Exists(theISecuritySettings.CertificateFileName)) { MessageBox.Show("Certificate File does not exist "); _TagThatIsBeingExecuted = null; bDisplayPwdMsg = true; } /* if Credential file name not specified */ else if ((credIndex + 1) == theISecuritySettings.CredentialsFileName.Length) { MessageBox.Show("Session can not be executed as the credential name is not specified "); _TagThatIsBeingExecuted = null; bDisplayPwdMsg = true; } /* If credential file donot exist */ else if (!File.Exists(theISecuritySettings.CredentialsFileName)) { MessageBox.Show("Credential File do not exist "); _TagThatIsBeingExecuted = null; bDisplayPwdMsg = true; } (GetSelectedSessionNew().Implementation as Dvtk.Sessions.ISecure).SecuritySettings.TlsPassword = "******"; while (!bDisplayPwdMsg) { try { (GetSelectedSessionNew().Implementation as Dvtk.Sessions.ISecure).CreateSecurityCredentialHandler(); bDisplayPwdMsg = true; (GetSelectedSessionNew().Implementation as Dvtk.Sessions.ISecure).DisposeSecurityCredentialHandler(); } catch (Exception theException) { if (theException.GetType().FullName == "Wrappers.Exceptions.PasswordExpection") { bDisplayPwdMsg = false; PassWordForm passWordForm = new PassWordForm(GetSelectedSessionNew(), bPwdMsg); bPwdMsg = false; if (passWordForm.ShowDialog() != DialogResult.OK) { bDisplayPwdMsg = true; bPwdMsg = false; _TagThatIsBeingExecuted = null; } } else { MessageBox.Show(theException.Message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); bDisplayPwdMsg = true; _TagThatIsBeingExecuted = null; } } } } } if (_TagThatIsBeingExecuted != null) { // Update the UI. StartExecution theStartExecution = new StartExecution(GetSelectedUserNode()); Notify(theStartExecution); // If this is a script file tag, start execution of the script. if (_TagThatIsBeingExecuted is Script) { ExecuteSelectedScript(); } // If this is a emulator tag, start execution of the correct emulator. if (_TagThatIsBeingExecuted is Emulator) { ExecuteSelectedEmulator(); } // If this is a media session tag, start execution of the media validator. if (_TagThatIsBeingExecuted is DvtkApplicationLayer.MediaSession) { ExecuteMediaDirectoryValidation(MediaDirectoryInfo); } else { session.IsExecute = false; // Update the UI. EndExecution theEndExecution = new EndExecution(GetSelectedTag()); Notify(theEndExecution); } } } }
//This method performs the validation of a media directory. private void ExecuteMediaDirectoryValidation( DirectoryInfo MediaDirectoryInfo) { _MainForm = (MainForm)_ParentForm._MainForm; ArrayList theMediaFilesToBeValidatedLocalList = null; DvtkApplicationLayer.MediaSession theMediaSession = GetSelectedSessionNew() as DvtkApplicationLayer.MediaSession; if (theMediaSession == null) { // Sanity check. Debug.Assert(false); } else { theMediaSession.IsExecute = true; mediaFilesToBeValidated.Clear(); //Recursively get all the media files from all the sub directories theMediaFilesToBeValidatedLocalList = GetFilesRecursively(MediaDirectoryInfo); foreach (string theMediaFileName in theMediaFilesToBeValidatedLocalList) { listOfFileNames.Add(Path.GetFileName(theMediaFileName)); mediaFilesToBeValidated.Enqueue(theMediaFileName); } if (mediaFilesToBeValidated.Count == 0) { // No directory selected, so no media validation to perform. // Update UI. _TagThatIsBeingExecuted = null; MessageBox.Show("The Selected Directory has no media files", "No Media Files present!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); EndExecution theEndExecution = new EndExecution(GetSelectedTag()); Notify(theEndExecution); } else { bool isExecutionCancelled = false; if (!isExecutionCancelled) { _FirstMediaFileToValidate = (string)mediaFilesToBeValidated.Peek(); ValidateMediaDirectory(); } } } }
public void ResultsFromCreationDicomdirAsynchronously(IAsyncResult theIAsyncResult) { DvtkApplicationLayer.MediaSession theMediaSession = (DvtkApplicationLayer.MediaSession)GetExecutingSession(); try { // Obligated to call the following method according to the asynchronous design pattern. theMediaSession.MediaSessionImplementation.EndGenerationDICOMDIR(theIAsyncResult); } catch (Exception ex) { // // Problem: // Errors thrown from a workerthread are eaten by the .NET 1.x CLR. // Workaround: // Directly call the global (untrapped) exception handler callback. // Do NOT rely on // either // - System.AppDomain.CurrentDomain.UnhandledException // or // - System.Windows.Forms.Application.ThreadException // These events will only be triggered for the main thread not for worker threads. // // CustomExceptionHandler eh = new CustomExceptionHandler(); // System.Threading.ThreadExceptionEventArgs args = new ThreadExceptionEventArgs(ex); // eh.OnThreadException(this, args); // // Rethrow. This rethrow may work in the future .NET 2.x CLR. // Currently eaten. // throw ex; } theMediaSession.MediaSessionImplementation.EndResultsGathering(); DvtkApplicationLayer.MediaSession mediaSession = (DvtkApplicationLayer.MediaSession)_TagThatIsBeingExecuted; mediaSession.CreateMediaFiles(); _FirstMediaFileToValidate = "dicomdir_creation_logging"; // Update the UI. Do this with an invoke, because the thread that is calling this // method is NOT the thread that created all controls used! _EndExecution = new EndExecution(_TagThatIsBeingExecuted); theMediaSession.IsExecute = false; _TagThatIsBeingExecuted = null; _MainForm = (MainForm)_ParentForm._MainForm; if(_MainForm != null) { _MainForm.MainStatusBar.Text = "DICOMDIR creation completed."; } _NotifyDelegate = new NotifyDelegate(_ParentForm.Notify); _ParentForm.Invoke(_NotifyDelegate, new object[]{_EndExecution}); }