using HH.WCS.ZhongCeJinTan.api;
|
using HH.WCS.ZhongCeJinTan.core;
|
using HH.WCS.ZhongCeJinTan.device;
|
using HH.WCS.ZhongCeJinTan.process;
|
using HH.WCS.ZhongCeJinTan.util;
|
using HH.WCS.ZhongCeJinTan.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.ZhongCeJinTan.core.Monitor;
|
|
namespace HH.WCS.ZhongCeJinTan
|
{
|
internal class Program
|
{
|
static void Main(string[] args) {
|
|
//string currentProcessName = Process.GetCurrentProcess().ProcessName;
|
//Process[] processes = Process.GetProcessesByName(currentProcessName);
|
//if (processes.Length <= 1)
|
//{
|
// Console.WriteLine("程序正在运行...");
|
// Console.ReadLine();
|
//}
|
//else {
|
// Console.WriteLine("程序已经在运行,无法开启新的实例。");
|
//}
|
|
|
Settings.Init();
|
//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.RunAsLocalService();
|
x.SetDescription("hh");
|
x.SetDisplayName("hh.wms");
|
x.SetServiceName("hh.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.92:8801";//{SettingHelper.port}
|
var url = "http://+:8801";
|
using (WebApp.Start<Startup>(url))
|
{
|
Console.WriteLine("Running on {0}", url);
|
Console.ReadLine();
|
while (true) { }
|
}
|
});
|
}
|
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() {
|
|
//1.0 开启api
|
Startup();
|
//2.0 开启tcp
|
StartTcp();
|
|
List<Task> tasks = new List<Task>();
|
|
|
//添加agv任务推送线程
|
tasks.Add(GetTask(TaskCore.Dispatch));
|
|
//添加wcs出库任务推送线程
|
tasks.Add(GetTask(TaskCore.Dispatch1));
|
|
// 创建任务(根据未执行的作业创建对应任务)
|
tasks.Add(GetTask(Monitor.CreateTask));
|
|
//修改作业状态(根据作业对应任务的状态)
|
tasks.Add(GetTask(Monitor.UpdateWorkState));
|
|
|
|
}
|
public void Stop() { Console.WriteLine("work stopped"); }
|
private Task GetTask(Action action) {
|
var task = Task.Run(() => {
|
while (true) {
|
try {
|
action();
|
}
|
catch (Exception ex) {
|
LogHelper.Error(ex.Message, ex);
|
}
|
Thread.Sleep(3000);
|
}
|
});
|
return task;
|
}
|
}
|
}
|
}
|