Program类:
1using System.Collections.Generic;
2using System.ServiceProcess;
3using System.Text;
4#region
5namespace IDC_SECURITY
6{
7static class Program
8{
9/// <summary>
10/// 应用程序的主入口点。
11/// </summary>
12static void Main()
13{
14ServiceBase[] ServicesToRun;
15
16// 同一进程中可以运行多个用户服务。若要将
17// 另一个服务添加到此进程中,请更改下行以
18// 创建另一个服务对象。例如,
19//
20// ServicesToRun = new ServiceBase[] {new Service1(), new MySecondUserService()};
21//
22ServicesToRun = new ServiceBase[] { new IDC_SECURITY_SMS() };
23
24ServiceBase.Run(ServicesToRun);
25}
26}
2using System.ServiceProcess;
3using System.Text;
4#region
5namespace IDC_SECURITY
6{
7static class Program
8{
9/// <summary>
10/// 应用程序的主入口点。
11/// </summary>
12static void Main()
13{
14ServiceBase[] ServicesToRun;
15
16// 同一进程中可以运行多个用户服务。若要将
17// 另一个服务添加到此进程中,请更改下行以
18// 创建另一个服务对象。例如,
19//
20// ServicesToRun = new ServiceBase[] {new Service1(), new MySecondUserService()};
21//
22ServicesToRun = new ServiceBase[] { new IDC_SECURITY_SMS() };
23
24ServiceBase.Run(ServicesToRun);
25}
26}
27}
服务的主类:
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Data;
5using System.Diagnostics;
6using System.ServiceProcess;
7using System.Text;
8using System.Timers;
9using System.Data.SqlClient;
10
11namespace IDC_SECURITY
12{
13public partial class IDC_SECURITY_SMS : ServiceBase
14{
15public System.Timers.Timer Check_Timer = new System.Timers.Timer();
16public BackgroundWorker AsyncChkThd = new System.ComponentModel.BackgroundWorker();
17
18public IDC_SECURITY_SMS()
19{
20//配置服务信息
21this.AutoLog = true;
22this.CanPauseAndContinue = true;
23this.CanShutdown = true;
24this.CanStop = true;
25this.ServiceName = "短信检测IDC状况";
26
27//配置Timer
28this.Check_Timer.Interval = Convert.ToInt32(MyConfig.GetTimeTick());
29this.Check_Timer.Elapsed += new ElapsedEventHandler(Check_Timer_Elapsed);
30
31//配置BackgroundWorker
32this.AsyncChkThd.DoWork += new DoWorkEventHandler(AsyncChkThd_DoWork);
33
34InitializeComponent();
35}
36
37void AsyncChkThd_DoWork(object sender, DoWorkEventArgs e)
38{
39RunChk();
40}
41
42void RunChk()
43{
44//检查WEB
45//检查DB
46List<DB_MSG> DBLIST = MyConfig.GetAllDBCONFIG();
47foreach (DB_MSG DM in DBLIST)
48{
49CHECK.CheckAndLog(DM);
50}
51List<WEB_MSG> WEBLIST = MyConfig.GetAllWebCONFIG();
52foreach (WEB_MSG WM in WEBLIST)
53{
54CHECK.CheckAndLog(WM);
55}
56}
57
58void Check_Timer_Elapsed(object sender, ElapsedEventArgs e)
59{
60AsyncChkThd.RunWorkerAsync();
61}
62
63protected override void OnStart(string[] args)
64{
65// TODO: 在此处添加代码以启动服务。
66Check_Timer.Enabled = true;
67}
68
69protected override void OnStop()
70{
71// TODO: 在此处添加代码以执行停止服务所需的关闭操作。
72Check_Timer.Enabled = false;
73}
74}
75}
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Data;
5using System.Diagnostics;
6using System.ServiceProcess;
7using System.Text;
8using System.Timers;
9using System.Data.SqlClient;
10
11namespace IDC_SECURITY
12{
13public partial class IDC_SECURITY_SMS : ServiceBase
14{
15public System.Timers.Timer Check_Timer = new System.Timers.Timer();
16public BackgroundWorker AsyncChkThd = new System.ComponentModel.BackgroundWorker();
17
18public IDC_SECURITY_SMS()
19{
20//配置服务信息
21this.AutoLog = true;
22this.CanPauseAndContinue = true;
23this.CanShutdown = true;
24this.CanStop = true;
25this.ServiceName = "短信检测IDC状况";
26
27//配置Timer
28this.Check_Timer.Interval = Convert.ToInt32(MyConfig.GetTimeTick());
29this.Check_Timer.Elapsed += new ElapsedEventHandler(Check_Timer_Elapsed);
30
31//配置BackgroundWorker
32this.AsyncChkThd.DoWork += new DoWorkEventHandler(AsyncChkThd_DoWork);
33
34InitializeComponent();
35}
36
37void AsyncChkThd_DoWork(object sender, DoWorkEventArgs e)
38{
39RunChk();
40}
41
42void RunChk()
43{
44//检查WEB
45//检查DB
46List<DB_MSG> DBLIST = MyConfig.GetAllDBCONFIG();
47foreach (DB_MSG DM in DBLIST)
48{
49CHECK.CheckAndLog(DM);
50}
51List<WEB_MSG> WEBLIST = MyConfig.GetAllWebCONFIG();
52foreach (WEB_MSG WM in WEBLIST)
53{
54CHECK.CheckAndLog(WM);
55}
56}
57
58void Check_Timer_Elapsed(object sender, ElapsedEventArgs e)
59{
60AsyncChkThd.RunWorkerAsync();
61}
62
63protected override void OnStart(string[] args)
64{
65// TODO: 在此处添加代码以启动服务。
66Check_Timer.Enabled = true;
67}
68
69protected override void OnStop()
70{
71// TODO: 在此处添加代码以执行停止服务所需的关闭操作。
72Check_Timer.Enabled = false;
73}
74}
75}
服务设计类:
1namespace IDC_SECURITY
2{
3partial class IDC_SECURITY_SMS
4{
5/// <summary>
6/// 必需的设计器变量。
7/// </summary>
8private System.ComponentModel.IContainer components = null;
9
10/// <summary>
11/// 清理所有正在使用的资源。
12/// </summary>
13/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
14protected override void Dispose(bool disposing)
15{
16if (disposing && (components != null))
17{
18components.Dispose();
19}
20base.Dispose(disposing);
21}
22
23组件设计器生成的代码
36}
37}
2{
3partial class IDC_SECURITY_SMS
4{
5/// <summary>
6/// 必需的设计器变量。
7/// </summary>
8private System.ComponentModel.IContainer components = null;
9
10/// <summary>
11/// 清理所有正在使用的资源。
12/// </summary>
13/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
14protected override void Dispose(bool disposing)
15{
16if (disposing && (components != null))
17{
18components.Dispose();
19}
20base.Dispose(disposing);
21}
22
23组件设计器生成的代码
36}
37}
配置获取工具类:
1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.Xml;
5using System.IO;
6
7namespace IDC_SECURITY
8{
9public abstract class MyConfig
10{
11public static readonly string XmlPath = "D:/SMS/SMS_CONFIG.xml";
12//配置类型
13public enum CONFIGTYPE { DBCONFIG, WEBCONFIG, LOGCONFIG, TIMECONFIG, COMNAME };
14//XML属性列表
15public enum AttriNames
16{
17DB_NAME, DB_CONNSTR, DB_VAL, DB_CMDSTR, DB_SENDPHONE, DB_ERRORMSG,
18WEB_NAME, WEB_URL, WEB_USEMETA, WEB_METANAME, WEB_VAL, WEB_SENDPHONE, WEB_ERRORMSG,
19LOG_PATH,
20TIME_COUNT,
21NAME
22};
23
24/// <summary>
25/// 获取配置子列
26/// </summary>
27/// <param name="ConfigType">配置节类型</param>
28/// <returns></returns>
29public static XmlNodeList GetConfigs(CONFIGTYPE ConfigType)
30{
31XmlDocument XmlDoc = new XmlDocument();
32XmlDoc.Load(XmlPath);
33
34XmlNode RootNode = null;
35if (ConfigType == CONFIGTYPE.DBCONFIG)
36{
37RootNode = XmlDoc.SelectSingleNode("CONFIG/DB_CONFIG");
38}
39else if (ConfigType == CONFIGTYPE.LOGCONFIG)
40{
41RootNode = XmlDoc.SelectSingleNode("CONFIG/LOG_CONFIG");
42}
43else if (ConfigType == CONFIGTYPE.WEBCONFIG)
44{
45RootNode = XmlDoc.SelectSingleNode("CONFIG/WEB_CONFIG");
46}
47else if (ConfigType == CONFIGTYPE.TIMECONFIG)
48{
49RootNode = XmlDoc.SelectSingleNode("CONFIG/TIME_CONFIG");
50}
51else if (ConfigType == CONFIGTYPE.COMNAME)
52{
53RootNode = XmlDoc.SelectSingleNode("CONFIG/COM_NAME");
54}
55
56return RootNode.ChildNodes;
57}
58/// <summary>
59/// 获取节点属性值
60/// </summary>
61/// <param name="AttributeName"></param>
62/// <param name="XNode"></param>
63/// <returns></returns>
64public static string GetXmlNodeValue(AttriNames AttributeName,XmlNode XNode)
65{
66return XNode.Attributes[AttributeName.ToString()].Value;
67}
68/// <summary>
69/// 获取日志存放根目录
70/// </summary>
71/// <returns></returns>
72public static string GetLogPath()
73{
74string PathRtn="";
75XmlNodeList XNL = GetConfigs(CONFIGTYPE.LOGCONFIG);
76for(int i=0;i<XNL.Count;i++)
77{
78if(XNL[i].NodeType==XmlNodeType.Element)
79{
80PathRtn=XNL[i].Attributes[AttriNames.LOG_PATH.ToString()].Value;
81break;
82}
83}
84return PathRtn;
85}
86/// <summary>
87/// 遍历获取所有待测试数据库连接
88/// </summary>
89/// <returns></returns>
90public static List<DB_MSG> GetAllDBCONFIG()
91{
92List <DB_MSG> DBOBJ_LIST= new List<DB_MSG>();
93foreach (XmlNode XN in GetConfigs(CONFIGTYPE.DBCONFIG))
94{
95if (XN.NodeType == XmlNodeType.Element)
96{
97DB_MSG DBMOBJ = new DB_MSG();
98DBMOBJ.CmdStr = GetXmlNodeValue(AttriNames.DB_CMDSTR, XN);
99DBMOBJ.ConnStr = GetXmlNodeValue(AttriNames.DB_CONNSTR, XN);
100DBMOBJ.Name = GetXmlNodeValue(AttriNames.DB_NAME, XN);
101DBMOBJ.SendList = GetXmlNodeValue(AttriNames.DB_SENDPHONE, XN);
102DBMOBJ.Val = GetXmlNodeValue(AttriNames.DB_VAL, XN);
103DBMOBJ.ErrorMsg = GetXmlNodeValue(AttriNames.DB_ERRORMSG, XN);
104
105DBOBJ_LIST.Add(DBMOBJ);
106}
107}
108
109return DBOBJ_LIST;
110}
111/// <summary>
112/// 遍历获取所有待测试网页
113/// </summary>
114/// <returns></returns>
115public static List<WEB_MSG> GetAllWebCONFIG()
116{
117List<WEB_MSG> WEBOBJ_LIST = new List<WEB_MSG>();
118foreach (XmlNode XN in GetConfigs(CONFIGTYPE.WEBCONFIG))
119{
120if (XN.NodeType == XmlNodeType.Element)
121{
122WEB_MSG WEBOBJ = new WEB_MSG();
123WEBOBJ.ErrorMsg = GetXmlNodeValue(AttriNames.WEB_ERRORMSG, XN);
124WEBOBJ.MetaName = GetXmlNodeValue(AttriNames.WEB_METANAME, XN);
125WEBOBJ.Name = GetXmlNodeValue(AttriNames.WEB_NAME, XN);
126WEBOBJ.SendList = GetXmlNodeValue(AttriNames.WEB_SENDPHONE, XN);
127WEBOBJ.Url = GetXmlNodeValue(AttriNames.WEB_URL, XN);
128WEBOBJ.UseMeta = bool.Parse(GetXmlNodeValue(AttriNames.WEB_USEMETA, XN));
129WEBOBJ.Val = GetXmlNodeValue(AttriNames.WEB_VAL, XN);
130
131WEBOBJ_LIST.Add(WEBOBJ);
132}
133}
134
135return WEBOBJ_LIST;
136}
137/// <summary>
138/// 获取定时器时间间隔
139/// </summary>
140/// <returns></returns>
141public static int GetTimeTick()
142{
143int RtnTick = 0;
144XmlNodeList XNL = GetConfigs(CONFIGTYPE.TIMECONFIG);
145for (int i = 0; i < XNL.Count; i++)
146{
147if (XNL[i].NodeType == XmlNodeType.Element)
148{
149RtnTick =
150Convert.ToInt32(XNL[i].Attributes[AttriNames.TIME_COUNT.ToString()].Value);
151break;
152}
153}
154
155return RtnTick;
156}
157/// <summary>
158/// 获取发送串口名
159/// </summary>
160/// <returns></returns>
161public static string GetComName()
162{
163string RtnComName = "";
164XmlNodeList XNL = GetConfigs(CONFIGTYPE.COMNAME);
165for (int i = 0; i < XNL.Count; i++)
166{
167if (XNL[i].NodeType == XmlNodeType.Element)
168{
169RtnComName = XNL[i].Attributes[AttriNames.NAME.ToString()].Value;
170break;
171}
172}
173
174return RtnComName;
175}
176}
177}
2using System.Collections.Generic;
3using System.Text;
4using System.Xml;
5using System.IO;
6
7namespace IDC_SECURITY
8{
9public abstract class MyConfig
10{
11public static readonly string XmlPath = "D:/SMS/SMS_CONFIG.xml";
12//配置类型
13public enum CONFIGTYPE { DBCONFIG, WEBCONFIG, LOGCONFIG, TIMECONFIG, COMNAME };
14//XML属性列表
15public enum AttriNames
16{
17DB_NAME, DB_CONNSTR, DB_VAL, DB_CMDSTR, DB_SENDPHONE, DB_ERRORMSG,
18WEB_NAME, WEB_URL, WEB_USEMETA, WEB_METANAME, WEB_VAL, WEB_SENDPHONE, WEB_ERRORMSG,
19LOG_PATH,
20TIME_COUNT,
21NAME
22};
23
24/// <summary>
25/// 获取配置子列
26/// </summary>
27/// <param name="ConfigType">配置节类型</param>
28/// <returns></returns>
29public static XmlNodeList GetConfigs(CONFIGTYPE ConfigType)
30{
31XmlDocument XmlDoc = new XmlDocument();
32XmlDoc.Load(XmlPath);
33
34XmlNode RootNode = null;
35if (ConfigType == CONFIGTYPE.DBCONFIG)
36{
37RootNode = XmlDoc.SelectSingleNode("CONFIG/DB_CONFIG");
38}
39else if (ConfigType == CONFIGTYPE.LOGCONFIG)
40{
41RootNode = XmlDoc.SelectSingleNode("CONFIG/LOG_CONFIG");
42}
43else if (ConfigType == CONFIGTYPE.WEBCONFIG)
44{
45RootNode = XmlDoc.SelectSingleNode("CONFIG/WEB_CONFIG");
46}
47else if (ConfigType == CONFIGTYPE.TIMECONFIG)
48{
49RootNode = XmlDoc.SelectSingleNode("CONFIG/TIME_CONFIG");
50}
51else if (ConfigType == CONFIGTYPE.COMNAME)
52{
53RootNode = XmlDoc.SelectSingleNode("CONFIG/COM_NAME");
54}
55
56return RootNode.ChildNodes;
57}
58/// <summary>
59/// 获取节点属性值
60/// </summary>
61/// <param name="AttributeName"></param>
62/// <param name="XNode"></param>
63/// <returns></returns>
64public static string GetXmlNodeValue(AttriNames AttributeName,XmlNode XNode)
65{
66return XNode.Attributes[AttributeName.ToString()].Value;
67}
68/// <summary>
69/// 获取日志存放根目录
70/// </summary>
71/// <returns></returns>
72public static string GetLogPath()
73{
74string PathRtn="";
75XmlNodeList XNL = GetConfigs(CONFIGTYPE.LOGCONFIG);
76for(int i=0;i<XNL.Count;i++)
77{
78if(XNL[i].NodeType==XmlNodeType.Element)
79{
80PathRtn=XNL[i].Attributes[AttriNames.LOG_PATH.ToString()].Value;
81break;
82}
83}
84return PathRtn;
85}
86/// <summary>
87/// 遍历获取所有待测试数据库连接
88/// </summary>
89/// <returns></returns>
90public static List<DB_MSG> GetAllDBCONFIG()
91{
92List <DB_MSG> DBOBJ_LIST= new List<DB_MSG>();
93foreach (XmlNode XN in GetConfigs(CONFIGTYPE.DBCONFIG))
94{
95if (XN.NodeType == XmlNodeType.Element)
96{
97DB_MSG DBMOBJ = new DB_MSG();
98DBMOBJ.CmdStr = GetXmlNodeValue(AttriNames.DB_CMDSTR, XN);
99DBMOBJ.ConnStr = GetXmlNodeValue(AttriNames.DB_CONNSTR, XN);
100DBMOBJ.Name = GetXmlNodeValue(AttriNames.DB_NAME, XN);
101DBMOBJ.SendList = GetXmlNodeValue(AttriNames.DB_SENDPHONE, XN);
102DBMOBJ.Val = GetXmlNodeValue(AttriNames.DB_VAL, XN);
103DBMOBJ.ErrorMsg = GetXmlNodeValue(AttriNames.DB_ERRORMSG, XN);
104
105DBOBJ_LIST.Add(DBMOBJ);
106}
107}
108
109return DBOBJ_LIST;
110}
111/// <summary>
112/// 遍历获取所有待测试网页
113/// </summary>
114/// <returns></returns>
115public static List<WEB_MSG> GetAllWebCONFIG()
116{
117List<WEB_MSG> WEBOBJ_LIST = new List<WEB_MSG>();
118foreach (XmlNode XN in GetConfigs(CONFIGTYPE.WEBCONFIG))
119{
120if (XN.NodeType == XmlNodeType.Element)
121{
122WEB_MSG WEBOBJ = new WEB_MSG();
123WEBOBJ.ErrorMsg = GetXmlNodeValue(AttriNames.WEB_ERRORMSG, XN);
124WEBOBJ.MetaName = GetXmlNodeValue(AttriNames.WEB_METANAME, XN);
125WEBOBJ.Name = GetXmlNodeValue(AttriNames.WEB_NAME, XN);
126WEBOBJ.SendList = GetXmlNodeValue(AttriNames.WEB_SENDPHONE, XN);
127WEBOBJ.Url = GetXmlNodeValue(AttriNames.WEB_URL, XN);
128WEBOBJ.UseMeta = bool.Parse(GetXmlNodeValue(AttriNames.WEB_USEMETA, XN));
129WEBOBJ.Val = GetXmlNodeValue(AttriNames.WEB_VAL, XN);
130
131WEBOBJ_LIST.Add(WEBOBJ);
132}
133}
134
135return WEBOBJ_LIST;
136}
137/// <summary>
138/// 获取定时器时间间隔
139/// </summary>
140/// <returns></returns>
141public static int GetTimeTick()
142{
143int RtnTick = 0;
144XmlNodeList XNL = GetConfigs(CONFIGTYPE.TIMECONFIG);
145for (int i = 0; i < XNL.Count; i++)
146{
147if (XNL[i].NodeType == XmlNodeType.Element)
148{
149RtnTick =
150Convert.ToInt32(XNL[i].Attributes[AttriNames.TIME_COUNT.ToString()].Value);
151break;
152}
153}
154
155return RtnTick;
156}
157/// <summary>
158/// 获取发送串口名
159/// </summary>
160/// <returns></returns>
161public static string GetComName()
162{
163string RtnComName = "";
164XmlNodeList XNL = GetConfigs(CONFIGTYPE.COMNAME);
165for (int i = 0; i < XNL.Count; i++)
166{
167if (XNL[i].NodeType == XmlNodeType.Element)
168{
169RtnComName = XNL[i].Attributes[AttriNames.NAME.ToString()].Value;
170break;
171}
172}
173
174return RtnComName;
175}
176}
177}
配置XML文件:
1<?xml version="1.0" encoding="utf-8" ?>
2<CONFIG>
3<DB_CONFIG>
4<!--名称,连接串,表,值,操作命令-->
5<!--如不指定CMDSTR,则默认为SELECT COUNT(*) FROM-->
6<!--发送手机列采用|分割-->
7<DB_MSG DB_NAME="客服中心数据库" DB_CONNSTR="." DB_CMDSTR="SELECT top 1 * FROM tmpOrder(nolock)" DB_VAL="jfj" DB_SENDPHONE="13810450902" DB_ERRORMSG="客服中心数据库无法访问!"></DB_MSG>
8</DB_CONFIG>
9<WEB_CONFIG>
10<!--地址,正则关键字,值-->
11<!--如果没有制定正则,则默认获取MATE-->
12<!--如果正则和MATE都为空,则直接获取网页内容-->
13<!--当设定USEMETA为true,则执行Meta检查,否则不执行-->
14<WEB_MSG WEB_NAME="网站首页" WEB_URL="http://www.Example.com" WEB_VAL="Exalple" WEB_USEMATE="true" WEB_METANAME="ExamMeta" WEB_SENDPHONE="13811111111" WEB_ERRORMSG="网站首页出现问题"></WEB_MSG>
15<WEB_MSG WEB_NAME="网站单品页" WEB_URL="http://www.Example.com/ProductInfo/1111.html" WEB_VAL="单品" WEB_USEMETA="true" WEB_METANAME="Meta_A" WEB_SENDPHONE="13811111111" WEB_ERRORMSG="网站单品页出现问题!"></WEB_MSG>
16</WEB_CONFIG>
17<LOG_CONFIG>
18<!--运行日志-->
19<!--日志文件目录分级:根目录/年/月/日-->
20<!--日志文件名:yyyyMMdd-->
21<LOG_MSG LOG_PATH="D:/SMSLOG/"></LOG_MSG>
22</LOG_CONFIG>
23<TIME_CONFIG>
24<!--定时器时间,毫秒为单位-->
25<TIME_TICK TIME_COUNT="600000"></TIME_TICK>
26</TIME_CONFIG>
27<COM_NAME>
28<!--发送串口名-->
29<SEND_COM NAME="COM1"></SEND_COM>
30</COM_NAME>
31</CONFIG>
2<CONFIG>
3<DB_CONFIG>
4<!--名称,连接串,表,值,操作命令-->
5<!--如不指定CMDSTR,则默认为SELECT COUNT(*) FROM-->
6<!--发送手机列采用|分割-->
7<DB_MSG DB_NAME="客服中心数据库" DB_CONNSTR="." DB_CMDSTR="SELECT top 1 * FROM tmpOrder(nolock)" DB_VAL="jfj" DB_SENDPHONE="13810450902" DB_ERRORMSG="客服中心数据库无法访问!"></DB_MSG>
8</DB_CONFIG>
9<WEB_CONFIG>
10<!--地址,正则关键字,值-->
11<!--如果没有制定正则,则默认获取MATE-->
12<!--如果正则和MATE都为空,则直接获取网页内容-->
13<!--当设定USEMETA为true,则执行Meta检查,否则不执行-->
14<WEB_MSG WEB_NAME="网站首页" WEB_URL="http://www.Example.com" WEB_VAL="Exalple" WEB_USEMATE="true" WEB_METANAME="ExamMeta" WEB_SENDPHONE="13811111111" WEB_ERRORMSG="网站首页出现问题"></WEB_MSG>
15<WEB_MSG WEB_NAME="网站单品页" WEB_URL="http://www.Example.com/ProductInfo/1111.html" WEB_VAL="单品" WEB_USEMETA="true" WEB_METANAME="Meta_A" WEB_SENDPHONE="13811111111" WEB_ERRORMSG="网站单品页出现问题!"></WEB_MSG>
16</WEB_CONFIG>
17<LOG_CONFIG>
18<!--运行日志-->
19<!--日志文件目录分级:根目录/年/月/日-->
20<!--日志文件名:yyyyMMdd-->
21<LOG_MSG LOG_PATH="D:/SMSLOG/"></LOG_MSG>
22</LOG_CONFIG>
23<TIME_CONFIG>
24<!--定时器时间,毫秒为单位-->
25<TIME_TICK TIME_COUNT="600000"></TIME_TICK>
26</TIME_CONFIG>
27<COM_NAME>
28<!--发送串口名-->
29<SEND_COM NAME="COM1"></SEND_COM>
30</COM_NAME>
31</CONFIG>
检查类:
1using System;
2using System.Collections;
3using System.Text;
4using System.Data;
5using System.Data.SqlClient;
6using System.Net;
7using System.Web;
8using System.IO;
9using System.Text.RegularExpressions;
10using System.Configuration;
11
12namespace IDC_SECURITY
13{
14public class CHECK
15{
16public CHECK()
17{
18}
19/// <summary>
20/// 检查数据库
21/// </summary>
22/// <param name="dbmsg"></param>
23public static void CheckAndLog(DB_MSG dbmsg)
24{
25//声明返回对象
26CheckResults ChkRtn = new CheckResults();
27ChkRtn.ChkName = dbmsg.Name;
28ChkRtn.ChkTime = System.DateTime.Now;
29ChkRtn.ChkType = MyConfig.CONFIGTYPE.DBCONFIG;
30ChkRtn.ChkErrorMsg = dbmsg.ErrorMsg;
31
32string[] SendArray = dbmsg.SendList.Split('|');
33ArrayList AL = new ArrayList();
34foreach (string SendTo in SendArray)
35{
36AL.Add(SendTo);
37}
38ChkRtn.ChkList = AL;
39//数据库检查
40SqlConnection SqlConn = new SqlConnection(dbmsg.ConnStr);
41SqlCommand SqlCmd = new SqlCommand();
42SqlCmd.Connection = SqlConn;
43SqlCmd.CommandType = CommandType.Text;
44
45//如果存在测试命令
46if (dbmsg.CmdStr != "" && dbmsg.Val != "")
47{
48try
49{
50SqlCmd.CommandText = dbmsg.CmdStr;
51SqlConn.Open();
52string ChkVal = SqlCmd.ExecuteScalar().ToString();
53if (ChkVal == dbmsg.Val)
54{
55ChkRtn.ChkResult = true;
56}
57else
58{
59ChkRtn.ChkResult = false;
60}
61}
62catch
63{
64//如果发生异常,表明数据库出问题
65ChkRtn.ChkResult = false;
66}
67}
68else
69{
70//如过不存在数据库测试命令
71try
72{
73SqlConn.Open();
74SqlConn.Close();
75ChkRtn.ChkResult = true;
76}
77catch
78{
79//数据库无法打开,表明数据库出问题
80ChkRtn.ChkResult = false;
81}
82}
83
84LOG.WriteCheckResult(ChkRtn);
85if (!ChkRtn.ChkResult)
86{
87string ComName = MyConfig.GetComName();
88
89foreach (object SendToObj in ChkRtn.ChkList)
90{
91SMS_SEND SMSObj =
92new SMS_SEND();
93string SendResult =
94SMSObj.SendMsg(ChkRtn.ChkName + ":" + ChkRtn.ChkErrorMsg, SendToObj.ToString(), ComName);
95LOG.WriteSmsOpLog(ChkRtn.ChkName + ":" + ChkRtn.ChkErrorMsg, SendResult);
96}
97}
98}
99/// <summary>
100/// 检查WEB
101/// </summary>
102/// <param name="webmsg"></param>
103/// <returns></returns>
104public static void CheckAndLog(WEB_MSG webmsg)
105{
106//声明测试对象
107CheckResults ChkRtn = new CheckResults();
108ChkRtn.ChkName = webmsg.Name;
109ChkRtn.ChkTime = System.DateTime.Now;
110ChkRtn.ChkType = MyConfig.CONFIGTYPE.WEBCONFIG;
111ChkRtn.ChkErrorMsg = webmsg.ErrorMsg;
112//测试结果发送对象
113ArrayList AL = new ArrayList();
114string[] TArray = webmsg.SendList.Split('|');
115foreach (string TA in TArray)
116{
117AL.Add(TA);
118}
119ChkRtn.ChkList = AL;
120
121if (webmsg.UseMeta)
122{
123//如果测试目标为META
124try
125{
126if (GetMeta(webmsg.MetaName, GetResponseBack(webmsg.Url)) == webmsg.Val)
127{
128ChkRtn.ChkResult = true;
129}
130else
131{
132ChkRtn.ChkResult = false;
133}
134}
135catch
136{
137//如果访问出错,则网站出问题
138ChkRtn.ChkResult = false;
139}
140}
141else
142{
143//如果测试目标不是META
144//则直接验证返回页面是否是制定值
145try
146{
147string AllSrcCode = GetResponseBack(webmsg.Url);
148
149if (AllSrcCode.Contains(webmsg.Val))
150{
151ChkRtn.ChkResult = true;
152}
153else
154{
155ChkRtn.ChkResult = false;
156}
157}
158catch
159{
160ChkRtn.ChkResult = false;
161}
162}
163
164LOG.WriteCheckResult(ChkRtn);
165if (!ChkRtn.ChkResult)
166{
167string ComName = MyConfig.GetComName();
168
169foreach (object SendToObj in ChkRtn.ChkList)
170{
171SMS_SEND SMSObj = new SMS_SEND();
172string SendResult =
173SMSObj.SendMsg(ChkRtn.ChkName + ":" + ChkRtn.ChkErrorMsg, SendToObj.ToString(), ComName);
174LOG.WriteSmsOpLog(ChkRtn.ChkName + ":" + ChkRtn.ChkErrorMsg, SendResult);
175}
176}
177}
178
179/// <summary>
180/// 获取网络响应
181/// </summary>
182/// <param name="Uri"></param>
183/// <returns></returns>
184private static string GetResponseBack(string Uri)
185{
186try
187{
188HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(Uri);
189myRequest.Timeout = 3000;
190
191
192HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
193
194Stream Stm = myResponse.GetResponseStream();
195StreamReader srd = new StreamReader(Stm);
196string BackStr = srd.ReadToEnd();
197srd.Close();
198Stm.Close();
199myResponse.Close();
200
201return BackStr;
202}
203catch
204{
205return "Error";
206}
207}
208
209/// <summary>
210/// 获取响应数据中指定Meta的值
211/// </summary>
212/// <param name="MetaName"></param>
213/// <param name="SrcStr"></param>
214/// <returns></returns>
215private static string GetMeta(string MetaName,string SrcStr)
216{
217string RegexStr =
218string.Format(@"<meta Name=\""{0}\"" content[\s]?=[\s\""\']+(.*?)[\""\']+.*?>", MetaName);
219Regex MetaRegex =
220new Regex(RegexStr, RegexOptions.IgnoreCase);
221Match Mc =
222MetaRegex.Match(SrcStr);
223if (Mc != null)
224{
225return Mc.Groups[1].ToString();
226}
227else
228{
229return "";
230}
231}
232}
233}
2using System.Collections;
3using System.Text;
4using System.Data;
5using System.Data.SqlClient;
6using System.Net;
7using System.Web;
8using System.IO;
9using System.Text.RegularExpressions;
10using System.Configuration;
11
12namespace IDC_SECURITY
13{
14public class CHECK
15{
16public CHECK()
17{
18}
19/// <summary>
20/// 检查数据库
21/// </summary>
22/// <param name="dbmsg"></param>
23public static void CheckAndLog(DB_MSG dbmsg)
24{
25//声明返回对象
26CheckResults ChkRtn = new CheckResults();
27ChkRtn.ChkName = dbmsg.Name;
28ChkRtn.ChkTime = System.DateTime.Now;
29ChkRtn.ChkType = MyConfig.CONFIGTYPE.DBCONFIG;
30ChkRtn.ChkErrorMsg = dbmsg.ErrorMsg;
31
32string[] SendArray = dbmsg.SendList.Split('|');
33ArrayList AL = new ArrayList();
34foreach (string SendTo in SendArray)
35{
36AL.Add(SendTo);
37}
38ChkRtn.ChkList = AL;
39//数据库检查
40SqlConnection SqlConn = new SqlConnection(dbmsg.ConnStr);
41SqlCommand SqlCmd = new SqlCommand();
42SqlCmd.Connection = SqlConn;
43SqlCmd.CommandType = CommandType.Text;
44
45//如果存在测试命令
46if (dbmsg.CmdStr != "" && dbmsg.Val != "")
47{
48try
49{
50SqlCmd.CommandText = dbmsg.CmdStr;
51SqlConn.Open();
52string ChkVal = SqlCmd.ExecuteScalar().ToString();
53if (ChkVal == dbmsg.Val)
54{
55ChkRtn.ChkResult = true;
56}
57else
58{
59ChkRtn.ChkResult = false;
60}
61}
62catch
63{
64//如果发生异常,表明数据库出问题
65ChkRtn.ChkResult = false;
66}
67}
68else
69{
70//如过不存在数据库测试命令
71try
72{
73SqlConn.Open();
74SqlConn.Close();
75ChkRtn.ChkResult = true;
76}
77catch
78{
79//数据库无法打开,表明数据库出问题
80ChkRtn.ChkResult = false;
81}
82}
83
84LOG.WriteCheckResult(ChkRtn);
85if (!ChkRtn.ChkResult)
86{
87string ComName = MyConfig.GetComName();
88
89foreach (object SendToObj in ChkRtn.ChkList)
90{
91SMS_SEND SMSObj =
92new SMS_SEND();
93string SendResult =
94SMSObj.SendMsg(ChkRtn.ChkName + ":" + ChkRtn.ChkErrorMsg, SendToObj.ToString(), ComName);
95LOG.WriteSmsOpLog(ChkRtn.ChkName + ":" + ChkRtn.ChkErrorMsg, SendResult);
96}
97}
98}
99/// <summary>
100/// 检查WEB
101/// </summary>
102/// <param name="webmsg"></param>
103/// <returns></returns>
104public static void CheckAndLog(WEB_MSG webmsg)
105{
106//声明测试对象
107CheckResults ChkRtn = new CheckResults();
108ChkRtn.ChkName = webmsg.Name;
109ChkRtn.ChkTime = System.DateTime.Now;
110ChkRtn.ChkType = MyConfig.CONFIGTYPE.WEBCONFIG;
111ChkRtn.ChkErrorMsg = webmsg.ErrorMsg;
112//测试结果发送对象
113ArrayList AL = new ArrayList();
114string[] TArray = webmsg.SendList.Split('|');
115foreach (string TA in TArray)
116{
117AL.Add(TA);
118}
119ChkRtn.ChkList = AL;
120
121if (webmsg.UseMeta)
122{
123//如果测试目标为META
124try
125{
126if (GetMeta(webmsg.MetaName, GetResponseBack(webmsg.Url)) == webmsg.Val)
127{
128ChkRtn.ChkResult = true;
129}
130else
131{
132ChkRtn.ChkResult = false;
133}
134}
135catch
136{
137//如果访问出错,则网站出问题
138ChkRtn.ChkResult = false;
139}
140}
141else
142{
143//如果测试目标不是META
144//则直接验证返回页面是否是制定值
145try
146{
147string AllSrcCode = GetResponseBack(webmsg.Url);
148
149if (AllSrcCode.Contains(webmsg.Val))
150{
151ChkRtn.ChkResult = true;
152}
153else
154{
155ChkRtn.ChkResult = false;
156}
157}
158catch
159{
160ChkRtn.ChkResult = false;
161}
162}
163
164LOG.WriteCheckResult(ChkRtn);
165if (!ChkRtn.ChkResult)
166{
167string ComName = MyConfig.GetComName();
168
169foreach (object SendToObj in ChkRtn.ChkList)
170{
171SMS_SEND SMSObj = new SMS_SEND();
172string SendResult =
173SMSObj.SendMsg(ChkRtn.ChkName + ":" + ChkRtn.ChkErrorMsg, SendToObj.ToString(), ComName);
174LOG.WriteSmsOpLog(ChkRtn.ChkName + ":" + ChkRtn.ChkErrorMsg, SendResult);
175}
176}
177}
178
179/// <summary>
180/// 获取网络响应
181/// </summary>
182/// <param name="Uri"></param>
183/// <returns></returns>
184private static string GetResponseBack(string Uri)
185{
186try
187{
188HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(Uri);
189myRequest.Timeout = 3000;
190
191
192HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
193
194Stream Stm = myResponse.GetResponseStream();
195StreamReader srd = new StreamReader(Stm);
196string BackStr = srd.ReadToEnd();
197srd.Close();
198Stm.Close();
199myResponse.Close();
200
201return BackStr;
202}
203catch
204{
205return "Error";
206}
207}
208
209/// <summary>
210/// 获取响应数据中指定Meta的值
211/// </summary>
212/// <param name="MetaName"></param>
213/// <param name="SrcStr"></param>
214/// <returns></returns>
215private static string GetMeta(string MetaName,string SrcStr)
216{
217string RegexStr =
218string.Format(@"<meta Name=\""{0}\"" content[\s]?=[\s\""\']+(.*?)[\""\']+.*?>", MetaName);
219Regex MetaRegex =
220new Regex(RegexStr, RegexOptions.IgnoreCase);
221Match Mc =
222MetaRegex.Match(SrcStr);
223if (Mc != null)
224{
225return Mc.Groups[1].ToString();
226}
227else
228{
229return "";
230}
231}
232}
233}
检查结果类:
1using System;
2using System.Collections;
3using System.Text;
4
5namespace IDC_SECURITY
6{
7public class CheckResults
8{
9private MyConfig.CONFIGTYPE checktype;
10private bool checkresult;
11private DateTime checktime;
12private string checkname;
13private ArrayList checklist;
14private string errormsg;
15
16public CheckResults()
17{
18}
19public CheckResults(
20MyConfig.CONFIGTYPE Chk_Type,
21bool Chk_Result, DateTime Chk_Time,
22string Chk_Name,ArrayList Chk_List,
23string Chk_ErrorMsg)
24{
25this.checktype = Chk_Type;
26this.checkresult = Chk_Result;
27this.checktime = Chk_Time;
28this.checkname = Chk_Name;
29this.checklist=Chk_List;
30this.errormsg = Chk_ErrorMsg;
31}
32/// <summary>
33/// 测试类型
34/// </summary>
35public MyConfig.CONFIGTYPE ChkType
36{
37set { this.checktype = value; }
38get { return this.checktype; }
39}
40/// <summary>
41/// 测试结果
42/// </summary>
43public bool ChkResult
44{
45set { this.checkresult = value; }
46get { return this.checkresult; }
47}
48/// <summary>
49/// 测试时间
50/// </summary>
51public DateTime ChkTime
52{
53set { this.checktime = value; }
54get { return this.checktime; }
55}
56/// <summary>
57/// 测试名称
58/// </summary>
59public string ChkName
60{
61set { this.checkname = value; }
62get { return this.checkname; }
63}
64/// <summary>
65/// 测试结果发送列表
66/// </summary>
67public ArrayList ChkList
68{
69set { this.checklist = value; }
70get { return checklist; }
71}
72/// <summary>
73/// 测试错误信息
74/// </summary>
75public string ChkErrorMsg
76{
77set { this.errormsg = value; }
78get { return this.errormsg; }
79}
80}
81}
2using System.Collections;
3using System.Text;
4
5namespace IDC_SECURITY
6{
7public class CheckResults
8{
9private MyConfig.CONFIGTYPE checktype;
10private bool checkresult;
11private DateTime checktime;
12private string checkname;
13private ArrayList checklist;
14private string errormsg;
15
16public CheckResults()
17{
18}
19public CheckResults(
20MyConfig.CONFIGTYPE Chk_Type,
21bool Chk_Result, DateTime Chk_Time,
22string Chk_Name,ArrayList Chk_List,
23string Chk_ErrorMsg)
24{
25this.checktype = Chk_Type;
26this.checkresult = Chk_Result;
27this.checktime = Chk_Time;
28this.checkname = Chk_Name;
29this.checklist=Chk_List;
30this.errormsg = Chk_ErrorMsg;
31}
32/// <summary>
33/// 测试类型
34/// </summary>
35public MyConfig.CONFIGTYPE ChkType
36{
37set { this.checktype = value; }
38get { return this.checktype; }
39}
40/// <summary>
41/// 测试结果
42/// </summary>
43public bool ChkResult
44{
45set { this.checkresult = value; }
46get { return this.checkresult; }
47}
48/// <summary>
49/// 测试时间
50/// </summary>
51public DateTime ChkTime
52{
53set { this.checktime = value; }
54get { return this.checktime; }
55}
56/// <summary>
57/// 测试名称
58/// </summary>
59public string ChkName
60{
61set { this.checkname = value; }
62get { return this.checkname; }
63}
64/// <summary>
65/// 测试结果发送列表
66/// </summary>
67public ArrayList ChkList
68{
69set { this.checklist = value; }
70get { return checklist; }
71}
72/// <summary>
73/// 测试错误信息
74/// </summary>
75public string ChkErrorMsg
76{
77set { this.errormsg = value; }
78get { return this.errormsg; }
79}
80}
81}
数据库信息:
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace IDC_SECURITY
6{
7/// <summary>
8/// 数据库连接
9/// </summary>
10public class DB_MSG
11{
12public DB_MSG()
13{
14}
15/// <summary>
16/// 连接名
17/// </summary>
18private string DB_Name;
19/// <summary>
20/// 连接字符串
21/// </summary>
22private string DB_ConnStr;
23/// <summary>
24/// 测试命令
25/// </summary>
26private string DB_CmdStr;
27/// <summary>
28/// 测试值,与测试命令或者测试表名配套使用
29/// </summary>
30private string DB_Value;
31/// <summary>
32/// 手机短信发送目标列表,用|分割
33/// </summary>
34private string DB_SendList;
35/// <summary>
36/// 错误信息
37/// </summary>
38private string DB_ErrorMsg;
39/// <summary>
40/// 错误信息
41/// </summary>
42public string ErrorMsg
43{
44set { this.DB_ErrorMsg = value; }
45get { return DB_ErrorMsg; }
46}
47/// <summary>
48/// 连接名
49/// </summary>
50public string Name
51{
52set { DB_Name = value; }
53get { return DB_Name; }
54}
55/// <summary>
56/// 连接字符串
57/// </summary>
58public string ConnStr
59{
60set { DB_ConnStr = value; }
61get { return DB_ConnStr; }
62}
63/// <summary>
64/// 测试命令
65/// </summary>
66public string CmdStr
67{
68set { DB_CmdStr = value; }
69get { return DB_CmdStr; }
70}
71/// <summary>
72/// 测试值
73/// </summary>
74public string Val
75{
76set { DB_Value = value; }
77get { return DB_Value; }
78}
79/// <summary>
80/// 手机短信发送目标列表,用|分割
81/// </summary>
82public string SendList
83{
84set { DB_SendList = value; }
85get { return DB_SendList; }
86}
87}
88}
2using System.Collections.Generic;
3using System.Text;
4
5namespace IDC_SECURITY
6{
7/// <summary>
8/// 数据库连接
9/// </summary>
10public class DB_MSG
11{
12public DB_MSG()
13{
14}
15/// <summary>
16/// 连接名
17/// </summary>
18private string DB_Name;
19/// <summary>
20/// 连接字符串
21/// </summary>
22private string DB_ConnStr;
23/// <summary>
24/// 测试命令
25/// </summary>
26private string DB_CmdStr;
27/// <summary>
28/// 测试值,与测试命令或者测试表名配套使用
29/// </summary>
30private string DB_Value;
31/// <summary>
32/// 手机短信发送目标列表,用|分割
33/// </summary>
34private string DB_SendList;
35/// <summary>
36/// 错误信息
37/// </summary>
38private string DB_ErrorMsg;
39/// <summary>
40/// 错误信息
41/// </summary>
42public string ErrorMsg
43{
44set { this.DB_ErrorMsg = value; }
45get { return DB_ErrorMsg; }
46}
47/// <summary>
48/// 连接名
49/// </summary>
50public string Name
51{
52set { DB_Name = value; }
53get { return DB_Name; }
54}
55/// <summary>
56/// 连接字符串
57/// </summary>
58public string ConnStr
59{
60set { DB_ConnStr = value; }
61get { return DB_ConnStr; }
62}
63/// <summary>
64/// 测试命令
65/// </summary>
66public string CmdStr
67{
68set { DB_CmdStr = value; }
69get { return DB_CmdStr; }
70}
71/// <summary>
72/// 测试值
73/// </summary>
74public string Val
75{
76set { DB_Value = value; }
77get { return DB_Value; }
78}
79/// <summary>
80/// 手机短信发送目标列表,用|分割
81/// </summary>
82public string SendList
83{
84set { DB_SendList = value; }
85get { return DB_SendList; }
86}
87}
88}
WEB信息类:
1using System;
2using System.Collections;
3using System.Text;
4
5namespace IDC_SECURITY
6{
7/// <summary>
8/// 网站测试
9/// </summary>
10public class WEB_MSG
11{
12public WEB_MSG()
13{
14
15}
16/// <summary>
17/// 测试名
18/// </summary>
19private string WEB_Name;
20/// <summary>
21/// 测试URL
22/// </summary>
23private string WEB_URL;
24/// <summary>
25/// 是否使用Meta
26/// </summary>
27private bool WEB_UseMeta;
28/// <summary>
29/// 测试Meta名
30/// </summary>
31private string WEB_MetaName;
32/// <summary>
33/// 测试错误信息
34/// </summary>
35private string WEB_ErrorMsg;
36private string WEB_Value;
37/// <summary>
38/// 测试结果发送列表
39/// </summary>
40private string WEB_List;
41
42/// <summary>
43/// 测试网站名
44/// </summary>
45public string Name
46{
47set { WEB_Name = value; }
48get { return WEB_Name; }
49}
50/// <summary>
51/// 测试URL
52/// </summary>
53public string Url
54{
55set { WEB_URL = value; }
56get { return WEB_URL; }
57}
58/// <summary>
59/// 是否使用Meta
60/// </summary>
61public bool UseMeta
62{
63set { WEB_UseMeta = value; }
64get { return WEB_UseMeta; }
65}
66/// <summary>
67/// 测试Meta名
68/// </summary>
69public string MetaName
70{
71set { this.WEB_MetaName = value; }
72get { return WEB_MetaName; }
73}
74/// <summary>
75/// 测试页面部分值
76/// </summary>
77public string Val
78{
79set { WEB_Value = value; }
80get { return WEB_Value; }
81}
82/// <summary>
83/// 测试错误信息
84/// </summary>
85public string ErrorMsg
86{
87set { this.WEB_ErrorMsg = value; }
88get { return WEB_ErrorMsg; }
89}
90/// <summary>
91/// 结果发送列表
92/// </summary>
93public string SendList
94{
95set { WEB_List = value; }
96get { return WEB_List; }
97}
98}
99}
100
2using System.Collections;
3using System.Text;
4
5namespace IDC_SECURITY
6{
7/// <summary>
8/// 网站测试
9/// </summary>
10public class WEB_MSG
11{
12public WEB_MSG()
13{
14
15}
16/// <summary>
17/// 测试名
18/// </summary>
19private string WEB_Name;
20/// <summary>
21/// 测试URL
22/// </summary>
23private string WEB_URL;
24/// <summary>
25/// 是否使用Meta
26/// </summary>
27private bool WEB_UseMeta;
28/// <summary>
29/// 测试Meta名
30/// </summary>
31private string WEB_MetaName;
32/// <summary>
33/// 测试错误信息
34/// </summary>
35private string WEB_ErrorMsg;
36private string WEB_Value;
37/// <summary>
38/// 测试结果发送列表
39/// </summary>
40private string WEB_List;
41
42/// <summary>
43/// 测试网站名
44/// </summary>
45public string Name
46{
47set { WEB_Name = value; }
48get { return WEB_Name; }
49}
50/// <summary>
51/// 测试URL
52/// </summary>
53public string Url
54{
55set { WEB_URL = value; }
56get { return WEB_URL; }
57}
58/// <summary>
59/// 是否使用Meta
60/// </summary>
61public bool UseMeta
62{
63set { WEB_UseMeta = value; }
64get { return WEB_UseMeta; }
65}
66/// <summary>
67/// 测试Meta名
68/// </summary>
69public string MetaName
70{
71set { this.WEB_MetaName = value; }
72get { return WEB_MetaName; }
73}
74/// <summary>
75/// 测试页面部分值
76/// </summary>
77public string Val
78{
79set { WEB_Value = value; }
80get { return WEB_Value; }
81}
82/// <summary>
83/// 测试错误信息
84/// </summary>
85public string ErrorMsg
86{
87set { this.WEB_ErrorMsg = value; }
88get { return WEB_ErrorMsg; }
89}
90/// <summary>
91/// 结果发送列表
92/// </summary>
93public string SendList
94{
95set { WEB_List = value; }
96get { return WEB_List; }
97}
98}
99}
100
日志记录类:
1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.IO;
5
6namespace IDC_SECURITY
7{
8public class LOG
9{
10private static DateTime HappenTime;
11
12private static void CheckFileExist(CheckResults Chk)
13{
14HappenTime = Chk.ChkTime;
15string RootPath = MyConfig.GetLogPath();
16if (!Directory.Exists(RootPath + HappenTime.Year.ToString()))
17{
18Directory.CreateDirectory(RootPath + HappenTime.Year.ToString());
19Directory.CreateDirectory(RootPath + HappenTime.Year.ToString() +
20"/" + HappenTime.Month.ToString());
21}
22else
23{
24if (!Directory.Exists(RootPath + HappenTime.Year.ToString() +
25"/" + HappenTime.Month.ToString()))
26{
27Directory.CreateDirectory(RootPath + HappenTime.Year.ToString() +
28"/" + HappenTime.Month.ToString());
29}
30}
31
32if (!File.Exists(RootPath + HappenTime.Year.ToString() +
33"/" + HappenTime.Month.ToString() + "/" +
34HappenTime.ToString("yyyyMMdd") + ".txt"))
35{
36FileStream FS =
37File.Create(RootPath + HappenTime.Year.ToString() +
38"/" + HappenTime.Month.ToString() + "/" +
39HappenTime.ToString("yyyyMMdd") + ".txt");
40FS.Close();
41}
42}
43/// <summary>
44/// 写入检查结果
45/// </summary>
46/// <param name="Chk"></param>
47public static void WriteCheckResult(CheckResults Chk)
48{
49CheckFileExist(Chk);
50StreamWriter SWT =
51new StreamWriter(
52MyConfig.GetLogPath() +
53Chk.ChkTime.Year.ToString() +
54"/" + Chk.ChkTime.Month.ToString() +
55"/" + Chk.ChkTime.ToString("yyyyMMdd") +
56".txt", true, Encoding.UTF8);
57
58SWT.WriteLine("[检查]");
59SWT.WriteLine("[时间:" + Chk.ChkTime.ToString("yyyy年MM月dd日 hh:mm:ss") + "]");
60SWT.WriteLine("[类型:" + Chk.ChkType.ToString() + "]");
61SWT.WriteLine("[名称:" + Chk.ChkName + "]");
62SWT.WriteLine("[结果:" + Chk.ChkResult.ToString() + "]");
63SWT.WriteLine("\r\n");
64SWT.Close();
65}
66/// <summary>
67/// 记录短信发送信息
68/// </summary>
69/// <param name="LogContent"></param>
70public static void WriteSmsOpLog(string LogContent, string SendResult)
71{
72StreamWriter SWT =
73new StreamWriter(MyConfig.GetLogPath() +
74DateTime.Now.Year.ToString() + "/" +
75DateTime.Now.Month.ToString() + "/" +
76DateTime.Now.ToString("yyyyMMdd") +
77".txt", true, Encoding.UTF8);
78
79SWT.WriteLine("[短信]");
80SWT.WriteLine("[时间:" +
81System.DateTime.Now.ToString("yyyy年MM月dd日 hh:mm:ss" + "]"));
82SWT.WriteLine("[内容:" + LogContent + "]");
83SWT.WriteLine("[结果:" + SendResult + "]");
84SWT.WriteLine("\r\n");
85SWT.Close();
86}
87}
88}
2using System.Collections.Generic;
3using System.Text;
4using System.IO;
5
6namespace IDC_SECURITY
7{
8public class LOG
9{
10private static DateTime HappenTime;
11
12private static void CheckFileExist(CheckResults Chk)
13{
14HappenTime = Chk.ChkTime;
15string RootPath = MyConfig.GetLogPath();
16if (!Directory.Exists(RootPath + HappenTime.Year.ToString()))
17{
18Directory.CreateDirectory(RootPath + HappenTime.Year.ToString());
19Directory.CreateDirectory(RootPath + HappenTime.Year.ToString() +
20"/" + HappenTime.Month.ToString());
21}
22else
23{
24if (!Directory.Exists(RootPath + HappenTime.Year.ToString() +
25"/" + HappenTime.Month.ToString()))
26{
27Directory.CreateDirectory(RootPath + HappenTime.Year.ToString() +
28"/" + HappenTime.Month.ToString());
29}
30}
31
32if (!File.Exists(RootPath + HappenTime.Year.ToString() +
33"/" + HappenTime.Month.ToString() + "/" +
34HappenTime.ToString("yyyyMMdd") + ".txt"))
35{
36FileStream FS =
37File.Create(RootPath + HappenTime.Year.ToString() +
38"/" + HappenTime.Month.ToString() + "/" +
39HappenTime.ToString("yyyyMMdd") + ".txt");
40FS.Close();
41}
42}
43/// <summary>
44/// 写入检查结果
45/// </summary>
46/// <param name="Chk"></param>
47public static void WriteCheckResult(CheckResults Chk)
48{
49CheckFileExist(Chk);
50StreamWriter SWT =
51new StreamWriter(
52MyConfig.GetLogPath() +
53Chk.ChkTime.Year.ToString() +
54"/" + Chk.ChkTime.Month.ToString() +
55"/" + Chk.ChkTime.ToString("yyyyMMdd") +
56".txt", true, Encoding.UTF8);
57
58SWT.WriteLine("[检查]");
59SWT.WriteLine("[时间:" + Chk.ChkTime.ToString("yyyy年MM月dd日 hh:mm:ss") + "]");
60SWT.WriteLine("[类型:" + Chk.ChkType.ToString() + "]");
61SWT.WriteLine("[名称:" + Chk.ChkName + "]");
62SWT.WriteLine("[结果:" + Chk.ChkResult.ToString() + "]");
63SWT.WriteLine("\r\n");
64SWT.Close();
65}
66/// <summary>
67/// 记录短信发送信息
68/// </summary>
69/// <param name="LogContent"></param>
70public static void WriteSmsOpLog(string LogContent, string SendResult)
71{
72StreamWriter SWT =
73new StreamWriter(MyConfig.GetLogPath() +
74DateTime.Now.Year.ToString() + "/" +
75DateTime.Now.Month.ToString() + "/" +
76DateTime.Now.ToString("yyyyMMdd") +
77".txt", true, Encoding.UTF8);
78
79SWT.WriteLine("[短信]");
80SWT.WriteLine("[时间:" +
81System.DateTime.Now.ToString("yyyy年MM月dd日 hh:mm:ss" + "]"));
82SWT.WriteLine("[内容:" + LogContent + "]");
83SWT.WriteLine("[结果:" + SendResult + "]");
84SWT.WriteLine("\r\n");
85SWT.Close();
86}
87}
88}
短信发送类:(不同设备,程序不同)
1using System;
2using System.Collections;
3using System.ComponentModel;
4using System.Data;
5using System.Runtime.InteropServices;
6using System.Text;
7using System.Configuration;
8
9namespace IDC_SECURITY
10{
11public class SMS_SEND
12{
13基本配置与设置
173
174public SMS_SEND()
175{
176StringBuilder szNeedSndMsg = new StringBuilder(1024);
177StringBuilder szSndPhNbr = new StringBuilder(30);
178StringBuilder szNextMsg = new StringBuilder(1024);
179StringBuilder szRcvPh = new StringBuilder(30);
180StringBuilder szRcvMsg = new StringBuilder(300);
181StringBuilder szRcvDateTime = new StringBuilder(30);
182}
183/// <summary>
184/// 打开串口
185/// </summary>
186/// <param name="ComName">串口名称</param>
187/// <returns></returns>
188private bool OpenComm(string ComName)
189{
190//正版授权注册 iErrCode=1 校验正确 iErrCode=-100 错误
191iErrCode = iSetSerialNo("www.etoneinfo.com", "dfyhJjDkF");
192//串口名称
193strTmp = ComName;
194//打开串口
195hComm = hOpenComm(strTmp);
196
197if (!hComm.Equals(null) && (hComm.ToInt32() != 0) &&
198((UInt32)hComm != INVALID_HANDLE_VALUE))
199{
200//自动初始
201bRet = bAutoInit(hComm, ref CommInfo, iSMSFormat, strErrInfo);
202
203strTmp = new String(CommInfo.szSCA);
204iTmp = strTmp.IndexOf('\0');
205strSCA = new StringBuilder(strTmp, iTmp);
206
207//打开成功
208return true;
209}
210else
211{
212//打开失败
213return false;
214}
215}
216/// <summary>
217/// 关闭串口
218/// </summary>
219/// <param name="ComName">串口名称</param>
220/// <returns></returns>
221private bool CloseComm(string ComName)
222{
223bRet = bCloseComm(hComm);
224if (bRet)
225{
226//关闭成功
227hComm = IntPtr.Zero;
228return true;
229}
230else
231{
232//关闭失败
233return false;
234}
235}
236/// <summary>
237/// 清空SIM卡
238/// </summary>
239/// <returns></returns>
240private bool CLearSIM()
241{
242bRet = bClrSIM(hComm, strErrInfo);
243if (bRet)
244{
245//清空成功
246return true;
247}
248else
249{
250//清空失败
251return false;
252}
253}
254/// <summary>
255/// 发送短信
256/// </summary>
257/// <param name="MsgContent">短信内容</param>
258/// <param name="NumToSend">目标号码</param>
259/// <param name="ComName">发送串口</param>
260/// <returns></returns>
261public string SendMsg(string MsgContent, string NumToSend, string ComName)
262{
263strNextMsg = new StringBuilder(512);
264iTmp = strNextMsg.Length;
265strSndPhNbr = new System.Text.StringBuilder(NumToSend);
266strNeedSndMsg = new System.Text.StringBuilder(MsgContent);
267OpenComm(ComName);
268if (hComm.Equals(null) || (hComm.ToInt32() == 0)
269|| ((UInt32)hComm == INVALID_HANDLE_VALUE))
270{
271//串口打开失败
272return "串口打开失败";
273}
274string SndResult = "";
275while (strNeedSndMsg.Length > 0)
276{
277bSndSucc = false;
278bRet = bSendMsg(hComm, strNeedSndMsg, strSndPhNbr,
279strSCA, strNextMsg, SMS_FORMAT_PDU, strErrInfo);
280if (bRet == false) //发送失败
281{
282bSndSucc = false;
283SndResult = "发送失败";
284break;
285}
286else
287{
288if (strNextMsg.Length <= 0) //超长部分的待发内容
289{
290bSndSucc = true; //发送成功
291SndResult = "发送成功";
292}
293strNeedSndMsg = strNextMsg;
294strNextMsg = new StringBuilder(512);
295}
296}
297
298if (bSndSucc)
299{
300//发送成功
301CloseComm(ComName);
302return SndResult;
303}
304else
305{
306//发送失败
307CloseComm(ComName);
308return SndResult;
309}
310}
311}
312}
2using System.Collections;
3using System.ComponentModel;
4using System.Data;
5using System.Runtime.InteropServices;
6using System.Text;
7using System.Configuration;
8
9namespace IDC_SECURITY
10{
11public class SMS_SEND
12{
13基本配置与设置
173
174public SMS_SEND()
175{
176StringBuilder szNeedSndMsg = new StringBuilder(1024);
177StringBuilder szSndPhNbr = new StringBuilder(30);
178StringBuilder szNextMsg = new StringBuilder(1024);
179StringBuilder szRcvPh = new StringBuilder(30);
180StringBuilder szRcvMsg = new StringBuilder(300);
181StringBuilder szRcvDateTime = new StringBuilder(30);
182}
183/// <summary>
184/// 打开串口
185/// </summary>
186/// <param name="ComName">串口名称</param>
187/// <returns></returns>
188private bool OpenComm(string ComName)
189{
190//正版授权注册 iErrCode=1 校验正确 iErrCode=-100 错误
191iErrCode = iSetSerialNo("www.etoneinfo.com", "dfyhJjDkF");
192//串口名称
193strTmp = ComName;
194//打开串口
195hComm = hOpenComm(strTmp);
196
197if (!hComm.Equals(null) && (hComm.ToInt32() != 0) &&
198((UInt32)hComm != INVALID_HANDLE_VALUE))
199{
200//自动初始
201bRet = bAutoInit(hComm, ref CommInfo, iSMSFormat, strErrInfo);
202
203strTmp = new String(CommInfo.szSCA);
204iTmp = strTmp.IndexOf('\0');
205strSCA = new StringBuilder(strTmp, iTmp);
206
207//打开成功
208return true;
209}
210else
211{
212//打开失败
213return false;
214}
215}
216/// <summary>
217/// 关闭串口
218/// </summary>
219/// <param name="ComName">串口名称</param>
220/// <returns></returns>
221private bool CloseComm(string ComName)
222{
223bRet = bCloseComm(hComm);
224if (bRet)
225{
226//关闭成功
227hComm = IntPtr.Zero;
228return true;
229}
230else
231{
232//关闭失败
233return false;
234}
235}
236/// <summary>
237/// 清空SIM卡
238/// </summary>
239/// <returns></returns>
240private bool CLearSIM()
241{
242bRet = bClrSIM(hComm, strErrInfo);
243if (bRet)
244{
245//清空成功
246return true;
247}
248else
249{
250//清空失败
251return false;
252}
253}
254/// <summary>
255/// 发送短信
256/// </summary>
257/// <param name="MsgContent">短信内容</param>
258/// <param name="NumToSend">目标号码</param>
259/// <param name="ComName">发送串口</param>
260/// <returns></returns>
261public string SendMsg(string MsgContent, string NumToSend, string ComName)
262{
263strNextMsg = new StringBuilder(512);
264iTmp = strNextMsg.Length;
265strSndPhNbr = new System.Text.StringBuilder(NumToSend);
266strNeedSndMsg = new System.Text.StringBuilder(MsgContent);
267OpenComm(ComName);
268if (hComm.Equals(null) || (hComm.ToInt32() == 0)
269|| ((UInt32)hComm == INVALID_HANDLE_VALUE))
270{
271//串口打开失败
272return "串口打开失败";
273}
274string SndResult = "";
275while (strNeedSndMsg.Length > 0)
276{
277bSndSucc = false;
278bRet = bSendMsg(hComm, strNeedSndMsg, strSndPhNbr,
279strSCA, strNextMsg, SMS_FORMAT_PDU, strErrInfo);
280if (bRet == false) //发送失败
281{
282bSndSucc = false;
283SndResult = "发送失败";
284break;
285}
286else
287{
288if (strNextMsg.Length <= 0) //超长部分的待发内容
289{
290bSndSucc = true; //发送成功
291SndResult = "发送成功";
292}
293strNeedSndMsg = strNextMsg;
294strNextMsg = new StringBuilder(512);
295}
296}
297
298if (bSndSucc)
299{
300//发送成功
301CloseComm(ComName);
302return SndResult;
303}
304else
305{
306//发送失败
307CloseComm(ComName);
308return SndResult;
309}
310}
311}
312}