| | |
| | | /// </summary> |
| | | //static string _url_root = "ws://localhost:40001"; |
| | | //static string _url_prj = "ws://localhost:8001"; |
| | | static string _url_root = "ws://192.168.201.17:40001"; |
| | | // static string _url_prj = "ws://192.168.201.17:8001"; |
| | | static string _url_prj = "ws://192.168.3.152:8001"; |
| | | |
| | | /// <summary> |
| | | /// æäº¤è°åº¦é¡¹ç® |
| | | /// </summary> |
| | | /// <param name="currentViewPrj"></param> |
| | | /// <param name="cbSuccess"></param> |
| | | /// <param name="cbFail"></param> |
| | | /// <returns></returns> |
| | | public static async Task<string> SubmitPrj(IStation.CalcModel.AnaPrj currentViewPrj) |
| | | { |
| | | if (isDebug) |
| | | { |
| | | return " is isDebug"; |
| | | } |
| | | if (currentViewPrj == null) |
| | | { |
| | | return "currentViewPrj is null"; |
| | | } |
| | | IStation.ZyDto.SubmitPrj dto_prj = new ZyDto.SubmitPrj(); |
| | | |
| | | if (string.IsNullOrEmpty(currentViewPrj.ID)) |
| | | { |
| | | var time = DateTime.Now; |
| | | currentViewPrj.ID = $"{time.Year}{time.Month}{time.Day}{time.Hour}{time.Minute}{time.Second}"; |
| | | } |
| | | dto_prj.schemeID = currentViewPrj.ID; |
| | | 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(); |
| | | await ws.ConnectAsync(new Uri(_url_prj), CancellationToken.None); |
| | | if (ws.State != WebSocketState.Open) |
| | | { |
| | | return "WebSocketState is close"; |
| | | } |
| | | |
| | | var inputJson = JsonHelper.Object2Json(dto_prj); |
| | | var inputBytes = Encoding.UTF8.GetBytes(inputJson); |
| | | IStation.LogHelper.Info(inputJson); |
| | | await ws.SendAsync(new ArraySegment<byte>(inputBytes), WebSocketMessageType.Text, true, CancellationToken.None); |
| | | try |
| | | { |
| | | List<byte> outputBytes = new List<byte>();//å
¨é¨æ¶æ¯å®¹å¨ |
| | | var buffer = new byte[1024 * 4];//ç¼å²åº |
| | | var result = await ws.ReceiveAsync(new ArraySegment<byte>(buffer), CancellationToken.None); //çå¬Socketä¿¡æ¯ |
| | | while (!result.CloseStatus.HasValue) //æ¯å¦å
³é |
| | | { |
| | | if (result.MessageType == WebSocketMessageType.Text)//ææ¬æ¶æ¯ |
| | | { |
| | | outputBytes.AddRange(buffer.Take(result.Count)); |
| | | if (result.EndOfMessage)//æ¶æ¯æ¯å¦å·²æ¥æ¶å®å
¨ |
| | | { |
| | | //åéè¿æ¥çæ¶æ¯ |
| | | string outputJson = Encoding.UTF8.GetString(outputBytes.ToArray(), 0, outputBytes.Count); |
| | | var outPrj = JsonHelper.Json2Object<OutPrj>(outputJson); |
| | | if (outPrj == null) |
| | | return "return is null"; |
| | | if (outPrj.result == 1) |
| | | { |
| | | //cbSuccess.Invoke(outPrj.schemeID); |
| | | } |
| | | else |
| | | { |
| | | return "outPrj result:" + outPrj.result; |
| | | } |
| | | } |
| | | } |
| | | // result = await ws.ReceiveAsync(new ArraySegment<byte>(buffer), CancellationToken.None);//ç»§ç»çå¬Socketä¿¡æ¯ |
| | | } |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | IStation.LogHelper.WriteError("Error:101", ex); |
| | | return "ex:" + ex.Message; |
| | | } |
| | | finally |
| | | { |
| | | try |
| | | { |
| | | //å
³éWebSocket |
| | | await ws.CloseOutputAsync(WebSocketCloseStatus.NormalClosure, "AcknowledgeCloseframe", CancellationToken.None); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | IStation.LogHelper.WriteError("Error:111", ex); |
| | | // return "ex:" + ex.Message; |
| | | } |
| | | ws.Abort(); |
| | | ws.Dispose(); |
| | | } |
| | | return null; |
| | | } |
| | | public static string _url_root = "ws://192.168.201.17:40001"; |
| | | |
| | | |
| | | /// <summary> |