Hi …
i run into some problems integrating Scripter / Debugger into my vb.net program …
Maybe you can help me ? We need debugging feature and i cannot get it running. Actually we’re trying and make our order ready.
Empty form starting debugger:
Imports System.IO
Imports Alternet.Scripter
Imports Alternet.Scripter.Debugger
Public Class Form1 : Implements IScriptRemoteControl
Private scriptRun As ScriptRun
Private scriptObject As IDisposable
Private ipcPortName As String
Private ipcObjectUri As String
Private debuggerProcess As Process
Private scriptRunning As Boolean
Private onScriptFinished As ScriptFinishedDelegate
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim sDebugger As String = Path.Combine(Application.StartupPath, "AlternetStudio.exe")
Dim sFile As String = Path.Combine(Application.StartupPath, "script.vb")
Try
' Write Database script to file
' TODO
'Using writer As StreamWriter = New StreamWriter(sFile)
' writer.Write("Imports Windows")
'End Using
Catch ex As Exception
MsgBox("Error Creating Source File")
Return
End Try
If Not New FileInfo(sDebugger).Exists Then
MessageBox.Show("Can not find Script Debugger executable")
Return
End If
scriptRun = New ScriptRun()
scriptRun.ScriptSource.FromScriptFile(sFile)
scriptRun.ScriptLanguage = ScriptLanguage.VisualBasic
' Only for testing
Dim item As ScriptGlobalItem
item = New ScriptGlobalItem("scriptRunning", GetType(Boolean), scriptRunning)
scriptRun.GlobalItems.Clear()
scriptRun.GlobalItems.Add(item)
DebuggerCommunication.StartServer(Me, ipcPortName, ipcObjectUri)
scriptRun.ScriptSource.WithDefaultReferences(ScriptTechnologyEnvironment.WindowsForms, False, False)
scriptRun.ScriptSource.References.Add(GetType(Form1).Assembly.Location)
debuggerProcess = Process.Start(New ProcessStartInfo() With {.UseShellExecute = False, .FileName = sDebugger, .Arguments = String.Format("""-mainScriptFile={0}"" ""-controlledProcessId={1}"" ""-myCodeModules={2}"" ""-ipcPortName={3}"" ""-ipcObjectUri={4}"" ""-references={5}""", New Object() {Me.scriptRun.ScriptSource.ScriptFile, Process.GetCurrentProcess().Id, Me.scriptRun.ScriptHost.ExecutableModulePath, If(Me.ipcPortName, String.Empty), If(Me.ipcObjectUri, String.Empty), String.Join(",", Me.scriptRun.ScriptSource.References)})})
debuggerProcess.EnableRaisingEvents = True
AddHandler debuggerProcess.Exited, AddressOf Debugger_Exited
End Sub
Private Function CompileScriptIfNeeded() As Boolean
If Not Me.scriptRun.Compiled Then
Me.scriptRun.ScriptHost.AssemblyFileName = Guid.NewGuid().ToString("N") + ".dll"
Return Me.scriptRun.Compile()
End If
Return True
End Function
Private Sub InvokeOnScriptCompiled(onScriptCompiled As ScriptCompiledDelegate, result As ScriptCompilationResult)
If onScriptCompiled IsNot Nothing Then
Try
onScriptCompiled(result)
Catch ex As SystemException
onScriptCompiled(result)
Catch ex2 As Exception
MessageBox.Show(ex2.ToString())
End Try
End If
End Sub
Private Sub Debugger_Exited(sender As Object, e As EventArgs)
' Save file content to database
' TODO
End Sub
Public Sub CompileScript(onScriptCompiled As ScriptCompiledDelegate) Implements IScriptRemoteControl.CompileScript
BeginInvoke(New Action(Sub()
Dim flag As Boolean = CompileScriptIfNeeded()
Try
InvokeOnScriptCompiled(onScriptCompiled, New ScriptCompilationResult() With {.IsSuccessful = flag, .TargetAssemblyName = Me.scriptRun.ScriptHost.ExecutableModulePath, .Errors = Me.scriptRun.ScriptHost.CompilerErrors})
Catch ex As Exception
MessageBox.Show(ex.ToString())
End Try
End Sub))
End Sub
Public Function IsScriptRunning() As Boolean Implements IScriptRemoteControl.IsScriptRunning
Return scriptRunning
End Function
Public Sub StartScript(onScriptFinished As ScriptFinishedDelegate) Implements IScriptRemoteControl.StartScript
Me.onScriptFinished = onScriptFinished
BeginInvoke(New Action(Sub()
Me.scriptRunning = True
' ?!? Maybe needed ?!?
Me.scriptRun.RunMethod("Main")
End Sub))
End Sub
Public Sub StopScript() Implements IScriptRemoteControl.StopScript
End Sub
End Class
Script.vb
Imports System
Imports Microsoft.VisualBasic
Imports System.ComponentModel
Imports System.Windows.Forms
Public Class RexelConverter
Inherits System.ComponentModel.Component
Public Sub New()
End Sub
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
MyBase.Dispose(disposing)
End Sub
Public Shared Sub Main()
Dim f As RexelConverter = New RexelConverter
Console.WriteLine("Test 1 ")
End Sub
End Class