?? scanftpthread.cs
字號:
using System;
using System.Threading;
using System.IO;
using MonitorSystem.FtpClient;
using MonitorSystem.BasicClass;
namespace MonitorSystem.MonitorCenter
{
/// <summary>
/// ScanFTPThread 的摘要說明。
/// </summary>
public class ScanFTPThread
{
private Thread m_Thread;
private bool m_Pause;
private bool m_Exit;
private FileSystemWatcher FileWatcher;
private static LogFileQueue m_InitLogQueue;
private static ConfigFile m_ConfigFile;
private SystemLog m_SysLog;
private FTPClass ftpClient;
private FTPSite InterftpSite;
private string WatchDir; //設定監控產生LOG文件的目錄
private string WatchFilter; //監控目錄文件過濾器
public void Init(ref LogFileQueue iLogFileQueue, ref ConfigFile iConfigFile)
{
m_InitLogQueue = iLogFileQueue;
m_ConfigFile = iConfigFile;
m_SysLog = new SystemLog();
}
public void Run()
{
try
{
WatchDir = m_ConfigFile.MonitorLogPath ;
if(WatchDir[WatchDir.Length-1]!='\\')
WatchDir+="\\";
WatchFilter = m_ConfigFile.MonitorLogFilter;
FileWatcher = new FileSystemWatcher();
FileWatcher.Path = WatchDir; // 通過配置文件來進行指定
FileWatcher.Filter = WatchFilter;
FileWatcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
| NotifyFilters.FileName | NotifyFilters.DirectoryName;
// 添加事件響應,監控到LOG目錄有新文件產生時,將文件名加入待處理隊列
FileWatcher.Created += new FileSystemEventHandler(OnChanged);
FileWatcher.EnableRaisingEvents = true;
while(true)
{
#region 控制標志
while(m_Pause)
{
try
{
Thread.Sleep(1000);
}
catch(Exception)
{
}
continue;
}
if(m_Exit)
{
break;
}
#endregion
#region 下載SP流量文件
try
{
InterftpSite = new FTPSite();
ftpClient = new FTPClass();
ftpClient.setRemoteHost(m_ConfigFile.InterfaceIP);
ftpClient.setRemotePort(m_ConfigFile.InterfacePort);
ftpClient.setRemoteUser(m_ConfigFile.FtpUser);
ftpClient.setRemotePass(m_ConfigFile.FtpPsw);
ftpClient.setRemotePath(m_ConfigFile.Download_Path);
InterftpSite.FTPControl=ftpClient;
string[] fileList = InterftpSite.GetFileListFromRemote("CNT????????????.txt",m_ConfigFile.Download_Path,0);
foreach(string str in fileList)
{
InterftpSite.DealDownLoadORUpLoadFile(str,m_ConfigFile.MonitorLogPath + "\\bak\\",0,0);
File.Move(m_ConfigFile.MonitorLogPath + "\\bak\\" + str,m_ConfigFile.MonitorLogPath + "\\" + str);
File.Delete(m_ConfigFile.MonitorLogPath + "\\bak\\" + str);
}
}
catch(Exception ex)
{
m_SysLog.WriteToSysLog(ex.Message + ex.StackTrace);
}
finally
{
if(InterftpSite!=null)
{
InterftpSite=null;
}
if(ftpClient!=null)
{
ftpClient.close();
ftpClient=null;
}
}
#endregion
#region 睡眠
try
{
Thread.Sleep(60 * 1000);
}
catch(Exception)
{
}
#endregion
}
}
catch(Exception ex)
{
m_SysLog.WriteToSysLog(ex.Message);
}
}
public static void OnChanged(object source, FileSystemEventArgs e)
{
if(e.ChangeType == WatcherChangeTypes.Created )
{
if(e.Name.ToUpper().StartsWith("MONITOR"))
{
string PlatformID = e.Name.Substring(8,4);
for(int i=0; i<m_ConfigFile.PlatformID.Length; i++)
{
if(m_ConfigFile.PlatformID[i]==Convert.ToInt32(PlatformID))
{
CenterService.m_bPlatformCheck[i] = true;
m_InitLogQueue.Enqueue(e.FullPath);
}
}
}
else
{
m_InitLogQueue.Enqueue(e.FullPath);
}
}
}
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 + -