123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799 |
- using JsonRpcLite.Network;
- using JsonRpcLite.Rpc;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using Vinno.IUS.Common.Log;
- using Vinno.vCloud.Common.FIS.AfterSales;
- using Vinno.vCloud.Common.FIS.Consultation;
- using Vinno.vCloud.Common.FIS.Helper;
- using Vinno.vCloud.Common.FIS.LiveVideos;
- using Vinno.vCloud.Common.FIS.Notification;
- using Vinno.vCloud.Common.FIS.Remedicals;
- using Vinno.vCloud.Common.FIS.Upgraders;
- using Vinno.vCloud.FIS.CrossPlatform.Common;
- using Vinno.vCloud.FIS.CrossPlatform.Common.Enum;
- using Vinno.vCloud.FIS.CrossPlatform.Common.Helper;
- using Vinno.vCloud.FIS.CrossPlatform.Common.SQLite;
- using WingInterfaceLibrary.DTO.Device;
- using WingInterfaceLibrary.Enum;
- using WingInterfaceLibrary.Enum.NotificationEnum;
- using WingInterfaceLibrary.Interface;
- using WingInterfaceLibrary.LiveConsultation;
- using WingInterfaceLibrary.Notifications.Live;
- using WingInterfaceLibrary.Request;
- using WingInterfaceLibrary.Request.Device;
- using WingInterfaceLibrary.Request.Remote;
- using WingInterfaceLibrary.Request.User;
- namespace Vinno.vCloud.Common.FIS
- {
- internal class vCloudTerminalV2 : IvCloudTerminalV2
- {
- private readonly Dictionary<TerminalFeatureType, object> _features = new Dictionary<TerminalFeatureType, object>();
- private readonly ConnectionInfo _connectionInfo;
- private readonly string _deviceName;
- private readonly string _password;
- private readonly bool _isUserDefined;
- private readonly LoginSource _loginSource;
- private readonly Platform _platform;
- private readonly string _deviceType;
- private readonly string _url;
- private readonly int _usScreenWidth;
- private readonly int _usScreenHeight;
- private readonly bool _isUseHttps;
- private readonly int _connectionCheckCycle;
- private readonly bool _isUseOldTerminalSdk;
- private string _token;
- private string _prefix;
- private JsonRpcClient _client;
- private JsonRpcHttpClientEngine _clientEngine;
- private IConnectService _connectService;
- private ILiveConsultationService _liveConsultationService;
- private IVinnoServerService _vinnoServerService;
- private IDeviceService _deviceService;
- private IOrganizationService _organizationService;
- private TerminalStatus _status;
- private ConnectionCheckerV2 _connectionChecker;
- private HeartRateKeeperV2 _heartRateKeeper;
- private bool _disposed;
- private int _reconnectCounter;
- private FISWebSocket _webSocket;
- private CacheDeviceDTO _deviceInfo;
- /// <summary>
- /// Gets the global remedical working folder.
- /// </summary>
- internal static string WorkingFolder { get; private set; }
- /// <summary>
- /// Raised when the status is changed.
- /// </summary>
- public event EventHandler StatusChanged;
- /// <summary>
- /// Gets the unique id.
- /// </summary>
- public string UniqueId { get; private set; }
- /// <inheritdoc />
- /// <summary>
- /// Gets the status of the Terminal
- /// </summary>
- /// <remarks>
- /// </remarks>
- public TerminalStatus Status
- {
- get => _status;
- private set
- {
- if (_status != value)
- {
- _status = value;
- CommonParameter.Instance.DeviceStatus = (EnumDeviceStatus)_status;
- OnStatusChanged();
- }
- }
- }
- public bool IsSupportResearchMode
- {
- get
- {
- return Status == TerminalStatus.Logon && vCloudServerConfig.Instance.IsSupportResearchMode;
- }
- }
- public string DeviceCode => _deviceInfo?.DeviceCode;
- public string Url => _url;
- public bool UseSSL => _isUseHttps;
- public vCloudTerminalV2(ConnectionInfo connectionInfo, bool isUseHttps, bool isUseOldTerminalSdk)
- {
- _usScreenHeight = connectionInfo.USScreenHeight;
- _usScreenWidth = connectionInfo.USScreenWidth;
- _isUseOldTerminalSdk = isUseOldTerminalSdk;
- _isUseHttps = isUseHttps;
- _prefix = "http://";
- if (_isUseHttps)
- {
- _prefix = "https://";
- }
- _connectionInfo = connectionInfo;
- _deviceName = connectionInfo.Account.Name;
- _password = connectionInfo.Account.Password;
- _isUserDefined = connectionInfo.Account.IsUserDefined;
- _url = connectionInfo.ServerUrl;
- _loginSource = connectionInfo.LoginSource;
- _deviceType = connectionInfo.DeviceType;
- //Set the default value 10 seconds.
- _connectionCheckCycle = 10;
- _status = TerminalStatus.Offline;
- switch (CrossPlatformHelper.Instance.Platform)
- {
- case EnumPlatform.Windows:
- if (CommonParameter.Instance.IsSonopost)
- {
- WorkingFolder = connectionInfo.FISFolder;
- }
- else
- {
- if (Directory.Exists("D:"))
- {
- WorkingFolder = @"D:\FISRepository";
- }
- else
- {
- WorkingFolder = connectionInfo.FISFolder;
- }
- }
- break;
- case EnumPlatform.Linux:
- WorkingFolder = @"/userdata/FISRepository";
- break;
- default:
- WorkingFolder = connectionInfo.FISFolder;
- break;
- }
- DirectoryHelper.CreateDirectory(WorkingFolder);
- CreateJsonrpcClient();
- if (!_isUseOldTerminalSdk)
- {
- CreateConnectionKeeper();
- }
- }
- /// <inheritdoc />
- /// <summary>
- /// Get the feature instance by feature enum.
- /// </summary>
- /// <typeparam name="T">The interface of the feature</typeparam>
- /// <param name="featureType">The feature type</param>
- /// <returns>The instance of the feature</returns>
- /// <remarks>
- /// If the feature doesn't exist, this method will return null.
- /// </remarks>
- public T GetFeature<T>(TerminalFeatureType featureType) where T : IFeatureV2
- {
- if (_features.ContainsKey(featureType))
- {
- var feature = _features[featureType];
- if (feature is T t)
- {
- return t;
- }
- }
- return default(T);
- }
- /// <summary>
- /// Connect to server.
- /// </summary>
- internal void Connect(string uniqueId = "", string terminalId = "")
- {
- try
- {
- Logger.WriteLineError($"vCloudTerminalV2 connect begin {_deviceName} login url:{_prefix}{_url}");
- if (!_isUseOldTerminalSdk)
- {
- var connectRequest = new ConnectRequest
- {
- DeviceUniqueCode = CommonParameter.Instance.MachineId,
- Password = _isUserDefined ? _password : string.Empty,
- DeviceModel = _connectionInfo.DeviceMode,
- DeviceType = _deviceType.ToString(),
- SoftwareVersion = _connectionInfo.SoftwareVersion,
- SystemVersion = _connectionInfo.USOS,
- CPUModel = _connectionInfo.USCPU,
- SystemLanguage = _connectionInfo.LanguageName,
- Description = "",
- Name = _deviceName,
- OrganizationCode = "",
- DepartmentCode = "",
- LoginSource = _connectionInfo.LoginSource,
- Platform = _connectionInfo.Platform,
- InstallVersion = CommonParameter.Instance.IsSonopost ? string.Empty : _connectionInfo.FISIMPLVersion?.ToString(),
- };
- ConnectResultInfo result = JsonRpcHelper.Connect(_connectService, connectRequest);
- if (result == null)
- {
- throw new InvalidDataException("vCloudTerminalV2 Connect Result is null");
- }
- else if (!result.IsSuccess)
- {
- if (result.ErrorCode == 2035)
- {
- Status = TerminalStatus.WrongAccount;
- }
- else if (result.ErrorCode == 2036)
- {
- Status = TerminalStatus.WrongPassword;
- }
- else
- {
- throw new InvalidDataException($"vCloudTerminalV2 Connect Fail,Error Code is {result.ErrorCode}");
- }
- }
- else
- {
- UniqueId = result.UniqueCode;
- _token = result.Token;
- HandleLoginResult();
- }
- }
- else
- {
- UniqueId = uniqueId;
- _deviceInfo = new CacheDeviceDTO
- {
- DeviceCode = terminalId
- };
- RemedicalSQLiteHelperV2.Instance.Initialize(WorkingFolder);
- ReleaseFeatures();
- UpdateFeatures(_connectionInfo.EnabledFeatures);
- Status = TerminalStatus.Logon;
- }
- }
- catch (Exception e)
- {
- Logger.WriteLineError($"vCloudTerminalV2 {_deviceName} login url:{_url} failed {e}");
- Status = TerminalStatus.LoginFailed;
- }
- }
- public void Disconnect()
- {
- var status = TerminalStatus.Logoff;
- try
- {
- var tokenRequest = new TokenRequest
- {
- Token = _token,
- };
- bool result = JsonRpcHelper.Disconnect(_connectService, tokenRequest);
- if (!result)
- {
- throw new Exception($"vCloudTerminalV2 Disconnect Result is fail");
- }
- else if (result)
- {
- Logger.WriteLineInfo($"vCloudTerminalV2 Disconnect Success");
- status = TerminalStatus.Logoff;
- }
- }
- catch (Exception e)
- {
- Logger.WriteLineError($"Disconnect terminal {_deviceName} error {e}");
- }
- finally
- {
- Release();
- Status = status;
- }
- }
- /// <summary>
- /// Update enabled feature types.
- /// </summary>
- /// <param name="enabledFeatureTypes">The enabled feature types.</param>
- public void UpdateFeatures(IEnumerable<TerminalFeatureType> enabledFeatureTypes)
- {
- CommonParameter.Instance.IsFeatureReleased = false;
- var removedFeatures = _features.Keys.Where(f => !enabledFeatureTypes.Contains(f)).ToList();
- foreach (var feature in removedFeatures)
- {
- var disposable = _features[feature] as IDisposable;
- disposable?.Dispose();
- _features.Remove(feature);
- }
- foreach (var enabledFeature in enabledFeatureTypes)
- {
- if (!_features.ContainsKey(enabledFeature))
- {
- var feature = GetFeature(enabledFeature);
- _features.Add(enabledFeature, feature);
- }
- }
- }
- /// <summary>
- /// Get Device Info
- /// </summary>
- /// <returns></returns>
- public void GetDeviceByToken()
- {
- var tokenRequest = new TokenRequest
- {
- Token = _token,
- };
- var cacheDeviceDTO = JsonRpcHelper.GetDeviceByToken(_connectService, tokenRequest);
- if (cacheDeviceDTO == null)
- {
- throw new InvalidOperationException("vCloudTerminalV2 GetDeviceByToken Result is null");
- }
- else
- {
- _deviceInfo = cacheDeviceDTO;
- }
- }
- /// <summary>
- /// Set Device Is Encrypted Show
- /// </summary>
- /// <param name="isEncryptedShow"></param>
- /// <returns></returns>
- public bool SetIsEncryptedShow(bool isEncryptedShow)
- {
- try
- {
- var setDeviceIsEncryptedShowRequest = new SetDeviceIsEncryptedShowRequest
- {
- IsEncryptedShow = isEncryptedShow,
- Token = _token
- };
- bool result = JsonRpcHelper.SetDeviceIsEncryptedShow(_connectService, setDeviceIsEncryptedShowRequest);
- if (!result)
- {
- throw new Exception($"vCloudTerminalV2 SetDeviceIsEncryptedShowAsync Result is false");
- }
- else
- {
- return true; ;
- }
- }
- catch (Exception ex)
- {
- Logger.WriteLineError($"vCloudTerminalV2 SetDeviceIsEncryptedShow Error:{ex}");
- return false;
- }
- }
- public void Dispose()
- {
- if (!_disposed)
- {
- Release();
- _disposed = true;
- }
- GC.SuppressFinalize(this);
- }
- private void HandleLoginResult()
- {
- Status = TerminalStatus.Logoning;
- var tokenRequest = new TokenRequest
- {
- Token = _token
- };
- var result = JsonRpcHelper.QueryServerConfig(_deviceService, tokenRequest);
- if (result == null)
- {
- throw new InvalidDataException($"vCloudTerminalV2 QueryServerConfig Result is null");
- }
- else
- {
- vCloudServerConfig.Instance.IsUploadThumbnail = result.IsUploadThumbnail;
- vCloudServerConfig.Instance.PatientType = result.PatientType;
- vCloudServerConfig.Instance.HeartRateSeconds = result.HeartRateSeconds;
- vCloudServerConfig.Instance.NotificationUrl = result.NotificationUrl;
- vCloudServerConfig.Instance.MergedChannel = result.MergedChannel;
- vCloudServerConfig.Instance.LiveConsultationRateSeconds = result.LiveConsultationRateSeconds;
- vCloudServerConfig.Instance.MergedVideoOutputHeight = result.MergedVideoOutputHeight;
- vCloudServerConfig.Instance.MergedVideoOutputWidth = result.MergedVideoOutputWidth;
- vCloudServerConfig.Instance.IsSelfRtcService = result.IsSelfRtcService;
- vCloudServerConfig.Instance.RemoteControlHeartRateSeconds = result.RemoteControlHeartRateSeconds;
- vCloudServerConfig.Instance.LiveProtocol = result.LiveProtocol;
- vCloudServerConfig.Instance.LiveProtocolType = result.LiveProtocolType;
- vCloudServerConfig.Instance.FISWebUrl = result.FISWebUrl;
- vCloudServerConfig.Instance.IsSupportResearchMode = result.IsResearchEditionService;
- Logger.WriteLineInfo($"vCloudServerConfig:{vCloudServerConfig.Instance}");
- if (result.ServerConfigList != null)
- {
- foreach (var kp in result.ServerConfigList)
- {
- Logger.WriteLineInfo($"ServerConfigList Key:{kp.Key},Value:{kp.Value} ");
- }
- }
- }
- GetDeviceByToken();
- if (_deviceInfo == null)
- {
- throw new ArgumentNullException($"GetDeviceByToken Failed,Result is null");
- }
- if (_deviceInfo.IsEncryptedShow)
- {
- Logger.WriteLineInfo("Start SetIsEncryptedShow False");
- SetIsEncryptedShow(false);
- _deviceInfo.IsEncryptedShow = false;
- Logger.WriteLineInfo("SetIsEncryptedShow False Finish");
- }
- CreateHeartRateKeeper();
- CreateWebSocket();
- RemedicalSQLiteHelperV2.Instance.Initialize(WorkingFolder);
- ReleaseFeatures();
- UpdateFeatures(_connectionInfo.EnabledFeatures);
- _reconnectCounter = 0;
- Status = TerminalStatus.Logon;
- Logger.WriteLineInfo($"{_deviceName} Login url:{_url} successed, Token:{_token}, UniqueId:{UniqueId}");
- }
- private void CreateWebSocket()
- {
- if (string.IsNullOrWhiteSpace(vCloudServerConfig.Instance.NotificationUrl))
- {
- Logger.WriteLineError($"CreateWebSocket Error Because The Notificaion Url is null");
- return;
- }
- if (_webSocket == null)
- {
- var uri = vCloudServerConfig.Instance.NotificationUrl.Replace("{0}", _token);
- uri = uri.Replace("{1}", "0");
- Logger.WriteLineInfo($"Websocket uri :{uri}");
- _webSocket = new FISWebSocket(uri);
- _webSocket.NotificationReceived += OnNoitificationReceived;
- _webSocket.Connect();
- }
- }
- private void DisposeWebSocket()
- {
- try
- {
- if (_webSocket != null)
- {
- _webSocket.NotificationReceived -= OnNoitificationReceived;
- _webSocket.Dispose();
- _webSocket = null;
- }
- }
- catch (Exception ex)
- {
- Logger.WriteLineError($"VCloudTerminalV2 Dispose WebSocket Error:{ex}");
- }
- }
- private void OnNoitificationReceived(object sender, NotificationArgs e)
- {
- switch (e.NotificationType)
- {
- case NotificationTypeEnum.ConnectionNotification:
- Logger.WriteLineInfo($"VCloudTerminalV2 ConnectionNotification Receive");
- break;
- case NotificationTypeEnum.DisconnectNotification:
- Logger.WriteLineInfo($"VCloudTerminalV2 DisconnectNotification Receive");
- break;
- case NotificationTypeEnum.ConnectStatusToDeviceNotification:
- try
- {
- if (e.Params is ConnectStatusToDeviceNotification connectStatusToDeviceNotification)
- {
- HandleConnectStatusToDeviceNotification(connectStatusToDeviceNotification);
- }
- }
- catch (Exception ex)
- {
- Logger.WriteLineError($"AfterSalesV2 Handle ConnectStatusToDeviceNotification Error:{ex}");
- }
- break;
- }
- }
- private void HandleConnectStatusToDeviceNotification(ConnectStatusToDeviceNotification connectStatusToDeviceNotification)
- {
- if (connectStatusToDeviceNotification.ControlType == ControlDeviceParameterEnum.Start)
- {
- Logger.WriteLineInfo($"VCloudTerminalV2 ConnectStatusToDeviceNotification StartControl Receive");
- var isConsultationLiveService = connectStatusToDeviceNotification.TransactionType == TransactionTypeEnum.Consultion;
- var afterSales = GetFeature<IAfterSalesV2>(TerminalFeatureType.AfterSales);
- if (afterSales != null)
- {
- bool result;
- var controlDeviceResponseRequest = new ControlDeviceResponseRequest
- {
- ControlType = ControlDeviceParameterEnum.Start,
- UserCode = connectStatusToDeviceNotification.ControlUserCode,
- UserName = connectStatusToDeviceNotification.ControlUserName,
- Token = _token,
- LoginSource = connectStatusToDeviceNotification.LoginSource,
- };
- if (isConsultationLiveService)
- {
- result = JsonRpcHelper.AcceptRemoteConnnectionInLiveConsultationService(_liveConsultationService, controlDeviceResponseRequest);
- }
- else
- {
- result = JsonRpcHelper.AcceptRemoteConnnectionInDeviceService(_deviceService, controlDeviceResponseRequest);
- }
- if (result)
- {
- afterSales.UpdateAfterSalesInfo(connectStatusToDeviceNotification.ControlUserCode, connectStatusToDeviceNotification.ControlUserName, connectStatusToDeviceNotification.LoginSource);
- }
- }
- else
- {
- var controlDeviceResponseRequest = new ControlDeviceResponseRequest
- {
- ControlType = ControlDeviceParameterEnum.RejectConnect,
- UserCode = connectStatusToDeviceNotification.ControlUserCode,
- UserName = connectStatusToDeviceNotification.ControlUserName,
- Token = _token,
- LoginSource = connectStatusToDeviceNotification.LoginSource,
- };
- bool result;
- if (isConsultationLiveService)
- {
- result = JsonRpcHelper.AcceptRemoteConnnectionInLiveConsultationService(_liveConsultationService, controlDeviceResponseRequest);
- }
- else
- {
- result = JsonRpcHelper.AcceptRemoteConnnectionInDeviceService(_deviceService, controlDeviceResponseRequest);
- }
- if (result)
- {
- Logger.WriteLineInfo($"VCloudTerminalV2 RejectRemoteControl Success");
- }
- else
- {
- Logger.WriteLineError($"VCloudTerminalV2 RejectRemoteControl Failed");
- }
- }
- }
- }
- private void CreateHeartRateKeeper()
- {
- if (_heartRateKeeper == null)
- {
- _heartRateKeeper = new HeartRateKeeperV2(_deviceService, _token, vCloudServerConfig.Instance.HeartRateSeconds);
- _heartRateKeeper.Start();
- }
- }
- private void DisposeHeartRateKeeper()
- {
- try
- {
- if (_heartRateKeeper != null)
- {
- _heartRateKeeper.Stop();
- _heartRateKeeper = null;
- }
- }
- catch (Exception ex)
- {
- Logger.WriteLineError($"vCloudTerminalV2 DisposeHeartRateKeeper Error:{ex}");
- }
- }
- private void OnStatusChanged()
- {
- Logger.WriteLineInfo($"VCloudTerminalV2 Status Changed:{_status}");
- StatusChanged?.Invoke(this, EventArgs.Empty);
- }
- private void CreateConnectionKeeper()
- {
- _connectionChecker = new ConnectionCheckerV2(_vinnoServerService, _connectionCheckCycle);
- var defaultStatus = false;
- if (!_connectionChecker.Check(false))
- {
- Status = TerminalStatus.Offline;
- }
- else
- {
- Status = TerminalStatus.Online;
- defaultStatus = true;
- }
- if (_connectionChecker != null)//当网络异常或者Server无法访问时,_connectionChecker.Check()一般会消耗十几秒,此时用户可能已经修改服务器地址,并重新登录,此时_connectionChecker已经被Dispose
- {
- _connectionChecker.Offlined += OnOfflined;
- _connectionChecker.Start(defaultStatus);
- }
- }
- private void DisposeConnectionKeeper()
- {
- try
- {
- if (_connectionChecker != null)
- {
- _connectionChecker.Offlined -= OnOfflined;
- _connectionChecker.Stop();
- _connectionChecker = null;
- }
- }
- catch (Exception ex)
- {
- Logger.WriteLineError($"VCloudTerminalV2 Dispose WebSocket Error:{ex}");
- }
- }
- private void OnOfflined(object sender, EventArgs e)
- {
- Release();
- Status = TerminalStatus.Offline;
- //No need to reconnect after instance release
- if (_disposed) return;
- //Reconnect
- if (_reconnectCounter < 5)
- {
- if (!string.IsNullOrEmpty(_deviceName) && !string.IsNullOrEmpty(_password))
- {
- CreateJsonrpcClient();
- CreateConnectionKeeper();
- if (Status == TerminalStatus.Online)
- {
- Status = TerminalStatus.Reconnecting;
- Connect();
- _reconnectCounter++;
- }
- }
- }
- else
- {
- Dispose();
- }
- }
- private void Release()
- {
- DisposeConnectionKeeper();
- DisposeHeartRateKeeper();
- DisposeWebSocket();
- ReleaseFeatures();
- ReleaseJsonrpcClient();
- }
- private void CreateJsonrpcClient()
- {
- try
- {
- _client = new JsonRpcClient();
- _clientEngine = new JsonRpcHttpClientEngine($"{_prefix}{_url}");
- _client.UseEngine(_clientEngine);
- _connectService = _client.CreateProxy<IConnectService>(8000);
- _vinnoServerService = _client.CreateProxy<IVinnoServerService>(6000);
- _deviceService = _client.CreateProxy<IDeviceService>();
- _liveConsultationService = _client.CreateProxy<ILiveConsultationService>();
- _organizationService = _client.CreateProxy<IOrganizationService>();
- }
- catch (Exception ex)
- {
- Logger.WriteLineError($"VCloudTerminalV2 CreateJsonrpcClient Error:{ex}");
- }
- }
- private void ReleaseJsonrpcClient()
- {
- try
- {
- if (_client != null)
- {
- _client.Dispose();
- _client = null;
- _clientEngine = null;
- _connectService = null;
- _vinnoServerService = null;
- _deviceService = null;
- _liveConsultationService = null;
- }
- }
- catch (Exception ex)
- {
- Logger.WriteLineError($"VCloudTerminal V2 ReleaseJsonrpcClient Error:{ex}");
- }
- }
- private void ReleaseFeatures()
- {
- CommonParameter.Instance.IsFeatureReleased = true;
- foreach (var type in _features.Keys.ToList())
- {
- var feature = _features[type];
- var disposable = feature as IDisposable;
- disposable?.Dispose();
- _features.Remove(type);
- }
- }
- private IFeatureV2 GetFeature(TerminalFeatureType terminalFeatureType)
- {
- switch (terminalFeatureType)
- {
- case TerminalFeatureType.Remedical:
- return new RemedicalV2(_token, _client);
- case TerminalFeatureType.LiveVideo:
- return new LiveVideoV2(_token, UniqueId, _usScreenWidth, _usScreenHeight, _webSocket, _client, _connectionInfo.DeviceMode, _deviceType, _connectionInfo.SoftwareVersion);
- case TerminalFeatureType.AfterSales:
- return new AfterSalesV2(_token, _client, _webSocket, _deviceInfo, _deviceType);
- case TerminalFeatureType.Upgrade:
- return new UpgradersV2(_client);
- case TerminalFeatureType.Consultation:
- return new ConsultationV2(_client, _token, _deviceInfo);
- default:
- return null;
- }
- }
- public bool IsEncryptedShow()
- {
- if (_deviceInfo == null)
- {
- return false;
- }
- else
- {
- return _deviceInfo.IsEncryptedShow;
- }
- }
- /// <summary>
- /// get terminal Organization name after this must login successed
- /// </summary>
- /// <returns></returns>
- public string GetOrganizationName()
- {
- try
- {
- if (_deviceInfo == null)
- {
- return null;
- }
- var getOrganizationByCodeRequest = new GetOrganizationByCodeRequest
- {
- OrganizationCode = _deviceInfo.OrganizationCode,
- Token = _token,
- };
- var result = JsonRpcHelper.GetOrganizationByCode(_organizationService, getOrganizationByCodeRequest);
- if (result == null)
- {
- Logger.WriteLineError($"vCloudTerminalV2 GetOrganizationName Fail:result is null");
- return null;
- }
- else
- {
- return result.OrganizationName;
- }
- }
- catch (Exception ex)
- {
- Logger.WriteLineError($"vCloudTerminalV2 GetOrganizationName Error:{ex}");
- return null;
- }
- }
- }
- }
|