PVInfoBridge.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using NEIntelligentControl2.Models.PV;
  2. using NEIntelligentControl2.Service.WebSocket;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace NEIntelligentControl2.Models.Messages
  9. {
  10. /// <summary>
  11. /// 光伏信息
  12. /// </summary>
  13. internal class PVInfoBridge : IMessage
  14. {
  15. public List<string> MessageTypes { get; set; } = new List<string>() { "PVInformation".GetConfiguration() };
  16. public Action<Dictionary<string, PVInfo>> Messaged { get; set; }
  17. public async Task OnMessage(object message)
  18. {
  19. try
  20. {
  21. await Task.Run(onmessage);
  22. }
  23. catch (Exception e)
  24. {
  25. Console.WriteLine($"光伏信息WebSocket数据解析失败:{e.Message}");
  26. }
  27. void onmessage()
  28. {
  29. var ss = message as Dictionary<string, PVInfo>;
  30. if (ss == null) return;
  31. Messaged?.Invoke(ss);
  32. }
  33. }
  34. }
  35. }