New file |
| | |
| | | using HH.WCS.Mobox3.FJJT.api; |
| | | using HH.WCS.Mobox3.FJJT.core; |
| | | using HH.WCS.Mobox3.FJJT.device; |
| | | using HH.WCS.Mobox3.FJJT.process; |
| | | using HH.WCS.Mobox3.FJJT.util; |
| | | using HH.WCS.Mobox3.FJJT.wms; |
| | | using Microsoft.Owin.Hosting; |
| | | using NLog; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Diagnostics; |
| | | using System.Linq; |
| | | using System.Net; |
| | | using System.Net.Sockets; |
| | | using System.Text; |
| | | using System.Threading; |
| | | using System.Threading.Tasks; |
| | | using Topshelf; |
| | | using Monitor = HH.WCS.Mobox3.FJJT.core.Monitor; |
| | | |
| | | namespace HH.WCS.Mobox3.FJJT |
| | | { |
| | | internal class Program |
| | | { |
| | | static void Main(string[] args) { |
| | | |
| | | string currentProcessName = Process.GetCurrentProcess().ProcessName; |
| | | Process[] processes = Process.GetProcessesByName(currentProcessName); |
| | | if (processes.Length <= 1) |
| | | { |
| | | Settings.Init(); |
| | | //1.0 开启api |
| | | Startup(); |
| | | //2.0 开启tcp |
| | | StartTcp(); |
| | | //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("hh123"); |
| | | x.SetDisplayName("hh123.wms"); |
| | | x.SetServiceName("hh123.wms"); |
| | | }); |
| | | |
| | | var exitCode = (int)Convert.ChangeType(rc, rc.GetTypeCode()); |
| | | Environment.ExitCode = exitCode; |
| | | } |
| | | } |
| | | |
| | | private static void Startup() { |
| | | Console.WriteLine("Startup ApiController"); |
| | | Task.Run(() => { |
| | | //var url = "http://192.168.1.87:8901";//{SettingHelper.port} |
| | | var url = $"http://+:{Settings.port}";// |
| | | Console.WriteLine(url); |
| | | using (WebApp.Start<Startup>(url)) { |
| | | Console.WriteLine("Running on {0}", url); |
| | | Console.ReadLine(); |
| | | } |
| | | }); |
| | | } |
| | | private static void StartTcp() { |
| | | //new TcpServer("192.168.1.87"); |
| | | 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>(); |
| | | // 添加任务推送线程 |
| | | tasks.Add(GetTask(WCSCore.Dispatch)); |
| | | // 监听成型机叫料任务 |
| | | tasks.Add(GetTask(Monitor.MonitorCXJCallMaterialMesTask)); |
| | | // 监听钢包满料下线任务 |
| | | tasks.Add(GetTask(Monitor.MonitorGBOffLineMesTask)); |
| | | // 监听斜裁出库任务表 |
| | | tasks.Add(GetTask(Monitor.MonitorXcOutTask)); |
| | | // 自动补充空工装任务 |
| | | tasks.Add(GetTask(Monitor.AutoReplenishEmptyPallet)); |
| | | // 监听托盘物料表、物料表,并更新 |
| | | tasks.Add(GetTask(Monitor.MonitorPalletAndMateral)); |
| | | // 定时更新库存中间表 |
| | | tasks.Add(GetTask(Monitor.UpdateInventoryRegularly,60000)); |
| | | // 定时批次状态表 |
| | | tasks.Add(GetTask(Monitor.AutoUpdateBatchStatus, 60000)); |
| | | Task.WaitAll(tasks.ToArray()); |
| | | } |
| | | public void Stop() { Console.WriteLine("work stopped"); } |
| | | private Task GetTask(Action action ,int time = 3000) { |
| | | var task = Task.Run(() => { |
| | | while (true) { |
| | | try { |
| | | action(); |
| | | } |
| | | catch (Exception ex) { |
| | | LogHelper.Error(ex.Message, ex); |
| | | } |
| | | Thread.Sleep(time); |
| | | } |
| | | }); |
| | | return task; |
| | | } |
| | | } |
| | | } |
| | | } |