Imports UTS_Core.UTSModule.Station

Namespace UTSModule.Test.Command.SystemCommand
    Public Class CallExecutor
        Inherits TestCommandExecutor

        Private ReadOnly _moduleName As String
        Private ReadOnly _localVariable As New Dictionary(Of String,String)

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

            _moduleName = command.Parameter(0)

            Dim varNames() as String = command.Parameter(1).Split(":"c)
            Dim varValues() as String = command.Parameter(2).Split(":"c)
            For i As Integer = 0 To varNames.Count-1
                _localVariable.Add(varNames(i),varValues(i))
            Next
        End Sub

        Public Overrides Function Execute() As TestCommandReturn
            Dim tester As UtsTester = UtsTester.CreateTester()
            Dim rowNode As RowNode = tester.GetModule(_moduleName)

            If rowNode Is Nothing Then
                CommandReturn.ExecuteResult = False
                CommandReturn.RecordValue = String.Empty
                CommandReturn.ExecuteResultTipString = $"未查询到[{_moduleName}]模块存在"
            Else
                rowNode.IsRetry = IsRetry

                Dim moduleResult As TestCommandReturn = tester.ExecutePlan(rowNode, _localVariable)

                CommandReturn.ExecuteResult = moduleResult.ExecuteResult
                CommandReturn.RecordValue = String.Empty
                CommandReturn.ExecuteResultTipString = moduleResult.ExecuteResultTipString
            End If

            Return CommandReturn
        End Function
    End Class
End Namespace