StoreSystem.cs
3.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
using log4net;
using Microsoft.Win32;
using OnlineStore.Common;
using OnlineStore.DeviceLibrary;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
namespace KTKSAStoreSystem
{
public partial class StoreSystem : ServiceBase
{
public StoreSystem()
{
InitializeComponent();
}
public static readonly ILog LOGGER = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private KTK_SA_BoxBean store = null;
protected override void OnStart(string[] args)
{
LogUtil.info(LOGGER, "Server OnStart Begin!");
try
{
this.store = SAStoreManager.InitStore();
if (store == null)
{
LogUtil.error(LOGGER, "加载料仓失败");
return;
}
}
catch (Exception ex)
{
LOGGER.Error("启动服务出错:" + ex.ToString());
}
// store.StartRun();
LogUtil.info(LOGGER, "Server OnStart End!");
}
protected override void OnStop()
{
LogUtil.info(LOGGER, "Server OnStop Begin !");
try
{
if (store != null)
{
if (store.storeRunStatus > StoreRunStatus.Wait)
{
store.StopRun();
}
KNDManager.CloseAllDO();
KNDManager.CloseAllConnection();
}
}
catch (Exception ex)
{
LOGGER.Error("关闭服务出错:" + ex.ToString());
}
LogUtil.info(LOGGER, "Server OnStop End !");
}
protected override void OnShutdown()
{
LogUtil.info(LOGGER, "Server OnShutdown Begin !");
base.OnShutdown();
LogUtil.info(LOGGER, "开始停止服务 !");
this.Stop();
LogUtil.info(LOGGER, "Server OnShutdown End !");
}
protected override bool OnPowerEvent(PowerBroadcastStatus powerStatus)
{
//LogUtil.info(LOGGER, "Server OnPowerEvent Begin !");
LogUtil.info(LOGGER, "powerStatus=" + powerStatus);
bool result= base.OnPowerEvent(powerStatus);
if (powerStatus.Equals(PowerBroadcastStatus.Suspend))
{
LogUtil.info(LOGGER, "电源挂起,开始停止服务 !");
this.Stop();
}
return result;
//LogUtil.info(LOGGER, "Server OnPowerEvent End !");
}
////下面是系统注销或关闭事件处理程序,
//private void SystemEvents_SessionEnding(object sender, SessionEndingEventArgs e)
//{
// SessionEndReasons reason = e.Reason;
// switch (reason)
// {
// case SessionEndReasons.Logoff:
// LOGGER.Info("用户正在注销。");
// break;
// case SessionEndReasons.SystemShutdown:
// LOGGER.Info("操作系统正在关闭,停止服务");
// this.Stop();
// break;
// }
//}
}
}