天津投入产出系统后端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

93 lines
3.4 KiB

using System;
using System.Threading;
using QMAPP.FJC.BLL.CompleteStatistics;
//using QMAPP.ServicesAgent;
namespace CompleteStatisticsService
{
public class RunCompleteStatistics
{
protected bool DoseRun = false;
private Thread _thread;
//private readonly ServiceAgent _agent = new ServiceAgent();
public void Start()
{
try {
string info = string.Format("完工数量统计服务开始");
QMFrameWork.Log.LogManager.LogHelper.Info(
new QMFrameWork.Log.LogInfo {ClientIP = "localhost", UserName = "admin", Info = info});
//ServiceAgent.Init();
QMFrameWork.Data.DataFactory.Configure(true);
this.DoseRun = true;
this._thread = new Thread(this.Porcess) {IsBackground = true};
this._thread.Start();
}
catch (Exception ex) {
QMFrameWork.Log.LogManager.LogHelper.Error(
new QMFrameWork.Log.LogInfo { ClientIP = "localhost", UserName = "admin", Info = "完工数量统计", ErrorInfo = ex });
throw;
}
}
public void Stop()
{
string info = string.Format("完工数量统计服务停止");
QMFrameWork.Log.LogManager.LogHelper.Info(
new QMFrameWork.Log.LogInfo {ClientIP = "localhost", UserName = "admin", Info = info});
this.DoseRun = false;
}
public void Destroy()
{
string info = string.Format("完工数量统计服务销毁");
QMFrameWork.Log.LogManager.LogHelper.Info(
new QMFrameWork.Log.LogInfo {ClientIP = "localhost", UserName = "admin", Info = info});
try {
if (this._thread != null) {
this._thread.Abort();
this._thread = null;
}
}
catch {
// ignored
}
}
protected virtual void Porcess()
{
while (this.DoseRun) {
try {
this.GenericCompleteStatistics();
}
catch (Exception ex) {
QMFrameWork.Log.LogManager.LogHelper.Error(
new QMFrameWork.Log.LogInfo {ClientIP = "localhost", UserName = "admin", Info = "完工数量统计", ErrorInfo = ex});
}
finally {
Thread.Sleep(30000);
}
}
}
private void GenericCompleteStatistics()
{
CompleteStatisticsBLL bll = new CompleteStatisticsBLL();
int interval = bll.GetRunPeriod();
DateTime lastRunTime = bll.GetLastRunTime();
DateTime judgementTime = lastRunTime.AddMinutes(interval);
if (judgementTime < DateTime.Now)
{
QMFrameWork.Log.LogManager.LogHelper.Info(
new QMFrameWork.Log.LogInfo { ClientIP = "localhost", UserName = "admin", Info = "完工数量统计开始" });
bll.GenericCompleteStatistics(lastRunTime, judgementTime);
QMFrameWork.Log.LogManager.LogHelper.Info(
new QMFrameWork.Log.LogInfo { ClientIP = "localhost", UserName = "admin", Info = "完工数量统计结束" });
}
}
}
}