Exemplo n.º 1
0
        /// <summary>
        /// /// <summary>
        /// Method for executing a session in a synchronous manner.
        /// </summary>
        /// <param name="baseInput">baseInput Object (in this case ScriptInput Object) </param>
        /// <returns></returns>
        public override Result Execute(BaseInput baseInput)
        {
            CreateSessionInstance(sessionFileName);
            ScriptInput scriptInput = (ScriptInput)baseInput;
            string scriptFileName = scriptInput.FileName.Replace(".", "_");
            string extension = Path.GetExtension(scriptInput.FileName);
            string tempName = Path.GetFileName(scriptFileName);
            string name = CreateResultFileName(tempName);
            string fileName = Path.GetFileName(scriptInput.FileName);
            string scriptFullFileName = "";
            if (Path.GetDirectoryName(scriptInput.FileName )!= "") {
                scriptFullFileName = scriptInput.FileName;
            }
            else {
                scriptFullFileName = Path.Combine(((DvtkSession.ScriptSession)implementation).DicomScriptRootDirectory ,scriptInput.FileName);
            }
            //scriptInput.Arguments[2] = fileName;
            if (optionVerbose) {
                implementation.ActivityReportEvent +=new Dvtk.Events.ActivityReportEventHandler(ActivityReportEventHandler);
            }
            if(
                (string.Compare(extension, ".dss", true) == 0) ||
                (string.Compare(extension, ".ds", true) == 0)
                ) {
                if ((Path.GetDirectoryName(scriptInput.FileName)!= "") && (Path.GetDirectoryName(scriptInput.FileName)!= null)) {
                    ((DvtkSession.ScriptSession)implementation).DicomScriptRootDirectory = Path.GetDirectoryName(scriptInput.FileName);
                }
                implementation.StartResultsGathering(name);
                result = ((DvtkSession.ScriptSession)implementation).ExecuteScript(
                    fileName,
                    scriptInput.ContinueOnError
                    );
                implementation.EndResultsGathering();

            } else if (string.Compare(extension, ".vbs", true) == 0) {
                VisualBasicScript Vbs = new VisualBasicScript(
                    (DvtkSession.ScriptSession)implementation, Path.GetDirectoryName(scriptFullFileName), Path.GetFileName(scriptFullFileName));

                // An array of an array is needed!! Otherwise it won't work.
                ArrayList arraylist = new ArrayList();
                arraylist.Add(scriptInput.Arguments);
                Vbs.Execute(arraylist.ToArray());
                // Won't work.Vbs.Execute(scriptInput.Arguments);
            }else {
                Console.WriteLine(" Not a valid Script File");
            }
            return CreateResults(name);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Execute the Visual Basic Script.
        /// </summary>
        public void ExecuteVisualBasicScript()
        {
            VisualBasicScript Vbs = new VisualBasicScript(
                (DvtkSession.ScriptSession)implementation, scriptFileName);

            String[] emptyArray = {};
            ArrayList listContainingExmptyArray = new ArrayList();
            listContainingExmptyArray.Add(emptyArray);

            Vbs.Execute(listContainingExmptyArray.ToArray());
        }
Exemplo n.º 3
0
        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;
            }
        }