?? downloadrulethread.cs
字號:
using System;
using System.Threading;
using MonitorSystem.FtpClient;
using MonitorSystem.BasicClass;
namespace MonitorSystem.MonitorInterface
{
/// <summary>
/// 定時從監控中心下載監控規則文件
/// </summary>
public class DownloadRuleThread
{
private Thread m_Thread;
private bool m_Pause;
private bool m_Exit;
private ConfigFile m_ConfigFile;
private FTPClass Interftp;
private FTPSite InterftpSite;
private SystemLog m_SysLog;
private string NameFormat;
public DownloadRuleThread()
{
m_SysLog = new SystemLog();
m_Pause = false;
m_Exit = false;
}
public void Init(ConfigFile iCfgFile)
{
m_ConfigFile = iCfgFile;
//匹配文件名
string strPlatformID=String.Format("{0:0000}",m_ConfigFile.PlatformID);
NameFormat = m_ConfigFile.RuleFileNameFormat.Replace("XXXX", strPlatformID);
NameFormat = NameFormat.Replace("YYYY","????");
}
public void Run()
{
while(true)
{
while(m_Pause)
{
try
{
Thread.Sleep(1000);
}
catch(Exception)
{
}
continue;
}
if(m_Exit)
{
break;
}
try
{
//設置FTP初始信息
InterftpSite = new FTPSite();
Interftp = new FTPClass();
Interftp.setRemoteHost(m_ConfigFile.CenterIP);
Interftp.setRemotePort(m_ConfigFile.CenterPort);
Interftp.setRemoteUser(m_ConfigFile.CenterFtpUserName);
Interftp.setRemotePass(m_ConfigFile.CenterFtpPsw);
Interftp.setRemotePath(m_ConfigFile.CenterRule_Path);
InterftpSite.FTPControl=Interftp;
string[] Remotefilename = InterftpSite.GetFileListFromRemote(NameFormat,m_ConfigFile.CenterRule_Path,0);
foreach(string Remotefilenamelist in Remotefilename)
{
InterftpSite.DealDownLoadORUpLoadFile(Remotefilenamelist,m_ConfigFile.RuleRemote_Path,0,1);
InterftpSite.DealDownLoadORUpLoadFile(Remotefilenamelist,m_ConfigFile.RuleTemp_Path,0,0);
}
}
catch(Exception ex)
{
string msg = ex.Message;
m_SysLog.WriteToSysLog(msg);
}
finally
{
if(InterftpSite!=null)
{
InterftpSite=null;
}
if(Interftp!=null)
{
Interftp.close();
Interftp=null;
}
}
if(m_Exit)
{
break;
}
try
{
Thread.Sleep(m_ConfigFile.DownloadTimeSpan);
}
catch(Exception)
{
}
}
}
public void Startup()
{
m_Thread = new Thread(new ThreadStart(this.Run));
// Start the thread
m_Pause = false;
m_Exit = false;
m_Thread.Start();
}
public void Join()
{
if(m_Thread != null)
{
m_Thread.Interrupt();
m_Thread.Join();
}
else
{
return;
}
}
public bool IsAlive()
{
if(m_Thread != null)
{
return m_Thread.IsAlive;
}
else
{
return false;
}
}
public void Suspend()
{
if(m_Pause == false)
m_Pause = true;
}
public void Resume()
{
if(m_Pause == true)
m_Pause = false;
}
public void SetExit()
{
if(m_Exit == false)
m_Exit = true;
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -