📄 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()
{
// 该调用是 Windows.Forms 组件设计器所必需的。
InitializeComponent();
this.InitCenter();
}
// 进程的主入口点
static void Main()
{
System.ServiceProcess.ServiceBase[] ServicesToRun;
// 同一进程中可以运行多个用户服务。若要将
// 另一个服务添加到此进程,请更改下一行
// 以创建另一个服务对象。例如,
//
// ServicesToRun = New System.ServiceProcess.ServiceBase[] {new Service1(), new MySecondUserService()};
//
ServicesToRun = new System.ServiceProcess.ServiceBase[] { new CenterService() };
System.ServiceProcess.ServiceBase.Run(ServicesToRun);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器
/// 修改此方法的内容。
/// </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>
/// 设置具体的操作,以便服务可以执行它的工作。
/// </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>
/// 继续服务
/// </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 线程关闭、挂起、继续
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 + -