1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- using NEIntelligentControl2.Models;
- using NEIntelligentControl2.Models.Windturbine;
- using NEIntelligentControl2.Service.WebSocket;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace NEIntelligentControl2.Service.Windturbine
- {
- public class SuggestionManager : IMessage
- {
- public List<string> MessageTypes { get; set; }
- private MessageBridge _MessageBridge;
- /// <summary>
- /// 推荐数量更改
- /// </summary>
- public Action<int> OnCountChanged { get; set; }
- /// <summary>
- /// 获得推荐风机
- /// </summary>
- public Action<List<WindturbineSuggestion>> OnSuggestion { get; set; }
- public List<WindturbineSuggestion> WindturbineSuggestions { get; set; }
- public SuggestionManager(MessageBridge mb)
- {
- _MessageBridge = mb;
- MessageTypes = new List<string>() { "SubscribeSuggestion".GetConfiguration() };
- _MessageBridge.Register(this);
- }
- public async Task OnMessage(object message)
- {
- List<WindturbineSuggestion> vals = message as List<WindturbineSuggestion>;
- await Task.Run(() =>
- {
- if (vals == null) return;
- WindturbineSuggestions = vals;
- OnCountChanged?.Invoke(vals.Count);
- OnSuggestion?.Invoke(vals);
- });
- }
- }
- }
|