Imports System.Text Imports EgtUILib Imports System.IO Public Class ExecuteWindowVM Inherits VMBase #Region "FIELDS & PROPERTIES" ' Evento per chiusura finestra Public Event m_CloseWindow(bDialogResult As Boolean) Private ReadOnly scriptFilePath As String = IO.Path.Combine(IniFile.m_sTempDir, $"tmpLua.lua") Private m_sScriptText As String Public Property sScriptText As String Get Return m_sScriptText End Get Set(value As String) m_sScriptText = value NotifyPropertyChanged(NameOf(sScriptText)) End Set End Property Private Sub SetScriptFile(value As String) m_sScriptText = value NotifyPropertyChanged(NameOf(sScriptText)) End Sub Private m_bReload_IsEnable As Boolean = File.Exists(scriptFilePath) Public ReadOnly Property bReload_IsEnable As Boolean Get Return m_bReload_IsEnable End Get End Property #Region "Messages" Public ReadOnly Property OkMsg As String Get Return EgtMsg(20041) End Get End Property Public ReadOnly Property SaveMsg As String Get Return EgtMsg(6453) End Get End Property #End Region ' Messages ' Definizione Comandi Private m_cmdOk As ICommand Private m_cmdReload As ICommand #End Region ' Fields & Properties #Region "CONSTRUCTOR" Sub New() End Sub #End Region ' Constructor #Region "METHODS" Private Sub SaveScript(sPathFileScript As String, sScriptText As String) If String.IsNullOrWhiteSpace(sPathFileScript) OrElse String.IsNullOrWhiteSpace(sScriptText) Then Return File.WriteAllText(sPathFileScript, sScriptText, Encoding.UTF8) End Sub Private Function ReadScript(sPathFileScript As String) As String If String.IsNullOrWhiteSpace(sPathFileScript) Then Return String.Empty Return File.ReadAllText(sPathFileScript) End Function #End Region ' Methods #Region "COMMANDS" #Region "Ok_Command" Public ReadOnly Property Ok_Command As ICommand Get If m_cmdOk Is Nothing Then m_cmdOk = New Command(AddressOf Ok) End If Return m_cmdOk End Get End Property Public Sub Ok() ' Salva il file script SaveScript(scriptFilePath, m_sScriptText) ' Esegue il file script EgtLuaExecFile(scriptFilePath) ' Chiudo finestra RaiseEvent m_CloseWindow(True) End Sub #End Region ' Ok_Command #Region "Reload_Command" Public ReadOnly Property Reload_Command As ICommand Get If m_cmdReload Is Nothing Then m_cmdReload = New Command(AddressOf Reload) End If Return m_cmdReload End Get End Property Public Sub Reload() If File.Exists(scriptFilePath) Then SetScriptFile(ReadScript(scriptFilePath)) End If End Sub #End Region ' Reload_Command #End Region ' Commands End Class