Debugger integration vb.net

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

Hi,

We will try to recreate the project using your code and send you a working example early next week.

If you could send us the complete source code of your project, this would be of great help!

Kind regards,
Dmitry

Hi Dmitry,

i think i’ve found my fault, forget to set scriptmode to debug, but i ran into another problem:

i start an debugger process and want the globalcode for code completion in debugger/editor. As i found in Studio Source there is a -globalCode parameter right ?

Also solved, maybe workspace didn’t rebuild the whole project. Can i monitor Global objects in script debugger ?

        debuggerProcess = Process.Start(New ProcessStartInfo With {
        .UseShellExecute = False,
        .FileName = pathToDebugDemo,
        .Arguments = String.Format("""-mainScriptFile={0}"" ""-controlledProcessId={1}"" ""-myCodeModules={2}"" ""-ipcPortName={3}"" ""-ipcObjectUri={4}"" ""-references={5}"" ""-globalCode={6}""", scriptRun.ScriptSource.ScriptFile, Process.GetCurrentProcess().Id, scriptRun.ScriptHost.ExecutableModulePath, If(ipcPortName, String.Empty), If(ipcObjectUri, String.Empty), String.Join(",", scriptRun.ScriptSource.References), scriptRun.ScriptHost.GlobalCode)
        })

Hi,

Could you please try running the sample application that I’ve uploaded here:

(you will need to change the debuggerPath variable to point to the AlterNET Studio executable.

On my tests, AlterNET Studio understands global code and can evaluate it as well:

Kind regards,
Dmitry

Perfect - it’s working now, so i can strip down the Studio Source code and remove form designer and so on.
One question - can i add global variables to the watch list or only evaluate by moving over the code ?

Actually last question - what about licensing on azure ci/cd pipelines ?
Can i include the license file generated by Licensemanager and build with this license (i’ve read it’s node-locked ?)

Many thanks for your support!
michael

Hi,

Yes, you can add individual fields of ScriptGlobalClass to the watch, and evaluate it via Debug->Evaluate Expression.

y

I will send you a node-unlocked license via email, so that you can use it with Azure pipeline.

Kind regards,
Dmitry