VCloudClientsProxy.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  1. using System;
  2. using System.Collections.Concurrent;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading;
  8. using System.Threading.Tasks;
  9. using Vinno.IUS.Common;
  10. using Vinno.IUS.Common.Log;
  11. using Vinno.IUS.Common.Network.Transfer;
  12. using Vinno.vCloud.Client.Proxy.Interfaces;
  13. using Vinno.vCloud.Protocol.Infrastructures;
  14. using Vinno.vCloud.Protocol.Initializers;
  15. using Vinno.vCloud.Protocol.Messages.Client.Account;
  16. using Vinno.vCloud.Protocol.Messages.Client.Remedical.Reports;
  17. using Vinno.vCloud.Protocol.Messages.Client.Remedical.TerminalDatas;
  18. using Vinno.vCloud.Protocol.Messages.Client.Remedical.TerminialReords;
  19. using Vinno.vCloud.Protocol.Messages.Client.RemoteDiagnosis;
  20. using Vinno.vCloud.Protocol.Messages.Common;
  21. using Vinno.vCloud.Protocol.Messages.Live;
  22. using Vinno.vCloud.Protocol.Messages.Report;
  23. namespace Vinno.vCloud.Client.Proxy
  24. {
  25. public class VCloudClientsProxy
  26. {
  27. private DefaultLogEngine _logEngine;
  28. private ConcurrentDictionary<string, IFlyinsonoClient> _vCloudClients = new ConcurrentDictionary<string, IFlyinsonoClient>();
  29. private string _hostUrl;
  30. private static VCloudClientsProxy _instance;
  31. /// <summary>
  32. /// The unique instance of app manager
  33. /// </summary>
  34. public static VCloudClientsProxy Instance => _instance ?? (_instance = new VCloudClientsProxy());
  35. public event EventHandler<ConversationMemberNotification> MeetingMemberNotificationArrived;//成员改变通知
  36. public event EventHandler<HangupConversationMemberNotification> MeetingHangupNotificationArrived;//挂断通知
  37. public event EventHandler<RejectConversationNotification> MeetingRejectNotificationArrived;//对方拒绝通知
  38. public event EventHandler<AcceptConversationNotification> MeetingAcceptNotificationArrived;//发起者收到对方接受通知
  39. public event EventHandler<PendingTimeoutConversationNotification> MeetingPendingMemberTimeoutNotificationArrived;//应答超时通知
  40. private readonly ManualResetEvent _closeEvent = new ManualResetEvent(false);
  41. private readonly int _sessionCheckInterval = 30 * 60 * 1000;
  42. /// <summary>
  43. /// instance intialize
  44. /// </summary>
  45. public void Initialize(string hostUrl)
  46. {
  47. _hostUrl = hostUrl;
  48. ClientTagsInitializer.Initialize();
  49. var logPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "VCloudClientsProxyLogs");
  50. CommonParameters.DataFolder = logPath;
  51. _logEngine = new DefaultLogEngine();
  52. Logger.RegisterEngine(_logEngine);
  53. StartCheckSessions();
  54. }
  55. /// <summary>
  56. /// Login with specified wechat token, vCloud user name and password
  57. /// </summary>
  58. /// <param name="wechatToken"></param>
  59. /// <param name="userName"></param>
  60. /// <param name="password"></param>
  61. /// <returns></returns>
  62. public LoginStatus Login(string openId, string userName, string password)
  63. {
  64. Logger.WriteLineInfo($"VCloudClient Login openId:{openId} Name:{userName}");
  65. var client = CreateCloudClient(openId, _hostUrl);
  66. var result = client.LoginByOpenId(openId, userName, password);
  67. if (result == LoginStatus.Success)
  68. {
  69. _vCloudClients.AddOrUpdate(openId, client, (k, c) => client);
  70. }
  71. else
  72. {
  73. CloudClientDispose(client);
  74. }
  75. return result;
  76. }
  77. private VCloudClient CreateCloudClient(string openId, string hostUrl)
  78. {
  79. Logger.WriteLineInfo($"VCloudClient CreateCloudClient openId:{openId} hostUrl:{hostUrl}");
  80. var client = new VCloudClient(openId, hostUrl);
  81. client.MeetingMemberNotificationArrived += OnMeetingMemberNotificationArrived;
  82. client.MeetingHangupNotificationArrived += OnMeetingHangupNotificationArrived;
  83. client.RejectMeetingNotificationArrived += OnMeetingRejectNotificationArrived;
  84. client.AcceptMeetingNotificationArrived += OnMeetingAcceptNotificationArrived;
  85. client.ChatPendingMemberTimeoutNotificationArrived += OnMneetingPendingMemberTimeoutNotificationArrived;
  86. return client;
  87. }
  88. private void CloudClientDispose(VCloudClient vCloudClient)
  89. {
  90. vCloudClient.MeetingMemberNotificationArrived -= OnMeetingMemberNotificationArrived;
  91. vCloudClient.MeetingHangupNotificationArrived -= OnMeetingHangupNotificationArrived;
  92. vCloudClient.RejectMeetingNotificationArrived -= OnMeetingRejectNotificationArrived;
  93. vCloudClient.AcceptMeetingNotificationArrived -= OnMeetingAcceptNotificationArrived;
  94. vCloudClient.ChatPendingMemberTimeoutNotificationArrived -= OnMneetingPendingMemberTimeoutNotificationArrived;
  95. vCloudClient.Dispose();
  96. }
  97. private void OnMeetingAcceptNotificationArrived(object sender, AcceptMeetingNotification e)
  98. {
  99. if (sender is VCloudClient vCloudClient)
  100. {
  101. MeetingAcceptNotificationArrived?.Invoke(this, new AcceptConversationNotification
  102. {
  103. OpenId = vCloudClient.OpenId,
  104. AcceptMeetingNotification = e
  105. });
  106. }
  107. }
  108. private void OnMeetingRejectNotificationArrived(object sender, RejectMeetingNotification e)
  109. {
  110. if (sender is VCloudClient vCloudClient)
  111. {
  112. MeetingRejectNotificationArrived?.Invoke(this, new RejectConversationNotification
  113. {
  114. OpenId = vCloudClient.OpenId,
  115. RejectMeetingNotification = e
  116. });
  117. }
  118. }
  119. private void OnMeetingHangupNotificationArrived(object sender, MeetingHangupNotification e)
  120. {
  121. if (sender is VCloudClient vCloudClient)
  122. {
  123. MeetingHangupNotificationArrived?.Invoke(this, new HangupConversationMemberNotification
  124. {
  125. OpenId = vCloudClient.OpenId,
  126. MeetingHangupNotification = e
  127. });
  128. }
  129. }
  130. private void OnMeetingMemberNotificationArrived(object sender, MeetingMemberNotification e)
  131. {
  132. if (sender is VCloudClient vCloudClient)
  133. {
  134. MeetingMemberNotificationArrived?.Invoke(this, new ConversationMemberNotification
  135. {
  136. OpenId = vCloudClient.OpenId,
  137. MeetingMemberNotification = e
  138. });
  139. }
  140. }
  141. private void OnMneetingPendingMemberTimeoutNotificationArrived(object sender, ChatPendingMemberTimeoutNotification e)
  142. {
  143. if (sender is VCloudClient vCloudClient)
  144. {
  145. MeetingPendingMemberTimeoutNotificationArrived?.Invoke(this, new PendingTimeoutConversationNotification()
  146. {
  147. OpenId = vCloudClient.OpenId,
  148. Notification = e
  149. });
  150. }
  151. }
  152. /// <summary>
  153. /// 开始会诊
  154. /// </summary>
  155. /// <param name="openId"></param>
  156. /// <param name="roomId"></param>
  157. /// <param name="consultationId"></param>
  158. /// <returns></returns>
  159. public ConsultationResult StartConversation(string openId, string roomId, string consultationId)
  160. {
  161. Logger.WriteLineInfo($"VCloudClient StartConversation openId:{openId} roomId:{roomId} consultationId:{consultationId}");
  162. var vCloudClient = GetVCloudClient(openId);
  163. if (vCloudClient != null)
  164. {
  165. var consultationMessage = vCloudClient.FindConsultationById(consultationId);
  166. vCloudClient.ArrangeConsultation(new ArrangeAppointmentRequest()
  167. {
  168. Id = consultationId,
  169. AppointDate = DateTime.UtcNow,
  170. ExpertId = consultationMessage?.ExpertId
  171. });
  172. return vCloudClient.StartConversation(roomId, consultationId);
  173. }
  174. return null;
  175. }
  176. public LiveStates CancelStartConversation(string openId, string roomId)
  177. {
  178. Logger.WriteLineInfo($"VCloudClient CancelStartConversation openId:{openId} roomId:{roomId}");
  179. var vCloudClient = GetVCloudClient(openId);
  180. if (vCloudClient != null)
  181. {
  182. return vCloudClient.CancelStartConversation(roomId);
  183. }
  184. return LiveStates.UnknowException;
  185. }
  186. public LiveStates ExitConsultation(string openId, string roomId, bool forceClosed, string terminalId, string consultationId)
  187. {
  188. Logger.WriteLineInfo($"VCloudClient ExitConsultation openId:{openId} roomId:{roomId} consultationId:consultationId");
  189. var vCloudClient = GetVCloudClient(openId);
  190. if (vCloudClient != null)
  191. {
  192. return vCloudClient.ExitConsultation(roomId, forceClosed, terminalId, consultationId);
  193. }
  194. return LiveStates.UnknowException;
  195. }
  196. /// <summary>
  197. ///
  198. /// </summary>
  199. /// <param name="roomId"></param>
  200. /// <param name="initiatorId">发起者</param>
  201. /// <returns></returns>
  202. public LiveStates AcceptConsultation(string openId, string roomId, string initiatorId)
  203. {
  204. var vCloudClient = GetVCloudClient(openId);
  205. if (vCloudClient != null)
  206. {
  207. return vCloudClient.AcceptConsultation(roomId, FeatureSource.RemoteDiagnosis, LiveStates.OK, initiatorId);
  208. }
  209. return LiveStates.UnknowException;
  210. }
  211. public LiveStates RejectConsultation(string openId, string roomId, string initiatorId)
  212. {
  213. var vCloudClient = GetVCloudClient(openId);
  214. if (vCloudClient != null)
  215. {
  216. return vCloudClient.RejectConsultation(roomId, initiatorId);
  217. }
  218. return LiveStates.UnknowException;
  219. }
  220. public ConsultationResult InviteConsultationMember(string openId, string roomId, List<RecipientInfo> recipientInfos)
  221. {
  222. var vCloudClient = GetVCloudClient(openId);
  223. if (vCloudClient != null)
  224. {
  225. return vCloudClient.InviteConsultationMember(roomId, FeatureSource.RemoteDiagnosis, recipientInfos);
  226. }
  227. return new ConsultationResult(LiveStates.UnknowException);
  228. }
  229. /// <summary>
  230. /// 通过openId获取用户信息
  231. /// </summary>
  232. /// <param name="openId"></param>
  233. /// <returns></returns>
  234. public WechatUserInfo GetUserInfoByOpenId(string openId)
  235. {
  236. Logger.WriteLineInfo($"VCloudClient GetUserInfoByOpenId {openId}");
  237. _vCloudClients.TryGetValue(openId, out IFlyinsonoClient vCloudClient);
  238. if (vCloudClient != null)
  239. {
  240. var userInfo = vCloudClient.GetUserInfoByOpenId(openId);
  241. Logger.WriteLineInfo($"VCloudClient GetUserInfoByOpenId, client existed, openId:{openId}, name:{userInfo.UserId} {userInfo.NickName}");
  242. return userInfo;
  243. }
  244. var client = CreateCloudClient(openId, _hostUrl);
  245. var result = client.LoginByOpenId(openId);
  246. if (result == LoginStatus.Success)
  247. {
  248. _vCloudClients.AddOrUpdate(openId, client, (k, c) => client);
  249. var userInfo= client.GetUserInfoByOpenId(openId);
  250. Logger.WriteLineInfo($"VCloudClient GetUserInfoByOpenId, login success, openId:{openId}, name:{userInfo.UserId} {userInfo.NickName}");
  251. return userInfo;
  252. }
  253. else
  254. {
  255. Logger.WriteLineInfo($"VCloudClient GetUserInfoByOpenId, login failed, openId:{openId}");
  256. CloudClientDispose(client);
  257. }
  258. return null;
  259. }
  260. private IFlyinsonoClient GetVCloudClient(string openId)
  261. {
  262. Logger.WriteLineInfo($"VCloudClient GetVCloudClient openId:{openId}");
  263. _vCloudClients.TryGetValue(openId, out IFlyinsonoClient vCloudClient);
  264. if (vCloudClient != null)
  265. {
  266. vCloudClient.Activate();
  267. return vCloudClient;
  268. }
  269. else
  270. {
  271. var client = CreateCloudClient(openId, _hostUrl);
  272. var result = client.LoginByOpenId(openId);
  273. if (result == LoginStatus.Success)
  274. {
  275. _vCloudClients.AddOrUpdate(openId, client, (k, c) => client);
  276. return client;
  277. }
  278. else
  279. {
  280. CloudClientDispose(client);
  281. }
  282. }
  283. return null;
  284. }
  285. /// <summary>
  286. /// 获取会诊我的超声机
  287. /// </summary>
  288. /// <param name="openId"></param>
  289. /// <returns></returns>
  290. public List<TerminalInfo> GetMyTerminals(string openId)
  291. {
  292. var vCloudClient = GetVCloudClient(openId);
  293. if (vCloudClient != null)
  294. {
  295. return vCloudClient.GetMyTerminals();
  296. }
  297. return null;
  298. }
  299. /// <summary>
  300. /// 获取会诊我的医院
  301. /// </summary>
  302. /// <param name="openId"></param>
  303. /// <returns></returns>
  304. public List<OrganBaseInfoMessage> GetMyHospitals(string openId)
  305. {
  306. Logger.WriteLineInfo($"VCloudClient GetMyHospitals openId:{openId}");
  307. var vCloudClient = GetVCloudClient(openId);
  308. if (vCloudClient != null)
  309. {
  310. return vCloudClient.GetMyHospitals();
  311. }
  312. return null;
  313. }
  314. /// <summary>
  315. /// 查询会诊记录
  316. /// </summary>
  317. public FindNewAppointmentsResult6 FindConsultationRecords(string openId, int startIndex, int pageSize, AppointmentsFilterMessage filter)
  318. {
  319. Logger.WriteLineInfo($"VCloudClient FindConsultationRecords openId:{openId} startIndex:{startIndex} pageSize:{pageSize}");
  320. var vCloudClient = GetVCloudClient(openId);
  321. if (vCloudClient != null)
  322. {
  323. return vCloudClient.FindConsultationRecords(startIndex, pageSize, filter);
  324. }
  325. return null;
  326. }
  327. /// <summary>
  328. /// 创建会诊
  329. /// </summary>
  330. public string CreateConsultationRecord(string openId, CreateAppointmentRequest1 request)
  331. {
  332. Logger.WriteLineInfo($"VCloudClient CreateConsultationRecord openId:{openId}");
  333. var vCloudClient = GetVCloudClient(openId);
  334. if (vCloudClient != null)
  335. {
  336. return vCloudClient.CreateConsultationRecord(request);
  337. }
  338. return null;
  339. }
  340. /// <summary>
  341. /// 通过医院获取专家列表
  342. /// </summary>
  343. /// <param name=""></param>
  344. /// <returns></returns>
  345. public List<ExpertDetailMessage> FindMyExpertsByHospitalId(string openId, string hospitalId)
  346. {
  347. var vCloudClient = GetVCloudClient(openId);
  348. if (vCloudClient != null)
  349. {
  350. return vCloudClient.FindMyExpertsByHospitalId(hospitalId);
  351. }
  352. return null;
  353. }
  354. /// <summary>
  355. /// 获取检查部位
  356. /// </summary>
  357. /// <param name="openId"></param>
  358. /// <returns></returns>
  359. public List<string> GetCheckPoint(string openId)
  360. {
  361. var vCloudClient = GetVCloudClient(openId);
  362. if (vCloudClient != null)
  363. {
  364. return vCloudClient.GetCheckPoint();
  365. }
  366. return null;
  367. }
  368. /// <summary>
  369. ///通过远程记录Id查询图像
  370. /// </summary>
  371. /// <param name="request"></param>
  372. /// <returns></returns>
  373. public GetPatientRecordDatasSuccess9 GetPatientRecordImageById(string openId, GetPatientRecordDatasRequest11 request)
  374. {
  375. Logger.WriteLineInfo($"VCloudClient GetPatientRecordImageById openId:{openId}");
  376. var vCloudClient = GetVCloudClient(openId);
  377. if (vCloudClient != null)
  378. {
  379. return vCloudClient.GetPatientRecordImageById(request);
  380. }
  381. return null;
  382. }
  383. /// <summary>
  384. /// 通过记录Id获取报告
  385. /// </summary>
  386. /// <param name="request"></param>
  387. /// <returns></returns>
  388. public NewGetReportsSuccess5 GetReportByecordId(string openId, NewGetReportsRequest5 request)
  389. {
  390. Logger.WriteLineInfo($"VCloudClient GetReportByecordId openId:{openId}");
  391. var vCloudClient = GetVCloudClient(openId);
  392. if (vCloudClient != null)
  393. {
  394. return vCloudClient.GetReportByecordId(request);
  395. }
  396. return null;
  397. }
  398. /// <summary>
  399. /// 查询报告详情
  400. /// </summary>
  401. /// <param name="openId"></param>
  402. /// <param name="recordId"></param>
  403. /// <param name="reportId"></param>
  404. /// <returns></returns>
  405. public NewReportInfoMessage5 GetReportById(string openId, string recordId, string reportId)
  406. {
  407. Logger.WriteLineInfo($"VCloudClient GetReportById openId:{openId}");
  408. var vCloudClient = GetVCloudClient(openId);
  409. if (vCloudClient != null)
  410. {
  411. return vCloudClient.GetReportById(recordId, reportId);
  412. }
  413. return null;
  414. }
  415. /// <summary>
  416. /// 查询分时远程诊断记录
  417. /// </summary>
  418. /// <param name="request"></param>
  419. /// <returns></returns>
  420. public GetRecords11Success GetExamRecords(string openId, GetClientRecord11Request request)
  421. {
  422. Logger.WriteLineInfo($"VCloudClient GetExamRecords openId:{openId}");
  423. var vCloudClient = GetVCloudClient(openId);
  424. if (vCloudClient != null)
  425. {
  426. return vCloudClient.GetExamRecords(request);
  427. }
  428. return null;
  429. }
  430. /// <summary>
  431. /// Log out with specifed wechat token
  432. /// </summary>
  433. /// <param name="wechatToken"></param>
  434. /// <returns></returns>
  435. public bool Logout(string openId)
  436. {
  437. var result = _vCloudClients.TryRemove(openId, out var client);
  438. if (result && client != null)
  439. {
  440. client.Logout();
  441. CloudClientDispose(client as VCloudClient);
  442. return true;
  443. }
  444. return false;
  445. }
  446. /// <summary>
  447. /// 查询系统默认报告模板
  448. /// </summary>
  449. /// <param name="openId"></param>
  450. /// <param name="languageCode"></param>
  451. /// <returns></returns>
  452. public List<ReportTemplateMessage> GetReportTemplates(string openId, string languageCode)
  453. {
  454. var vCloudClient = GetVCloudClient(openId);
  455. if (vCloudClient != null)
  456. {
  457. return vCloudClient.GetReportTemplates(languageCode);
  458. }
  459. return new List<ReportTemplateMessage>();
  460. }
  461. /// <summary>
  462. /// 查询系统默认词条
  463. /// </summary>
  464. /// <param name="openId"></param>
  465. /// <param name="languageCode"></param>
  466. /// <returns></returns>
  467. public List<ReportTemplateMessage> GetThesaurusTemplates(string openId, string languageCode)
  468. {
  469. var vCloudClient = GetVCloudClient(openId);
  470. if (vCloudClient != null)
  471. {
  472. return vCloudClient.GetThesaurusTemplates(languageCode);
  473. }
  474. return new List<ReportTemplateMessage>();
  475. }
  476. /// <summary>
  477. /// 获取会诊信息
  478. /// </summary>
  479. /// <param name="id"></param>
  480. /// <returns></returns>
  481. public ConsultationMessage FindConsultationById(string openId, string id)
  482. {
  483. var vCloudClient = GetVCloudClient(openId);
  484. if (vCloudClient != null)
  485. {
  486. return vCloudClient.FindConsultationById(id);
  487. }
  488. return null;
  489. }
  490. /// <summary>
  491. /// 上传会诊状态
  492. /// </summary>
  493. /// <param name=""></param>
  494. /// <returns></returns>
  495. public bool UpdateRecordState(string openId, UpdateAppointmentStateRequest request)
  496. {
  497. var vCloudClient = GetVCloudClient(openId);
  498. if (vCloudClient != null)
  499. {
  500. return vCloudClient.UpdateRecordState(request);
  501. }
  502. return false;
  503. }
  504. /// <summary>
  505. /// 安排申请单
  506. /// </summary>
  507. /// <param name="request"></param>
  508. /// <returns></returns>
  509. public bool ArrangeConsultation(string openId, ArrangeAppointmentRequest request)
  510. {
  511. var vCloudClient = GetVCloudClient(openId);
  512. if (vCloudClient != null)
  513. {
  514. return vCloudClient.ArrangeConsultation(request);
  515. }
  516. return false;
  517. }
  518. /// <summary>
  519. /// 安排申请单
  520. /// </summary>
  521. /// <param name="request"></param>
  522. /// <returns></returns>
  523. public NewGetReportsSuccess5 GetConsultationReports(string openId, GetConsultationReportsRequest5 request)
  524. {
  525. var vCloudClient = GetVCloudClient(openId);
  526. if (vCloudClient != null)
  527. {
  528. return vCloudClient.GetConsultationReports(request);
  529. }
  530. return null;
  531. }
  532. /// <summary>
  533. /// 保存报告
  534. /// </summary>
  535. /// <param name="openId"></param>
  536. /// <param name="request"></param>
  537. /// <returns></returns>
  538. public string SaveReport(string openId, NewAddReportRequest4 request)
  539. {
  540. var vCloudClient = GetVCloudClient(openId);
  541. if (vCloudClient != null)
  542. {
  543. return vCloudClient.SaveReport(request);
  544. }
  545. return string.Empty;
  546. }
  547. /// <summary>
  548. /// Start a thread to check sessions intervally.
  549. /// </summary>
  550. private async void StartCheckSessions()
  551. {
  552. Logger.WriteLineInfo("SessionManager start check sessions.");
  553. await Task.Run(() =>
  554. {
  555. while (!_closeEvent.WaitOne(_sessionCheckInterval))
  556. {
  557. try
  558. {
  559. var removeSessionId = new List<string>();
  560. foreach (var session in _vCloudClients.Values)
  561. {
  562. session.DeActivate();
  563. if (session.LeftTime <= 0)
  564. {
  565. removeSessionId.Add(session.OpenId);
  566. }
  567. }
  568. foreach (var openId in removeSessionId)
  569. {
  570. _vCloudClients.TryRemove(openId, out IFlyinsonoClient vCloudClient);
  571. CloudClientDispose(vCloudClient as VCloudClient);
  572. }
  573. }
  574. catch (Exception ex)
  575. {
  576. Logger.WriteLineError($"CheckSessions error:{ex.Message}");
  577. }
  578. Logger.WriteLineVerbose("Sessions checked.");
  579. }
  580. });
  581. }
  582. /// <summary>
  583. /// 上传会诊截图
  584. /// </summary>
  585. /// <param name="consulationId"></param>
  586. /// <param name="imageToken"></param>
  587. /// <returns></returns>
  588. public bool UploadConsultationImages(string openId, string consulationId, string imageToken)
  589. {
  590. var vCloudClient = GetVCloudClient(openId);
  591. if (vCloudClient != null)
  592. {
  593. return vCloudClient.UploadConsultationImages(consulationId, imageToken);
  594. }
  595. return false;
  596. }
  597. /// <summary>
  598. /// 上传会诊视频
  599. /// </summary>
  600. /// <param name="consulationId"></param>
  601. /// <param name="imageToken"></param>
  602. /// <returns></returns>
  603. public bool UploadConsulationVideos(string openId, string consulationId, string videoToken, string previewToken)
  604. {
  605. var vCloudClient = GetVCloudClient(openId);
  606. if (vCloudClient != null)
  607. {
  608. return vCloudClient.UploadConsulationVideos(consulationId, videoToken, previewToken);
  609. }
  610. return false;
  611. }
  612. public string UploadFile(string openId, byte[] fileData)
  613. {
  614. var vCloudClient = GetVCloudClient(openId);
  615. if (vCloudClient != null)
  616. {
  617. return vCloudClient.UploadFile(fileData);
  618. }
  619. return null;
  620. }
  621. public byte[] DownloadFile(string openId, string fileToken)
  622. {
  623. var vCloudClient = GetVCloudClient(openId);
  624. if (vCloudClient != null)
  625. {
  626. return vCloudClient.DownloadFile(fileToken);
  627. }
  628. return null;
  629. }
  630. /// <summary>
  631. /// Stop the session check thread.
  632. /// </summary>
  633. public void StopCheckSessions()
  634. {
  635. _closeEvent.Set();
  636. }
  637. }
  638. }