1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- using System;
- using Vinno.IUS.Common.Log;
- using Vinno.IUS.Common.Network.Leaf;
- using Vinno.IUS.Common.Network.Tcp;
- using Vinno.vCloud.Protocol.Infrastructures;
- using Vinno.vCloud.Protocol.Messages.Login;
- namespace Vinno.vCloud.Common.FIS.Test
- {
- public class vCloudTerminalTester
- {
- /// <summary>
- /// Test the connection by given parameters.
- /// </summary>
- /// <param name="host">The host of the server.</param>
- /// <param name="port">The port of the server.</param>
- /// <param name="account">The account of the terminal.</param>
- /// <param name="password">The password of the terminal.</param>
- /// <returns></returns>
- public static DeviceTestResult Test(string host, int port, string account, string password)
- {
- ClientLeaf leaf = null;
- try
- {
- var url = $"{host}:{port}";
- leaf = new ClientLeaf(new LeafIdContext(), LeafMode.Dual, new TcpCreator(url));
- if (!leaf.Online)
- {
- leaf.Close();
- leaf = null;
- return DeviceTestResult.CanNotConnect;
- }
- var request = new AuthenticateAccountRequest
- {
- Name = account,
- Password = password,
- Type = LoginType.Terminal
- };
- var result = leaf.Send(request, 5000);
- var authenticateAccountResult = AuthenticateAccountResult.Convert(result);
- if (authenticateAccountResult != null)
- {
- switch (authenticateAccountResult.Status)
- {
- case AuthenticateStatus.Success:
- return DeviceTestResult.Success;
- case AuthenticateStatus.WrongAccount:
- case AuthenticateStatus.WrongPassword:
- return DeviceTestResult.ErrorAccountOrPassword;
- }
- }
- }
- catch (Exception ex)
- {
- Logger.WriteLineError($"Terminal connection test error:{ex}");
- }
- finally
- {
- leaf?.Close();
- }
- return DeviceTestResult.CanNotConnect;
- }
- }
- }
|