From 785c92f5078cb7aeb05b13f6da627defb6525b36 Mon Sep 17 00:00:00 2001
From: ningshuxia <ningshuxia0927@outlook.com>
Date: 星期三, 20 三月 2024 13:09:40 +0800
Subject: [PATCH] 代码修改

---
 IStation.Application.Core/1-dispatch/1-solution/DispatchSolution_Controller.cs |  176 +++++++++++++++++++++++++++++-----------------------------
 1 files changed, 88 insertions(+), 88 deletions(-)

diff --git a/IStation.Application.Core/1-dispatch/1-solution/DispatchSolution_Controller.cs b/IStation.Application.Core/1-dispatch/1-solution/DispatchSolution_Controller.cs
index 1afd288..88d37b1 100644
--- a/IStation.Application.Core/1-dispatch/1-solution/DispatchSolution_Controller.cs
+++ b/IStation.Application.Core/1-dispatch/1-solution/DispatchSolution_Controller.cs
@@ -29,103 +29,17 @@
             Log.Debug(flowId, JsonHelper.Object2Json(input));
 
             var scadaInput = GetScadaDispatchInput(DateTime.Now.AddSeconds(300), DateTime.Now);
-            var scadaOutput = await GetRealScada1(flowId, scadaInput);
+            var scadaOutput = await GetRealScada(flowId, scadaInput);
             if (scadaOutput == null || scadaOutput.Scadas == null)
             {
                 Log.Info(flowId, "Scada:鏁版嵁鑾峰彇澶辫触锛岃皟搴︾粓姝�!");
                 throw YOops.Oh(eResultCode.Error, ErrorCodes.L001, "Scada:鏁版嵁鑾峰彇澶辫触锛岃皟搴︾粓姝�!");
             }
 
-
-            return new DispatchSolutionOutput();
+            return TempOutHelper.GetDispatchSolutionOutput(input.FlowId);
         }
 
         private async Task<ScadaDispatchOutput> GetRealScada(string flowId, ScadaDispatchInput input)
-        {
-            if (input == null)
-            {
-                Log.Info(flowId, "ScadaDispatchInput is null");
-                return default;
-            }
-
-            var ws = await CreateAsync("ws://localhost:5102/api/WebSocket/GetNotReadCount");
-            if (ws == null || ws.State != WebSocketState.Open)
-            {
-                Log.Info(flowId, "webSocket:杩炴帴澶辫触!");
-                return default;
-            }
-            Log.Info(flowId, "webSocket:杩炴帴鎴愬姛!");
-
-            ScadaDispatchOutput output = null;
-            var inputJson = JsonHelper.Object2FormatJson(input);
-            Log.Debug(flowId, inputJson);
-            var inputBytes = Encoding.UTF8.GetBytes(inputJson);
-            await ws.SendAsync(inputBytes, WebSocketMessageType.Text, true, CancellationToken.None);
-            try
-            {
-                var buffer = new ArraySegment<byte>(new byte[1024 * 4]);
-                WebSocketReceiveResult result = null;
-                using (var ms = new MemoryStream())
-                {
-                    do
-                    {
-                        result = await ws.ReceiveAsync(buffer, CancellationToken.None);
-                        ms.Write(buffer.Array, buffer.Offset, result.Count);
-                    }
-                    while (!result.EndOfMessage);
-
-                    ms.Seek(0, SeekOrigin.Begin);
-                    if (result.MessageType == WebSocketMessageType.Text && !result.CloseStatus.HasValue)
-                    {
-                        using (var reader = new StreamReader(ms, Encoding.UTF8))
-                        {
-                            string outputJson = reader.ReadToEnd();
-                            output = new ScadaDispatchOutput();
-                            output.Scadas = JsonHelper.Json2Object<Dictionary<string, Dictionary<DateTime, string>>>(outputJson);
-                        }
-                    }
-                }
-            }
-            catch (Exception ex)
-            {
-                Log.Error(flowId, ex.Message);
-            }
-            finally
-            {
-                try
-                {
-                    //鍏抽棴WebSocket
-                    await ws.CloseOutputAsync(WebSocketCloseStatus.NormalClosure, "AcknowledgeCloseframe", CancellationToken.None);
-                }
-                catch (Exception ex)
-                {
-                    Log.Error(flowId, "鍏抽棴WebSocket寮傚父", ex);
-                }
-                ws.Abort();
-                ws.Dispose();
-            }
-
-            return output;
-        }
-
-        /// <summary>
-        /// 鍒涘缓瀹㈡埛绔疄渚�
-        /// </summary> 
-        /// <returns></returns>
-        public static async Task<ClientWebSocket> CreateAsync(string ServerUri)
-        {
-            var webSocket = new ClientWebSocket();
-            webSocket.Options.RemoteCertificateValidationCallback = delegate { return true; };
-
-            await webSocket.ConnectAsync(new Uri(ServerUri), CancellationToken.None);
-            if (webSocket.State == WebSocketState.Open)
-            {
-                return webSocket;
-            }
-            return null;
-        }
-
-        private async Task<ScadaDispatchOutput> GetRealScada1(string flowId, ScadaDispatchInput input)
         {
             if (input == null)
             {
@@ -381,5 +295,91 @@
 
 
 
+        //private async Task<ScadaDispatchOutput> GetRealScada(string flowId, ScadaDispatchInput input)
+        //{
+        //    if (input == null)
+        //    {
+        //        Log.Info(flowId, "ScadaDispatchInput is null");
+        //        return default;
+        //    }
+
+        //    var ws = await CreateAsync("ws://localhost:5102/api/WebSocket/GetNotReadCount");
+        //    if (ws == null || ws.State != WebSocketState.Open)
+        //    {
+        //        Log.Info(flowId, "webSocket:杩炴帴澶辫触!");
+        //        return default;
+        //    }
+        //    Log.Info(flowId, "webSocket:杩炴帴鎴愬姛!");
+
+        //    ScadaDispatchOutput output = null;
+        //    var inputJson = JsonHelper.Object2FormatJson(input);
+        //    Log.Debug(flowId, inputJson);
+        //    var inputBytes = Encoding.UTF8.GetBytes(inputJson);
+        //    await ws.SendAsync(inputBytes, WebSocketMessageType.Text, true, CancellationToken.None);
+        //    try
+        //    {
+        //        var buffer = new ArraySegment<byte>(new byte[1024 * 4]);
+        //        WebSocketReceiveResult result = null;
+        //        using (var ms = new MemoryStream())
+        //        {
+        //            do
+        //            {
+        //                result = await ws.ReceiveAsync(buffer, CancellationToken.None);
+        //                ms.Write(buffer.Array, buffer.Offset, result.Count);
+        //            }
+        //            while (!result.EndOfMessage);
+
+        //            ms.Seek(0, SeekOrigin.Begin);
+        //            if (result.MessageType == WebSocketMessageType.Text && !result.CloseStatus.HasValue)
+        //            {
+        //                using (var reader = new StreamReader(ms, Encoding.UTF8))
+        //                {
+        //                    string outputJson = reader.ReadToEnd();
+        //                    output = new ScadaDispatchOutput();
+        //                    output.Scadas = JsonHelper.Json2Object<Dictionary<string, Dictionary<DateTime, string>>>(outputJson);
+        //                }
+        //            }
+        //        }
+        //    }
+        //    catch (Exception ex)
+        //    {
+        //        Log.Error(flowId, ex.Message);
+        //    }
+        //    finally
+        //    {
+        //        try
+        //        {
+        //            //鍏抽棴WebSocket
+        //            await ws.CloseOutputAsync(WebSocketCloseStatus.NormalClosure, "AcknowledgeCloseframe", CancellationToken.None);
+        //        }
+        //        catch (Exception ex)
+        //        {
+        //            Log.Error(flowId, "鍏抽棴WebSocket寮傚父", ex);
+        //        }
+        //        ws.Abort();
+        //        ws.Dispose();
+        //    }
+
+        //    return output;
+        //}
+
+        ///// <summary>
+        ///// 鍒涘缓瀹㈡埛绔疄渚�
+        ///// </summary> 
+        ///// <returns></returns>
+        //public static async Task<ClientWebSocket> CreateAsync(string ServerUri)
+        //{
+        //    var webSocket = new ClientWebSocket();
+        //    webSocket.Options.RemoteCertificateValidationCallback = delegate { return true; };
+
+        //    await webSocket.ConnectAsync(new Uri(ServerUri), CancellationToken.None);
+        //    if (webSocket.State == WebSocketState.Open)
+        //    {
+        //        return webSocket;
+        //    }
+        //    return null;
+        //}
+
+
     }
 }
\ No newline at end of file

--
Gitblit v1.9.3