1
czw
2025-07-04 58c1a87f19a96a1d62df382a01ed0dfd36e2f84b
1
6个文件已修改
241 ■■■■■ 已修改文件
HnSx/Build/Project/代码/VS自定义类/AutoThread.cs 77 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
HnSx/Build/Project/代码/界面事件.cs 29 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
HnSx/HnSx.json 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
HnSx/RunTime/Code/集成互联.cs 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
HnSx/Scripts/Custom.json 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
HnSx/Scripts/Script.json 125 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
HnSx/Build/Project/´úÂë/VS×Ô¶¨ÒåÀà/AutoThread.cs
@@ -27,6 +27,8 @@
using NLog.Targets;
using NLog;
using ServiceStack.Messaging.Rcon;
using System.Runtime.ExceptionServices;
using System.Runtime.InteropServices;
namespace GZ.Projects.HnSx
{
@@ -108,7 +110,33 @@
        {
        }
        public void TaskEverythingRun()
        public async void ThreadwebSoc()
        {
            List<object> list = new List<object>();
            //read Alldata from database
            //将数据缓存到内存。
            try
            {
                Thread.Sleep(1000);
                while (true)
                {
                    if (/*list.Count > 0 && */WebSocketClientWithReconnect.GetWebSocketState() == WebSocketState.Open)
                        for (int i = 60000; i < 70000; i++)
                        {
                            Thread.Sleep(1000);
                            Console.WriteLine($"{DateTime.Now.ToString("HH:mm:ss.fff")}>>>GGG{i}");
                            var b = WebSocketClientWithReconnect.Instance?.SendAsync($"He >>GGG{i}").Result;
                            Console.WriteLine("发送完成!!" + b);
                        }
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex.Message, ex);
            }
        }
        public async Task TaskEverythingRun()
        {
            var host = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName());
            foreach (var ip in host.AddressList)
@@ -119,35 +147,8 @@
                    //new HttpServer(ip.ToString()).HttpServerRun();
                    //new TcpServer(ip.ToString());
                    //var server = new EnhancedWebSocketServer($"http://{ip.ToString()}:8809/").StartAsync();
                    var client = new WebSocketClientWithReconnect($"ws://{ip.ToString()}:8809/socket")/*.StartAsync()*/;
                    //Task.Run(async () =>
                    //{
                    client.StartAsync();
                    Task.Run(async () =>
                    {
                        while (true)
                        {
                            for (int i = 0; i < 10000; i++)
                            {
                                Thread.Sleep(1000);
                                Console.WriteLine($"{DateTime.Now.ToString("HH:mm:ss.fff")}>>>Server{i}");
                               await client.SendAsync($"Hello Server{i}!");
                            }
                        }
                    });
                    //Task.Run(async () =>
                    //{
                    //    while (true)
                    //    {
                    //        for (int i = 60000; i < 70000; i++)
                    //        {
                    //            Thread.Sleep(1000);
                    //            Console.WriteLine($"{DateTime.Now.ToString("HH:mm:ss.fff")}>>>GGG{i}");
                    //            await client.SendAsync($"Hello GGG{i}!");
                    //        }
                    //    }
                    //});
                    //});
                    new WebSocketClientWithReconnect($"ws://{ip.ToString()}:8809/socket").StartAsync();
                    break;
                }
            }
@@ -470,7 +471,8 @@
    public class WebSocketClientWithReconnect
    {
        private ClientWebSocket _webSocket;
        public static ClientWebSocket _webSocket;
        private static WebSocketClientWithReconnect _instance;
        private readonly Uri _serverUri;
        private readonly CancellationTokenSource _cts = new CancellationTokenSource();
        private readonly int _reconnectDelayMs;
@@ -485,9 +487,18 @@
            _serverUri = new Uri(serverUrl);
            _reconnectDelayMs = reconnectDelayMs;
        }
        public static WebSocketClientWithReconnect Instance
        {
            get
            {
                return _instance;
            }
        }
        public static WebSocketState GetWebSocketState() => _webSocket != null ? _webSocket.State : WebSocketState.Closed;
        public async Task StartAsync()
        {
            _instance = this;
            while (!_cts.IsCancellationRequested)
            {
                try
@@ -570,7 +581,7 @@
            }
        }
        public async Task SendAsync(string message)
        public async Task<bool> SendAsync(string message)
        {
            if (_webSocket?.State != WebSocketState.Open)
            {
@@ -579,7 +590,7 @@
            var bytes = System.Text.Encoding.UTF8.GetBytes(message);
            await _webSocket.SendAsync(new ArraySegment<byte>(bytes), WebSocketMessageType.Text, true, _cts.Token);
            return true;
        }
    }
HnSx/Build/Project/´úÂë/½çÃæÊ¼þ.cs
@@ -83,6 +83,35 @@
            try
            {
                #region    [脚本][20250704090126015][业务逻辑.Program2]
                        AutoThread.InvokeMethod(AutoThread.Instance, "ThreadwebSoc");
                        #endregion [脚本][20250704090126015][业务逻辑.Program2]
                    }
                    catch (Exception ex)
                    {
                        Conn.log默认日志.Error(ex.ToString());
                    }
                    finally
                    {
                        System.Threading.Thread.Sleep(10000);
                    }
                }
                ExitJudgeStack.TryPop(out int exitJudgeVal);
            });
            /// <summary>
            /// ç¨‹åºç‰‡æ®µ:Program2
            /// æè¿°:
            /// </summary>
            System.Threading.Tasks.Task.Factory.StartNew(() =>
            {
                System.Threading.Thread.CurrentThread.IsBackground = true;
                ExitJudgeStack.Push(0);
                //一直执行,直到满足结束条件
                while (true)
                {
                    if (IsExitApp) { break; }
                    try
                    {
                        #region    [脚本][20250704090126015][业务逻辑.Program2]
                AutoThread.InvokeMethod(AutoThread.Instance, "ThreadSettingInit", new object[] { tag });
                #endregion [脚本][20250704090126015][业务逻辑.Program2]
            }
HnSx/HnSx.json
@@ -9,5 +9,5 @@
  "DevelopVersion": "1.0.6.0",
  "Encode": "1bKKzS3nmbstyerHBqNS0Q==",
  "CreationTime": "0001-01-01 00:00:00",
  "LastWriteTime": "2025-07-04 11:18:35"
  "LastWriteTime": "2025-07-04 14:55:05"
}
HnSx/RunTime/Code/¼¯³É»¥Áª.cs
@@ -28,12 +28,12 @@
    /// </summary>
    public class Conn
    {
        public static GZ.Modular.Log.ILogger é»˜è®¤ä¸šåŠ¡æ—¥å¿— = null;
        public static GZ.Modular.Redis.RedisTagHelper é»˜è®¤Redis = new GZ.Modular.Redis.RedisTagHelper(默认业务日志);
        public static GZ.Modular.Log.ILogger log默认日志 = null;
        public static GZ.Modular.Redis.RedisTagHelper é»˜è®¤Redis = new GZ.Modular.Redis.RedisTagHelper(log默认日志);
        public Conn()
        {
            string[] allKeys = System.Configuration.ConfigurationManager.AppSettings.AllKeys;
        é»˜è®¤ä¸šåŠ¡æ—¥å¿— = new GZ.Modular.Log.NLogger("NLogger",7,"",true,"mongodb://localhost:27017?connectTimeoutMS=3000&socketTimeoutMS=5000","HnSx");
        log默认日志 = new GZ.Modular.Log.NLogger("NLogger",7,"",true,"mongodb://localhost:27017?connectTimeoutMS=3000&socketTimeoutMS=5000","HnSx");
        
        }
    }
HnSx/Scripts/Custom.json
@@ -23,6 +23,6 @@
    }
  ],
  "CreationTime": "2025-07-01 10:23:43",
  "LastWriteTime": "2025-07-04 11:04:09",
  "LastWriteTime": "2025-07-04 14:55:05",
  "HasSaved": true
}
HnSx/Scripts/Script.json
@@ -11,48 +11,9 @@
      "ParentID": "",
      "Children": [
        {
          "ID": "20250701110610426",
          "Name": "Program1",
          "Desc": "",
          "Content": "AutoThread.InvokeMethod(AutoThread.Instance, \"TaskEverythingRun\");",
          "ContentCopy": "AutoThread.InvokeMethod(AutoThread.Instance, \"TaskEverythingRun\");",
          "ParentID": "20250701102338326",
          "Children": [],
          "Type": "Program",
          "Property": {
            "SyncExec": "True",
            "RepeatExec": "None",
            "ExceCount": 1,
            "ExceInternal": 3000,
            "StartCondition": {
              "Type": "View",
              "Event": "",
              "Expression": "",
              "Judge": "",
              "Command": {},
              "HmiEvent": {
                "20250704082900797": [
                  "Open"
                ]
              }
            },
            "EndCondition": {
              "Type": "None",
              "Event": "",
              "Expression": "",
              "Judge": "",
              "Command": {},
              "HmiEvent": {}
            }
          },
          "FullName": "业务逻辑.Program1",
          "ParentFullName": "业务逻辑",
          "Enabled": "Enabled"
        },
        {
          "ID": "20250704090126015",
          "Name": "Program2",
          "Desc": "",
          "Name": "初始化配置",
          "Desc": "exec",
          "Content": "AutoThread.InvokeMethod(AutoThread.Instance, \"ThreadSettingInit\", new object[] { tag });",
          "ContentCopy": "AutoThread.InvokeMethod(AutoThread.Instance, \"ThreadSettingInit\", new object[] { tag });",
          "ParentID": "20250701102338326",
@@ -84,7 +45,85 @@
              "HmiEvent": {}
            }
          },
          "FullName": "业务逻辑.Program2",
          "FullName": "业务逻辑.初始化配置",
          "ParentFullName": "业务逻辑",
          "Enabled": "Enabled"
        },
        {
          "ID": "20250701110610426",
          "Name": "启动连接服务",
          "Desc": "比如tcp http å’Œ websocket",
          "Content": "AutoThread.InvokeMethod(AutoThread.Instance, \"TaskEverythingRun\");",
          "ContentCopy": "AutoThread.InvokeMethod(AutoThread.Instance, \"TaskEverythingRun\");",
          "ParentID": "20250701102338326",
          "Children": [],
          "Type": "Program",
          "Property": {
            "SyncExec": "True",
            "RepeatExec": "None",
            "ExceCount": 1,
            "ExceInternal": 3000,
            "StartCondition": {
              "Type": "View",
              "Event": "",
              "Expression": "",
              "Judge": "",
              "Command": {},
              "HmiEvent": {
                "20250704082900797": [
                  "Open"
                ]
              }
            },
            "EndCondition": {
              "Type": "None",
              "Event": "",
              "Expression": "",
              "Judge": "",
              "Command": {},
              "HmiEvent": {}
            }
          },
          "FullName": "业务逻辑.启动连接服务",
          "ParentFullName": "业务逻辑",
          "Enabled": "Enabled"
        },
        {
          "ID": "20250704145122680",
          "Name": "高速扫码分拣模块",
          "Desc": "1",
          "Content": "AutoThread.InvokeMethod(AutoThread.Instance, \"ThreadwebSoc\");",
          "ContentCopy": "AutoThread.InvokeMethod(AutoThread.Instance, \"ThreadwebSoc\");",
          "ParentID": "20250701102338326",
          "Children": [],
          "Type": "Program",
          "Property": {
            "SyncExec": "False",
            "RepeatExec": "Until",
            "ExceCount": 1,
            "ExceInternal": 3000,
            "StartCondition": {
              "Type": "View",
              "Event": "",
              "Expression": "",
              "Judge": "",
              "Command": {},
              "HmiEvent": {
                "20250704082900797": [
                  "Open"
                ]
              }
            },
            "EndCondition": {
              "Type": "None",
              "Event": "",
              "Expression": "",
              "Judge": "",
              "Command": {},
              "HmiEvent": {}
            }
          },
          "FullName": "业务逻辑.高速扫码分拣模块",
          "ParentFullName": "业务逻辑",
          "Enabled": "Enabled"
        }
@@ -153,6 +192,6 @@
    }
  ],
  "CreationTime": "2025-07-01 10:23:38",
  "LastWriteTime": "2025-07-04 11:04:09",
  "LastWriteTime": "2025-07-04 14:55:05",
  "HasSaved": true
}