Exemple #1
0
        public override bool IsRepresentingSame(TreeNodeTag theTreeNodeTag)
        {
            bool isRepresentingSame = false;

            EmulatorTag theEmulatorTag = theTreeNodeTag as EmulatorTag;

            if (theEmulatorTag != null)
            {
                if ((theEmulatorTag._Session == _Session) && (theEmulatorTag._EmulatorType == _EmulatorType))
                {
                    isRepresentingSame = true;
                }
            }

            return(isRepresentingSame);
        }
Exemple #2
0
        public override bool IsRepresentingSame(TreeNodeTag theTreeNodeTag)
        {
            bool isRepresentingSame = false;

            ResultsFileTag theResultsFileTag = theTreeNodeTag as ResultsFileTag;

            if (theResultsFileTag != null)
            {
                if ((theResultsFileTag._Session == _Session) && (theResultsFileTag._ResultsFileName == _ResultsFileName))
                {
                    isRepresentingSame = true;
                }
            }

            return(isRepresentingSame);
        }
Exemple #3
0
        public override bool IsRepresentingSame(TreeNodeTag theTreeNodeTag)
        {
            bool isRepresentingSame = false;

            SessionTag theSessionTag = theTreeNodeTag as SessionTag;

            if (theSessionTag != null)
            {
                if (theSessionTag._Session == _Session)
                {
                    isRepresentingSame = true;
                }
            }

            return(isRepresentingSame);
        }
Exemple #4
0
        public override bool IsRepresentingSame(TreeNodeTag theTreeNodeTag)
        {
            bool isRepresentingSame = false;

            EmulatorTag theEmulatorTag = theTreeNodeTag as EmulatorTag;

            if (theEmulatorTag != null)
            {
                if ((theEmulatorTag._Session == _Session) && (theEmulatorTag._EmulatorType == _EmulatorType))
                {
                    isRepresentingSame = true;
                }
            }

            return(isRepresentingSame);
        }
Exemple #5
0
 public virtual bool IsRepresentingSame(TreeNodeTag theTreeNodeTag)
 {
     return(false);
 }
        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});
            }
        }
        /// <summary>
        /// Is the main results file for the selected tree node tag in use when a script or emulator
        /// will be executed or media files will be validated?
        /// </summary>
        /// <param name="treeNodeTag">The selected tree node tag.</param>
        /// <returns>Indicates if the main results file for the selected tree node tag is in use.</returns>
        public bool IsFileInUse(TreeNodeTag treeNodeTag, out string errorText)
        {
            bool isFileInUse = false;
            string resultsFileNameOnly = "";
            errorText = "";

            if (treeNodeTag is ScriptFileTag)
            {
                ScriptFileTag scriptFileTag = treeNodeTag as ScriptFileTag;

                resultsFileNameOnly = ResultsFile.GetSummaryNameForScriptFile(scriptFileTag._Session, scriptFileTag._ScriptFileName);
            }
            else if (treeNodeTag is EmulatorTag)
            {
                EmulatorTag emulatorTag = treeNodeTag as EmulatorTag;

                resultsFileNameOnly = ResultsFile.GetSummaryNameForEmulator(emulatorTag._Session, emulatorTag._EmulatorType);
            }

            if (resultsFileNameOnly != "")
            {
                string resultsFullFileName = Path.Combine(treeNodeTag._Session.ResultsRootDirectory, resultsFileNameOnly);
                FileStream fileStream = null;

                try
                {
                    fileStream = File.OpenRead(resultsFullFileName);
                }
                catch(IOException exception)
                {
                    if (!(exception is FileNotFoundException))
                    {
                        isFileInUse = true;
                        errorText = exception.Message;
                    }
                }
                finally
                {
                    if (fileStream != null)
                    {
                        fileStream.Close();
                    }
                }
            }

            return isFileInUse;
        }
        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);
            }
        }
        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);
                    }
                }
            }
        }
Exemple #10
0
        public override bool IsRepresentingSame(TreeNodeTag theTreeNodeTag)
        {
            bool isRepresentingSame = false;

            ScriptFileTag theScriptFileTag = theTreeNodeTag as ScriptFileTag;

            if (theScriptFileTag != null)
            {
                if ((theScriptFileTag._Session == _Session) && (theScriptFileTag._ScriptFileName == _ScriptFileName))
                {
                    isRepresentingSame = true;
                }
            }

            return(isRepresentingSame);
        }
        public void Execute()
        {
            string errorTextFromIsFileInUse;

            if (!Directory.Exists(GetSelectedSession().ResultsRootDirectory))
            {
                MessageBox.Show("The results directory specified for this session is not valid.\nExecution is cancelled.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (IsFileInUse(GetSelectedTreeNodeTag(), out errorTextFromIsFileInUse))
            {
                string firstPartWarningText = "";

                if (GetSelectedTreeNodeTag() is ScriptFileTag)
                {
                    firstPartWarningText = "Unable to execute script.\n\n";
                }
                else if (GetSelectedTreeNodeTag() is EmulatorTag)
                {
                    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  = GetSelectedTreeNodeTag();

                // Update the UI.
                StartExecution theStartExecution = new StartExecution(GetSelectedNode());
                Notify(theStartExecution);

                // If this is a script file tag, start execution of the script.
                if (_TagThatIsBeingExecuted is ScriptFileTag)
                {
                    ExecuteSelectedScript();
                }

                // If this is a emulator tag, start execution of the correct emulator.
                if (_TagThatIsBeingExecuted is EmulatorTag)
                {
                    ExecuteSelectedEmulator();
                }

                // If this is a media session tag, start execution of the media validator.
                if (_TagThatIsBeingExecuted is MediaSessionTag)
                {
                    ExecuteSelectedMediaSession();
                }
            }
        }
        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 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.
                        }
                    }
                }
            }
        }
Exemple #14
0
 public EndExecution(TreeNodeTag theTag)
 {
     _Tag = theTag;
 }
Exemple #15
0
 public virtual bool IsRepresentingSame(TreeNodeTag theTreeNodeTag)
 {
     return(false);
 }
Exemple #16
0
        public override bool IsRepresentingSame(TreeNodeTag theTreeNodeTag)
        {
            bool isRepresentingSame = false;

            SessionTag theSessionTag = theTreeNodeTag as SessionTag;

            if (theSessionTag != null)
            {
                if (theSessionTag._Session == _Session)
                {
                    isRepresentingSame = true;
                }
            }

            return(isRepresentingSame);
        }
        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;
            }
        }
Exemple #18
0
        public override bool IsRepresentingSame(TreeNodeTag theTreeNodeTag)
        {
            bool isRepresentingSame = false;

            ResultsCollectionTag theResultsCollectionTag = theTreeNodeTag as ResultsCollectionTag;

            if (theResultsCollectionTag != null)
            {
            if ( (theResultsCollectionTag._Session == _Session) && (theResultsCollectionTag._ResultsCollectionName == _ResultsCollectionName) )

            {
                    isRepresentingSame = true;
                }
            }

            return(isRepresentingSame);
        }