public Replenishment(ShipmentRouter router) : base(60 * 1000, 60 * 1000) { m_router = router; if (!int.TryParse(ConfigurationManager.AppSettings["LostTime"], out lostTime)) { lostTime = 60; } }
protected override void OnStart(string[] args) { string msg = Encoding.UTF8.GetString(CompactResponse.RetOK); LogWrapper.Warn("服务正在启动:" + System.Environment.NewLine + msg); try { m_configFacade.LoadAll(null); m_configFacade.Enable = true; string path = ConfigurationManager.AppSettings["Path"]; string ip = ConfigurationManager.AppSettings["IP"]; int port = int.Parse(ConfigurationManager.AppSettings["RoutePort"]); bool checkSig; bool.TryParse(ConfigurationManager.AppSettings["CheckSig"], out checkSig); string connectionString = ConfigurationManager.AppSettings["OrderDB"]; OrderAccess.Instance.Connect(connectionString); string key = ConfigurationManager.AppSettings["RechargeKey"]; if (string.IsNullOrEmpty(key)) { router = new ShipmentRouter(path, checkSig); } else { router = new ShipmentRouterQY(path, key); } repleni = new Replenishment(router); router.Start(ip, port); repleni.Start(); LogWrapper.Warn("服务启动成功"); } catch (System.Exception ex) { LogWrapper.Error("服务启动失败", ex); } }
protected override void OnStop() { LogWrapper.Warn("服务正在停止"); try { m_configFacade.Enable = false; repleni.Close(); router.Stop(); router = null; LogWrapper.Warn("服务停止成功"); } catch (System.Exception ex) { LogWrapper.Error("服务停止失败", ex); } }