1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- using System;
- using System.Threading;
- using System.Threading.Tasks;
- using Vinno.IUS.Common.Log;
- using Vinno.vCloud.Common.FIS.Helper;
- using WingInterfaceLibrary.Enum;
- using WingInterfaceLibrary.Interface;
- using WingInterfaceLibrary.Request.Remote;
- namespace Vinno.vCloud.Common.FIS.AfterSales
- {
- internal class AfterSalesHeartRateKeeperV2
- {
- private readonly IDeviceService _deviceService;
- private readonly string _token;
- private readonly int _heartRate;
- private readonly ManualResetEvent _waitEvent = new ManualResetEvent(false);
- public AfterSalesHeartRateKeeperV2(IDeviceService deviceService, string token, int heartRate = 5)
- {
- _deviceService = deviceService;
- _heartRate = heartRate;
- _token = token;
- }
- /// <summary>
- /// Start the Heartrate to keep the session available.
- /// </summary>
- public void Start()
- {
- DoHeartRate();
- }
- /// <summary>
- /// Stop the Heartrate
- /// </summary>
- public void Stop()
- {
- _waitEvent.Set();
- }
- /// <summary>
- /// Do HartRate
- /// </summary>
- /// <returns></returns>
- private void DoHeartRate()
- {
- Task.Run(() =>
- {
- while (!_waitEvent.WaitOne(TimeSpan.FromSeconds(_heartRate)))
- {
- try
- {
- bool result = false;
- var remoteConnectHeartRateRequest = new RemoteConnectHeartRateRequest()
- {
- Token = _token,
- TransactionType = TransactionTypeEnum.AfterSales,
- };
- result = JsonRpcHelper.DeviceRemoteConnectHeartRate(_deviceService, remoteConnectHeartRateRequest);
- if (!result)
- {
- Logger.WriteLineError($"AfterSales HeartRateKeeperV2 error,The Result is False");
- }
- }
- catch (Exception ex)
- {
- Logger.WriteLineError($"AfterSales HeartRateKeeperV2 Do HeartRate Error:{ex}");
- }
- }
- });
- }
- }
- }
|