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

        Private ReadOnly _destVer As String


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

            If IsNumeric(command.Parameter(0)) Then

                _destVer = command.Parameter(0)
            Else
                _destVer = $"0"
            End If

            If IsNumeric(command.Parameter(1)) Then

                _destVer &= $".{command.Parameter(1)}"
            Else
                _destVer &= $".0"
            End If

            If IsNumeric(command.Parameter(2)) Then
                _destVer &= $".{command.Parameter(2)}"
            Else
                _destVer &= $".0"

            End If


            CommandReturn.LowerLimit = _destVer

            CommandReturn.UpperLimit = _destVer

            CommandReturn.RecordValue = Windows.Forms.Application.ProductVersion

            CommandReturn.ExecuteResultTipString = String.Empty

            CommandReturn.ExecuteResult = True
        End Sub

        Public Overrides Function Execute() As TestCommandReturn
            Dim appVer As Version = Version.Parse(CommandReturn.RecordValue)
            Dim cmdVer As New Version()

            If Version.TryParse(_destVer, cmdVer) Then
                If appVer < cmdVer Then
                    CommandReturn.ExecuteResult = False
                    CommandReturn.ExecuteResultTipString = $"应用程序版本 {appVer} 低于 指定版本 {_destVer}"
                Else
                    CommandReturn.ExecuteResult = True
                    CommandReturn.ExecuteResultTipString = $"版本校验成功"
                End If
            Else
                CommandReturn.ExecuteResult = False
                CommandReturn.ExecuteResultTipString = $"非法的字符串：{_destVer}"
            End If

            Return CommandReturn
        End Function

    End Class
End Namespace