📄 configfile.cs
字号:
using System;
using System.IO;
using System.Configuration;
using System.Collections.Specialized;
using MonitorSystem.BasicClass;
namespace MonitorSystem.MonitorCenter
{
/// <summary>
/// Summary description for ConfigFile.
/// </summary>
public class ConfigFile
{
/// <summary>
/// SP流量包含的平台ID列表
/// </summary>
public int[] PlatformID;
///<summary>
/// 监控日志文件存放路径,上传路径
///</summary>
public string MonitorLogPath;
///<summary>
/// 规则配置文件(xml)存放路径
///</summary>
public string RuleFilePath;
/// <summary>
/// 规则配置文件(xml)下载路径
/// </summary>
public string RuleFileRemotePath;
/// <summary>
/// 监控日志文件后缀名
/// </summary>
public string MonitorLogFilter;
///<summary>
/// 监控日志文件名格式
///</summary>
public string LogNameFormat;
///<summary>
/// 监控规则文件名格式
///</summary>
public string RuleNameFormat;
/// <summary>
/// 连接数据库MonitorCenter的字符串
/// </summary>
public string ConnectionStr;
/// <summary>
/// 监控日志表名
/// </summary>
public string LogTableName;
/// <summary>
/// 监控执行表名
/// </summary>
public string AlertTableName;
/// <summary>
/// 平台心跳检测间隔时间
/// </summary>
public TimeSpan PlatformCheckTimeSpan;
/// <summary>
/// 解析线程对log文件解析失败后,重试的次数
/// </summary>
public int TryCount;
/// <summary>
/// 对log文件解析失败后,重试的时间间隔
/// </summary>
public TimeSpan TryReadTimeSpan;
/// <summary>
/// SP流量接口IP地址
/// </summary>
public string InterfaceIP;
/// <summary>
/// SP流量接口FTP端口号
/// </summary>
public int InterfacePort;
/// <summary>
/// SP流量接口FTP用户名
/// </summary>
public string FtpUser;
/// <summary>
/// SP流量接口FTP密码
/// </summary>
public string FtpPsw;
/// <summary>
/// SP流量接口文件下载路径
/// </summary>
public string Download_Path;
public SystemLog m_SysLog = new SystemLog();
public ConfigFile()
{
}
/// <summary>
/// 从指定文件初始化当前配置文件
/// </summary>
public int InitConfigFromFile()
{
AppSettingsReader settingreader;
settingreader = new AppSettingsReader();
try
{
string PlatformIDList = (string) settingreader.GetValue("MonitorSystem.Center.PlatformID", typeof(string));
this.MonitorLogPath = (string) settingreader.GetValue("MonitorSystem.Center.MonitorLogPath", typeof(string));
this.RuleFilePath = (string) settingreader.GetValue("MonitorSystem.Center.RuleFileLocalPath", typeof(string));
this.RuleFileRemotePath = (string) settingreader.GetValue("MonitorSystem.Center.RuleFileRemotePath", typeof(string));
this.MonitorLogFilter = (string) settingreader.GetValue("MonitorSystem.Center.MonitorLogFilter", typeof(string));
this.LogNameFormat = (string) settingreader.GetValue("MonitorSystem.Center.LogNameFormat", typeof(string));
this.RuleNameFormat = (string) settingreader.GetValue("MonitorSystem.Center.RuleNameFormat", typeof(string));
this.ConnectionStr = (string) settingreader.GetValue("MonitorSystem.Center.WriteLog2DB.ConnectionString", typeof(string));
this.LogTableName = (string) settingreader.GetValue("MonitorSystem.Center.LogTableName", typeof(string));
this.AlertTableName = (string) settingreader.GetValue("MonitorSystem.Center.AlertTableName", typeof(string));
this.InterfaceIP = (string) settingreader.GetValue("MonitorNode.InterfaceIP", typeof(string));
this.InterfacePort = Convert.ToInt32((string) settingreader.GetValue("MonitorNode.InterfacePort", typeof(string)));
this.FtpUser = (string) settingreader.GetValue("MonitorNode.FTPUser", typeof(string));
this.FtpPsw = (string) settingreader.GetValue("MonitorNode.FTPPsw", typeof(string));
this.Download_Path = (string) settingreader.GetValue("MonitorNode.DownloadPath", typeof(string));
this.PlatformCheckTimeSpan = TimeSpan.FromMilliseconds(Convert.ToDouble((string) settingreader.GetValue("MonitorSystem.Center.PlatformCheck.TimeInterval", typeof(string))));
TryCount = Convert.ToInt32((string)settingreader.GetValue("MonitorCenter.ReadLog.TryCount", typeof(string)));
TryReadTimeSpan = TimeSpan.FromMilliseconds(Convert.ToDouble(settingreader.GetValue("MonitorCenter.ReadLog.TryReadTimeSpan",typeof(string))));
string[] PlatformIDArry = PlatformIDList.Split(',');
this.PlatformID = new int[PlatformIDArry.Length];
for(int n=0;n<PlatformIDArry.Length;n++)
{
PlatformID[n]=Convert.ToInt32(PlatformIDArry[n]);
}
}
catch(Exception e)
{
m_SysLog.WriteToSysLog(e.Message);
settingreader = null;
return -1;
}
finally
{
if(settingreader != null)
settingreader = null;
}
try
{
if(this.MonitorLogPath[this.MonitorLogPath.Length-1] != '\\')
{
this.MonitorLogPath = this.MonitorLogPath + "\\";
}
if(this.RuleFilePath[this.RuleFilePath.Length-1] != '\\')
{
this.RuleFilePath = this.RuleFilePath + "\\";
}
if(this.RuleFileRemotePath[this.RuleFileRemotePath.Length-1] != '\\')
{
this.RuleFileRemotePath = this.RuleFileRemotePath + "\\";
}
//如果没有目录则创建
if(!Directory.Exists(MonitorLogPath))
Directory.CreateDirectory(MonitorLogPath);
if(!Directory.Exists(RuleFilePath))
Directory.CreateDirectory(RuleFilePath);
if(!Directory.Exists(RuleFileRemotePath))
Directory.CreateDirectory(RuleFileRemotePath);
}
catch(Exception ex)
{
m_SysLog.WriteToSysLog(0,ex.Message);
}
return 0;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -