1
pulg
2025-06-16 6bdde43d71b83885a8261849fa26683937716ad6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
ˆ¤NameÀ¤Userƒ¤Name¬1nvisibleMan¤Icon‚¤GuidÙ$f8cd88b1-1b2f-4fa2-8b36-77a9264dca6e¢Id̅§ServiceÀ«TimeCreated×ÿŠJœÀg¿ºÃ¢Id’Ù$4b7eb4c4-7c03-4aee-9f74-1e5c93b3be46¢IdÙ4Microsoft.VisualStudio.Conversations.Chat.HelpWindow¨Metadata€¨IsThreadðConversationMode°ExperimentalChatªResponders‘ƒ¤Name®GitHub Copilot¤Icon‚¤GuidÙ$4515b9bd-70a1-45fa-9545-d4536417c596¢Id§Service‚¤NameÙ7Microsoft.VisualStudio.Copilot.CopilotChatAgentProvider§Version£0.3’Š­CorrelationIdÙ$7bb4b94c-1be0-4840-80b8-aad1069c024d©MessageIdÙ$c2544384-1083-497f-a96d-26fb0bfe834b§Context‘Œ®ValueContainer”Ù“Microsoft.VisualStudio.Copilot.DocumentContext, Microsoft.VisualStudio.Copilot, Version=17.13.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3aӊ ’Ò…§Contentډ”using HH.WCS.QingXigongchang.api;
using HH.WCS.QingXigongchang.core;
using HH.WCS.QingXigongchang.device;
using HH.WCS.QingXigongchang.process;
using HH.WCS.QingXigongchang.util;
using HH.WCS.QingXigongchang.wms;
using Microsoft.Owin.Hosting;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Net.WebSockets;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Topshelf;
using Monitor = HH.WCS.QingXigongchang.core.Monitor;
 
namespace HH.WCS.QingXigongchang
{
    internal class Program
    {
        #region å…³é—­æŽ§åˆ¶å° å¿«é€Ÿç¼–辑模式、插入模式
        const int STD_INPUT_HANDLE = -10;
        const uint ENABLE_QUICK_EDIT_MODE = 0x0040;
        const uint ENABLE_INSERT_MODE = 0x0020;
        [DllImport("kernel32.dll", SetLastError = true)]
        internal static extern IntPtr GetStdHandle(int hConsoleHandle);
        [DllImport("kernel32.dll", SetLastError = true)]
        internal static extern bool GetConsoleMode(IntPtr hConsoleHandle, out uint mode);
        [DllImport("kernel32.dll", SetLastError = true)]
        internal static extern bool SetConsoleMode(IntPtr hConsoleHandle, uint mode);
 
        public static void DisbleQuickEditMode()
        {
            IntPtr hStdin = GetStdHandle(STD_INPUT_HANDLE);
            uint mode;
            GetConsoleMode(hStdin, out mode);
            mode &= ~ENABLE_QUICK_EDIT_MODE;//移除快速编辑模式
            mode &= ~ENABLE_INSERT_MODE;      //移除插入模式
            SetConsoleMode(hStdin, mode);
        }
        #endregion
        static void Main(string[] args)
        {
            string currentProcessName = Process.GetCurrentProcess().ProcessName;
            Process[] processes = Process.GetProcessesByName(currentProcessName);
            if (processes.Length <= 1)
            {
                LogHelper.Info(">>>>>>>>>>>>>>>>>>> ç¨‹åºå¯åЍ<<<<<<<<<<<<<<<<<<<<<<<<");
            }
            else
            {
                Console.WriteLine("程序已经在运行,无法开启新的实例。");
                return;
            }
            List<int> ints = new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
 
            foreach (var item in ints.GroupBy(x => (x + 1) / 2))
            {
                Console.WriteLine(item.Key + ":::" + JsonConvert.SerializeObject(item.ToList()));
            }
 
            string avvv = "";
            Encoding.UTF8.GetBytes(avvv);
 
            //List<string> strings = new List<string>() { "", "1", "" };
            //byte[] a = new byte[] { };
            //var _b = a.Skip(addr).Take(len).toarray();
 
            //_b.skip(_b.tolist().FindIndex(x => x > 0));
            //var a = Settings.GetDeviceInfoList()[2].taskPri;
 
            //string te = "成品-空托上线xiaoban";
            //var aa=Settings.GetDeviceInfoList();
 
            //    return true;
            //});
            var List = new List<Location>();
 
            List.Add(new Location
            {
                S_LOC_CODE = "1-2",
                N_COL = 2,
                N_ROW = 1,
                N_CURRENT_NUM = 2
            });
 
            List.Add(new Location
            {
                S_LOC_CODE = "1-1",
                N_COL = 1,
                N_ROW = 1,
                N_CURRENT_NUM = 2
            });
 
            List.Add(new Location
            {
                S_LOC_CODE = "3-1",
                N_COL = 1,
                N_ROW = 3,
                N_CURRENT_NUM = 0
            });
 
            List.Add(new Location
            {
                S_LOC_CODE = "2-2",
                N_COL = 2,
                N_ROW = 2,
                N_CURRENT_NUM = 1
            });
 
            List.Add(new Location
            {
                S_LOC_CODE = "2-1",
                N_COL = 1,
                N_ROW = 2,
                N_CURRENT_NUM = 0
            });
 
 
            var bbbc = List.OrderBy(x => x.N_COL).ThenBy(x => x.N_ROW).Skip(List.FindLastIndex(x => x.N_ROW == 3));//.Select(x => new { x.N_ROW, x.N_COL });
            var bbb = List.GroupBy(x => x.N_ROW).OrderBy(x => x.ToList().FindAll(y => y.N_CURRENT_NUM > 0).Count);
            Dictionary<string, int> map = new Dictionary<string, int>();
            map.Add("1-2", -3);
            map.Add("1-3", 3);
            map.Add("1-4", 0);
            map.Add("2-3", 2);
            map.Add("2-4", 1);
            map.Add("3-4", -2);
            var _map = map.OrderBy(x => x.Value);
            var _map2 = map.OrderBy(x => x.Value > 0);
            var _map3 = map.OrderBy(x => x.Value).ThenBy(n => Math.Abs(n.Value)).ToArray();
            var _map4 = map.OrderBy(x => Math.Abs(x.Value)).ThenBy(n => n.Value).ToArray();
            var _map5 = map.OrderBy(x => x.Value >= 0).ThenBy(n => Math.Abs(n.Value)).ToArray();
            //foreach (var item in map)
            {
                //Console.WriteLine(item);
            }
            //var v = new string[] { "QX-04_J", "QX-04_D", "QX04_J", "QX4_X", "QX-12_A", "QX-08_X", "QX-08_XC", "QX-08_DC" };
            //foreach (var item in v)
            //{
            //    var m = System.Text.RegularExpressions.Regex.Matches(item, @"QX-\d+_[A-Z]+");
            //    if (m.Count > 0)
            //        foreach (Match match in m)
            //        {
            //            Console.WriteLine(match.Value);
            //        }
            //}
            Console.WriteLine("");
            //new WmsController().BindLoc3(new { loc = "PPMKCK=1-2", LineNo = "翻斗机", ItemCode = "550mlæ°´_15入_膜包_6" });
            //var b = new List<Location>(List);
            //b.RemoveRange(0, 2);
            //var b = List.OrderBy(x => x.N_CURRENT_NUM).GroupBy(x => x.N_COL);
 
            //var a = TaskHelper.GetAgvTask(new WMSTask { S_TASK_NO = "WW0001" });
            //var æ˜¯ = Settings.GetDoorOneToMany();
 
 
            //SuGGAttribute.attributes = new Dictionary<string, string>();
            #region èŽ·å–è¡¨é…ç½®
            int tableCount = 0;
            LogHelper.Info("开始加载表配置信息");
            try
            {
                var jsonFile = System.AppDomain.CurrentDomain.BaseDirectory + "\\TableSetting.json";
                if (!File.Exists(jsonFile))
                {
                    LogHelper.Error("获取json文件失败!原因:这个json文件就不存在,有个屁的值,\n ä½ åŽ»çœ‹çœ‹è¿™ä¸ªè·¯å¾„æœ‰æ²¡æœ‰æ–‡ä»¶â†’:【" + jsonFile + "】", new FileLoadException("没有表配置文件"));
                    Console.ReadKey();
                }
                using (System.IO.StreamReader file = System.IO.File.OpenText(jsonFile))
                {
                    using (JsonTextReader reader = new JsonTextReader(file))
                    {
                        JObject o = (JObject)JToken.ReadFrom(reader);
                        foreach (Newtonsoft.Json.Linq.JProperty keyValue in o.Properties())
                        {
                            string value = keyValue.Value.ToString();
                            if (string.IsNullOrEmpty(value))
                            {
                                LogHelper.Error("【" + keyValue.Name.Trim() + "】" + "表配置表名为空!", new ArgumentException("表名为空"));
                                Console.ReadKey();
                            }
                            SuGGAttribute.attributes.Add(keyValue.Name.Trim(), value);
                            tableCount++;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error("加载表配置文件失败!" + ex.Message, ex);
                Console.ReadKey();
            }
            if (tableCount == 0)
            {
                LogHelper.Error("加载到0个表配置信息。", new Exception("加载表配置文件失败!"));
                Console.ReadKey();
            }
            #endregion
            #region æµ‹è¯•代码区域。 
 
            //LocationHelper.DoAction(db =>
            //{
            //    var S_CNTRS = "FTP2312050001vTP2312050002";
            //    var fulectlist = LocationHelper.GetFuLeTrayCodeList(f => S_CNTRS.Contains(f.trayCode.Trim()));
            //    LogHelper.Info("Fu成品取货" + S_CNTRS + "--<>--" + JsonConvert.SerializeObject(fulectlist));
            //    //foreach (var item in fulectlist)
            //    //{
            //    //    item.SQL_State = "完成";
            //    //    db.Updateable<FuLeTrayCode>(item).UpdateColumns(it => new { it.SQL_State }).ExecuteCommand();
            //    //}
            //    if (fulectlist.Any())
            //        db.Updateable<FuLeTrayCode>(fulectlist).ReSetValue(it => { it.SQL_State = "完成" }).ExecuteCommand();
            //    return true;
            //});
 
            //var l = LocationHelper.GetAllLocList().First();
            //var b = l.S_LOC_CODE;
            //LocationHelper.lOCReSetValue(x => x.S_LOC_CODE == b, lo =>
            //{
            //    lo.S_LOCK_STATE = "出库锁";
            //});
 
            //l = LocationHelper.GetAllLocList().First();
            //b = l.S_LOCK_STATE;
            //LocationHelper.lOCReSetValue(x => x.S_LOC_CODE.Trim() == l.S_LOC_CODE, y =>
            //{
            //    y.N_CURRENT_NUM++;
            //});
            //var c = LocationHelper.GetAllLocList().First();
            //var d = c.N_CURRENT_NUM;
 
 
            //var asasd = Settings.GetInStockCacheList();
            //var locs = LocationHelper.GetAllLocList();
            //var b = locs.OrderBy(x => x.N_COL).ThenBy(x => x.N_ROW).GroupBy(x => x.N_COL).ToList();
            //foreach (var item in b)
            //{
            //    var _collocs = item.ToList();
            //}
            //var l = LocationHelper.GetAllLocList();
            #endregion
 
            //关闭 å¿«é€Ÿç¼–辑、插入模式
            DisbleQuickEditMode();
 
            #region å³äº§ é“å¡‘  éžå³äº§ é“å¡‘
            //Container c_tie = ContainerHelper.GetContainer(x => x.S_CNTR_CODE == "UsNow2347" && x.S_TYPE == "铁筐");
            //if (c_tie == null)
            //{
            //    LocationHelper.DoAction(db =>
            //    {
            //        var res = db.Insertable<Container>(new Container
            //        {
            //            S_CNTR_CODE = "UsNow2347",
            //            S_TYPE = "铁筐",
            //        }).ExecuteCommand() > 0;
            //        return res;
            //    });
            //}
            //c_tie = ContainerHelper.GetContainer(x => x.S_CNTR_CODE == "UsAfter2347" && x.S_TYPE == "塑料筐");
            //if (c_tie == null)
            //{
            //    LocationHelper.DoAction(db =>
            //    {
            //        var res = db.Insertable<Container>(new Container
            //        {
            //            S_CNTR_CODE = "UsAfter2347",
            //            S_TYPE = "塑料筐",
            //        }).ExecuteCommand() > 0;
            //        return res;
            //    });
            //}
            // å³+tmesapn
            #endregion
 
 
            {
 
 
                if (true)
                {
                    Task task = null;
                    var ips = "";
                    var host = Dns.GetHostEntry(Dns.GetHostName());
                    foreach (var ip in host.AddressList)
                    {
                        if (ip.AddressFamily == AddressFamily.InterNetwork)
                        {
                            Console.WriteLine($"ip= {ip.ToString()}");
                            ips = ip.ToString();
                            break;
                        }
                    }
                    if (false)
                        Task.Run(() =>
                        {
                            // è®¾ç½®ç›‘听的端口和地址
                            int port = 8080;
                            string url = $"http://{ips}:" + port + "/";
 
                            // åˆ›å»ºä¸€ä¸ªæ–°çš„ HttpListener
                            HttpListener listener = new HttpListener();
                            listener.Prefixes.Add(url);
 
                            // å¼€å§‹ç›‘听
                            listener.Start();
                            Console.WriteLine("HTTP服务器已启动,监听地址:" + url);
 
                            while (true)
                            {
                                // ç­‰å¾…客户端连接
                                HttpListenerContext context = listener.GetContext();
                                HttpListenerRequest request = context.Request;
                                HttpListenerResponse response = context.Response;
 
                                // è¯»å–请求内容并输出到控制台
                                Stream body = request.InputStream;
                                StreamReader reader = new StreamReader(body, request.ContentEncoding);
                                string content = reader.ReadToEnd();
                                Console.WriteLine("收到请求: " + content + ">" + request.Url);
                                // èŽ·å–è¯·æ±‚çš„æ–‡ä»¶è·¯å¾„
                                string filePath = request.Url.AbsolutePath.Substring(1).ToLower();
                                var file = false;
                                // æ£€æŸ¥è¯·æ±‚的文件类型并返回相应的静态文件
                                if (filePath.EndsWith(".js"))
                                {
                                    file = true;
                                    filePath = Path.Combine("Static", filePath);
                                    //response.ContentType = "text/javascript";
                                }
                                else if (filePath.EndsWith(".css"))
                                {
                                    file = true;
                                    filePath = Path.Combine("Static", filePath);
                                    //response.ContentType = "text/css";
                                }
                                else if (string.IsNullOrEmpty(filePath))
                                {
                                    file = true;
                                    filePath = Path.Combine("Static", "W.html");
                                    response.ContentType = "text/html";
 
                                    // è®¾ç½®å“åº”内容和状态码
                                    //byte[] buffer = File.ReadAllBytes(Path.Combine("Static", "W.html")); ;//
                                    //buffer = System.Text.Encoding.UTF8.GetBytes(File.ReadAllText(Path.Combine("Static", "W.html")));
 
                                    //response.ContentLength64 = buffer.Length;
                                    //response.OutputStream.Write(buffer, 0, buffer.Length);
                                    //response.ContentType = "text/html";
                                    //response.StatusCode = 200;
                                    //response.OutputStream.Close();
                                }
                                else
                                {
                                    response.StatusCode = 404;
                                    var bt = Encoding.UTF8.GetBytes("地址无效!");
                                    response.OutputStream.Write(bt, 0, bt.Length);
                                    response.OutputStream.Close();
                                }
                                //// è¯»å–文件内容并发送给客户端
                                if (file)
                                    try
                                    {
                                        //byte[] buffer = File.ReadAllBytes(filePath);
                                        byte[] buffer = System.Text.Encoding.UTF8.GetBytes(File.ReadAllText(filePath));
                                        response.ContentLength64 = buffer.Length;
                                        response.OutputStream.Write(buffer, 0, buffer.Length);
                                        response.StatusCode = 200;
                                    }
                                    catch (FileNotFoundException ex)
                                    {
                                        response.StatusCode = 404;
                                        response.OutputStream.Write(Encoding.UTF8.GetBytes("文件未找到"), 0, Encoding.UTF8.GetBytes("文件未找到").Length);
                                    }
                                    catch (Exception ex)
                                    {
                                        Console.WriteLine(ex.Message);
                                    }
                                    finally
                                    {
                                        response.OutputStream.Close();
                                    }
                            }
                        });
 
                    //Task.Run(() =>
                    //{
                    var httpListener = new HttpListener();
                    httpListener.Prefixes.Add($"http://{ips}:8181/");
                    httpListener.Start();
                    Console.WriteLine($"Listening on http://{ips}:8181/");
 
                    while (true)
                    {
                        var context = httpListener.GetContext();
                        if (context.Request.IsWebSocketRequest)
                        {
                            ProcessRequest(context);
                        }
                    }
                    //});
                }
                // è¦æ‰§è¡Œçš„ C# ä»£ç å­—符串
                //        string code = @"
                //    int Add(int a, int b, int c)
                //    {
                //        return a + b + c;
                //    }
                //    Add(a, b, c);
                //";
 
                //        // å®šä¹‰å‚æ•°
                //        var gg = new tempClass();
                //        gg.a = 5;
                //        gg.b = 10;
                //        gg.c = 15;
 
                //        try
                //        {
                //            // æ‰§è¡Œä»£ç å¹¶èŽ·å–ç»“æžœ
                //            var result = CSharpScript.Create<int>(code, ScriptOptions.Default, typeof(tempClass)).RunAsync(gg);
                //            result.Wait();
                //            Console.WriteLine($"Result: {result.Result}");
                //        }
                //        catch (CompilationErrorException e)
                //        {
                //            Console.WriteLine("Compilation Errors:");
                //            foreach (var diagnostic in e.Diagnostics)
                //            {
                //                Console.WriteLine($"{diagnostic.Id}: {diagnostic.GetMessage()}");
                //            }
                //        }
                //        catch (Exception e)
                //        {
                //            Console.WriteLine($"Execution Error: {e.Message}");
                //        }
 
                ////string code1 = @"
                ////public class ScriptedClass
                ////{
                ////    public string HelloWorld { get; set; }
                ////    public ScriptedClass()
                ////    {
                ////        HelloWorld = ""Hello Roslyn!"";
                ////    }
 
                ////}";
 
                ////var script = CSharpScript.RunAsync(code1).Result;
 
                ////var result = script.ContinueWithAsync<string>("new ScriptedClass().HelloWorld").Result;
 
                ////Console.WriteLine(result.ReturnValue);
 
                //var loc = new Location
                //{
                //    S_LOC_CODE = "2-1",
                //    N_COL = 1,
                //    N_ROW = 2,
                //    N_CURRENT_NUM = 0
                //};
                //string code = @"int result = 1 + 2; Console.WriteLine(result);if (S_LOC_CODE==""2-1"")return true; else return false;";
                //var options = ScriptOptions.Default.WithImports("System");
                //var script1 = CSharpScript.Create<bool>(code, options, typeof(Location));
                //var v = script1.RunAsync(loc);
                //v.Wait();
                //Console.WriteLine(v.Result.ReturnValue);
                //code = @"int result = 1 + 2; return new tempClass().Good(S_LOC_CODE);";
                //options = ScriptOptions.Default.WithImports("System");
                //var script2 = CSharpScript.Create(code, options.WithReferences(typeof(tempClass).Assembly), typeof(Location));
                //var v2 = script2.RunAsync(loc);
                //v2.Wait();
                //Console.WriteLine(v.Result.ReturnValue);
 
 
 
                //Console.SetWindowSize(120, 36);
                //Console.SetBufferSize(120, 36);
                //Console.Title = "清溪 wcs程序控制总台";
                //Console.CursorVisible = false;
                //Console.SetCursorPosition(0, 0);
                //Console.WriteLine("根目录" + System.Environment.CurrentDirectory);
                //Console.WriteLine("系统目录" + System.Environment.SystemDirectory);
                //Console.WriteLine("该进程的命令行" + System.Environment.CommandLine);
                //Console.WriteLine("获取此本地计算机的 NetBIOS åç§°ã€‚" + System.Environment.MachineName);
                //Console.WriteLine("获取当前计算机上的处理器数" + System.Environment.ProcessorCount);
                //Console.WriteLine("一个包含平台标识符和版本号的对象" + System.Environment.OSVersion);
                //Console.WriteLine("获取为此环境定义的换行字符串。" + System.Environment.NewLine);
                //Console.WriteLine("获取当前登录用户" + System.Environment.UserName);
                //Console.WriteLine("获取一个值,用以指示当前进程是否在用户交互模式中运行" + System.Environment.UserInteractive);
                //Console.WriteLine("获取与当前用户关联的网络域名。" + System.Environment.UserDomainName);
                //Console.WriteLine("获取系统启动后经过的毫秒数" + System.Environment.TickCount);
                //Console.WriteLine("获取当前的堆栈跟踪信息。" + System.Environment.StackTrace);
                //Console.WriteLine(" èŽ·å–æ˜ å°„åˆ°è¿›ç¨‹ä¸Šä¸‹æ–‡çš„ç‰©ç†å†…å­˜é‡ã€‚" + System.Environment.WorkingSet);
                //Console.WriteLine("用于显示公共语言运行时版本的对象" + System.Environment.Version);
                //Console.WriteLine("从当前进程检索环境变量的值" + System.Environment.GetEnvironmentVariable("Path"));
                //Console.WriteLine("从当前进程检索环境变量的值" + System.Environment.GetEnvironmentVariables());
                //Console.WriteLine("从当前进程或者从当前用户或本地计算机的 Windows æ“ä½œç³»ç»Ÿæ³¨å†Œè¡¨é¡¹æ£€ç´¢æ‰€æœ‰çŽ¯å¢ƒå˜é‡ååŠå…¶å€¼" + System.Environment.GetEnvironmentVariables());
                //Console.WriteLine("返回桌面的路径" + System.Environment.GetFolderPath(SpecialFolder.Desktop));
                //Console.SetCursorPosition(0, 0);
 
                //for (int i = 0; i < 15; i++)
                //{
                //    Console.WriteLine(i + "···················································");
                //}
 
                //for (int i = 0; i < 6; i++)
                //{
                //    Console.SetCursorPosition(2, i * 2);
                //    Console.WriteLine("vv");
                //    Thread.Sleep(1000);
                //}
 
            }
            ;
 
 
            //LocationHelper.DoAction(db =>
            //{
            //    //var a = db.Queryable<Location>().Includes(aa => aa.LocCntrRels).Where(x => x.S_LOC_CODE == "PGKQ-03-10").ToList();
 
            //    //var a = db.Queryable
            //ContainerHelper.GetCntrItemRel
 
 
 
 
            //1.0 å¼€å¯api
            Startup();
            //2.0 å¼€å¯tcp
            StartTcp();
 
            LocationHelper.DoAction(db =>
            {
                var c = db.Queryable<CntrItemRel>().Where(a => a.S_CNTR_CODE.Contains("TP" + Settings._TPcc)).OrderByDescending(x => x.T_CREATE).ToList().FirstOrDefault();
 
                LogHelper.Info("托盘初始化1- " + c?.S_CNTR_CODE);
 
                if (c != null)
                {
                    string tp = c.S_CNTR_CODE.Split('v')[0];
                    var t = tp.Split('_')[0];
                    Settings._TPnum = Convert.ToInt32(t.Substring(8));
                }
                LogHelper.Info("托盘初始化2- " + Settings._TPnum);
                return true;
            });
            //3.0 å¼€å¯çº¿ç¨‹
            var rc = HostFactory.Run(x =>
            {
                x.Service<WorkThread>(s =>
                {
                    s.ConstructUsing(name => new WorkThread());
                    s.WhenStarted(tc => tc.Start());
                    s.WhenStopped(tc => tc.Stop());
                });
                x.RunAsLocalSystem();
 
                x.SetDescription("hh");
                x.SetDisplayName("hh.wms");
                x.SetServiceName("hh.wms");
 
            });
 
            var exitCode = (int)Convert.ChangeType(rc, rc.GetTypeCode());
            Environment.ExitCode = exitCode;
        }
 
        private static async void ProcessRequest(HttpListenerContext context)
        {
            var webSocketContext = await context.AcceptWebSocketAsync(null);
            var webSocket = webSocketContext.WebSocket;
 
            while (webSocket.State == WebSocketState.Open)
            {
                var buffer = new ArraySegment<byte>(new byte[1024]);
                var received = await webSocket.ReceiveAsync(buffer, CancellationToken.None);
 
                if (received.MessageType == WebSocketMessageType.Close)
                {
                    await webSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, "", CancellationToken.None);
                }
                else
                {
                    string read = Encoding.UTF8.GetString(buffer.Array).TrimEnd('\0');
                    if (read != "reLoad")
                    {
                        Console.WriteLine("WebSocket Request Received   " + read);
                        await webSocket.SendAsync(new ArraySegment<byte>(Encoding.UTF8.GetBytes("Connection opened")), WebSocketMessageType.Text, true, CancellationToken.None);
                    }
                    else
                    {
                        // Echo the message back to the client                       
                        //await webSocket.SendAsync(new ArraySegment<byte>(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(DeviceProcess.Deviceooo))), WebSocketMessageType.Text, true, CancellationToken.None);
                        if (!DeviceProcess.Deviceooo.Any())
                        {
                            DeviceProcess.Deviceooo.Add("192.168.1.1", new
                            {
                                äº§çº¿å· = "ccc1",
                                å¯Œå‹’产线号 = "plc.FuLeLineNo",
                                è®¾å¤‡å· = new List<string> { "","66"},
                                è®¾å¤‡ç±»åž‹ = "plc.deviceType",
                                è´§ä½ = new List<string> { "","22233"},
                                ä»»åŠ¡æƒé‡ = "plc.taskPri",
                                ä¿¡å· = "3f0010210d0a",
                            });
                            DeviceProcess.Deviceooo.Add("192.168.1.2", new
                            {
                                äº§çº¿å· = "ccc12",
                                å¯Œå‹’产线号 = "plc.FuLeLineNo2",
                                è®¾å¤‡å· = "plc.deviceNo2",
                                è®¾å¤‡ç±»åž‹ = "plc.deviceTyp2e",
                                è´§ä½ = "plc.location2",
                                ä»»åŠ¡æƒé‡ = "plc.taskPri2",
                                ä¿¡å· = "3f0010210d0a",
                            });
                        }
                        await webSocket.SendAsync(new ArraySegment<byte>(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(DeviceProcess.Deviceooo))), WebSocketMessageType.Text, true, CancellationToken.None);
                    }
                }
            }
        }
        private static void Startup()
        {
            Task.Run(() =>
            {
                var url = "http://+:8801";//{SettingHelper.port}
            restart:
                try
                {
                    using (WebApp.Start<Startup>(url))
                    {
                        Console.WriteLine("Running on {0}", url);
                        while (true)
                            Thread.Sleep(int.MaxValue);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                    Thread.Sleep(1000);
                }
                Console.WriteLine("API - ç»ˆæ­¢");
                goto restart;
            });
            //Console.WriteLine("Startup ApiController");
            //Action action = () =>
            //{
            //    var url = "http://+:8801";//{SettingHelper.port}
            //    using (WebApp.Start<Startup>(url))
            //    {
            //        Console.WriteLine("Running on {0}", url);
            //        Console.ReadLine();
            //    }
            //    Console.WriteLine("API - ç»ˆæ­¢");
            //};
            //Task task = Task.Run(action);
            //Action action1 = () =>
            //{
            //    while (true)
            //    {
            //        if (task.IsCanceled || task.IsCompleted || task.IsFaulted)
            //        {
            //            Console.WriteLine("API - çº¿ç¨‹ä¸­æ–­ï¼Œé‡å¯é‡å¯ã€‚");
            //            task = Task.Run(action);
            //        }
            //        Thread.Sleep(1000);
            //    }
            //};
            //Task.Run(action1);
        }
        private static void StartTcp()
        {
            var host = Dns.GetHostEntry(Dns.GetHostName());
            foreach (var ip in host.AddressList)
            {
                if (ip.AddressFamily == AddressFamily.InterNetwork)
                {
                    Console.WriteLine($"ip= {ip.ToString()}");
                    new TcpServer(ip.ToString());
                }
            }
        }
 
        public class WorkThread
        {
            public void Start()
            {
                List<Task> tasks = new List<Task>
                {
                    GetTask(Monitor.A),//计数器  æ¸…除 æŽ§åˆ¶å°
                    //添加任务推送线程
                    GetTask(TaskCore.Dispatch),
 
                    GetTask(TaskCore.ChargeHostAgv),
                    //手动转运
                    GetTask(Monitor.BottleCapAuto2),
                    /// è‡ªåŠ¨è½¬è¿
                    GetTask(Monitor.BottleCapAuto3, 1),
                    //分拣锁排 - æ¸…除  æŽ’空了才解锁。 
                    GetTask(Monitor.BottleCapAuto4),
                    //自动领料 - ä¸Šè¾“送线 
                    GetTask(Monitor.BottleCapAuto5),
                    //空框中转,转拆框
                    GetTask(Monitor.BottleCapAuto6),
                    //出库单批分
                    GetTask(Monitor.BottleCapAuto7),
                    //自动中转
                    GetTask(Monitor.BB7),
 
                    //tasks.Add(GetTask(DeviceProcess.WJGInoutEF));
 
                    /// æ°´ç›–同。  å…¥åº“人工解,  å‡ºå…¥ä»Žå‡ºåº“位转 550 å‡ºå…¥åº“。 5L 
                    /* - - é‡åšç“¶ç›–流程。 ä¸ä½¿ç”¨å…¥åº“了
                    //水盖也入库
                    GetTask(DeviceProcess.TakeNotUsing2WH),
                    GetTask(DeviceProcess.TakeNotUsing2FDJXB),
                    GetTask(DeviceProcess.TakeEmpty2WH),
                    GetTask(DeviceProcess.TakeNotUsing2PGXB)
                    */
                };
 
 
 
                //tasks.Add(GetTask(DeviceProcess.TakeNotUsing2PGJ));/// æ°´ç›–空框, æ— èŒç©ºæ¡†  æ”¾ TakeNotUsing2FDJXB ä¸€èµ·äº†
 
                //上线区   å‡ºåº“满框空了  åŒºæ¡†  - ä»“库先进显出。 åŒåˆ— å…ˆè¿›åŽå‡º
 
                //翻斗机 å–空 é€æ»¡   ï¼ˆå³äº§ å–上线即产满区    éžå³äº§ å–出库满区)
 
                //翻斗机  å–满 ï¼ŒæŒ‰åˆ— ä»Žå³å¾€å·¦å– - 
                //tasks.Add(GetTask(Monitor.TipperAuto));
                //电梯
                //tasks.Add(GetTask(Monitor.ElevatorTask));
                //电梯
                //tasks.Add(GetTask(Monitor.OutGo));
 
                Task.WaitAll(tasks.ToArray());
            }
            public void Stop() { Console.WriteLine("work stopped"); }
            private Task GetTask(Action action, int i = 0)
            {
                var task = Task.Run(() =>
                {
                    while (true)
                    {
                        try
                        {
                            action();
                        }
                        catch (Exception ex)
                        {
                            LogHelper.Error(ex.Message, ex);
                            if (i == 1)
                                Monitor.AutoTurn = 0;
                        }
                        Thread.Sleep(2500);
                    }
                });
                return task;
            }
        }
    }
 
    public class tempClass
    {
        public int a;
        public int b;
 
        public int c { get; set; }
 
        public string Good(string a)
        {
            if (a == "2-1")
                return "oooooooooo";
            return a;
        }
    }
}
¯OriginalContentÀªSelections¨FilePathÙ1E:\!AGIT\WCS\HH.WCS.Mobox\农夫清溪\Program.cs¨Language¢C#¯CopilotTypeName¯DocumentContext¨TypeName‚¤Name¯DocumentContext§IsArray¢Id‘Ù$d3c74391-f447-40ee-944b-2d67b41cf5db¯ProviderMoniker‚¤NameÙ6Microsoft.VisualStudio.Copilot.DocumentContextProvider§Version£0.3¦SourceÙ6Microsoft.VisualStudio.Copilot.DocumentContextProvider¦Member¤file©CanReduceéRequestIdÙ$7bb4b94c-1be0-4840-80b8-aad1069c024d©ReferenceÀ¦Traits’ƒ¯ProviderMoniker‚¤NameÙ9Microsoft.VisualStudio.Copilot.CSharpProjectTraitProvider§Version£0.3£Key¯LanguageVersion¥Valueƒ®ValueContainer”Ù˜Microsoft.VisualStudio.Copilot.LanguageVersionTrait, Microsoft.VisualStudio.Copilot, Version=17.13.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3aÓ‚¨Language¢C#§Version£7.3¯CopilotTypeName¯LanguageVersion¨TypeName‚¤Name¯LanguageVersion§IsArrayƒ¯ProviderMoniker‚¤NameÙ9Microsoft.VisualStudio.Copilot.CSharpProjectTraitProvider§Version£0.3£Key¶CSharpTargetFrameworks¥Valueƒ®ValueContainer”Ù£Microsoft.VisualStudio.Copilot.CSharpTargetFrameworkTrait, Microsoft.VisualStudio.Copilot.Core, Version=17.13.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3aÓ6‚°TargetFrameworks‘¶'.NET Framework 4.6.1'ªIsDocumentïCopilotTypeName¶CSharpTargetFrameworks¨TypeName‚¤Name¶CSharpTargetFrameworks§IsArray«IsEphemeral§Content‘’…¢IdÄYX)F@ 3¹§­-½ªVisibility«Annotations§ContentÙJ远程方在没有完成关闭握手的情况下关闭了 WebSocket è¿žæŽ¥¨Mentions¨Metadata€¦IntentÀ¨GuidanceÀ¥ModelÀ²DirectedResponders©Functions’‰­CorrelationIdÙ$7bb4b94c-1be0-4840-80b8-aad1069c024d©MessageIdÙ$2d95f5de-302d-4c08-b96a-e7d1d136fd0a§Context§Content¨Metadata€©SessionId’Ù$4b7eb4c4-7c03-4aee-9f74-1e5c93b3be46¢IdÙ4Microsoft.VisualStudio.Conversations.Chat.HelpWindow¦Authorƒ¤Name®GitHub Copilot¤Icon‚¤GuidÙ$4515b9bd-70a1-45fa-9545-d4536417c596¢Id§Service‚¤NameÙ7Microsoft.VisualStudio.Copilot.CopilotChatAgentProvider§Version£0.3¦Status©FollowUps