1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- using JsonRpcLite.Network;
- using JsonRpcLite.Rpc;
- using System;
- using Vinno.IUS.Common.Log;
- using Vinno.vCloud.Common.FIS.Helper;
- using WingInterfaceLibrary.Interface;
- namespace Vinno.vCloud.Common.FIS.Test
- {
- public class VCloudServerConnectionTestV2 : VCloudTestItem
- {
- private readonly string _vCloudServerConnectionTestError1 = "vCloudServerConnectionTestError1";
- private readonly string _vCloudServerConnectionTestError2 = "vCloudServerConnectionTestError2";
- private readonly string _prefix;
- private JsonRpcHttpClientEngine _clientEngine;
- private IVinnoServerService _vinnoServerService;
- public JsonRpcClient Client { get; private set; }
- public VCloudServerConnectionTestV2(VCloudServiceTest vCloudServiceTest, bool isUseHttps) : base("vCloudServerConnection", vCloudServiceTest)
- {
- _prefix = "http://";
- if (isUseHttps)
- {
- _prefix = "https://";
- }
- }
- 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);
- }
- return new VCloudServiceTestResult(Id, VCloudTestItemStatus.TestDone);
- }
- private VCloudSubItemTestStatus CheckvCloudServerConnected()
- {
- try
- {
- Client = new JsonRpcClient();
- _clientEngine = new JsonRpcHttpClientEngine($"{_prefix}{VCloudServiceTest.VCloudHost}:{VCloudServiceTest.VCloudPort}");
- Client.UseEngine(_clientEngine);
- _vinnoServerService = Client.CreateProxy<IVinnoServerService>(6000);
- var result = JsonRpcHelper.Echo(_vinnoServerService);
- if (result == null || result.Code != 0)
- {
- return VCloudSubItemTestStatus.Failed;
- }
- else
- {
- return VCloudSubItemTestStatus.Successful;
- }
- }
- catch (Exception ex)
- {
- Logger.WriteLineInfo($"vCloudServiceTest - CheckvCloudServerConnected Error :{ex}");
- return VCloudSubItemTestStatus.Failed;
- }
- }
- public void Close()
- {
- if (Client != null)
- {
- Client.Dispose();
- Client = null;
- _clientEngine = null;
- _vinnoServerService = null;
- }
- }
- }
- }
|