⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 downloadrulethread.cs

📁 监控系统
💻 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 + -