?? monitorcenter.cs
字號:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using MonitorSystem.BasicClass;
namespace MonitorSystem.MonitorCenter
{
public class CenterService : System.ServiceProcess.ServiceBase
{
private LogFileQueue m_queLogfile;
private RecordQueue m_queRecord;
private ScanFTPThread m_thrScanftp;
private ReadLogThread m_thrReadLog;
private RecProcThread m_thrRecProc;
private PlatformCheckThread m_thrPlatformCheck;
public static bool[] m_bPlatformCheck;
private SystemLog m_SysLog;
private ConfigFile m_CfgFile;
/// <summary>
/// 必需的設計器變量。
/// </summary>
private System.ComponentModel.Container components = null;
public CenterService()
{
// 該調(diào)用是 Windows.Forms 組件設計器所必需的。
InitializeComponent();
this.InitCenter();
}
// 進程的主入口點
static void Main()
{
System.ServiceProcess.ServiceBase[] ServicesToRun;
// 同一進程中可以運行多個用戶服務。若要將
// 另一個服務添加到此進程,請更改下一行
// 以創(chuàng)建另一個服務對象。例如,
//
// ServicesToRun = New System.ServiceProcess.ServiceBase[] {new Service1(), new MySecondUserService()};
//
ServicesToRun = new System.ServiceProcess.ServiceBase[] { new CenterService() };
System.ServiceProcess.ServiceBase.Run(ServicesToRun);
}
/// <summary>
/// 設計器支持所需的方法 - 不要使用代碼編輯器
/// 修改此方法的內(nèi)容。
/// </summary>
private void InitializeComponent()
{
//
// CenterService
//
this.CanPauseAndContinue = true;
this.CanShutdown = true;
this.ServiceName = "CenterService";
}
/// <summary>
/// 清理所有正在使用的資源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
/// <summary>
/// 設置具體的操作,以便服務可以執(zhí)行它的工作。
/// </summary>
protected override void OnStart(string[] args)
{
this.Start();
}
/// <summary>
/// 停止此服務。
/// </summary>
protected override void OnStop()
{
this.Stop();
}
/// <summary>
/// 暫停此服務
/// </summary>
protected override void OnPause()
{
this.Pause();
}
/// <summary>
/// 繼續(xù)服務
/// </summary>
protected override void OnContinue()
{
this.Resume();
}
protected override void OnShutdown()
{
this.Stop();
}
private void InitCenter()
{
m_SysLog = new SystemLog();
m_CfgFile = new ConfigFile();
m_CfgFile.InitConfigFromFile();
// 初始化待處理日志隊列
m_queLogfile = new LogFileQueue();
// 初始化待處理記錄隊列
m_queRecord = new RecordQueue();
// 將m_bNodeCheck的成員初始化為false,如有文件上傳就將相應的m_bNodeCheck[i]置為true
m_bPlatformCheck = new bool[m_CfgFile.PlatformID.Length];
for(int i=0; i<m_bPlatformCheck.Length; i++)
{
m_bPlatformCheck[i] = false;
}
}
#region 線程啟動
private void Start()
{
try
{
m_thrScanftp = new ScanFTPThread();
if (m_thrScanftp == null)
{
throw new Exception("m_thrScanftp failed");
}
m_thrScanftp.Init(ref m_queLogfile,ref m_CfgFile);
m_thrScanftp.Startup();
m_thrReadLog = new ReadLogThread();
if (m_thrReadLog == null)
{
throw new Exception("m_thrReadLog failed");
}
m_thrReadLog.Init(ref m_queLogfile,ref m_queRecord,ref m_CfgFile);
m_thrReadLog.Startup();
m_thrRecProc = new RecProcThread();
if (m_thrRecProc == null)
{
throw new Exception("m_thrRecProc failed");
}
m_thrRecProc.Init(ref m_queRecord,ref m_CfgFile);
m_thrRecProc.Startup();
m_thrPlatformCheck = new PlatformCheckThread();
if (m_thrPlatformCheck == null)
{
throw new Exception("m_thrPlatformCheck failed");
}
m_thrPlatformCheck.Init(ref m_queRecord,m_CfgFile);
m_thrPlatformCheck.Startup();
}
catch(Exception ex)
{
this.m_SysLog.WriteToSysLog(ex.Message);
}
}
#endregion
#region 線程關(guān)閉、掛起、繼續(xù)
private void Stop()
{
if(m_thrScanftp != null)
m_thrScanftp.SetExit();
if(m_thrScanftp != null)
m_thrScanftp.Resume();
if(m_thrScanftp != null)
{
if(m_thrScanftp.IsAlive())
m_thrScanftp.Join();
}
if(m_thrReadLog != null)
m_thrReadLog.SetExit();
if(m_thrReadLog != null)
m_thrReadLog.Resume();
if(m_thrReadLog != null)
{
if(m_thrReadLog.IsAlive())
m_thrReadLog.Join();
}
if(m_thrRecProc != null)
m_thrRecProc.SetExit();
if(m_thrRecProc != null)
m_thrRecProc.Resume();
if(m_thrRecProc != null)
{
if(m_thrRecProc.IsAlive())
m_thrRecProc.Join();
}
if(m_thrPlatformCheck != null)
m_thrPlatformCheck.SetExit();
if(m_thrPlatformCheck != null)
m_thrPlatformCheck.Resume();
if(m_thrPlatformCheck != null)
{
if(m_thrPlatformCheck.IsAlive())
m_thrPlatformCheck.Join();
}
m_queLogfile.Clear();
m_queRecord.Clear();
}
private void Pause()
{
m_thrScanftp.Suspend();
m_thrReadLog.Suspend();
m_thrRecProc.Suspend();
m_thrPlatformCheck.Suspend();
}
private void Resume()
{
m_thrScanftp.Resume();
m_thrReadLog.Resume();
m_thrRecProc.Resume();
m_thrPlatformCheck.Resume();
}
#endregion
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -