123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
- using log4net;
- using NEIntelligentControl2.Models.Datas;
- using NEIntelligentControl2.Models.Messages;
- using NEIntelligentControl2.Models.Pages;
- using NEIntelligentControl2.Models.Windturbine;
- using NEIntelligentControl2.Service.WebSocket;
- using NEIntelligentControl2.Views.Matrix;
- using System;
- using System.Collections.Generic;
- using System.Configuration;
- using System.Linq;
- using System.Security.Policy;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- namespace NEIntelligentControl2.Pages.Home
- {
- /// <summary>
- /// 风机AGC融合页面
- /// </summary>
- public partial class PageWindturbineAGC : Page
- {
- private static readonly ILog log = LogManager.GetLogger("File");
- private readonly IPageAction _IPageAction;
- private readonly WEBHelper _WEBHelper;
- private MessageBridge _MessageBridge;// websocket
- private WindturbineInfoBridge _WindturbineInfoBridge;// 风机信息数据桥
- /// <summary>
- /// 矩阵块
- /// </summary>
- private List<WindBlock> _WindBlocks;
- private bool _IsLoaded;
- private string RFDLTag = "";
- private string MBGLTag = "";
- private string SSGLTag = "";
- private string YFDLTag = "";
- private string NFDLTag = "";
- private string LLGLTag = "";
- private string _Url = "";
- public PageWindturbineAGC(IPageAction action, MessageBridge mb, WEBHelper web)
- {
- InitializeComponent();
- _IPageAction = action;
- _MessageBridge = mb;
- _WEBHelper = web;
- _WindturbineInfoBridge = new WindturbineInfoBridge() { Messaged = OnWindturbineMessage };
- _tbtitle1.Text = "信\n友\n一\n线";
- _tbtitle2.Text = "信\n友\n二\n线";
- _tbtitle3.Text = "信\n友\n三\n线";
- _Url = ConfigurationManager.AppSettings["DataServicePathDebug"];
- RFDLTag = ConfigurationManager.AppSettings["RFDLTag"];
- MBGLTag = ConfigurationManager.AppSettings["MBGLTag"];
- SSGLTag = ConfigurationManager.AppSettings["SSGLTag"];
- YFDLTag = ConfigurationManager.AppSettings["YFDLTag"];
- NFDLTag = ConfigurationManager.AppSettings["NFDLTag"];
- LLGLTag = ConfigurationManager.AppSettings["LLGLTag"];
- log.Warn($"日月年发");
- }
- private void OnWindturbineMessage(Dictionary<string, WindturbineInfo> obj)
- {
- if (!_IsLoaded)
- {
- InitWindturbine(obj);
- return;
- }
- Dispatcher.Invoke(() =>
- {
- foreach (var v in _WindBlocks)
- {
- if (!obj.ContainsKey(v.WindturbineId)) continue;
- v.Update(obj[v.WindturbineId]);
- }
- });
- }
- private void InitWindturbine(Dictionary<string, WindturbineInfo> obj)
- {
- if (obj == null || obj.Count == 0) return;
- _IsLoaded = true;
- _WindBlocks = new List<WindBlock>();
- var ls = obj.Values.ToList();
- ls.Sort((x, y) => x.ID - y.ID);
- Dispatcher.Invoke(() =>
- {
- foreach (var v in ls)
- {
- WindBlock bs = new WindBlock(v) { WindturbineId = v.WindturbineId };
- bs.Update(v);
- _WindBlocks.Add(bs);
- if ((v.ID >= 1 && v.ID <= 5) || (v.ID >= 11 && v.ID <= 13))
- {
- pb1.AddWindturbine(bs);
- }
- else if ((v.ID >= 6 && v.ID <= 10) || (v.ID >= 16 && v.ID <= 19))
- {
- pb2.AddWindturbine(bs);
- }
- else
- {
- pb3.AddWindturbine(bs);
- }
- }
- });
- }
- private void Page_Loaded(object sender, RoutedEventArgs e)
- {
- //var page = _IPageAction["Matrix.PageMatrix"];
- //_FrameMatrix.Navigate(page);
- var page2 = _IPageAction["AGC.PageAGC"];
- _FrameAGC.Navigate(page2);
- _MessageBridge.Register(_WindturbineInfoBridge);
- Task.Run(RefresData);
- }
- private async void RefresData()
- {
- string url = $"{_Url}/ts/latest?keys={RFDLTag},{YFDLTag},{NFDLTag}";
- while (true)
- {
- try
- {
- //
- var vs = GetValues(url);
- foreach (var v in vs)
- {
- log.Warn($"日月年发:{v.Value.Value}");
- }
- if (vs == null || vs.Count == 0) continue;
- var ss = GetValuesSingle(SSGLTag);
- log.Warn($"实时:{ss.Value}");
- var mb = GetValuesSingle(MBGLTag);
- log.Warn($"目标:{mb.Value}");
- var ll = GetValuesSingle(LLGLTag);
- log.Warn($"理论:{ll.Value}");
- Dispatcher.Invoke(() =>
- {
- try
- {
- tbps.Text = Math.Round(ss.Value, 2).ToString("0.00");
- tbpc.Text = Math.Round(mb.Value, 2).ToString("0.00");
- tbllgl.Text = Math.Round(ll.Value, 2).ToString("0.00");
- }
- catch (Exception e)
- {
- log.Error($"实时{e.Message}");
- }
- try
- {
- foreach (var v in vs)
- {
- if (v.Key == RFDLTag)
- {
- tbrf.Text = Math.Round(v.Value.Value, 2).ToString("0.00");
- }
- if (v.Key == YFDLTag)
- {
- tbyf.Text = Math.Round(v.Value.Value, 2).ToString("0.00");
- }
- if (v.Key == NFDLTag)
- {
- var nval = v.Value.Value;
- tbly.Text = Math.Round(nval / 50, 2).ToString("0.00");
- tbnf.Text = Math.Round(nval, 2).ToString("0.00");
- }
- }
- var date = DateTime.Parse("2023-2-18");
- var time = (int)(DateTime.Now - date).TotalDays;
- aqts.Text = $"{619 + time} 天";
- }
- catch (Exception e)
- {
- log.Error($"日月年发{e.Message}");
- }
- });
- }
- catch (Exception e)
- {
- log.Error($"右下{e.Message}");
- }
- await Task.Delay(1000);
- }
- }
- private Dictionary<string, TsData> GetValues(string url)
- {
- Dictionary<string, TsData> datas = new Dictionary<string, TsData>();
- try
- {
- datas = _WEBHelper.HttpGetJSON<Dictionary<string, TsData>>(url);
- }
- catch { }
- return datas;
- }
- private TsData GetValuesSingle(string key)
- {
- var data = new TsData();
- var url = $"{_Url}/ts/latest?keys={key}";
- try
- {
- var datas = _WEBHelper.HttpGetJSON<Dictionary<string, TsData>>(url);
- if (datas != null && datas.ContainsKey(key))
- {
- return datas[key];
- }
- return data;
- }
- catch { }
- return data;
- }
- }
- }
|