Imports EgtBEAMWALL.Core
Imports EgtUILib
Imports EgtWPFLib5

Module LuaExec

   Friend Function ExecBeam(sFile As String, sMachine As String, nFlag As Integer, bBtl As Boolean) As Boolean
      EgtOutLog("-- Start ExecBeam --")
      ' Recupero lo script da eseguire
      Dim sExecPath As String = ""
      Dim sExecName As String = ""
      GetMainPrivateProfileString(S_BEAM, K_BEAMBWEEXEC, "", sExecName)
      sExecPath = (Map.refMainWindowVM.MainWindowM.sBeamRoot & "\" & sExecName).TrimEnd({"\"c})
      If Not My.Computer.FileSystem.FileExists(sExecPath) Then
         EgtOutLog("Not found BeamExec script " & sExecPath)
         Return False
      End If
      ' Assegno i dati
      EgtLuaCreateGlobTable("BEAM")
      EgtLuaSetGlobStringVar("BEAM.BASEDIR", Map.refMainWindowVM.MainWindowM.sBeamRoot)
      EgtLuaSetGlobStringVar("BEAM.FILE", sFile)
      EgtLuaSetGlobStringVar("BEAM.MACHINE", sMachine)
      EgtLuaSetGlobIntVar("BEAM.FLAG", nFlag)
      ' Eseguo lo script
      Dim bOk As Boolean = False
      If EgtLuaExecFile(sExecPath) Then
         ' Recupero i risultati
         Dim nErr As Integer = 999
         EgtLuaGetGlobIntVar("BEAM.ERR", nErr)
         bOk = (nErr <= 0)
         If Not bOk Then EgtOutLog("BeamExec Err=" & nErr.ToString())
      Else
         EgtOutLog("Error executing Beam Exec script " & sExecPath)
         Return False
      End If
      ' Cancello tavola globale
      EgtLuaResetGlobVar("BEAM")
      Return bOk
   End Function

   Friend Function ExecWall(sFile As String, sMachine As String, nFlag As Integer, bBtl As Boolean) As Boolean
      EgtOutLog("-- Start ExecWall --")
      ' Recupero lo script da eseguire
      Dim sExecPath As String = ""
      Dim sExecName As String = ""
      GetMainPrivateProfileString(S_WALL, K_WALLBWEEXEC, "", sExecName)
      sExecPath = (Map.refMainWindowVM.MainWindowM.sWallRoot & "\" & sExecName).TrimEnd({"\"c})
      If Not My.Computer.FileSystem.FileExists(sExecPath) Then
         EgtOutLog("Not found WallExec script " & sExecPath)
         Return False
      End If
      ' Assegno i dati
      EgtLuaCreateGlobTable("WALL")
      EgtLuaSetGlobStringVar("WALL.FILE", sFile)
      EgtLuaSetGlobStringVar("WALL.MACHINE", sMachine)
      EgtLuaSetGlobIntVar("WALL.FLAG", nFlag)
      ' Eseguo lo script
      Dim bOk As Boolean = False
      If EgtLuaExecFile(sExecPath) Then
         ' Recupero i risultati
         Dim nErr As Integer = 999
         EgtLuaGetGlobIntVar("WALL.ERR", nErr)
         bOk = (nErr <= 0)
         If Not bOk Then EgtOutLog("WallExec Err=" & nErr.ToString())
      Else
         bOk = False
         EgtOutLog("Error executing Wall Exec script " & sExecPath)
      End If
      ' Cancello tavola globale
      EgtLuaResetGlobVar("WALL")
      Return bOk
   End Function

End Module
