forked from gpmagvs/VMSystem
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStartup.cs
More file actions
115 lines (103 loc) · 4.4 KB
/
Startup.cs
File metadata and controls
115 lines (103 loc) · 4.4 KB
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
using AGVSystemCommonNet6.Configuration;
using AGVSystemCommonNet6.DATABASE;
using AGVSystemCommonNet6.DATABASE.Helpers;
using AGVSystemCommonNet6.Microservices.AGVS;
using AGVSystemCommonNet6.Notify;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.FileProviders;
using NLog;
using VMSystem.Dispatch.Regions;
using VMSystem.TrafficControl;
using VMSystem.VMS;
namespace VMSystem
{
public static partial class Startup
{
public static void Fuck()
{
Console.WriteLine("Start!");
}
internal static async Task AutoSwitchRunMode()
{
_ = Task.Run(async () =>
{
await Task.Delay(1000);
if (await AGVSSerivces.SYSTEM.IsRunModeQuery())
{
SystemModes.RunModeSwitch(AGVSystemCommonNet6.AGVDispatch.RunMode.RUN_MODE.RUN, out string msg);
}
});
}
internal static void ConfigurationInit(Logger? logger = null)
{
WebApplicationBuilder builder = WebApplication.CreateBuilder();
string testAppsettingJsonFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "appsettings.Test.json");
builder.Configuration.AddJsonFile(testAppsettingJsonFilePath, optional: true, true);//嘗試注入測試用
string configRootFolder = builder.Configuration.GetValue<string>("AGVSConfigFolder");
configRootFolder = string.IsNullOrEmpty(configRootFolder) ? @"C:\AGVS" : configRootFolder;
logger?.Debug($"派車系統參數檔資料夾路徑={configRootFolder}");
AGVSConfigulator.Init(configRootFolder);
PartsAGVSHelper.LoadParameters(Path.Combine(configRootFolder, "PartConnection.json"));
string chargeConfigFilePath = Path.Combine(configRootFolder, $"ChargeConfiguration.json");
}
internal static async void DBInit(WebApplicationBuilder builder, WebApplication app)
{
try
{
//AGVSDatabase.Initialize().GetAwaiter().GetResult();
using AGVSDatabase database = new AGVSDatabase();
var queingTasks = database.tables.Tasks.Where(task => task.State == AGVSystemCommonNet6.AGVDispatch.Messages.TASK_RUN_STATUS.NAVIGATING ||
task.State == AGVSystemCommonNet6.AGVDispatch.Messages.TASK_RUN_STATUS.WAIT).ToList();
foreach (var _task in queingTasks)
{
_task.State = AGVSystemCommonNet6.AGVDispatch.Messages.TASK_RUN_STATUS.FAILURE;
_task.FailureReason = "系統重啟刪除任務";
_task.FinishTime = System.DateTime.Now;
}
await database.SaveChanges();
}
catch (Exception ex)
{
Console.WriteLine($"資料庫初始化異常-請確認資料庫! {ex.Message}");
Environment.Exit(4);
}
}
internal static void StaticFileInit(WebApplication app)
{
}
internal static void VMSInit()
{
StaMap.Download();
TrafficControlCenter.Initialize();
RegionManager.Initialze();
NotifyServiceHelper.OnMessage += NotifyServiceHelper_OnMessage;
}
private static void NotifyServiceHelper_OnMessage(object? sender, NotifyServiceHelper.NotifyMessage notifyMessage)
{
Logger _logger = LogManager.GetLogger("NotifierLog");
Task.Run(() =>
{
string msg = notifyMessage.message;
switch (notifyMessage.type)
{
case NotifyServiceHelper.NotifyMessage.NOTIFY_TYPE.info:
_logger.Info(msg);
break;
case NotifyServiceHelper.NotifyMessage.NOTIFY_TYPE.warning:
_logger.Warn(msg);
break;
case NotifyServiceHelper.NotifyMessage.NOTIFY_TYPE.error:
_logger.Error(msg);
break;
case NotifyServiceHelper.NotifyMessage.NOTIFY_TYPE.success:
_logger.Info(msg);
break;
default:
break;
}
//
});
}
}
}