BreastDiagnosis.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  1. using System;
  2. using System.Reflection;
  3. using System.Text.Json;
  4. using Vinno.AI.AIDiagnosisSDK.Interfaces;
  5. using Vinno.AI.AIDiagnosisSDK.Models;
  6. using Vinno.AI.CommonSDK.Enums;
  7. using Vinno.AI.CommonSDK.Interfaces;
  8. using Vinno.AI.CommonSDK.Models;
  9. using Vinno.AI.CommonSDK.Tools;
  10. namespace Vinno.AI.AIDiagnosisSDK
  11. {
  12. public class BreastDiagnosis : IAIDiagnosis
  13. {
  14. private readonly IAIDiagnosisService _aiDiagnosisService;
  15. private readonly AIEnumModuleType _type = AIEnumModuleType.Breast;
  16. private IAIImageProvider _imageProvider;
  17. private bool _initialized;
  18. private bool _disposed;
  19. /// <summary>
  20. /// Used For Detect One Image
  21. /// </summary>
  22. private PipeClient _singleImagePipeClient;
  23. /// <summary>
  24. /// Used For Provide Raw Image
  25. /// </summary>
  26. private PipeClient _rawImageProviderPipeClient;
  27. /// <summary>
  28. /// Used For Provide Byte Image
  29. /// </summary>
  30. private PipeClient _byteImageProviderPipeClient;
  31. /// <summary>
  32. /// Raised when the image evaluation is started.
  33. /// </summary>
  34. public event EventHandler StartEvaluationNotification;
  35. /// <summary>
  36. /// Raised when the image evaluation is finished.
  37. /// </summary>
  38. public event EventHandler<AIDiagResultPerImg> FinishEvaluationNotification;
  39. public BreastDiagnosis()
  40. {
  41. _aiDiagnosisService = AIManager.Instance.AIDiagnosisSystemJsonRpcClientManager?.GetService<IAIDiagnosisService>();
  42. if (AIManager.Instance.AINotificationManager != null)
  43. {
  44. AIManager.Instance.AINotificationManager.NotificationReceived += OnNotificationReceived;
  45. }
  46. _singleImagePipeClient = new PipeClient(AIDiagnosisSystemConsts.PipeForBreastDiagnosisSingleImage);
  47. _singleImagePipeClient.LogMsgThrow += OnLogMsgThrow;
  48. _singleImagePipeClient.Start();
  49. _rawImageProviderPipeClient = new PipeClient(AIDiagnosisSystemConsts.PipeForBreastDiagnosisRawImageProvider);
  50. _rawImageProviderPipeClient.LogMsgThrow += OnLogMsgThrow;
  51. _rawImageProviderPipeClient.Start();
  52. _byteImageProviderPipeClient = new PipeClient(AIDiagnosisSystemConsts.PipeForBreastDiagnosisByteImageProvider);
  53. _byteImageProviderPipeClient.LogMsgThrow += OnLogMsgThrow;
  54. _byteImageProviderPipeClient.Start();
  55. }
  56. /// <summary>
  57. /// 初始化AI Diagnosis
  58. /// </summary>
  59. /// <param name="BreastDiagnosisParameter">AI Diagnosis Parameter</param>
  60. /// <param name="imageProvider">Image Provider</param>
  61. public void Initialize(AIDiagnosisParameter BreastDiagnosisParameter, IAIImageProvider imageProvider = null)
  62. {
  63. try
  64. {
  65. if (!_initialized)
  66. {
  67. _imageProvider = imageProvider;
  68. _aiDiagnosisService.InitializeBreastDiagnosis(BreastDiagnosisParameter, _imageProvider != null);
  69. _initialized = true;
  70. }
  71. }
  72. catch (Exception ex)
  73. {
  74. AIManager.Instance.AILogManager?.WriteLogInfo(new AILogEventArgs(AIEnumLogType.ErrorLog, $"错误方法名:{MethodBase.GetCurrentMethod().DeclaringType.Name}.{MethodBase.GetCurrentMethod().Name}, 错误信息:{ex}"));
  75. }
  76. }
  77. /// <summary>
  78. /// Start Image Provider
  79. /// </summary>
  80. public void Start()
  81. {
  82. if (_imageProvider != null)
  83. {
  84. _imageProvider.ByteImageProvided += OnByteImageProvided;
  85. _imageProvider.RawImageProvided += OnRawImageProvided;
  86. _imageProvider.Start();
  87. _aiDiagnosisService.Start();
  88. }
  89. }
  90. /// <summary>
  91. /// Stop Image Provider
  92. /// </summary>
  93. public void Stop()
  94. {
  95. if (_imageProvider != null)
  96. {
  97. _imageProvider.ByteImageProvided -= OnByteImageProvided;
  98. _imageProvider.RawImageProvided -= OnRawImageProvided;
  99. _imageProvider.Stop();
  100. }
  101. _aiDiagnosisService.Stop();
  102. }
  103. private void OnLogMsgThrow(object sender, AILogEventArgs e)
  104. {
  105. AIManager.Instance.AILogManager?.WriteLogInfo(e);
  106. }
  107. private void OnNotificationReceived(object sender, AINotificationArgs e)
  108. {
  109. switch (e.NotificationType)
  110. {
  111. case AIEnumNotificationType.BreastDiagnosisStartEvaluationRaised:
  112. StartEvaluationNotification?.Invoke(this, EventArgs.Empty);
  113. break;
  114. case AIEnumNotificationType.BreastDiagnosisFinishEvaluationRaised:
  115. var transAIDiagResultPerImg = JsonSerializer.Deserialize<TransAIDiagResultPerImg>(e.Params?.ToString());
  116. var aiDiagResultPerImg = AICommonConvertHelper.ConvertTransAIDiagResultPerImgToAIDiagResultPerImg(transAIDiagResultPerImg);
  117. FinishEvaluationNotification?.Invoke(this, aiDiagResultPerImg);
  118. break;
  119. case AIEnumNotificationType.AIDiagnosisNotifyLogRaised:
  120. var logEventArgs = JsonSerializer.Deserialize<AILogEventArgs>(e.Params.ToString());
  121. AIManager.Instance.AILogManager?.WriteLogInfo(logEventArgs);
  122. break;
  123. }
  124. }
  125. /// <summary>
  126. /// 设置图片是否已裁剪
  127. /// </summary>
  128. /// <param name="isCropped"></param>
  129. public void SetIsCropped(bool isCropped)
  130. {
  131. try
  132. {
  133. _aiDiagnosisService.SetIsCropped(_type, isCropped);
  134. }
  135. catch (Exception ex)
  136. {
  137. AIManager.Instance.AILogManager?.WriteLogInfo(new AILogEventArgs(AIEnumLogType.ErrorLog, $"错误方法名:{MethodBase.GetCurrentMethod().DeclaringType.Name}.{MethodBase.GetCurrentMethod().Name}, 错误信息:{ex}"));
  138. }
  139. }
  140. /// <summary>
  141. /// 设置每秒图片吞吐量
  142. /// </summary>
  143. /// <param name="detectTps">每秒图片吞吐量,必须大于0</param>
  144. public void SetDetectTps(int detectTps)
  145. {
  146. if (detectTps <= 0)
  147. {
  148. throw new ArgumentOutOfRangeException($"DetectTps Must > 0. DetectTps : {detectTps}");
  149. }
  150. try
  151. {
  152. _aiDiagnosisService.SetDetectTps(_type, detectTps);
  153. }
  154. catch (Exception ex)
  155. {
  156. AIManager.Instance.AILogManager?.WriteLogInfo(new AILogEventArgs(AIEnumLogType.ErrorLog, $"错误方法名:{MethodBase.GetCurrentMethod().DeclaringType.Name}.{MethodBase.GetCurrentMethod().Name}, 错误信息:{ex}"));
  157. }
  158. }
  159. /// <summary>
  160. /// 设置间隔时间
  161. /// </summary>
  162. /// <param name="intervalTime"></param>
  163. public void SetIntervalTime(int intervalTime)
  164. {
  165. try
  166. {
  167. _aiDiagnosisService.SetIntervalTime(_type, intervalTime);
  168. }
  169. catch (Exception ex)
  170. {
  171. AIManager.Instance.AILogManager?.WriteLogInfo(new AILogEventArgs(AIEnumLogType.ErrorLog, $"错误方法名:{MethodBase.GetCurrentMethod().DeclaringType.Name}.{MethodBase.GetCurrentMethod().Name}, 错误信息:{ex}"));
  172. }
  173. }
  174. /// <summary>
  175. /// 设置检测模式
  176. /// </summary>
  177. /// <param name="detectMode"></param>
  178. public void SetDetectMode(AIEnumDetectMode detectMode)
  179. {
  180. try
  181. {
  182. _aiDiagnosisService.SetDetectMode(_type, detectMode);
  183. }
  184. catch (Exception ex)
  185. {
  186. AIManager.Instance.AILogManager?.WriteLogInfo(new AILogEventArgs(AIEnumLogType.ErrorLog, $"错误方法名:{MethodBase.GetCurrentMethod().DeclaringType.Name}.{MethodBase.GetCurrentMethod().Name}, 错误信息:{ex}"));
  187. }
  188. }
  189. /// <summary>
  190. /// 设置是否启用轮廓计算
  191. /// </summary>
  192. /// <param name="enableLesionSeg"></param>
  193. public void SetEnableLesionSeg(bool enableLesionSeg)
  194. {
  195. try
  196. {
  197. _aiDiagnosisService.SetEnableLesionSeg(_type, enableLesionSeg);
  198. }
  199. catch (Exception ex)
  200. {
  201. AIManager.Instance.AILogManager?.WriteLogInfo(new AILogEventArgs(AIEnumLogType.ErrorLog, $"错误方法名:{MethodBase.GetCurrentMethod().DeclaringType.Name}.{MethodBase.GetCurrentMethod().Name}, 错误信息:{ex}"));
  202. }
  203. }
  204. /// <summary>
  205. /// 设置是否启用描述
  206. /// </summary>
  207. /// <param name="enableDescription">是否启用病灶及脏器描述</param>
  208. public void SetEnableDescription(bool enableDescription)
  209. {
  210. try
  211. {
  212. _aiDiagnosisService.SetEnableDescription(_type, enableDescription, enableDescription);
  213. }
  214. catch (Exception ex)
  215. {
  216. AIManager.Instance.AILogManager?.WriteLogInfo(new AILogEventArgs(AIEnumLogType.ErrorLog, $"错误方法名:{MethodBase.GetCurrentMethod().DeclaringType.Name}.{MethodBase.GetCurrentMethod().Name}, 错误信息:{ex}"));
  217. }
  218. }
  219. /// <summary>
  220. /// 设置是否启用描述
  221. /// </summary>
  222. /// <param name="enableLessionDescription">是否启用病灶描述</param>
  223. /// <param name="enableOrganDescription">是否启用脏器描述</param>
  224. public void SetEnableDescription(bool enableLessionDescription, bool enableOrganDescription)
  225. {
  226. try
  227. {
  228. _aiDiagnosisService.SetEnableDescription(_type, enableLessionDescription, enableOrganDescription);
  229. }
  230. catch (Exception ex)
  231. {
  232. AIManager.Instance.AILogManager?.WriteLogInfo(new AILogEventArgs(AIEnumLogType.ErrorLog, $"错误方法名:{MethodBase.GetCurrentMethod().DeclaringType.Name}.{MethodBase.GetCurrentMethod().Name}, 错误信息:{ex}"));
  233. }
  234. }
  235. /// <summary>
  236. /// 检测单张Byte Image
  237. /// </summary>
  238. /// <param name="byteImage"></param>
  239. /// <returns></returns>
  240. public AIDiagResultPerImg DetectOneImage(byte[] byteImage)
  241. {
  242. if (byteImage == null)
  243. {
  244. throw new ArgumentNullException(nameof(byteImage));
  245. }
  246. try
  247. {
  248. _singleImagePipeClient.SendBytes(byteImage);
  249. var result = _aiDiagnosisService.DetectOneByteImage(_type);
  250. return AICommonConvertHelper.ConvertTransAIDiagResultPerImgToAIDiagResultPerImg(result);
  251. }
  252. catch (Exception ex)
  253. {
  254. AIManager.Instance.AILogManager?.WriteLogInfo(new AILogEventArgs(AIEnumLogType.ErrorLog, $"错误方法名:{MethodBase.GetCurrentMethod().DeclaringType.Name}.{MethodBase.GetCurrentMethod().Name}, 错误信息:{ex}"));
  255. return null;
  256. }
  257. }
  258. /// <summary>
  259. /// 检测单张Byte Image,其中enableLesionSeg与enableDescription仅此次调用生效
  260. /// </summary>
  261. /// <param name="byteImage"></param>
  262. /// <param name="enableLesionSeg">是否计算轮廓</param>
  263. /// <param name="enableDescription">是否计算病灶及脏器描述结果</param>
  264. /// <returns></returns>
  265. public AIDiagResultPerImg DetectOneImage(byte[] byteImage, bool enableLesionSeg, bool enableDescription)
  266. {
  267. if (byteImage == null)
  268. {
  269. throw new ArgumentNullException(nameof(byteImage));
  270. }
  271. try
  272. {
  273. _singleImagePipeClient.SendBytes(byteImage);
  274. var result = _aiDiagnosisService.DetectOneByteImageWithTempSetting(_type, enableLesionSeg, enableDescription, enableDescription);
  275. return AICommonConvertHelper.ConvertTransAIDiagResultPerImgToAIDiagResultPerImg(result);
  276. }
  277. catch (Exception ex)
  278. {
  279. AIManager.Instance.AILogManager?.WriteLogInfo(new AILogEventArgs(AIEnumLogType.ErrorLog, $"错误方法名:{MethodBase.GetCurrentMethod().DeclaringType.Name}.{MethodBase.GetCurrentMethod().Name}, 错误信息:{ex}"));
  280. return null;
  281. }
  282. }
  283. /// <summary>
  284. /// 检测单张Byte Image,其中enableLesionSeg与enableLesionDescription,enableOrganDescription仅此次调用生效
  285. /// </summary>
  286. /// <param name="byteImage"></param>
  287. /// <param name="enableLesionSeg">是否计算轮廓</param>
  288. /// <param name="enableLesionDescription">是否计算病灶描述结果</param>
  289. /// <param name="enableOrganDescription">是否计算脏器描述结果</param>
  290. /// <returns></returns>
  291. public AIDiagResultPerImg DetectOneImage(byte[] byteImage, bool enableLesionSeg, bool enableLesionDescription, bool enableOrganDescription)
  292. {
  293. if (byteImage == null)
  294. {
  295. throw new ArgumentNullException(nameof(byteImage));
  296. }
  297. try
  298. {
  299. _singleImagePipeClient.SendBytes(byteImage);
  300. var result = _aiDiagnosisService.DetectOneByteImageWithTempSetting(_type, enableLesionSeg, enableLesionDescription, enableOrganDescription);
  301. return AICommonConvertHelper.ConvertTransAIDiagResultPerImgToAIDiagResultPerImg(result);
  302. }
  303. catch (Exception ex)
  304. {
  305. AIManager.Instance.AILogManager?.WriteLogInfo(new AILogEventArgs(AIEnumLogType.ErrorLog, $"错误方法名:{MethodBase.GetCurrentMethod().DeclaringType.Name}.{MethodBase.GetCurrentMethod().Name}, 错误信息:{ex}"));
  306. return null;
  307. }
  308. }
  309. /// <summary>
  310. /// 检测单张Raw Image
  311. /// </summary>
  312. /// <param name="rawImage"></param>
  313. /// <returns></returns>
  314. public AIDiagResultPerImg DetectOneImage(AIRawImage rawImage)
  315. {
  316. if (rawImage == null)
  317. {
  318. throw new ArgumentNullException(nameof(rawImage));
  319. }
  320. try
  321. {
  322. _singleImagePipeClient.SendBytes(rawImage.DataBuffer);
  323. var result = _aiDiagnosisService.DetectOneRawImage(_type, rawImage.Height, rawImage.Width, rawImage.ColorType);
  324. return AICommonConvertHelper.ConvertTransAIDiagResultPerImgToAIDiagResultPerImg(result);
  325. }
  326. catch (Exception ex)
  327. {
  328. AIManager.Instance.AILogManager?.WriteLogInfo(new AILogEventArgs(AIEnumLogType.ErrorLog, $"错误方法名:{MethodBase.GetCurrentMethod().DeclaringType.Name}.{MethodBase.GetCurrentMethod().Name}, 错误信息:{ex}"));
  329. return null;
  330. }
  331. }
  332. /// <summary>
  333. /// 检测单张Raw Image,其中enableLesionSeg与enableDescription仅此次调用生效
  334. /// </summary>
  335. /// <param name="rawImage"></param>
  336. /// <param name="enableLesionSeg">是否计算轮廓</param>
  337. /// <param name="enableDescription">是否计算病灶及脏器描述结果</param>
  338. /// <returns></returns>
  339. public AIDiagResultPerImg DetectOneImage(AIRawImage rawImage, bool enableLesionSeg, bool enableDescription)
  340. {
  341. if (rawImage == null)
  342. {
  343. throw new ArgumentNullException(nameof(rawImage));
  344. }
  345. try
  346. {
  347. _singleImagePipeClient.SendBytes(rawImage.DataBuffer);
  348. var result = _aiDiagnosisService.DetectOneRawImageWithTempSetting(_type, rawImage.Height, rawImage.Width, rawImage.ColorType, enableLesionSeg, enableDescription, enableDescription);
  349. return AICommonConvertHelper.ConvertTransAIDiagResultPerImgToAIDiagResultPerImg(result);
  350. }
  351. catch (Exception ex)
  352. {
  353. AIManager.Instance.AILogManager?.WriteLogInfo(new AILogEventArgs(AIEnumLogType.ErrorLog, $"错误方法名:{MethodBase.GetCurrentMethod().DeclaringType.Name}.{MethodBase.GetCurrentMethod().Name}, 错误信息:{ex}"));
  354. return null;
  355. }
  356. }
  357. /// <summary>
  358. /// 检测单张Raw Image,其中enableLesionSeg与enableLesionDescription,enableOrganDescription仅此次调用生效
  359. /// </summary>
  360. /// <param name="rawImage"></param>
  361. /// <param name="enableLesionSeg">是否计算轮廓</param>
  362. /// <param name="enableLesionDescription">是否计算病灶描述结果</param>
  363. /// <param name="enableOrganDescription">是否计算脏器描述结果</param>
  364. /// <returns></returns>
  365. public AIDiagResultPerImg DetectOneImage(AIRawImage rawImage, bool enableLesionSeg, bool enableLesionDescription, bool enableOrganDescription = false)
  366. {
  367. if (rawImage == null)
  368. {
  369. throw new ArgumentNullException(nameof(rawImage));
  370. }
  371. try
  372. {
  373. _singleImagePipeClient.SendBytes(rawImage.DataBuffer);
  374. var result = _aiDiagnosisService.DetectOneRawImageWithTempSetting(_type, rawImage.Height, rawImage.Width, rawImage.ColorType, enableLesionSeg, enableLesionDescription, enableOrganDescription);
  375. return AICommonConvertHelper.ConvertTransAIDiagResultPerImgToAIDiagResultPerImg(result);
  376. }
  377. catch (Exception ex)
  378. {
  379. AIManager.Instance.AILogManager?.WriteLogInfo(new AILogEventArgs(AIEnumLogType.ErrorLog, $"错误方法名:{MethodBase.GetCurrentMethod().DeclaringType.Name}.{MethodBase.GetCurrentMethod().Name}, 错误信息:{ex}"));
  380. return null;
  381. }
  382. }
  383. /// <summary>
  384. /// 评估单幅图像 ,图像计算完成后,使用者希望调整结果,使部分结果在选定的矩形框内。
  385. /// </summary>
  386. /// <param name="aiRect">使用者给出的矩形框</param>
  387. /// <param name="aiDiagResultPerImg">图像的初始计算结果</param>
  388. /// <summary>
  389. public AIDiagResultPerImg CalculateCarotidInnerDiameterAndIntimaMediaThicknessInSpecifiedRect(byte[] bytesImage, AIRect aiRect, AIDiagResultPerImg aiDiagResultPerImg)
  390. {
  391. throw new NotSupportedException("CalculateCarotidInnerDiameterAndIntimaMediaThicknessInSpecifiedRectWithBytesImage Only Support Cartoid Diagnosis");
  392. }
  393. /// <summary>
  394. /// 评估单幅图像 ,图像计算完成后,使用者希望调整结果,使部分结果在选定的矩形框内。
  395. /// </summary>
  396. /// <param name="aiRect">使用者给出的矩形框</param>
  397. /// <param name="aiDiagResultPerImg">图像的初始计算结果</param>
  398. public AIDiagResultPerImg CalculateCarotidInnerDiameterAndIntimaMediaThicknessInSpecifiedRect(AIRawImage rawImage, AIRect aiRect, AIDiagResultPerImg aiDiagResultPerImg)
  399. {
  400. throw new NotSupportedException("CalculateCarotidInnerDiameterAndIntimaMediaThicknessInSpecifiedRectWithBytesImage Only Support Cartoid Diagnosis");
  401. }
  402. private void OnByteImageProvided(object sender, byte[] byteImage)
  403. {
  404. try
  405. {
  406. if (byteImage == null)
  407. {
  408. return;
  409. }
  410. _byteImageProviderPipeClient?.SendBytes(byteImage);
  411. _aiDiagnosisService.SendByteImageData(_type);
  412. }
  413. catch (Exception ex)
  414. {
  415. AIManager.Instance.AILogManager?.WriteLogInfo(new AILogEventArgs(AIEnumLogType.ErrorLog, $"错误方法名:{MethodBase.GetCurrentMethod().DeclaringType.Name}.{MethodBase.GetCurrentMethod().Name}, 错误信息:{ex}"));
  416. }
  417. }
  418. private void OnRawImageProvided(object sender, AIRawImage rawImage)
  419. {
  420. try
  421. {
  422. if (rawImage == null)
  423. {
  424. return;
  425. }
  426. _rawImageProviderPipeClient?.SendBytes(rawImage.DataBuffer);
  427. _aiDiagnosisService.SendRawImageData(_type, rawImage.Height, rawImage.Width, rawImage.ColorType);
  428. }
  429. catch (Exception ex)
  430. {
  431. AIManager.Instance.AILogManager?.WriteLogInfo(new AILogEventArgs(AIEnumLogType.ErrorLog, $"错误方法名:{MethodBase.GetCurrentMethod().DeclaringType.Name}.{MethodBase.GetCurrentMethod().Name}, 错误信息:{ex}"));
  432. }
  433. }
  434. /// <summary>
  435. /// Close AI Diagnosis
  436. /// </summary>
  437. public void Close()
  438. {
  439. try
  440. {
  441. if (_disposed)
  442. {
  443. return;
  444. }
  445. _initialized = false;
  446. if (_imageProvider != null)
  447. {
  448. _imageProvider.ByteImageProvided -= OnByteImageProvided;
  449. _imageProvider.RawImageProvided -= OnRawImageProvided;
  450. _imageProvider.Stop();
  451. _imageProvider = null;
  452. }
  453. _aiDiagnosisService.Close(_type);
  454. }
  455. catch (Exception ex)
  456. {
  457. AIManager.Instance.AILogManager?.WriteLogInfo(new AILogEventArgs(AIEnumLogType.ErrorLog, $"错误方法名:{MethodBase.GetCurrentMethod().DeclaringType.Name}.{MethodBase.GetCurrentMethod().Name}, 错误信息:{ex}"));
  458. }
  459. }
  460. public void Dispose()
  461. {
  462. try
  463. {
  464. if (!_disposed)
  465. {
  466. _initialized = false;
  467. if (AIManager.Instance.AINotificationManager != null)
  468. {
  469. AIManager.Instance.AINotificationManager.NotificationReceived -= OnNotificationReceived;
  470. }
  471. if (_imageProvider != null)
  472. {
  473. _imageProvider.ByteImageProvided -= OnByteImageProvided;
  474. _imageProvider.RawImageProvided -= OnRawImageProvided;
  475. _imageProvider.Stop();
  476. _imageProvider = null;
  477. }
  478. if (_singleImagePipeClient != null)
  479. {
  480. _singleImagePipeClient.Dispose();
  481. _singleImagePipeClient.LogMsgThrow -= OnLogMsgThrow;
  482. _singleImagePipeClient = null;
  483. }
  484. if (_rawImageProviderPipeClient != null)
  485. {
  486. _rawImageProviderPipeClient.Dispose();
  487. _rawImageProviderPipeClient.LogMsgThrow -= OnLogMsgThrow;
  488. _rawImageProviderPipeClient = null;
  489. }
  490. if (_byteImageProviderPipeClient != null)
  491. {
  492. _byteImageProviderPipeClient.Dispose();
  493. _byteImageProviderPipeClient.LogMsgThrow -= OnLogMsgThrow;
  494. _byteImageProviderPipeClient = null;
  495. }
  496. _disposed = true;
  497. }
  498. }
  499. catch (Exception ex)
  500. {
  501. AIManager.Instance.AILogManager?.WriteLogInfo(new AILogEventArgs(AIEnumLogType.ErrorLog, $"错误方法名:{MethodBase.GetCurrentMethod().DeclaringType.Name}.{MethodBase.GetCurrentMethod().Name}, 错误信息:{ex}"));
  502. }
  503. }
  504. }
  505. }