?? monitorinterface.cs
字號:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Threading;
using MonitorSystem.BasicClass;
using MonitorSystem.LogFileModule;
namespace MonitorSystem.MonitorInterface
{
public class InterfaceService : System.ServiceProcess.ServiceBase
{
private InitLogQueue m_queInitLog;
private RecordQueue m_queRecord;
private UploadLogQueue m_queUploadLog;
private DownloadRuleThread m_thrDownloadRule;
private LogToQueueThread m_thrLogToQueue;
private RecordToQueueThread m_thrRecordToQueue;
private RecordParseThread []m_thrRecordParse;
private UploadLogThread m_thrUploadLog;
private NodeCheckThead m_thrNodeCheck;
private LogPrintThread logPrintThread;
private ConfigFile m_CfgFile;
private SystemLog m_SysLog;
private LogFile m_LogFile;
private int ThreadCount = int.Parse(System.Configuration.ConfigurationSettings.AppSettings["MonitorCenter.ReadLog.RecordPraseThreadNum"]);
public static bool[] m_bNodeCheck;
/// <summary>
/// 必需的設計器變量。
/// </summary>
private System.ComponentModel.Container components = null;
public InterfaceService()
{
// 該調用是 Windows.Forms 組件設計器所必需的。
InitializeComponent();
this.InitMonInterface();
}
// 進程的主入口點
static void Main()
{
System.ServiceProcess.ServiceBase[] ServicesToRun;
// 同一進程中可以運行多個用戶服務。若要將
// 另一個服務添加到此進程,請更改下一行
// 以創建另一個服務對象。例如,
//
// ServicesToRun = New System.ServiceProcess.ServiceBase[] {new Service1(), new MySecondUserService()};
//
ServicesToRun = new System.ServiceProcess.ServiceBase[] { new InterfaceService() };
System.ServiceProcess.ServiceBase.Run(ServicesToRun);
}
/// <summary>
/// 設計器支持所需的方法 - 不要使用代碼編輯器
/// 修改此方法的內容。
/// </summary>
private void InitializeComponent()
{
//
// InterfaceService
//
this.CanPauseAndContinue = true;
this.CanShutdown = true;
this.ServiceName = "InterfaceService";
}
/// <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 InitMonInterface()
{
m_SysLog = new SystemLog();
m_CfgFile = new ConfigFile();
while(m_CfgFile.InitSysPath()==-1)
{
Thread.Sleep(60000);
}
// 初始化對象
this.m_LogFile = new LogFile();
this.m_queInitLog = new InitLogQueue();
this.m_queRecord = new RecordQueue();
this.m_queUploadLog = new UploadLogQueue();
// 將m_bNodeCheck的成員初始化為false,如有文件上傳就將相應的m_bNodeCheck[i]置為true
m_bNodeCheck = new bool[m_CfgFile.NodeID.Length];
for(int i=0; i<m_bNodeCheck.Length; i++)
{
m_bNodeCheck[i] = false;
}
}
#region 線程啟動
private void Start()
{
try
{
m_thrDownloadRule = new DownloadRuleThread();
if(m_thrDownloadRule==null)
{
throw new Exception("m_thrDownloadRule failed");
}
m_thrDownloadRule.Init(m_CfgFile);
m_thrDownloadRule.Startup();
m_thrLogToQueue=new LogToQueueThread();
if(m_thrLogToQueue==null)
{
throw new Exception("m_thrLogToQueue failed");
}
m_thrLogToQueue.Init(m_CfgFile,ref m_queInitLog);
m_thrLogToQueue.Startup();
m_thrRecordToQueue = new RecordToQueueThread();
if (m_thrRecordToQueue == null)
{
throw new Exception("m_thrRecordToQueue failed");
}
m_thrRecordToQueue.Init(m_CfgFile,ref m_queInitLog,ref m_queRecord);
m_thrRecordToQueue.Startup();
m_thrRecordParse = new RecordParseThread[ThreadCount];
for(int i=0;i<ThreadCount;i++)
{
m_thrRecordParse[i] = new RecordParseThread();
if (m_thrRecordParse[i] == null)
{
throw new Exception("m_thrRecordParse failed");
}
m_thrRecordParse[i].Init(ref m_queRecord,ref m_queUploadLog,m_CfgFile,ref m_LogFile);
m_thrRecordParse[i].Startup();
}
m_thrUploadLog = new UploadLogThread();
if (m_thrUploadLog == null)
{
throw new Exception("m_thrUploadLog failed");
}
m_thrUploadLog.Init(ref m_queUploadLog,m_CfgFile);
m_thrUploadLog.Startup();
m_thrNodeCheck = new NodeCheckThead();
if (m_thrNodeCheck == null)
{
throw new Exception("m_thrNodeCheck failed");
}
logPrintThread = new LogPrintThread();
if (logPrintThread == null)
{
throw new Exception("logPrintThread failed");
}
logPrintThread.Startup();
m_thrNodeCheck.Init(ref m_queRecord,m_CfgFile);
m_thrNodeCheck.Startup();
}
catch(Exception ex)
{
this.m_SysLog.WriteToSysLog(ex.Message);
this.Stop();
}
}
#endregion
#region 線程關閉、掛起、繼續
private void Stop()
{
try
{
if(m_thrDownloadRule != null)
m_thrDownloadRule.SetExit();
if(m_thrDownloadRule != null)
m_thrDownloadRule.Resume();
if(m_thrDownloadRule != null)
{
if(m_thrDownloadRule.IsAlive())
m_thrDownloadRule.Join();
}
if(m_thrLogToQueue != null)
m_thrLogToQueue.SetExit();
if(m_thrLogToQueue != null)
m_thrLogToQueue.Resume();
if(m_thrLogToQueue != null)
{
if(m_thrLogToQueue.IsAlive())
m_thrLogToQueue.Join();
}
if(m_thrRecordToQueue != null)
m_thrRecordToQueue.SetExit();
if(m_thrRecordToQueue != null)
m_thrRecordToQueue.Resume();
if(m_thrRecordToQueue != null)
{
if(m_thrRecordToQueue.IsAlive())
m_thrRecordToQueue.Join();
}
for(int i=0;i<ThreadCount;i++)
{
if(m_thrRecordParse[i] != null)
m_thrRecordParse[i].SetExit();
if(m_thrRecordParse[i] != null)
m_thrRecordParse[i].Resume();
if(m_thrRecordParse[i] != null)
{
if(m_thrRecordParse[i].IsAlive())
m_thrRecordParse[i].Join();
}
}
if(m_thrUploadLog != null)
m_thrUploadLog.SetExit();
if(m_thrUploadLog != null)
m_thrUploadLog.Resume();
if(m_thrUploadLog != null)
{
if(m_thrUploadLog.IsAlive())
m_thrUploadLog.Join();
}
if(m_thrNodeCheck != null)
m_thrNodeCheck.SetExit();
if(m_thrNodeCheck != null)
m_thrNodeCheck.Resume();
if(m_thrNodeCheck != null)
{
if(m_thrNodeCheck.IsAlive())
m_thrNodeCheck.Join();
}
if(logPrintThread != null)
logPrintThread.SetExit();
if(logPrintThread != null)
logPrintThread.Resume();
if(logPrintThread != null)
{
if(logPrintThread.IsAlive())
logPrintThread.Join();
}
this.m_queInitLog.Clear();
this.m_queRecord.Clear();
this.m_queUploadLog.Clear();
}
catch(Exception ex)
{
m_SysLog.WriteToSysLog(2, ex.Message);
}
}
private void Pause()
{
try
{
m_thrDownloadRule.Suspend();
m_thrLogToQueue.Suspend();
m_thrRecordToQueue.Suspend();
for(int i=0;i<ThreadCount;i++)
{
m_thrRecordParse[i].Suspend();
}
m_thrUploadLog.Suspend();
m_thrNodeCheck.Suspend();
logPrintThread.Suspend();
}
catch(Exception ex)
{
m_SysLog.WriteToSysLog(2, ex.Message);
}
}
private void Resume()
{
try
{
m_thrDownloadRule.Resume();
m_thrLogToQueue.Resume();
m_thrRecordToQueue.Resume();
for(int i=0;i<ThreadCount;i++)
{
m_thrRecordParse[i].Resume();
}
m_thrUploadLog.Resume();
m_thrNodeCheck.Resume();
logPrintThread.Resume();
}
catch(Exception ex)
{
m_SysLog.WriteToSysLog(2, ex.Message);
}
}
#endregion
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -