SuggestionManager.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using NEIntelligentControl2.Models;
  2. using NEIntelligentControl2.Models.Windturbine;
  3. using NEIntelligentControl2.Service.WebSocket;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace NEIntelligentControl2.Service.Windturbine
  10. {
  11. public class SuggestionManager : IMessage
  12. {
  13. public List<string> MessageTypes { get; set; }
  14. private MessageBridge _MessageBridge;
  15. /// <summary>
  16. /// 推荐数量更改
  17. /// </summary>
  18. public Action<int> OnCountChanged { get; set; }
  19. /// <summary>
  20. /// 获得推荐风机
  21. /// </summary>
  22. public Action<List<WindturbineSuggestion>> OnSuggestion { get; set; }
  23. public List<WindturbineSuggestion> WindturbineSuggestions { get; set; }
  24. public SuggestionManager(MessageBridge mb)
  25. {
  26. _MessageBridge = mb;
  27. MessageTypes = new List<string>() { "SubscribeSuggestion".GetConfiguration() };
  28. _MessageBridge.Register(this);
  29. }
  30. public async Task OnMessage(object message)
  31. {
  32. List<WindturbineSuggestion> vals = message as List<WindturbineSuggestion>;
  33. await Task.Run(() =>
  34. {
  35. if (vals == null) return;
  36. WindturbineSuggestions = vals;
  37. OnCountChanged?.Invoke(vals.Count);
  38. OnSuggestion?.Invoke(vals);
  39. });
  40. }
  41. }
  42. }