AutoEFDiagnosisService.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. using AI.Common;
  2. using AI.Common.Log;
  3. using AIDiagnosis.Common.Enums;
  4. using AIDiagnosis.Common.Models;
  5. using AutoEFDiagnosisSDK.Enums;
  6. using AutoEFInferenceCalcLib;
  7. using System;
  8. using System.Collections.Concurrent;
  9. using System.Collections.Generic;
  10. using System.IO;
  11. using System.Linq;
  12. using System.Threading;
  13. using Vinno.AI.AutoEFDiagnosisSDK.Enums;
  14. using Vinno.AI.AutoEFDiagnosisSDK.Interfaces;
  15. using Vinno.AI.AutoEFDiagnosisSDK.Models;
  16. using Vinno.AI.AutoEFDiagnosisService.Tools;
  17. using Vinno.AI.CommonSDK.Enums;
  18. using Vinno.AI.CommonSDK.Models;
  19. using Vinno.AI.CommonSDK.Tools;
  20. using Vinno.AI.Service.Common.Interfaces;
  21. using Vinno.AI.Service.Common.Models;
  22. using Vinno.AI.Service.Common.Tools;
  23. using AutoEFDiagnosis = AutoEFDiagnosisSDK.AutoEFDiagnosis;
  24. namespace Vinno.AI.AutoEFDiagnosisService
  25. {
  26. public class AutoEFDiagnosisService : IAutoEFDiagnosisService, IDisposable, IEngine
  27. {
  28. private readonly string _modelFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Networks");
  29. private readonly ConcurrentStack<byte[]> _singleImageCache;
  30. private PipeServer _singleImagePipeServer;
  31. private ImageProvider _imageProvider;
  32. private AutoEFDiagnosis _autoEFDiagnosis;
  33. private bool _disposed;
  34. public static List<FunctionInfo> AllFunctions { get; }
  35. static AutoEFDiagnosisService()
  36. {
  37. AllFunctions = AutoEFDiagnosis.AllFunctions;
  38. }
  39. public static void Init(FunctionInfo enableFunction, FunctionInfo currentUsedFunction)
  40. {
  41. AutoEFDiagnosis.Init(enableFunction, currentUsedFunction);
  42. }
  43. public AutoEFDiagnosisService()
  44. {
  45. try
  46. {
  47. _singleImageCache = new ConcurrentStack<byte[]>();
  48. _singleImagePipeServer = new PipeServer(AIDiagnosisSystemConsts.PipeForAutoEFDiagnosisSingleImage);
  49. _singleImagePipeServer.LogMsgThrow += OnLogMsgThrow;
  50. _singleImagePipeServer.DataReceived += OnDataReceived;
  51. _singleImagePipeServer.StartAndReceive();
  52. _imageProvider = new ImageProvider(AIEnumType.AutoEFDiagnosis);
  53. }
  54. catch (Exception ex)
  55. {
  56. Logger.Error($"AutoEFDiagnosisService-Constructor error:{ex}");
  57. }
  58. }
  59. /// <summary>
  60. /// 切换引擎
  61. /// </summary>
  62. /// <param name="functionInfo"></param>
  63. public void SwitchEngines(FunctionInfo functionInfo)
  64. {
  65. try
  66. {
  67. AutoEFDiagnosis.SwitchAIEngines(functionInfo);
  68. if (_autoEFDiagnosis != null)
  69. {
  70. _autoEFDiagnosis.SwitchAIEngines2(functionInfo);
  71. }
  72. }
  73. catch (Exception ex)
  74. {
  75. Logger.Error($"AutoEFDiagnosisService-SwitchEngines error:{ex}");
  76. }
  77. }
  78. public void Initialize(AutoEFDiagnosisParameter autoEFDiagnosisParameter, bool hasImageProvider)
  79. {
  80. try
  81. {
  82. CloseDiagnosis();
  83. var cpuNumber = autoEFDiagnosisParameter.CPUNumber;
  84. var layerCount = autoEFDiagnosisParameter.LayerCount;
  85. var edcontrolLayersCount = autoEFDiagnosisParameter.EdcontrolLayersCount;
  86. var escontrolLayersCount = autoEFDiagnosisParameter.EscontrolLayersCount;
  87. var isReturnEveryImgResult = autoEFDiagnosisParameter.IsReturnEveryImgResult;
  88. var detectMode = (EnumDetectMode)autoEFDiagnosisParameter.DetectMode;
  89. var detectTps = autoEFDiagnosisParameter.DetectTps;
  90. var intervalTime = autoEFDiagnosisParameter.IntervalTime;
  91. var cmPerPixel = autoEFDiagnosisParameter.CmPerPixel;
  92. EnumAutoEFDiagnosisType diagnosisType = autoEFDiagnosisParameter.AutoEFDiagnosisType == AIEnumAutoEFDiagnosisType.HumanAutoEFDiagnosis ? EnumAutoEFDiagnosisType.HumanAutoEFDiagnosis : EnumAutoEFDiagnosisType.VetAutoEFDiagnosis;
  93. _autoEFDiagnosis = new AutoEFDiagnosis(cpuNumber, _modelFolder, Setting.Instance.IsSaveDetectImage, Setting.Instance.IsSaveAllImage, Logger.LogDir, layerCount, escontrolLayersCount, edcontrolLayersCount, isReturnEveryImgResult, diagnosisType, hasImageProvider ? _imageProvider : null, cmPerPixel, detectMode, detectTps, intervalTime);
  94. _autoEFDiagnosis.StartEvaluation += OnStartEvaluation;
  95. _autoEFDiagnosis.FinishEvaluation += OnFinishEvaluation;
  96. _autoEFDiagnosis.NotifyError += OnNotifyError;
  97. _autoEFDiagnosis.NotifyLog += OnNotifyLog;
  98. }
  99. catch (Exception ex)
  100. {
  101. Logger.Error($"AutoEFDiagnosisService-Initialize error:{ex}");
  102. }
  103. }
  104. #region 兽用
  105. /// <summary>
  106. /// 启用AutoEF
  107. /// </summary>
  108. /// <param name="totalFrameCount">整个视频帧数</param>
  109. /// <param name="cmPerPixel">探头中像素与实际单位转换的参数</param>
  110. public void StartAutotEFCalculationForVet(long totalFrameCount, double cmPerPixel)
  111. {
  112. try
  113. {
  114. if (_autoEFDiagnosis == null)
  115. {
  116. Logger.Error($"StartAutotEF Error:AutoEF Diagnosis is null");
  117. return;
  118. }
  119. _autoEFDiagnosis.StartAutotEFCalculation(totalFrameCount, cmPerPixel);
  120. }
  121. catch (Exception ex)
  122. {
  123. Logger.Error($"AutoEFDiagnosisService-StartAutotEFCalculationForVet error:{ex}");
  124. }
  125. }
  126. /// <summary>
  127. /// 推入一张裸图并返回AutoEF结果
  128. /// </summary>
  129. /// <param name="frameTime"></param>
  130. /// <returns></returns>
  131. public void DetectOneRawImageForAutoEFCalculationForVet(int height, int width, AIEnumColorType colorType, double frameTime)
  132. {
  133. try
  134. {
  135. byte[] byteImage = null;
  136. int retryCount = 0;
  137. while (!_singleImageCache.TryPop(out byteImage) && retryCount < 50)
  138. {
  139. Thread.Sleep(10);
  140. retryCount++;
  141. }
  142. if (byteImage == null)
  143. {
  144. Logger.Error($"AutoEFDiagnosisService-DetectOneRawImageForAutoEFCalculationForVet Get Image Cache Fail");
  145. return;
  146. }
  147. var rawImage = new RawImage(byteImage, width, height, (EnumColorType)colorType);
  148. _autoEFDiagnosis.DetectOneImageAsync(rawImage, frameTime);
  149. }
  150. catch (Exception ex)
  151. {
  152. Logger.Error($"AutoEFDiagnosisService-DetectOneRawImageForAutoEFCalculationForVet error:{ex}");
  153. }
  154. }
  155. /// <summary>
  156. /// 推入一张图并返回AutoEF结果
  157. /// </summary>
  158. /// <param name="rawImage"></param>
  159. /// <param name="frameTime"></param>
  160. /// <returns></returns>
  161. public void DetectOneByteImageForAutoEFCalculationForVet(double frameTime)
  162. {
  163. try
  164. {
  165. byte[] byteImage = null;
  166. int retryCount = 0;
  167. while (!_singleImageCache.TryPop(out byteImage) && retryCount < 50)
  168. {
  169. Thread.Sleep(10);
  170. retryCount++;
  171. }
  172. if (byteImage == null)
  173. {
  174. Logger.Error($"AutoEFDiagnosisService-DetectOneByteImageForAutoEFCalculationForVet Get Image Cache Fail");
  175. return;
  176. }
  177. _autoEFDiagnosis.DetectOneImageAsync(byteImage, frameTime);
  178. }
  179. catch (Exception ex)
  180. {
  181. Logger.Error($"AutoEFDiagnosisService-DetectOneByteImageForAutoEFCalculationForVet error:{ex}");
  182. }
  183. }
  184. /// <summary>
  185. /// 停止AutoEF并返回结果,若IsReturnEveryImgResult为True,则返回所有帧的AutoEF结果,若IsReturnEveryImgResult为False,则只返回ES,ED两张图的结果
  186. /// </summary>
  187. /// <returns></returns>
  188. public Dictionary<double, AIEDESDetectResult> StopAutoEFCalculationForVet()
  189. {
  190. try
  191. {
  192. var result = _autoEFDiagnosis.StopAutotEFCalculation();
  193. if (result == null)
  194. {
  195. return null;
  196. }
  197. else
  198. {
  199. Dictionary<double, AIEDESDetectResult> dict = new Dictionary<double, AIEDESDetectResult>();
  200. foreach (var key in result.Keys.ToArray())
  201. {
  202. var aiEDESDetectResult = AIConvertHelper.ConvertVetEDESDetectResultToAIEDESDetectResult(result[key]);
  203. dict.Add(key, aiEDESDetectResult);
  204. }
  205. return dict;
  206. }
  207. }
  208. catch (Exception ex)
  209. {
  210. Logger.Error($"AutoEFDiagnosisService-StopAutoEFCalculationForVet error:{ex}");
  211. return null;
  212. }
  213. }
  214. #endregion 兽用
  215. #region 人用
  216. /// <summary>
  217. /// 启用AutoEF计算(仅支持人用)
  218. /// </summary>
  219. /// <param name="totalTime">表示要显示的AutoEF曲线的总时长</param>
  220. /// <param name="cmPerPixel">探头中像素与实际单位转换的参数</param>
  221. /// <param name="intervalTime">推理的间隔时间</param>
  222. public string StartAutotEFCalculation(double totalTime, float cmPerPixel, double intervalTime)
  223. {
  224. try
  225. {
  226. if (_autoEFDiagnosis == null)
  227. {
  228. Logger.Error($"StartAutotEF Error:AutoEF Diagnosis is null");
  229. return null;
  230. }
  231. return _autoEFDiagnosis.StartAutotEFCalculation(totalTime, cmPerPixel, intervalTime);
  232. }
  233. catch (Exception ex)
  234. {
  235. Logger.Error($"AutoEFDiagnosisService-StartAutotEFCalculation error:{ex}");
  236. }
  237. return null;
  238. }
  239. /// <summary>
  240. /// 推入一张裸图(仅支持人用)
  241. /// </summary>
  242. /// <param name="rawImage"></param>
  243. /// <param name="frameTime"></param>
  244. /// <returns></returns>
  245. public void DetectOneRawImageForAutoEFCalculation(string calculationId, int height, int width, AIEnumColorType colorType, double frameTime)
  246. {
  247. try
  248. {
  249. byte[] byteImage = null;
  250. int retryCount = 0;
  251. while (!_singleImageCache.TryPop(out byteImage) && retryCount < 50)
  252. {
  253. Thread.Sleep(10);
  254. retryCount++;
  255. }
  256. if (byteImage == null)
  257. {
  258. Logger.Error($"AutoEFDiagnosisService-DetectOneRawImageForAutoEFCalculation Get Image Cache Fail");
  259. return;
  260. }
  261. var rawImage = new RawImage(byteImage, width, height, (EnumColorType)colorType);
  262. _autoEFDiagnosis.DetectOneImageAsync(calculationId, rawImage, frameTime);
  263. }
  264. catch (Exception ex)
  265. {
  266. Logger.Error($"AutoEFDiagnosisService-DetectOneRawImageForAutoEFCalculation error:{ex}");
  267. }
  268. }
  269. /// <summary>
  270. /// 推入一张图(仅支持人用)
  271. /// </summary>
  272. /// <param name="byteImage"></param>
  273. /// <param name="frameTime"></param>
  274. /// <returns></returns>
  275. public void DetectOneByteImageForAutoEFCalculation(string calculationId, double frameTime)
  276. {
  277. try
  278. {
  279. byte[] byteImage = null;
  280. int retryCount = 0;
  281. while (!_singleImageCache.TryPop(out byteImage) && retryCount < 50)
  282. {
  283. Thread.Sleep(10);
  284. retryCount++;
  285. }
  286. if (byteImage == null)
  287. {
  288. Logger.Error($"AutoEFDiagnosisService-DetectOneByteImageForAutoEFCalculation Get Image Cache Fail");
  289. return;
  290. }
  291. _autoEFDiagnosis.DetectOneImageAsync(calculationId, byteImage, frameTime);
  292. }
  293. catch (Exception ex)
  294. {
  295. Logger.Error($"AutoEFDiagnosisService-DetectOneByteImageForAutoEFCalculation error:{ex}");
  296. }
  297. }
  298. /// <summary>
  299. /// 根据输入的容积结果计算ED、ES帧
  300. /// </summary>
  301. /// <param name="calculationId"></param>
  302. /// <returns></returns>
  303. public TransAICardiacCurveInfos StopAutoEFCalculation(string calculationId)
  304. {
  305. try
  306. {
  307. var result = _autoEFDiagnosis.StopAutotEFCalculation(calculationId);
  308. return AIConvertHelper.ConvertCardiacCurveInfosWithCalculationIdToTransAICardiacCurveInfos(result);
  309. }
  310. catch (Exception ex)
  311. {
  312. Logger.Error($"AutoEFDiagnosisService-StopAutoEFCalculation error:{ex}");
  313. return null;
  314. }
  315. }
  316. /// <summary>
  317. /// 检测单张图像(仅支持人用)
  318. /// </summary>
  319. /// <param name="calculationId"></param>
  320. /// <param name="height"></param>
  321. /// <param name="width"></param>
  322. /// <param name="colorType"></param>
  323. /// <param name="frameTime"></param>
  324. /// <returns></returns>
  325. public TransAICardiacCurveInfos DetectOneRawImage(string calculationId, int height, int width, AIEnumColorType colorType, double frameTime)
  326. {
  327. try
  328. {
  329. byte[] byteImage = null;
  330. int retryCount = 0;
  331. while (!_singleImageCache.TryPop(out byteImage) && retryCount < 50)
  332. {
  333. Thread.Sleep(10);
  334. retryCount++;
  335. }
  336. if (byteImage == null)
  337. {
  338. Logger.Error($"AutoEFDiagnosisService-DetectOneRawImage Get Image Cache Fail");
  339. return null;
  340. }
  341. var rawImage = new RawImage(byteImage, width, height, (EnumColorType)colorType);
  342. var result = _autoEFDiagnosis.DetectOneImage(calculationId, rawImage, frameTime);
  343. return AIConvertHelper.ConvertCardiacCurveInfosWithCalculationIdToTransAICardiacCurveInfos(result);
  344. }
  345. catch (Exception ex)
  346. {
  347. Logger.Error($"AutoEFDiagnosisService-DetectOneRawImage error:{ex}");
  348. return null;
  349. }
  350. }
  351. /// <summary>
  352. /// 检测单张图像(仅支持人用)
  353. /// </summary>
  354. /// <param name="calculationId"></param>
  355. /// <param name="frameTime"></param>
  356. /// <returns></returns>
  357. public TransAICardiacCurveInfos DetectOneByteImage(string calculationId, double frameTime)
  358. {
  359. try
  360. {
  361. byte[] byteImage = null;
  362. int retryCount = 0;
  363. while (!_singleImageCache.TryPop(out byteImage) && retryCount < 50)
  364. {
  365. Thread.Sleep(10);
  366. retryCount++;
  367. }
  368. if (byteImage == null)
  369. {
  370. Logger.Error($"AutoEFDiagnosisService-DetectOneByteImage Get Image Cache Fail");
  371. return null;
  372. }
  373. var result = _autoEFDiagnosis.DetectOneImage(calculationId, byteImage, frameTime);
  374. return AIConvertHelper.ConvertCardiacCurveInfosWithCalculationIdToTransAICardiacCurveInfos(result);
  375. }
  376. catch (Exception ex)
  377. {
  378. Logger.Error($"AutoEFDiagnosisService-DetectOneByteImage error:{ex}");
  379. return null;
  380. }
  381. }
  382. #endregion 人用
  383. public void Start()
  384. {
  385. try
  386. {
  387. if (_autoEFDiagnosis != null)
  388. {
  389. _autoEFDiagnosis.Start();
  390. }
  391. }
  392. catch (Exception ex)
  393. {
  394. Logger.Error($"AutoEFDiagnosisService-Start error:{ex}");
  395. }
  396. }
  397. public void Stop()
  398. {
  399. try
  400. {
  401. if (_autoEFDiagnosis != null)
  402. {
  403. _autoEFDiagnosis.Stop();
  404. }
  405. }
  406. catch (Exception ex)
  407. {
  408. Logger.Error($"AutoEFDiagnosisService-Stop error:{ex}");
  409. }
  410. }
  411. public void SetDetectTps(int detectTps)
  412. {
  413. try
  414. {
  415. if (_autoEFDiagnosis != null)
  416. {
  417. _autoEFDiagnosis.DetectTps = detectTps;
  418. }
  419. }
  420. catch (Exception ex)
  421. {
  422. Logger.Error($"AutoEFDiagnosisService-SetDetectTps error:{ex}");
  423. }
  424. }
  425. public void SetIntervalTime(int intervalTime)
  426. {
  427. try
  428. {
  429. if (_autoEFDiagnosis != null)
  430. {
  431. _autoEFDiagnosis.IntervalTime = intervalTime;
  432. }
  433. }
  434. catch (Exception ex)
  435. {
  436. Logger.Error($"AutoEFDiagnosisService-SetIntervalTime error:{ex}");
  437. }
  438. }
  439. public void SetDetectMode(AIEnumDetectMode detectMode)
  440. {
  441. try
  442. {
  443. if (_autoEFDiagnosis != null)
  444. {
  445. _autoEFDiagnosis.DetectMode = (EnumDetectMode)detectMode;
  446. }
  447. }
  448. catch (Exception ex)
  449. {
  450. Logger.Error($"AutoEFDiagnosisService-SetDetectMode error:{ex}");
  451. }
  452. }
  453. /// <summary>
  454. /// 设置一个像素代表的实际物理距离是多少cm
  455. /// </summary>
  456. /// <param name="cmPerPixel"></param>
  457. public void SetCmPerPixel(double cmPerPixel)
  458. {
  459. try
  460. {
  461. if (_autoEFDiagnosis != null)
  462. {
  463. _autoEFDiagnosis.CmPerPixel = cmPerPixel;
  464. }
  465. }
  466. catch (Exception ex)
  467. {
  468. Logger.Error($"AutoEFDiagnosisService-SetCmPerPixel error:{ex}");
  469. }
  470. }
  471. /// <summary>
  472. /// Send Raw Image Data For Pipe
  473. /// </summary>
  474. /// <param name="height"></param>
  475. /// <param name="width"></param>
  476. /// <param name="colorType"></param>
  477. public void SendRawImageData(int height, int width, AIEnumColorType colorType)
  478. {
  479. try
  480. {
  481. _imageProvider?.ReceiveRawImageData(height, width, (EnumColorType)colorType);
  482. }
  483. catch (Exception ex)
  484. {
  485. Logger.Error($"AutoEFDiagnosisService-SendRawImageData error:{ex}");
  486. }
  487. }
  488. /// <summary>
  489. /// Send Byte Image Data For Pipe
  490. /// </summary>
  491. public void SendByteImageData()
  492. {
  493. try
  494. {
  495. _imageProvider?.ReceiveByteImageData();
  496. }
  497. catch (Exception ex)
  498. {
  499. Logger.Error($"AutoEFDiagnosisService-SendByteImageData error:{ex}");
  500. }
  501. }
  502. public void Close()
  503. {
  504. try
  505. {
  506. Logger.Info($"AutoEFDiagnosisService-Close Invoke");
  507. CloseDiagnosis();
  508. }
  509. catch (Exception ex)
  510. {
  511. Logger.Error($"AutoEFDiagnosisService-Close error:{ex}");
  512. }
  513. }
  514. private void CloseDiagnosis()
  515. {
  516. if (_autoEFDiagnosis != null)
  517. {
  518. _autoEFDiagnosis.StartEvaluation -= OnStartEvaluation;
  519. _autoEFDiagnosis.FinishEvaluation -= OnFinishEvaluation;
  520. _autoEFDiagnosis.NotifyError -= OnNotifyError;
  521. _autoEFDiagnosis.NotifyLog -= OnNotifyLog;
  522. _autoEFDiagnosis.Close();
  523. _autoEFDiagnosis = null;
  524. }
  525. }
  526. public void Dispose()
  527. {
  528. try
  529. {
  530. if (!_disposed)
  531. {
  532. Logger.Info($"AutoEFDiagnosisService-Start Dispose");
  533. CloseDiagnosis();
  534. if (_singleImagePipeServer != null)
  535. {
  536. _singleImagePipeServer.DataReceived -= OnDataReceived;
  537. _singleImagePipeServer.Dispose();
  538. _singleImagePipeServer.LogMsgThrow -= OnLogMsgThrow;
  539. _singleImagePipeServer = null;
  540. }
  541. _disposed = true;
  542. Logger.Info($"AutoEFDiagnosisService Dispose End");
  543. }
  544. }
  545. catch (Exception ex)
  546. {
  547. Logger.Error($"AutoEFDiagnosisService-Dispose error:{ex}");
  548. }
  549. }
  550. private void OnStartEvaluation(object sender, EventArgs e)
  551. {
  552. NotificationSender.SendNotification(new AINotificationArgs() { NotificationType = AIEnumNotificationType.AutoEFDiagnosisStartEvaluationRaised });
  553. }
  554. private void OnFinishEvaluation(object sender, Tuple<CardiacCurveInfos, string> e)
  555. {
  556. var transAICardiacCurveInfos = AIConvertHelper.ConvertCardiacCurveInfosWithCalculationIdToTransAICardiacCurveInfos(e);
  557. NotificationSender.SendNotification(new AINotificationArgs() { NotificationType = AIEnumNotificationType.AutoEFDiagnosisFinishEvaluationRaised, Params = transAICardiacCurveInfos });
  558. }
  559. private void OnNotifyLog(object sender, LogEventArgs e)
  560. {
  561. if (e == null)
  562. {
  563. return;
  564. }
  565. switch (e.LogType)
  566. {
  567. case EnumLogType.InfoLog:
  568. Logger.Info($"AutoEFDiagnosisService OnNotifyLog:{e.Msg}");
  569. break;
  570. case EnumLogType.WarnLog:
  571. Logger.Warning($"AutoEFDiagnosisService OnNotifyLog:{e.Msg}");
  572. break;
  573. case EnumLogType.ErrorLog:
  574. case EnumLogType.FatalLog:
  575. default:
  576. Logger.Error($"AutoEFDiagnosisService OnNotifyLog:{e.Msg}");
  577. break;
  578. }
  579. var logEventArgs = AICommonServiceConvertHelper.ConvertLogEventArgsToAILogEventArgs(e);
  580. NotificationSender.SendNotification(new AINotificationArgs() { NotificationType = AIEnumNotificationType.AutoEFDiagnosisNotifyLogRaised, Params = logEventArgs });
  581. }
  582. private void OnNotifyError(object sender, ErrorEventArgs e)
  583. {
  584. Logger.Error($"AutoEFDiagnosisService OnNotifyError:{e.GetException()}");
  585. var logEventArgs = AICommonServiceConvertHelper.ConvertErrorEventArgsToAILogEventArgs(e);
  586. NotificationSender.SendNotification(new AINotificationArgs() { NotificationType = AIEnumNotificationType.AutoEFDiagnosisNotifyLogRaised, Params = logEventArgs });
  587. }
  588. private void OnLogMsgThrow(object sender, AILogEventArgs e)
  589. {
  590. if (e == null)
  591. {
  592. return;
  593. }
  594. switch (e.LogType)
  595. {
  596. case AIEnumLogType.ErrorLog:
  597. case AIEnumLogType.FatalLog:
  598. Logger.Error(e.Msg);
  599. break;
  600. case AIEnumLogType.WarnLog:
  601. Logger.Warning(e.Msg);
  602. break;
  603. case AIEnumLogType.InfoLog:
  604. default:
  605. Logger.Info(e.Msg);
  606. break;
  607. }
  608. }
  609. private void OnDataReceived(object sender, byte[] e)
  610. {
  611. try
  612. {
  613. _singleImageCache.Push(e);
  614. }
  615. catch (Exception ex)
  616. {
  617. Logger.Error($"AutoEFDiagnosisService-OnDataReceived error:{ex}");
  618. }
  619. }
  620. }
  621. }