123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- using Vinno.IUS.Common.Log;
- using Vinno.IUS.Common.Network.Leaf;
- using Vinno.IUS.Common.Network.Tcp;
- using Vinno.IUS.Common.Network.Transfer;
- using Vinno.vCloud.Protocol.Messages.Terminal;
- namespace Vinno.vCloud.Common.FIS.Test
- {
- public class VCloudServerConnectionTest : VCloudTestItem
- {
- private readonly string _vCloudServerConnectionTestError1 = "vCloudServerConnectionTestError1";
- private readonly string _vCloudServerConnectionTestError2 = "vCloudServerConnectionTestError2";
- private readonly string _currentUsVersion;
- private string _requriedUsVersion;
- public ClientLeaf Leaf { get; private set; }
- public VCloudServerConnectionTest(VCloudServiceTest vCloudServiceTest, string currentUsVersion) : base("vCloudServerConnection", vCloudServiceTest)
- {
- _currentUsVersion = currentUsVersion;
- }
- public override VCloudServiceTestResult Execute()
- {
- //Check it can conncect to vCloud server
- var result = TimeoutExecute(CheckvCloudServerConnected);
- if (result == VCloudSubItemTestStatus.Timeout)
- {
- return new VCloudServiceTestResult(Id, VCloudTestItemStatus.TestFailed, TimeoutError, "(001)");//ErrorCode=001
- }
- if (result == VCloudSubItemTestStatus.Failed)
- {
- return new VCloudServiceTestResult(Id, VCloudTestItemStatus.TestFailed, _vCloudServerConnectionTestError1, VCloudServiceTest.VCloudPort);
- }
- //Check current ultrasoic
- result = TimeoutExecute(CheckCurrentUsMachineVersion);
- if (result != VCloudSubItemTestStatus.Successful)
- {
- return new VCloudServiceTestResult(Id, VCloudTestItemStatus.TestFailed, _vCloudServerConnectionTestError2, _requriedUsVersion);
- }
- return new VCloudServiceTestResult(Id, VCloudTestItemStatus.TestDone);
- }
- private VCloudSubItemTestStatus CheckCurrentUsMachineVersion()
- {
- if (string.IsNullOrWhiteSpace(_requriedUsVersion))
- {
- Logger.WriteLineError($"required US software version is empty");
- }
- if (string.IsNullOrWhiteSpace(_currentUsVersion))
- {
- Logger.WriteLineError($"Current US software version is empty");
- return VCloudSubItemTestStatus.Failed;
- }
- var minVersions = _requriedUsVersion.Split('.');
- var usVersions = _currentUsVersion.Split('.');
- if (minVersions.Length >= usVersions.Length)
- {
- for (int i = 0; i < minVersions.Length; i++)
- {
- int usVersion = 0;
- int minVersion = 0;
- if (usVersions.Length - 1 < i)
- {
- usVersion = 0;
- }
- else
- {
- int.TryParse(usVersions[i], out usVersion);
- }
- int.TryParse(minVersions[i], out minVersion);
- if (usVersion > minVersion)
- {
- return VCloudSubItemTestStatus.Successful;
- }
- else if (usVersion < minVersion)
- {
- return VCloudSubItemTestStatus.Failed;
- }
- }
- return VCloudSubItemTestStatus.Successful;
- }
- else
- {
- for (int i = 0; i < usVersions.Length; i++)
- {
- int usVersion = 0;
- int minVersion = 0;
- if (minVersions.Length - 1 < i)
- {
- minVersion = 0;
- }
- else
- {
- int.TryParse(minVersions[i], out minVersion);
- }
- int.TryParse(usVersions[i], out usVersion);
- if (usVersion > minVersion)
- {
- return VCloudSubItemTestStatus.Successful;
- }
- else if (usVersion < minVersion)
- {
- return VCloudSubItemTestStatus.Failed;
- }
- }
- return VCloudSubItemTestStatus.Successful;
- }
- }
- private VCloudSubItemTestStatus CheckvCloudServerConnected()
- {
- _requriedUsVersion = string.Empty;
- int port = VCloudServiceTest.VCloudPort;
- var serverAddress = VCloudServiceTest.VCloudHost;
- Leaf = new ClientLeaf(new LeafIdContext(), LeafMode.Dual, new TcpCreator(serverAddress, port));
- if (!Leaf.Online)
- {
- Leaf.Close();
- return VCloudSubItemTestStatus.Failed;
- }
- using (var request = MessagePool.GetMessage<TerminalConnectionTestRequest>())
- {
- request.TerminalName = VCloudServiceTest.TerminalName;
- var result = Leaf.Send(request);
- if (result == null)
- {
- return VCloudSubItemTestStatus.Failed;
- }
- var testResult = TerminalConnectionTestResult.Convert(result);
- if (testResult == null)
- {
- return VCloudSubItemTestStatus.Failed;
- }
- _requriedUsVersion = testResult.RequriedUsVersion;
- }
- Logger.WriteLineInfo($"vCloudServiceTest - Required US version is {_requriedUsVersion}");
- return VCloudSubItemTestStatus.Successful;
- }
- public void Close()
- {
- Leaf?.Close();
- Leaf = null;
- }
- }
- }
|