/// <summary> /// Expand and compile the script to check if the syntax is OK. /// /// This is a "standalone" method. Use this when no Session object is available. /// </summary> /// <param name="scriptFullFileName">The full script file name.</param> /// <param name="includeAndCompileErrors">String containing include and compile errors if existing.</param> /// <returns>Boolean indicating if the script is correct.</returns> public static bool ExpandAndCompile(String scriptFullFileName, out String includeAndCompileErrors) { includeAndCompileErrors = ""; String includeErrors; String compileErrors; // Construct the following objects because this is a "standalone" method. DvtkSession.ScriptSession scriptSession = new Dvtk.Sessions.ScriptSession(); VisualBasicScript visualBasicScript = new VisualBasicScript(scriptSession, Path.GetDirectoryName(scriptFullFileName), Path.GetFileName(scriptFullFileName)); // Get the script host. DvtkScriptSupport.DvtkScriptHost dvtkScriptHost = visualBasicScript.GetDvtkScriptHost(); // Set the source code. dvtkScriptHost.SourceCode = visualBasicScript.GetExpandedContent(out includeErrors); // Add expand results. includeAndCompileErrors += includeErrors; // Compile. visualBasicScript.Compile(dvtkScriptHost, out compileErrors); // Add compile results. includeAndCompileErrors += compileErrors; return(includeAndCompileErrors.Length == 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()); }
/// <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); }
/// <summary> /// Expand and compile the script to check if the syntax is OK. /// /// This is a "standalone" method. Use this when no Session object is available. /// </summary> /// <param name="scriptFullFileName">The full script file name.</param> /// <param name="includeAndCompileErrors">String containing include and compile errors if existing.</param> /// <returns>Boolean indicating if the script is correct.</returns> public static bool ExpandAndCompile(String scriptFullFileName, out String includeAndCompileErrors) { includeAndCompileErrors = ""; String includeErrors; String compileErrors; // Construct the following objects because this is a "standalone" method. DvtkSession.ScriptSession scriptSession = new Dvtk.Sessions.ScriptSession(); VisualBasicScript visualBasicScript = new VisualBasicScript(scriptSession , Path.GetDirectoryName(scriptFullFileName), Path.GetFileName(scriptFullFileName)); // Get the script host. DvtkScriptSupport.DvtkScriptHost dvtkScriptHost = visualBasicScript.GetDvtkScriptHost(); // Set the source code. dvtkScriptHost.SourceCode = visualBasicScript.GetExpandedContent(out includeErrors); // Add expand results. includeAndCompileErrors+= includeErrors; // Compile. visualBasicScript.Compile(dvtkScriptHost, out compileErrors); // Add compile results. includeAndCompileErrors+= compileErrors; return(includeAndCompileErrors.Length == 0); }
// May only be called from UpdateTabContents. private void TCM_UpdateTabScript() { _TCM_UpdateCount++; bool theHtmlDescriptionExists = false; DvtkApplicationLayer.Script scriptFileTag = null; string theHtmlDescriptionFileName = null; DvtkApplicationLayer.ScriptSession scriptSession = null; Object selectedTag = GetSelectedTag(); TreeNode selectedNode = GetSelectedUserNode(); if (selectedTag is DvtkApplicationLayer.Script) { scriptFileTag = (DvtkApplicationLayer.Script)selectedTag; } else if (selectedTag is DvtkApplicationLayer.Result) { if (selectedNode.Parent.Tag is DvtkApplicationLayer.Script) { scriptFileTag = (DvtkApplicationLayer.Script)selectedNode.Parent.Tag; } } if (scriptFileTag == null) { // Not supposed to get here. throw new System.ApplicationException("Error: not expected to get here."); } scriptSession = (DvtkApplicationLayer.ScriptSession)GetSession(); // Is the description directory not empty? if (scriptSession.DescriptionDirectory != "") { DirectoryInfo theDirectoryInfo = new DirectoryInfo(scriptSession.DescriptionDirectory); // Does the description directory exist? if (theDirectoryInfo.Exists) { theHtmlDescriptionFileName = Path.Combine(scriptSession.DescriptionDirectory, scriptFileTag.ScriptFileName); theHtmlDescriptionFileName = theHtmlDescriptionFileName.Replace ('.', '_') + ".html"; // Does the html description file exists? if (File.Exists(theHtmlDescriptionFileName)) { // Now we know the html description file exists. theHtmlDescriptionExists = true; } } } if (theHtmlDescriptionExists) { RichTextBoxScript.Visible = false; this.webBrowserScript.Dispose(); this.webBrowserScript = new System.Windows.Forms.WebBrowser(); SetProperties_webBrowserScript(); this.TabScript.Controls.Add(this.webBrowserScript); webBrowserScript.Visible = true; webBrowserScript.Navigate(theHtmlDescriptionFileName); } else { webBrowserScript.Visible = false; RichTextBoxScript.Visible = true; RichTextBoxScript.Clear(); // If this is a Visual Basic Script... if (scriptFileTag.ScriptFileName.ToLower().EndsWith(".vbs")) { DvtkApplicationLayer.VisualBasicScript applicationLayerVisualBasicScript = new DvtkApplicationLayer.VisualBasicScript(scriptSession.ScriptSessionImplementation, scriptFileTag.ScriptFileName); if (_MainForm._UserSettings.ExpandVisualBasicScript) { String includeErrors = ""; String expandedContent = applicationLayerVisualBasicScript.GetExpandedContent(out includeErrors); // If include errors exist... if (includeErrors.Length > 0) { RichTextBoxScript.Text = includeErrors; RichTextBoxScript.SelectAll(); RichTextBoxScript.SelectionColor = Color.Red; RichTextBoxScript.Select(0, 0); RichTextBoxScript.SelectionColor = Color.Black; RichTextBoxScript.AppendText(expandedContent); } // If no include errors exist... else { RichTextBoxScript.Text = expandedContent; } } else { RichTextBoxScript.Text = applicationLayerVisualBasicScript.GetContent(); } } // If this is not a visual basic script... else { string theFullScriptFileName; theFullScriptFileName = Path.Combine(scriptSession.DicomScriptRootDirectory, scriptFileTag.ScriptFileName); RichTextBoxScript.LoadFile(theFullScriptFileName, RichTextBoxStreamType.PlainText); } } _TCM_UpdateCount--; }
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; } }
public void ViewExpandedScriptFile() { DvtkApplicationLayer.Script selectedScriptFileTag = GetSelectedTag() as DvtkApplicationLayer.Script; if (selectedScriptFileTag != null) { if (selectedScriptFileTag.ScriptFileName.ToLower().EndsWith(".vbs")) { DvtkApplicationLayer.VisualBasicScript applicationLayerVisualBasicScript = new DvtkApplicationLayer.VisualBasicScript(((DvtkApplicationLayer.ScriptSession)selectedScriptFileTag.ParentSession).ScriptSessionImplementation , selectedScriptFileTag.ScriptFileName); applicationLayerVisualBasicScript.ViewExpanded(); } } }