Namespace UTSModule.Test.Command.ProcessCommand
    Public Class ProcessExecuteExecutor
        Inherits TestCommandExecutor

        Private ReadOnly _exePath As String
        Private ReadOnly _exeArgs As String

        Private ReadOnly _timeout As Integer '程序执行的超时时间
        Private ReadOnly _stream As Integer '获取输出信息的对象
        Private ReadOnly _destSrc As String


        Sub New(command As TestCommand)
            MyBase.New(command)

            _exePath = TestCommandManger.ReplacePath(command.Parameter(0))
            _exeArgs = command.Parameter(1)

            If IsNumeric(command.Parameter(2)) Then
                _timeout = CInt(command.Parameter(2))
            Else
                _timeout = 0
            End If

            If IsNumeric(command.Parameter(3)) Then
                _stream = CInt(command.Parameter(3))
            Else
                _stream = 0
            End If

            _destSrc = command.Parameter(4)
        End Sub

        Public Overrides Function Execute() As TestCommandReturn
            '路径检测
            If IO.File.Exists(_exePath) = False Then
                CommandReturn.RecordValue = String.Empty
                CommandReturn.ExecuteResultTipString = $"[{_exePath}]文件不存在"
                CommandReturn.ExecuteResult = False
                Return CommandReturn
            End If

            Dim exeResult As String = ""
            '进程执行

            If ProcessCommandManager.RunCmdGetReturn(_exePath, _exeArgs, _timeout, _stream, _destSrc, exeResult) = False Then
                CommandReturn.ExecuteResultTipString = $"进程执行失败,{exeResult}"
                CommandReturn.ExecuteResult = False
            Else
                CommandReturn.RecordValue = exeResult
                CommandReturn.ExecuteResultTipString = $"进程执行完成"
                CommandReturn.ExecuteResult = True
            End If

            Return CommandReturn
        End Function
    End Class
End Namespace