| | |
| | |  |
| | |  |
| | | using IStation.Model; |
| | | using IStation.ZyDto; |
| | | using Microsoft.Ajax.Utilities; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Net.WebSockets; |
| | | using System.Security.Permissions; |
| | | using System.Text; |
| | | using System.Threading; |
| | | using System.Threading.Tasks; |
| | | using IsOpen = IStation.ZyDto.IsOpen; |
| | | using PumpIsopen = IStation.ZyDto.PumpIsopen; |
| | | using PumpTotalelectricity = IStation.ZyDto.PumpTotalelectricity; |
| | | |
| | | namespace IStation |
| | | { |
| | |
| | | /// </summary> |
| | | internal class ZyConnectHelper |
| | | { |
| | | public static bool isDebug = true; |
| | | public static bool isDebug = true ; |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | static string _url_root = "ws://192.168.201.17:40001"; |
| | | |
| | | /// <summary> |
| | | /// æäº¤è°åº¦é¡¹ç® |
| | | /// </summary> |
| | | /// <param name="currentViewPrj"></param> |
| | | /// <param name="cbSuccess"></param> |
| | | /// <param name="cbFail"></param> |
| | | /// <returns></returns> |
| | | public static async Task<bool> SubmitPrj(IStation.CalcModel.AnaPrj currentViewPrj, Action cbSuccess, Action<string> cbFail) |
| | | { |
| | | if (currentViewPrj == null) |
| | | { |
| | | return false; |
| | | } |
| | | IStation.ZyDto.SubmitPrj dto_prj = new ZyDto.SubmitPrj(); |
| | | dto_prj.Day = currentViewPrj.StartTime.ToString("yyyy-MM-dd"); |
| | | dto_prj.Items = new List<ZyDto.SubmitPrjItem>(); |
| | | |
| | | foreach (var bt in currentViewPrj.BlockTimes) |
| | | { |
| | | if (bt.OpenPumpCount == 0) |
| | | continue; |
| | | ZyDto.SubmitPrjItem dto_item = new ZyDto.SubmitPrjItem(); |
| | | dto_item.StartTime = bt.StartTime; |
| | | dto_item.EndTime = bt.EndTime; |
| | | dto_item.OpenPumpCount = bt.OpenPumpCount; |
| | | dto_prj.Items.Add(dto_item); |
| | | } |
| | | |
| | | var ws = new ClientWebSocket(); |
| | | |
| | | try |
| | | { |
| | | await ws.ConnectAsync(new Uri(_url_root), CancellationToken.None); |
| | | if (ws.State != WebSocketState.Open) |
| | | { |
| | | return default; |
| | | } |
| | | var inputJson = JsonHelper.Object2Json(dto_prj); |
| | | var inputBytes = Encoding.UTF8.GetBytes(inputJson); |
| | | await ws.SendAsync(new ArraySegment<byte>(inputBytes), WebSocketMessageType.Text, true, CancellationToken.None); |
| | | //å
³éWebSocket |
| | | await ws.CloseOutputAsync(WebSocketCloseStatus.NormalClosure, "AcknowledgeCloseframe", CancellationToken.None); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | cbFail.Invoke(ex.Message); |
| | | ws.Abort(); ws.Dispose(); |
| | | return false; |
| | | } |
| | | ws.Abort(); |
| | | ws.Dispose(); |
| | | cbSuccess.Invoke(); |
| | | return true; |
| | | } |
| | | |
| | | //static string _url_root = "ws://localhost:40001"; |
| | | //static string _url_prj = "ws://localhost:8001"; |
| | | public static string _url_root = "ws://192.168.201.17:40001"; |
| | | |
| | | |
| | | /// <summary> |
| | |
| | | /// <returns></returns> |
| | | public static async Task<double> GetTotalWaterByTimeRange_In(DateTime startTime, DateTime endTime, string resolution = "300") |
| | | { |
| | | if (isDebug) |
| | | return 0; |
| | | var tagDict = new Dictionary<string, string> |
| | | { |
| | | { "_0402010204012103002", "äºåæ°´1å·æ³µç´¯è®¡æµé" }, |
| | |
| | | /// <returns></returns> |
| | | public static async Task<double> GetTotalWaterByDay_In(DateTime day, string resolution = "300") |
| | | { |
| | | if(isDebug) |
| | | return 125 + new Random().Next(1, 10); |
| | | if (isDebug) |
| | | return 125 + new Random().Next(1, 10); |
| | | |
| | | var tagDict = new Dictionary<string, string> |
| | | { |
| | |
| | | if (r.MonitorRecords == null || !r.MonitorRecords.Any()) |
| | | continue; |
| | | var rrr = r.MonitorRecords.Where(x => x.Value != null).Select(x => x.Value.Value).ToList(); |
| | | //var rrr = (from x in r.MonitorRecords where x.Value != null orderby x select x.Value.Value)?.ToList(); |
| | | if (rrr == null || !rrr.Any()) |
| | | continue; |
| | | |
| | |
| | | /// <param name="endTime">ç»ææ¶é´</param> |
| | | /// <param name="resolution">æ¶é´æ¥é¿,é»è®¤300ç§</param> |
| | | /// <returns></returns> |
| | | public static async Task<double> GetTotalWaterByDay_Out(DateTime day, string resolution = "300") |
| | | public static async Task<double> GetTotalWaterByDay_Out(DateTime dayD, string resolution = "300") |
| | | { |
| | | if (isDebug) |
| | | return 135 + new Random().Next(10); |
| | |
| | | var input = new ZyDto.ScadaDispatchInput |
| | | { |
| | | search = "history", |
| | | starttime = new DateTime(day.Year, day.Month, day.Day, 0, 0, 0).ToString("G"), |
| | | endtime = new DateTime(day.Year, day.Month, day.Day, 23, 59, 59).ToString("G"), |
| | | starttime = new DateTime(dayD.Year, dayD.Month, dayD.Day, 0, 0, 0).ToString("G"), |
| | | endtime = new DateTime(dayD.Year, dayD.Month, dayD.Day, 23, 59, 59).ToString("G"), |
| | | Resolution = resolution, |
| | | taglist = tagDict.Select(x => x.Key).ToArray() |
| | | }; |
| | | |
| | | if (dayD == DateTime.Today) |
| | | { |
| | | input.endtime = DateTime.Now.AddMinutes(-5).ToString("G"); |
| | | } |
| | | double totalWaterSupply = 0; |
| | | var realScadaDataList = await GetRealScadaResult(input); |
| | | if (realScadaDataList != null && realScadaDataList.Any()) |
| | |
| | | var rrr = r.MonitorRecords.Where(x => x.Value != null).Select(x => x.Value.Value).ToList(); |
| | | if (rrr == null || !rrr.Any()) |
| | | continue; |
| | | |
| | | if (double.IsNaN(rrr.Last()) || double.IsNaN(rrr.First())) |
| | | { |
| | | throw new Exception("è·åçæ§æ°æ®å¤±è´¥"); |
| | | } |
| | | |
| | | totalWaterSupply += (rrr.Last() - rrr.First()); |
| | | } |
| | |
| | | /// <param name="endTime">ç»ææ¶é´</param> |
| | | /// <param name="resolution">æ¶é´æ¥é¿,é»è®¤300ç§</param> |
| | | /// <returns></returns> |
| | | public static async Task<List<IStation.ZyDto.MonitorRecord>> GetRealRiverWaterLevel (DateTime startTime, DateTime endTime, string resolution = "300") |
| | | public static async Task<List<IStation.ZyModel.MonitorRecord>> GetRealRiverWaterLevel(DateTime startTime, DateTime endTime, string resolution = "300") |
| | | { |
| | | var tag = "_0402010204089903001"; |
| | | var input = new ScadaDispatchInput |
| | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// è·åæ³µç弿ºæ
åµ |
| | | /// </summary> |
| | | /// <param name="startTime">å¼å§æ¶é´</param> |
| | | /// <param name="endTime">ç»ææ¶é´</param> |
| | | /// <param name="resolution">æ¶é´æ¥é¿,é»è®¤300ç§</param> |
| | | /// <returns></returns> |
| | | public static async Task<List<ZyModel.RealScadaData>> GetPumpOpenStatusBySingleDay(DateTime StartTime, string resolution = "300") |
| | | { |
| | | if (isDebug) |
| | | { |
| | | return null; |
| | | } |
| | | var tagDict = new Dictionary<string, string> |
| | | { |
| | | { "_0402010204012101001", "äºåæ°´1å·æ³µå¼å
³ç¶æ" }, |
| | | { "_0402010204012201001", "äºåæ°´2å·æ³µå¼å
³ç¶æ" }, |
| | | { "_0402010204012301001","äºåæ°´3å·æ³µå¼å
³ç¶æ" }, |
| | | { "_0402010204012401001", "äºåæ°´4å·æ³µå¼å
³ç¶æ" }, |
| | | {" _0402010204012501001", "äºåæ°´5å·æ³µå¼å
³ç¶æ" }, |
| | | }; |
| | | var input = new ScadaDispatchInput |
| | | { |
| | | search = "history", |
| | | starttime = new DateTime(StartTime.Year, StartTime.Month, StartTime.Day, 0, 0, 0).ToString("G"), |
| | | endtime = new DateTime(StartTime.Year, StartTime.Month, StartTime.Day, 23, 59, 59).ToString("G"), |
| | | Resolution = resolution, |
| | | taglist = tagDict.Select(x => x.Key).ToArray() |
| | | }; |
| | | var realScadaDataList = await GetRealScadaResult(input); |
| | | return realScadaDataList; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// è·åææ®µæ¶é´çç¨çµé |
| | | /// </summary> |
| | | /// <param name="StartTime"></param> |
| | | /// <param name="EndTime"></param> |
| | | /// <param name="resolution"></param> |
| | | /// <returns></returns> |
| | | public static async Task<List<ZyModel.RealScadaData>> GetPumpTotalElectricity(DateTime StartTime, DateTime EndTime, string resolution = "300") |
| | | { |
| | | var tagDict = new Dictionary<string, string> |
| | | { |
| | | { "_0402010204040193046", "äºåæ°´1å·æ³µæåçµè½" }, |
| | | { "_0402010204040193047", "äºåæ°´2å·æ³µæåçµè½" }, |
| | | { "_0402010204012308007", "äºåæ°´3å·æ³µæåçµè½" }, |
| | | { "_0402010204012408007", "äºåæ°´4å·æ³µæåçµè½" }, |
| | | {" _0402010204012508007", "äºåæ°´5å·æ³µæåçµè½" }, |
| | | }; |
| | | var input = new ScadaDispatchInput |
| | | { |
| | | search = "history", |
| | | starttime = new DateTime(StartTime.Year, StartTime.Month, StartTime.Day, 0, 0, 0).ToString("G"), |
| | | endtime = new DateTime(EndTime.Year, EndTime.Month, EndTime.Day, 23, 59, 59).ToString("G"), |
| | | Resolution = resolution, |
| | | taglist = tagDict.Select(x => x.Key).ToArray() |
| | | }; |
| | | var realScadaDataList = await GetRealScadaResult(input); |
| | | return realScadaDataList; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// è·å宿¶æ°æ®åå
¸ |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public static async Task<List<RealScadaRecord>> GetRealScadaResult(List<string> tags, object input) |
| | | public static async Task<List<ZyModel.RealScadaRecord>> GetRealScadaResult(List<string> tags, object input) |
| | | { |
| | | if (tags == null || !tags.Any()) |
| | | return default; |
| | |
| | | return default; |
| | | } |
| | | |
| | | var realScadaRecordList = new List<RealScadaRecord>(); |
| | | var realScadaRecordList = new List<ZyModel.RealScadaRecord>(); |
| | | var inputJson = JsonHelper.Object2Json(input); |
| | | var inputBytes = Encoding.UTF8.GetBytes(inputJson); |
| | | await ws.SendAsync(new ArraySegment<byte>(inputBytes), WebSocketMessageType.Text, true, CancellationToken.None); |
| | |
| | | var tag = dict.Value.keys.Trim(); |
| | | if (tags.Contains(tag)) |
| | | { |
| | | var data = new RealScadaRecord(); |
| | | var data = new ZyModel.RealScadaRecord(); |
| | | data.TagName = tag; |
| | | |
| | | if (double.TryParse(dict.Value.vals, out double value)) |
| | |
| | | /// è·å宿¶æ°æ®åå
¸ |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public static async Task<List<RealScadaData>> GetRealScadaResult(ScadaDispatchInput input) |
| | | public static async Task<List<ZyModel.RealScadaData>> GetRealScadaResult(ScadaDispatchInput input) |
| | | { |
| | | if (input == null) |
| | | return default; |
| | |
| | | { |
| | | return default; |
| | | } |
| | | |
| | | var realScadaDataList = new List<RealScadaData>(); |
| | | var realScadaDataList = new List<ZyModel.RealScadaData>(); |
| | | var inputJson = JsonHelper.Object2Json(input); |
| | | var inputBytes = Encoding.UTF8.GetBytes(inputJson); |
| | | await ws.SendAsync(new ArraySegment<byte>(inputBytes), WebSocketMessageType.Text, true, CancellationToken.None); |
| | |
| | | { |
| | | foreach (var dict in scadaDict) |
| | | { |
| | | var data = new RealScadaData(); |
| | | var data = new ZyModel.RealScadaData(); |
| | | data.TagName = dict.Key; |
| | | data.MonitorRecords = new List<IStation.ZyDto.MonitorRecord>(); |
| | | data.MonitorRecords = new List<IStation.ZyModel.MonitorRecord>(); |
| | | foreach (var item in dict.Value) |
| | | { |
| | | var record = new IStation.ZyDto.MonitorRecord(); |
| | | var record = new IStation.ZyModel.MonitorRecord(); |
| | | record.Time = item.Key; |
| | | if (double.TryParse(item.Value, out double value)) |
| | | { |
| | |
| | | } |
| | | realScadaDataList.Add(data); |
| | | } |
| | | |
| | | } |
| | | break; |
| | | } |
| | |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// Test1 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public static async Task<double> async_debug() |
| | | { |
| | | //var ws = new ClientWebSocket(); |
| | | // await ws.ConnectAsync(new Uri(_url_root), CancellationToken.None); |
| | | await Task.Run(() => |
| | | { |
| | | Thread.Sleep(1000); |
| | | }); |
| | | |
| | | return 1; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// |
| | |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | public class RealScadaData |
| | | { |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | public string TagName { get; set; } |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | public List<IStation.ZyDto.MonitorRecord> MonitorRecords { get; set; } |
| | | } |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | public class RealScadaRecord |
| | | { |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | public string TagName { get; set; } |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | public double Value { get; set; } |
| | | } |
| | | |
| | | } |
| | | } |