MesService.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. using Prism.Events;
  2. using Prism.Ioc;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Net.Http;
  7. using System.Text;
  8. using System.Threading;
  9. using System.Threading.Tasks;
  10. using TeamAAS_VP.Enums;
  11. using TeamAAS_VP.Events;
  12. using TeamAAS_VP.Interfaces;
  13. using TeamAAS_VP.Models;
  14. namespace TeamAAS_VP.Services
  15. {
  16. /// <summary>
  17. /// 基于 <see cref="HttpClient"/> 的 MES 通信服务实现。
  18. /// <para>
  19. /// 本服务通过注入的 <see cref="IConfigService"/> 获取设备配置(包含 MES 接口地址),
  20. /// 提供对站点查询(StationGetAsync)和提交(SubmitGetAsync)的 GET 请求封装并带有重试逻辑。
  21. /// </para>
  22. /// <para>
  23. /// 注意:
  24. /// - <see cref="_httpClient"/> 为可复用的单一实例,建议在服务生命周期内重用以避免端口耗尽。
  25. /// - 本类实现了显式的 <see cref="Dispose"/> 方法以释放内部 <see cref="HttpClient"/> 资源,调用后实例不可再用。
  26. /// </para>
  27. /// </summary>
  28. public class MesService : IMesService
  29. {
  30. IEventAggregator _eventAggregator;
  31. /// <summary>
  32. /// 用于执行 HTTP 请求的客户端实例。建议在服务生命周期内重用,避免频繁创建导致套接字/端口耗尽。
  33. /// </summary>
  34. private readonly HttpClient _httpClient;
  35. /// <summary>
  36. /// 配置服务,用于获取设备信息(包含 MES URL、是否启用 MES 等)。
  37. /// </summary>
  38. private readonly IConfigService _configService;
  39. /// <summary>
  40. /// 标记实例是否已释放,防止重复释放和在释放后继续使用导致未定义行为。
  41. /// </summary>
  42. private bool _disposed;
  43. /// <summary>
  44. /// 使用指定的配置服务创建 <see cref="MesService"/> 实例。
  45. /// </summary>
  46. /// <param name="configService">用于获取设备配置信息的实现,不能为空。</param>
  47. /// <exception cref="ArgumentNullException">当 <paramref name="configService"/> 为 null 时抛出。</exception>
  48. public MesService(IConfigService configService, IContainerProvider container, IEventAggregator ea)
  49. {
  50. _configService = configService ?? throw new ArgumentNullException(nameof(configService));
  51. _httpClient = new HttpClient();
  52. _disposed = false;
  53. _eventAggregator = ea;
  54. }
  55. /// <summary>
  56. /// 向配置中指定的 MES 站点 URL 发起 GET 请求(用于过站查询)。
  57. /// </summary>
  58. /// <param name="sn">要查询的序列号(SN)。</param>
  59. /// <param name="cancellationToken">可选的取消令牌,用于请求超时或取消。</param>
  60. /// <returns>
  61. /// 返回元组 (IsSuccess, Response):
  62. /// - IsSuccess: 请求是否视为成功(即 MES 返回了预期的 "SFC_OK" 且包含 "unit_process_check=OK")。
  63. /// - Response: 原始响应文本或错误信息说明(如 "MES功能未启用!"、"Missing MES station URL"、"Canceled" 等)。
  64. /// </returns>
  65. /// <remarks>
  66. /// 行为说明:
  67. /// - 从配置获取设备信息,若 MES 未启用则直接返回 IsSuccess=true 且 Response 为提示文本(不视为错误)。
  68. /// - 若未配置 MES URL 则返回 IsSuccess=false 与错误文本。
  69. /// - 使用配置的 URL(通过 <see cref="string.Format"/> 填充 sn)发起 GET 请求,最多重试 10 次。
  70. /// - 只有当响应包含 "SFC_OK" 且包含 "unit_process_check=OK" 时视为成功并立即返回。
  71. /// - 捕获 <see cref="OperationCanceledException"/> 返回 "Canceled",捕获其它异常则返回异常消息。
  72. /// - 若实例已被释放则抛出 <see cref="ObjectDisposedException"/>。
  73. /// </remarks>
  74. public async Task<(bool IsSuccess, string Response)> StationGetAsync(int deviceNo, string sn, string comp, CancellationToken cancellationToken = default)
  75. {
  76. // 如果已经释放,则抛出异常,防止在已释放资源上继续操作。
  77. if (_disposed) throw new ObjectDisposedException(nameof(MesService));
  78. var device = _configService.GetDeviceInfo();
  79. if (device == null || !device.EnableMES)
  80. {
  81. return (true, "MES功能未启用!");
  82. }
  83. if (string.IsNullOrWhiteSpace(device.MesUrl))
  84. return (false, "Missing MES station URL");
  85. if (device.F == "PTL")
  86. {
  87. if (string.IsNullOrEmpty(device.comp))
  88. {
  89. return (false, "PTL模式下comp不能为空");
  90. }
  91. }
  92. string url = "";
  93. string[] station = new string[3];
  94. string[] fixtureId = new string[3];
  95. station = device.Station.Split(',');
  96. fixtureId = device.FixtureId.Split(',');
  97. try
  98. {
  99. string str = station[deviceNo];
  100. }
  101. catch (Exception ex)
  102. {
  103. return (false, "本机应该有多站,station应该有多个值");
  104. }
  105. if (deviceNo == 0)//组装站
  106. {
  107. if (device.F == "PTL")
  108. {
  109. url = $"{device.MesUrl}?c=QUERY_RECORD&line={device.Line}&station={station[deviceNo]}&fixtureid={fixtureId[deviceNo]}&sn={sn}&comp={device.comp}:{comp}&p=unit_process_check,message,model,sn,wo";
  110. }
  111. else
  112. {
  113. url = $"{device.MesUrl}?c=QUERY_RECORD&line={device.Line}&station={station[deviceNo]}&fixtureid={fixtureId[deviceNo]}&sn={sn}&p=unit_process_check,message,model,sn,wo";
  114. }
  115. }
  116. else//保压站
  117. {
  118. url = $"{device.MesUrl}?c=QUERY_RECORD&line={device.Line}&station={station[deviceNo]}&fixtureid={fixtureId[deviceNo]}&sn={sn}&p=unit_process_check,message,model,sn,wo";
  119. }
  120. LogHelper.WriteLogMes($"【询问URL】{url}");
  121. SendTaskMessage($"【询问URL】{url}", MessageLevel.Info);
  122. (bool IsSuccess, string Response) result = (false, string.Empty);
  123. for (int i = 0; i < 3; i++)
  124. {
  125. try
  126. {
  127. using (var rsp = await _httpClient.GetAsync(url))
  128. {
  129. var text = await rsp.Content.ReadAsStringAsync();
  130. LogHelper.WriteLogMes($"【HTTP接收】{text}");
  131. SendTaskMessage($"【HTTP接收】{text}", MessageLevel.Info);
  132. // "SFC_OK" 代表和 MES 连接成功
  133. if (text.Contains("SFC_OK"))
  134. {
  135. if (text.Contains("message=OK"))
  136. {
  137. return (true, text);
  138. }
  139. }
  140. result = (false, text);
  141. }
  142. }
  143. catch (OperationCanceledException)
  144. {
  145. result = (false, "Canceled");
  146. }
  147. catch (Exception ex)
  148. {
  149. result = (false, ex.Message);
  150. }
  151. }
  152. return result;
  153. }
  154. /// <summary>
  155. /// 向 MES 发起站点查询请求,使用超时(秒)作为便捷重载。
  156. /// </summary>
  157. /// <param name="sn">序列号(SN)。</param>
  158. /// <param name="timeoutInSeconds">请求超时,单位为秒。</param>
  159. /// <returns>与 <see cref="StationGetAsync(string, CancellationToken)"/> 相同的返回语义。</returns>
  160. public async Task<(bool IsSuccess, string Response)> StationGetAsync(int deviceNo, string sn, string comp, double timeoutInSeconds)
  161. {
  162. using (var cts = new CancellationTokenSource(TimeSpan.FromSeconds(timeoutInSeconds)))
  163. {
  164. return await StationGetAsync(deviceNo, sn, comp, cts.Token);
  165. }
  166. }
  167. /// <summary>
  168. /// 向配置中指定的 MES 站点 URL 发起 GET 请求(用于过站查询)。
  169. /// </summary>
  170. /// <param name="sn">要查询的序列号(SN)。</param>
  171. /// <param name="cancellationToken">可选的取消令牌,用于请求超时或取消。</param>
  172. /// <returns>
  173. /// 返回元组 (IsSuccess, Response):
  174. /// - IsSuccess: 请求是否视为成功(即 MES 返回了预期的 "SFC_OK" 且包含 "unit_process_check=OK")。
  175. /// - Response: 原始响应文本或错误信息说明(如 "MES功能未启用!"、"Missing MES station URL"、"Canceled" 等)。
  176. /// </returns>
  177. /// <remarks>
  178. /// 行为说明:
  179. /// - 从配置获取设备信息,若 MES 未启用则直接返回 IsSuccess=true 且 Response 为提示文本(不视为错误)。
  180. /// - 若未配置 MES URL 则返回 IsSuccess=false 与错误文本。
  181. /// - 使用配置的 URL(通过 <see cref="string.Format"/> 填充 sn)发起 GET 请求,最多重试 10 次。
  182. /// - 只有当响应包含 "SFC_OK" 且包含 "unit_process_check=OK" 时视为成功并立即返回。
  183. /// - 捕获 <see cref="OperationCanceledException"/> 返回 "Canceled",捕获其它异常则返回异常消息。
  184. /// - 若实例已被释放则抛出 <see cref="ObjectDisposedException"/>。
  185. /// </remarks>
  186. public async Task<(bool IsSuccess, string Response)> StationGetExAsync(int deviceNo, string sn, string comp, CancellationToken cancellationToken = default)
  187. {
  188. // 如果已经释放,则抛出异常,防止在已释放资源上继续操作。
  189. if (_disposed) throw new ObjectDisposedException(nameof(MesService));
  190. var device = _configService.GetDeviceInfo(deviceNo);
  191. if (device == null)
  192. device = _configService.GetDeviceInfo();
  193. if (device == null || !device.EnableMES)
  194. {
  195. return (true, "MES功能未启用!");
  196. }
  197. if (string.IsNullOrWhiteSpace(device.MesUrl))
  198. return (false, "Missing MES station URL");
  199. string url = "";
  200. url = $"{device.MesUrl}?c=QUERY_RECORD&line={device.Line}&station={device.Station}&fixtureid={device.FixtureId}&sn={sn}&p=message,sn,wo";
  201. LogHelper.WriteLogMes($"【询问URL】{url}");
  202. SendTaskMessage($"【询问URL】{url}", MessageLevel.Info);
  203. (bool IsSuccess, string Response) result = (false, string.Empty);
  204. for (int i = 0; i < 3; i++)
  205. {
  206. try
  207. {
  208. using (var rsp = await _httpClient.GetAsync(url))
  209. {
  210. var text = await rsp.Content.ReadAsStringAsync();
  211. LogHelper.WriteLogMes($"【HTTP接收】{text}");
  212. SendTaskMessage($"【HTTP接收】{text}", MessageLevel.Info);
  213. // "SFC_OK" 代表和 MES 连接成功
  214. if (text.Contains("SFC_OK"))
  215. {
  216. if (text.Contains("message=OK"))
  217. {
  218. return (true, text);
  219. }
  220. }
  221. result = (false, text);
  222. }
  223. }
  224. catch (OperationCanceledException)
  225. {
  226. result = (false, "Canceled");
  227. }
  228. catch (Exception ex)
  229. {
  230. result = (false, ex.Message);
  231. }
  232. }
  233. return result;
  234. }
  235. public async Task<(bool IsSuccess, string Response)> StationGetExAsync(int deviceNo, string sn, string comp, double timeoutInSeconds)
  236. {
  237. using (var cts = new CancellationTokenSource(TimeSpan.FromSeconds(timeoutInSeconds)))
  238. {
  239. return await StationGetExAsync(deviceNo, sn, comp, cts.Token);
  240. }
  241. }
  242. /// <summary>
  243. /// 向配置中指定的 MES 提交 URL 发起 GET 请求(用于提交测试结果/记录)。
  244. /// </summary>
  245. /// <param name="sn">要提交的序列号(SN)。</param>
  246. /// <param name="isSuccess">表示此次记录是否通过(true => PASS,false => FAIL)。</param>
  247. /// <param name="start_time">开始时间,提交时使用 "yyyy-MM-dd HH:mm:ss" 格式。</param>
  248. /// <param name="stop_time">结束时间,提交时使用 "yyyy-MM-dd HH:mm:ss" 格式。</param>
  249. /// <param name="cancellationToken">可选的取消令牌,用于请求超时或取消。</param>
  250. /// <returns>
  251. /// 返回元组 (IsSuccess, Response):
  252. /// - IsSuccess: 提交是否被 MES 视为成功(收到 "SFC_OK" 且响应中无额外多行信息)。
  253. /// - Response: MES 返回文本或错误说明;当 MES 返回 "SFC_OK" 但包含额外多行信息(代表 SN 数据问题)时,IsSuccess 为 false 且 Response 为该文本。
  254. /// </returns>
  255. /// <remarks>
  256. /// 行为说明:
  257. /// - 从配置获取设备信息,若 MES 未启用则直接返回 IsSuccess=true 且 Response 为提示文本(不视为错误)。
  258. /// - 若未配置 MES 提交 URL 则返回 IsSuccess=false 与错误文本。
  259. /// - 使用配置的 URL(通过 <see cref="string.Format"/> 按顺序填充 sn、PASS/FAIL、start_time、stop_time)发起 GET 请求,最多重试 10 次。
  260. /// - 在收到包含 "SFC_OK" 的响应时,如果返回文本包含多行(有附加信息)则视为提交失败并返回该文本,否则视为提交成功。
  261. /// - 捕获 <see cref="OperationCanceledException"/> 返回 "Canceled",捕获其它异常则返回异常消息。
  262. /// - 若实例已被释放则抛出 <see cref="ObjectDisposedException"/>。
  263. /// </remarks>
  264. public async Task<(bool IsSuccess, string Response)> SubmitGetAsync(int deviceNo, string sn, string comp, bool isSuccess, Dictionary<string, string> data, DateTime start_time, DateTime stop_time, CancellationToken cancellationToken = default)
  265. {
  266. // 如果已经释放,则抛出异常,防止在已释放资源上继续操作。
  267. if (_disposed) throw new ObjectDisposedException(nameof(MesService));
  268. var device = _configService.GetDeviceInfo();
  269. if (device == null || !device.EnableMES)
  270. {
  271. return (true, "MES功能未启用!");
  272. }
  273. if (string.IsNullOrWhiteSpace(device.MesUrl))
  274. return (false, "Missing MES submit URL");
  275. if (device.F == "PTL")
  276. {
  277. if (string.IsNullOrEmpty(device.comp))
  278. {
  279. return (false, "PTL模式下comp不能为空");
  280. }
  281. }
  282. string res = isSuccess ? "PASS" : "FAIL";
  283. StringBuilder sb = new StringBuilder();
  284. if (device.F == "PTL")
  285. {
  286. sb.Append($"{device.MesUrl}?c=ADD_RECORD&line={device.Line}&station={device.Station}&fixtureid={device.FixtureId}&sn={sn}&f=PTL&comp={device.comp}:{comp}");
  287. foreach (var item in data)
  288. {
  289. sb.Append($"&{item.Key}={item.Value}");
  290. }
  291. sb.Append($"&result={res}&start_time={start_time.ToString("yyyy-MM-dd HH:mm:ss")}&stop_time={stop_time.ToString("yyyy-MM-dd HH:mm:ss")}");
  292. }
  293. else
  294. {
  295. sb.Append($"{device.MesUrl}?c=ADD_RECORD&line={device.Line}&station={device.Station}&fixtureid={device.FixtureId}&sn={sn}&f=PQC");
  296. foreach (var item in data)
  297. {
  298. sb.Append($"&{item.Key}={item.Value}");
  299. }
  300. sb.Append($"&result={res}&start_time={start_time.ToString("yyyy-MM-dd HH:mm:ss")}&stop_time={stop_time.ToString("yyyy-MM-dd HH:mm:ss")}");
  301. }
  302. string url = sb.ToString();
  303. //if (deviceNo == 0)//组装站
  304. //{
  305. // if (device.F == "PTL")
  306. // {
  307. // url = $"{device.MesUrl}?c=ADD_RECORD&line={device.Line}&station={station[deviceNo]}&fixtureid={fixtureId[deviceNo]}&sn={sn}&f=PTL&comp={device.comp}:{comp}" +
  308. // $"&gap={gap}&assy_pressure={assypress}" +
  309. // $"&result={res}&start_time={start_time.ToString("yyyy-MM-dd HH:mm:ss")}&stop_time={stop_time.ToString("yyyy-MM-dd HH:mm:ss")}";
  310. // }
  311. // else
  312. // {
  313. // url = $"{device.MesUrl}?c=ADD_RECORD&line={device.Line}&station={station[deviceNo]}&fixtureid={fixtureId[deviceNo]}&sn={sn}&f=PQC" +
  314. // $"&gap={gap}&assy_pressure={assypress}" +
  315. // $"&result={res}&start_time={start_time.ToString("yyyy-MM-dd HH:mm:ss")}&stop_time={stop_time.ToString("yyyy-MM-dd HH:mm:ss")}";
  316. // }
  317. //}
  318. //else
  319. //{
  320. // url = $"{device.MesUrl}?c=ADD_RECORD&line={device.Line}&station={station[deviceNo]}&fixtureid={fixtureId[deviceNo]}&sn={sn}&f=PQC" +
  321. // $"&pressure={press}&pressure_time={presstime}" +
  322. // $"&result={res}&start_time={start_time.ToString("yyyy-MM-dd HH:mm:ss")}&stop_time={stop_time.ToString("yyyy-MM-dd HH:mm:ss")}";
  323. //}
  324. LogHelper.WriteLogMes($"【上传URL】{url}");
  325. SendTaskMessage($"【上传URL】{url}", MessageLevel.Info);
  326. (bool IsSuccess, string Response) result = (false, string.Empty);
  327. for (int i = 0; i < 3; i++)
  328. {
  329. try
  330. {
  331. using (var rsp = await _httpClient.GetAsync(url, cancellationToken))
  332. {
  333. var text = await rsp.Content.ReadAsStringAsync();
  334. LogHelper.WriteLogMes($"【HTTP接收】{text}");
  335. SendTaskMessage($"【HTTP接收】{text}", MessageLevel.Info);
  336. // "SFC_OK" 代表和 MES 连接成功
  337. if (text.Contains("SFC_OK"))
  338. {
  339. // 如果有附加信息(多行),代表此 SN 数据有问题,视为失败并返回该文本
  340. if (text.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries).Length > 1)
  341. {
  342. return (false, text);
  343. }
  344. return (true, text);
  345. }
  346. result = (false, text);
  347. }
  348. }
  349. catch (OperationCanceledException)
  350. {
  351. result = (false, "Canceled");
  352. }
  353. catch (Exception ex)
  354. {
  355. result = (false, ex.Message);
  356. }
  357. }
  358. return result;
  359. }
  360. /// <summary>
  361. /// 向 MES 提交请求的超时重载,使用超时(秒)作为便捷参数。
  362. /// </summary>
  363. /// <param name="sn">序列号(SN)。</param>
  364. /// <param name="isSuccess">是否通过(PASS/FAIL)。</param>
  365. /// <param name="start_time">开始时间。</param>
  366. /// <param name="stop_time">结束时间。</param>
  367. /// <param name="timeoutInSeconds">请求超时,单位为秒。</param>
  368. /// <returns>与 <see cref="SubmitGetAsync(string, bool, DateTime, DateTime, CancellationToken)"/> 相同的返回语义。</returns>
  369. public async Task<(bool IsSuccess, string Response)> SubmitGetAsync(int deviceNo, string sn, string comp, bool isSuccess, Dictionary<string, string> data, DateTime start_time, DateTime stop_time, double timeoutInSeconds)
  370. {
  371. using (var cts = new CancellationTokenSource(TimeSpan.FromSeconds(timeoutInSeconds)))
  372. {
  373. return await SubmitGetAsync(deviceNo, sn, comp, isSuccess, data, start_time, stop_time, cts.Token);
  374. }
  375. }
  376. /// <summary>
  377. /// 获取服务器当前时间
  378. /// </summary>
  379. /// <param name="sn"></param>
  380. /// <param name="timeoutInSeconds"></param>
  381. /// <returns></returns>
  382. public async Task<(bool IsSuccess, DateTime Now)> GetServerTimeAsync(int deviceNo, string sn, double timeoutInSeconds)
  383. {
  384. // 如果已经释放,则抛出异常,防止在已释放资源上继续操作。
  385. if (_disposed) throw new ObjectDisposedException(nameof(MesService));
  386. var device = _configService.GetDeviceInfo(deviceNo);
  387. if (device == null)
  388. device = _configService.GetDeviceInfo();
  389. if (device == null || !device.EnableMES)
  390. {
  391. return (true, DateTime.UtcNow);
  392. }
  393. if (string.IsNullOrWhiteSpace(device.MesUrl))
  394. return (false, DateTime.UtcNow);
  395. string url = "";
  396. url = $"{device.MesUrl}?c=QUERY_RECORD&line={device.Line}&station={device.Station}&fixtureid={device.FixtureId}&sn={sn}&p=mes_server_time";
  397. LogHelper.WriteLogMes($"【询问URL】{url}");
  398. SendTaskMessage($"【询问URL】{url}", MessageLevel.Info);
  399. (bool IsSuccess, DateTime Now) result = (false, DateTime.UtcNow);
  400. for (int i = 0; i < 3; i++)
  401. {
  402. try
  403. {
  404. using (var rsp = await _httpClient.GetAsync(url))
  405. {
  406. var text = await rsp.Content.ReadAsStringAsync();
  407. LogHelper.WriteLogMes($"【HTTP接收】{text}");
  408. SendTaskMessage($"【HTTP接收】{text}", MessageLevel.Info);
  409. // "SFC_OK" 代表和 MES 连接成功
  410. if (text.Contains("SFC_OK"))
  411. {
  412. //按照分隔符'/n'分割字符串
  413. string[] lines = text.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
  414. //通过linq查找是否包含"mes_server_time"的行
  415. var timeLine = lines.FirstOrDefault(l => l.Contains("mes_server_time"));
  416. if (timeLine != null)
  417. {
  418. // 提取时间字符串
  419. var timeString = timeLine.Split('=')[1].Trim();
  420. if (DateTime.TryParse(timeString, out DateTime serverTime))
  421. {
  422. return (true, serverTime);
  423. }
  424. }
  425. }
  426. result = (false, DateTime.UtcNow);
  427. }
  428. }
  429. catch (OperationCanceledException)
  430. {
  431. result = (false, DateTime.UtcNow);
  432. }
  433. catch (Exception ex)
  434. {
  435. result = (false, DateTime.UtcNow);
  436. }
  437. }
  438. return result;
  439. }
  440. /// <summary>
  441. /// 释放服务占用的托管资源(当前仅 <see cref="_httpClient"/>)。
  442. /// <para>本方法为幂等操作,重复调用不会产生异常。调用后实例不可再用于发起请求,尝试使用将抛出 <see cref="ObjectDisposedException"/>。</para>
  443. /// </summary>
  444. public void Dispose()
  445. {
  446. if (!_disposed)
  447. {
  448. _httpClient.Dispose();
  449. _disposed = true;
  450. }
  451. }
  452. public void SendTaskMessage(string msg, MessageLevel level)
  453. {
  454. App.Current.Dispatcher.Invoke(() =>
  455. {
  456. _eventAggregator.GetEvent<TaskMessageNotification>().Publish(new Models.MessageStruct() { Message = msg, level = level });
  457. });
  458. }
  459. }
  460. }