Program类:
1
using System.Collections.Generic;
2
using System.ServiceProcess;
3
using System.Text;
4
#region
5
namespace IDC_SECURITY
6
{
7
static class Program
8
{
9
/// <summary>
10
/// 应用程序的主入口点。
11
/// </summary>
12
static void Main()
13
{
14
ServiceBase[] ServicesToRun;
15
16
// 同一进程中可以运行多个用户服务。若要将
17
// 另一个服务添加到此进程中,请更改下行以
18
// 创建另一个服务对象。例如,
19
//
20
// ServicesToRun = new ServiceBase[] {new Service1(), new MySecondUserService()};
21
//
22
ServicesToRun = new ServiceBase[] { new IDC_SECURITY_SMS() };
23
24
ServiceBase.Run(ServicesToRun);
25
}
26
}

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27}
服务的主类:
1
using System;
2
using System.Collections.Generic;
3
using System.ComponentModel;
4
using System.Data;
5
using System.Diagnostics;
6
using System.ServiceProcess;
7
using System.Text;
8
using System.Timers;
9
using System.Data.SqlClient;
10
11
namespace IDC_SECURITY
12
{
13
public partial class IDC_SECURITY_SMS : ServiceBase
14
{
15
public System.Timers.Timer Check_Timer = new System.Timers.Timer();
16
public BackgroundWorker AsyncChkThd = new System.ComponentModel.BackgroundWorker();
17
18
public IDC_SECURITY_SMS()
19
{
20
//配置服务信息
21
this.AutoLog = true;
22
this.CanPauseAndContinue = true;
23
this.CanShutdown = true;
24
this.CanStop = true;
25
this.ServiceName = "短信检测IDC状况";
26
27
//配置Timer
28
this.Check_Timer.Interval = Convert.ToInt32(MyConfig.GetTimeTick());
29
this.Check_Timer.Elapsed += new ElapsedEventHandler(Check_Timer_Elapsed);
30
31
//配置BackgroundWorker
32
this.AsyncChkThd.DoWork += new DoWorkEventHandler(AsyncChkThd_DoWork);
33
34
InitializeComponent();
35
}
36
37
void AsyncChkThd_DoWork(object sender, DoWorkEventArgs e)
38
{
39
RunChk();
40
}
41
42
void RunChk()
43
{
44
//检查WEB
45
//检查DB
46
List<DB_MSG> DBLIST = MyConfig.GetAllDBCONFIG();
47
foreach (DB_MSG DM in DBLIST)
48
{
49
CHECK.CheckAndLog(DM);
50
}
51
List<WEB_MSG> WEBLIST = MyConfig.GetAllWebCONFIG();
52
foreach (WEB_MSG WM in WEBLIST)
53
{
54
CHECK.CheckAndLog(WM);
55
}
56
}
57
58
void Check_Timer_Elapsed(object sender, ElapsedEventArgs e)
59
{
60
AsyncChkThd.RunWorkerAsync();
61
}
62
63
protected override void OnStart(string[] args)
64
{
65
// TODO: 在此处添加代码以启动服务。
66
Check_Timer.Enabled = true;
67
}
68
69
protected override void OnStop()
70
{
71
// TODO: 在此处添加代码以执行停止服务所需的关闭操作。
72
Check_Timer.Enabled = false;
73
}
74
}
75
}

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

服务设计类:
1
namespace IDC_SECURITY
2
{
3
partial class IDC_SECURITY_SMS
4
{
5
/// <summary>
6
/// 必需的设计器变量。
7
/// </summary>
8
private System.ComponentModel.IContainer components = null;
9
10
/// <summary>
11
/// 清理所有正在使用的资源。
12
/// </summary>
13
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
14
protected override void Dispose(bool disposing)
15
{
16
if (disposing && (components != null))
17
{
18
components.Dispose();
19
}
20
base.Dispose(disposing);
21
}
22
23
组件设计器生成的代码
36
}
37
}

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

36

37

配置获取工具类:
1
using System;
2
using System.Collections.Generic;
3
using System.Text;
4
using System.Xml;
5
using System.IO;
6
7
namespace IDC_SECURITY
8
{
9
public abstract class MyConfig
10
{
11
public static readonly string XmlPath = "D:/SMS/SMS_CONFIG.xml";
12
//配置类型
13
public enum CONFIGTYPE { DBCONFIG, WEBCONFIG, LOGCONFIG, TIMECONFIG, COMNAME };
14
//XML属性列表
15
public enum AttriNames
16
{
17
DB_NAME, DB_CONNSTR, DB_VAL, DB_CMDSTR, DB_SENDPHONE, DB_ERRORMSG,
18
WEB_NAME, WEB_URL, WEB_USEMETA, WEB_METANAME, WEB_VAL, WEB_SENDPHONE, WEB_ERRORMSG,
19
LOG_PATH,
20
TIME_COUNT,
21
NAME
22
};
23
24
/// <summary>
25
/// 获取配置子列
26
/// </summary>
27
/// <param name="ConfigType">配置节类型</param>
28
/// <returns></returns>
29
public static XmlNodeList GetConfigs(CONFIGTYPE ConfigType)
30
{
31
XmlDocument XmlDoc = new XmlDocument();
32
XmlDoc.Load(XmlPath);
33
34
XmlNode RootNode = null;
35
if (ConfigType == CONFIGTYPE.DBCONFIG)
36
{
37
RootNode = XmlDoc.SelectSingleNode("CONFIG/DB_CONFIG");
38
}
39
else if (ConfigType == CONFIGTYPE.LOGCONFIG)
40
{
41
RootNode = XmlDoc.SelectSingleNode("CONFIG/LOG_CONFIG");
42
}
43
else if (ConfigType == CONFIGTYPE.WEBCONFIG)
44
{
45
RootNode = XmlDoc.SelectSingleNode("CONFIG/WEB_CONFIG");
46
}
47
else if (ConfigType == CONFIGTYPE.TIMECONFIG)
48
{
49
RootNode = XmlDoc.SelectSingleNode("CONFIG/TIME_CONFIG");
50
}
51
else if (ConfigType == CONFIGTYPE.COMNAME)
52
{
53
RootNode = XmlDoc.SelectSingleNode("CONFIG/COM_NAME");
54
}
55
56
return RootNode.ChildNodes;
57
}
58
/// <summary>
59
/// 获取节点属性值
60
/// </summary>
61
/// <param name="AttributeName"></param>
62
/// <param name="XNode"></param>
63
/// <returns></returns>
64
public static string GetXmlNodeValue(AttriNames AttributeName,XmlNode XNode)
65
{
66
return XNode.Attributes[AttributeName.ToString()].Value;
67
}
68
/// <summary>
69
/// 获取日志存放根目录
70
/// </summary>
71
/// <returns></returns>
72
public static string GetLogPath()
73
{
74
string PathRtn="";
75
XmlNodeList XNL = GetConfigs(CONFIGTYPE.LOGCONFIG);
76
for(int i=0;i<XNL.Count;i++)
77
{
78
if(XNL[i].NodeType==XmlNodeType.Element)
79
{
80
PathRtn=XNL[i].Attributes[AttriNames.LOG_PATH.ToString()].Value;
81
break;
82
}
83
}
84
return PathRtn;
85
}
86
/// <summary>
87
/// 遍历获取所有待测试数据库连接
88
/// </summary>
89
/// <returns></returns>
90
public static List<DB_MSG> GetAllDBCONFIG()
91
{
92
List <DB_MSG> DBOBJ_LIST= new List<DB_MSG>();
93
foreach (XmlNode XN in GetConfigs(CONFIGTYPE.DBCONFIG))
94
{
95
if (XN.NodeType == XmlNodeType.Element)
96
{
97
DB_MSG DBMOBJ = new DB_MSG();
98
DBMOBJ.CmdStr = GetXmlNodeValue(AttriNames.DB_CMDSTR, XN);
99
DBMOBJ.ConnStr = GetXmlNodeValue(AttriNames.DB_CONNSTR, XN);
100
DBMOBJ.Name = GetXmlNodeValue(AttriNames.DB_NAME, XN);
101
DBMOBJ.SendList = GetXmlNodeValue(AttriNames.DB_SENDPHONE, XN);
102
DBMOBJ.Val = GetXmlNodeValue(AttriNames.DB_VAL, XN);
103
DBMOBJ.ErrorMsg = GetXmlNodeValue(AttriNames.DB_ERRORMSG, XN);
104
105
DBOBJ_LIST.Add(DBMOBJ);
106
}
107
}
108
109
return DBOBJ_LIST;
110
}
111
/// <summary>
112
/// 遍历获取所有待测试网页
113
/// </summary>
114
/// <returns></returns>
115
public static List<WEB_MSG> GetAllWebCONFIG()
116
{
117
List<WEB_MSG> WEBOBJ_LIST = new List<WEB_MSG>();
118
foreach (XmlNode XN in GetConfigs(CONFIGTYPE.WEBCONFIG))
119
{
120
if (XN.NodeType == XmlNodeType.Element)
121
{
122
WEB_MSG WEBOBJ = new WEB_MSG();
123
WEBOBJ.ErrorMsg = GetXmlNodeValue(AttriNames.WEB_ERRORMSG, XN);
124
WEBOBJ.MetaName = GetXmlNodeValue(AttriNames.WEB_METANAME, XN);
125
WEBOBJ.Name = GetXmlNodeValue(AttriNames.WEB_NAME, XN);
126
WEBOBJ.SendList = GetXmlNodeValue(AttriNames.WEB_SENDPHONE, XN);
127
WEBOBJ.Url = GetXmlNodeValue(AttriNames.WEB_URL, XN);
128
WEBOBJ.UseMeta = bool.Parse(GetXmlNodeValue(AttriNames.WEB_USEMETA, XN));
129
WEBOBJ.Val = GetXmlNodeValue(AttriNames.WEB_VAL, XN);
130
131
WEBOBJ_LIST.Add(WEBOBJ);
132
}
133
}
134
135
return WEBOBJ_LIST;
136
}
137
/// <summary>
138
/// 获取定时器时间间隔
139
/// </summary>
140
/// <returns></returns>
141
public static int GetTimeTick()
142
{
143
int RtnTick = 0;
144
XmlNodeList XNL = GetConfigs(CONFIGTYPE.TIMECONFIG);
145
for (int i = 0; i < XNL.Count; i++)
146
{
147
if (XNL[i].NodeType == XmlNodeType.Element)
148
{
149
RtnTick =
150
Convert.ToInt32(XNL[i].Attributes[AttriNames.TIME_COUNT.ToString()].Value);
151
break;
152
}
153
}
154
155
return RtnTick;
156
}
157
/// <summary>
158
/// 获取发送串口名
159
/// </summary>
160
/// <returns></returns>
161
public static string GetComName()
162
{
163
string RtnComName = "";
164
XmlNodeList XNL = GetConfigs(CONFIGTYPE.COMNAME);
165
for (int i = 0; i < XNL.Count; i++)
166
{
167
if (XNL[i].NodeType == XmlNodeType.Element)
168
{
169
RtnComName = XNL[i].Attributes[AttriNames.NAME.ToString()].Value;
170
break;
171
}
172
}
173
174
return RtnComName;
175
}
176
}
177
}

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

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

3

4

5

6

7


8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

检查类:
1
using System;
2
using System.Collections;
3
using System.Text;
4
using System.Data;
5
using System.Data.SqlClient;
6
using System.Net;
7
using System.Web;
8
using System.IO;
9
using System.Text.RegularExpressions;
10
using System.Configuration;
11
12
namespace IDC_SECURITY
13
{
14
public class CHECK
15
{
16
public CHECK()
17
{
18
}
19
/// <summary>
20
/// 检查数据库
21
/// </summary>
22
/// <param name="dbmsg"></param>
23
public static void CheckAndLog(DB_MSG dbmsg)
24
{
25
//声明返回对象
26
CheckResults ChkRtn = new CheckResults();
27
ChkRtn.ChkName = dbmsg.Name;
28
ChkRtn.ChkTime = System.DateTime.Now;
29
ChkRtn.ChkType = MyConfig.CONFIGTYPE.DBCONFIG;
30
ChkRtn.ChkErrorMsg = dbmsg.ErrorMsg;
31
32
string[] SendArray = dbmsg.SendList.Split('|');
33
ArrayList AL = new ArrayList();
34
foreach (string SendTo in SendArray)
35
{
36
AL.Add(SendTo);
37
}
38
ChkRtn.ChkList = AL;
39
//数据库检查
40
SqlConnection SqlConn = new SqlConnection(dbmsg.ConnStr);
41
SqlCommand SqlCmd = new SqlCommand();
42
SqlCmd.Connection = SqlConn;
43
SqlCmd.CommandType = CommandType.Text;
44
45
//如果存在测试命令
46
if (dbmsg.CmdStr != "" && dbmsg.Val != "")
47
{
48
try
49
{
50
SqlCmd.CommandText = dbmsg.CmdStr;
51
SqlConn.Open();
52
string ChkVal = SqlCmd.ExecuteScalar().ToString();
53
if (ChkVal == dbmsg.Val)
54
{
55
ChkRtn.ChkResult = true;
56
}
57
else
58
{
59
ChkRtn.ChkResult = false;
60
}
61
}
62
catch
63
{
64
//如果发生异常,表明数据库出问题
65
ChkRtn.ChkResult = false;
66
}
67
}
68
else
69
{
70
//如过不存在数据库测试命令
71
try
72
{
73
SqlConn.Open();
74
SqlConn.Close();
75
ChkRtn.ChkResult = true;
76
}
77
catch
78
{
79
//数据库无法打开,表明数据库出问题
80
ChkRtn.ChkResult = false;
81
}
82
}
83
84
LOG.WriteCheckResult(ChkRtn);
85
if (!ChkRtn.ChkResult)
86
{
87
string ComName = MyConfig.GetComName();
88
89
foreach (object SendToObj in ChkRtn.ChkList)
90
{
91
SMS_SEND SMSObj =
92
new SMS_SEND();
93
string SendResult =
94
SMSObj.SendMsg(ChkRtn.ChkName + ":" + ChkRtn.ChkErrorMsg, SendToObj.ToString(), ComName);
95
LOG.WriteSmsOpLog(ChkRtn.ChkName + ":" + ChkRtn.ChkErrorMsg, SendResult);
96
}
97
}
98
}
99
/// <summary>
100
/// 检查WEB
101
/// </summary>
102
/// <param name="webmsg"></param>
103
/// <returns></returns>
104
public static void CheckAndLog(WEB_MSG webmsg)
105
{
106
//声明测试对象
107
CheckResults ChkRtn = new CheckResults();
108
ChkRtn.ChkName = webmsg.Name;
109
ChkRtn.ChkTime = System.DateTime.Now;
110
ChkRtn.ChkType = MyConfig.CONFIGTYPE.WEBCONFIG;
111
ChkRtn.ChkErrorMsg = webmsg.ErrorMsg;
112
//测试结果发送对象
113
ArrayList AL = new ArrayList();
114
string[] TArray = webmsg.SendList.Split('|');
115
foreach (string TA in TArray)
116
{
117
AL.Add(TA);
118
}
119
ChkRtn.ChkList = AL;
120
121
if (webmsg.UseMeta)
122
{
123
//如果测试目标为META
124
try
125
{
126
if (GetMeta(webmsg.MetaName, GetResponseBack(webmsg.Url)) == webmsg.Val)
127
{
128
ChkRtn.ChkResult = true;
129
}
130
else
131
{
132
ChkRtn.ChkResult = false;
133
}
134
}
135
catch
136
{
137
//如果访问出错,则网站出问题
138
ChkRtn.ChkResult = false;
139
}
140
}
141
else
142
{
143
//如果测试目标不是META
144
//则直接验证返回页面是否是制定值
145
try
146
{
147
string AllSrcCode = GetResponseBack(webmsg.Url);
148
149
if (AllSrcCode.Contains(webmsg.Val))
150
{
151
ChkRtn.ChkResult = true;
152
}
153
else
154
{
155
ChkRtn.ChkResult = false;
156
}
157
}
158
catch
159
{
160
ChkRtn.ChkResult = false;
161
}
162
}
163
164
LOG.WriteCheckResult(ChkRtn);
165
if (!ChkRtn.ChkResult)
166
{
167
string ComName = MyConfig.GetComName();
168
169
foreach (object SendToObj in ChkRtn.ChkList)
170
{
171
SMS_SEND SMSObj = new SMS_SEND();
172
string SendResult =
173
SMSObj.SendMsg(ChkRtn.ChkName + ":" + ChkRtn.ChkErrorMsg, SendToObj.ToString(), ComName);
174
LOG.WriteSmsOpLog(ChkRtn.ChkName + ":" + ChkRtn.ChkErrorMsg, SendResult);
175
}
176
}
177
}
178
179
/// <summary>
180
/// 获取网络响应
181
/// </summary>
182
/// <param name="Uri"></param>
183
/// <returns></returns>
184
private static string GetResponseBack(string Uri)
185
{
186
try
187
{
188
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(Uri);
189
myRequest.Timeout = 3000;
190
191
192
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
193
194
Stream Stm = myResponse.GetResponseStream();
195
StreamReader srd = new StreamReader(Stm);
196
string BackStr = srd.ReadToEnd();
197
srd.Close();
198
Stm.Close();
199
myResponse.Close();
200
201
return BackStr;
202
}
203
catch
204
{
205
return "Error";
206
}
207
}
208
209
/// <summary>
210
/// 获取响应数据中指定Meta的值
211
/// </summary>
212
/// <param name="MetaName"></param>
213
/// <param name="SrcStr"></param>
214
/// <returns></returns>
215
private static string GetMeta(string MetaName,string SrcStr)
216
{
217
string RegexStr =
218
string.Format(@"<meta Name=\""{0}\"" content[\s]?=[\s\""\']+(.*?)[\""\']+.*?>", MetaName);
219
Regex MetaRegex =
220
new Regex(RegexStr, RegexOptions.IgnoreCase);
221
Match Mc =
222
MetaRegex.Match(SrcStr);
223
if (Mc != null)
224
{
225
return Mc.Groups[1].ToString();
226
}
227
else
228
{
229
return "";
230
}
231
}
232
}
233
}

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

检查结果类:
1
using System;
2
using System.Collections;
3
using System.Text;
4
5
namespace IDC_SECURITY
6
{
7
public class CheckResults
8
{
9
private MyConfig.CONFIGTYPE checktype;
10
private bool checkresult;
11
private DateTime checktime;
12
private string checkname;
13
private ArrayList checklist;
14
private string errormsg;
15
16
public CheckResults()
17
{
18
}
19
public CheckResults(
20
MyConfig.CONFIGTYPE Chk_Type,
21
bool Chk_Result, DateTime Chk_Time,
22
string Chk_Name,ArrayList Chk_List,
23
string Chk_ErrorMsg)
24
{
25
this.checktype = Chk_Type;
26
this.checkresult = Chk_Result;
27
this.checktime = Chk_Time;
28
this.checkname = Chk_Name;
29
this.checklist=Chk_List;
30
this.errormsg = Chk_ErrorMsg;
31
}
32
/// <summary>
33
/// 测试类型
34
/// </summary>
35
public MyConfig.CONFIGTYPE ChkType
36
{
37
set { this.checktype = value; }
38
get { return this.checktype; }
39
}
40
/// <summary>
41
/// 测试结果
42
/// </summary>
43
public bool ChkResult
44
{
45
set { this.checkresult = value; }
46
get { return this.checkresult; }
47
}
48
/// <summary>
49
/// 测试时间
50
/// </summary>
51
public DateTime ChkTime
52
{
53
set { this.checktime = value; }
54
get { return this.checktime; }
55
}
56
/// <summary>
57
/// 测试名称
58
/// </summary>
59
public string ChkName
60
{
61
set { this.checkname = value; }
62
get { return this.checkname; }
63
}
64
/// <summary>
65
/// 测试结果发送列表
66
/// </summary>
67
public ArrayList ChkList
68
{
69
set { this.checklist = value; }
70
get { return checklist; }
71
}
72
/// <summary>
73
/// 测试错误信息
74
/// </summary>
75
public string ChkErrorMsg
76
{
77
set { this.errormsg = value; }
78
get { return this.errormsg; }
79
}
80
}
81
}

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

数据库信息:
1
using System;
2
using System.Collections.Generic;
3
using System.Text;
4
5
namespace IDC_SECURITY
6
{
7
/// <summary>
8
/// 数据库连接
9
/// </summary>
10
public class DB_MSG
11
{
12
public DB_MSG()
13
{
14
}
15
/// <summary>
16
/// 连接名
17
/// </summary>
18
private string DB_Name;
19
/// <summary>
20
/// 连接字符串
21
/// </summary>
22
private string DB_ConnStr;
23
/// <summary>
24
/// 测试命令
25
/// </summary>
26
private string DB_CmdStr;
27
/// <summary>
28
/// 测试值,与测试命令或者测试表名配套使用
29
/// </summary>
30
private string DB_Value;
31
/// <summary>
32
/// 手机短信发送目标列表,用|分割
33
/// </summary>
34
private string DB_SendList;
35
/// <summary>
36
/// 错误信息
37
/// </summary>
38
private string DB_ErrorMsg;
39
/// <summary>
40
/// 错误信息
41
/// </summary>
42
public string ErrorMsg
43
{
44
set { this.DB_ErrorMsg = value; }
45
get { return DB_ErrorMsg; }
46
}
47
/// <summary>
48
/// 连接名
49
/// </summary>
50
public string Name
51
{
52
set { DB_Name = value; }
53
get { return DB_Name; }
54
}
55
/// <summary>
56
/// 连接字符串
57
/// </summary>
58
public string ConnStr
59
{
60
set { DB_ConnStr = value; }
61
get { return DB_ConnStr; }
62
}
63
/// <summary>
64
/// 测试命令
65
/// </summary>
66
public string CmdStr
67
{
68
set { DB_CmdStr = value; }
69
get { return DB_CmdStr; }
70
}
71
/// <summary>
72
/// 测试值
73
/// </summary>
74
public string Val
75
{
76
set { DB_Value = value; }
77
get { return DB_Value; }
78
}
79
/// <summary>
80
/// 手机短信发送目标列表,用|分割
81
/// </summary>
82
public string SendList
83
{
84
set { DB_SendList = value; }
85
get { return DB_SendList; }
86
}
87
}
88
}

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

WEB信息类:
1
using System;
2
using System.Collections;
3
using System.Text;
4
5
namespace IDC_SECURITY
6
{
7
/// <summary>
8
/// 网站测试
9
/// </summary>
10
public class WEB_MSG
11
{
12
public WEB_MSG()
13
{
14
15
}
16
/// <summary>
17
/// 测试名
18
/// </summary>
19
private string WEB_Name;
20
/// <summary>
21
/// 测试URL
22
/// </summary>
23
private string WEB_URL;
24
/// <summary>
25
/// 是否使用Meta
26
/// </summary>
27
private bool WEB_UseMeta;
28
/// <summary>
29
/// 测试Meta名
30
/// </summary>
31
private string WEB_MetaName;
32
/// <summary>
33
/// 测试错误信息
34
/// </summary>
35
private string WEB_ErrorMsg;
36
private string WEB_Value;
37
/// <summary>
38
/// 测试结果发送列表
39
/// </summary>
40
private string WEB_List;
41
42
/// <summary>
43
/// 测试网站名
44
/// </summary>
45
public string Name
46
{
47
set { WEB_Name = value; }
48
get { return WEB_Name; }
49
}
50
/// <summary>
51
/// 测试URL
52
/// </summary>
53
public string Url
54
{
55
set { WEB_URL = value; }
56
get { return WEB_URL; }
57
}
58
/// <summary>
59
/// 是否使用Meta
60
/// </summary>
61
public bool UseMeta
62
{
63
set { WEB_UseMeta = value; }
64
get { return WEB_UseMeta; }
65
}
66
/// <summary>
67
/// 测试Meta名
68
/// </summary>
69
public string MetaName
70
{
71
set { this.WEB_MetaName = value; }
72
get { return WEB_MetaName; }
73
}
74
/// <summary>
75
/// 测试页面部分值
76
/// </summary>
77
public string Val
78
{
79
set { WEB_Value = value; }
80
get { return WEB_Value; }
81
}
82
/// <summary>
83
/// 测试错误信息
84
/// </summary>
85
public string ErrorMsg
86
{
87
set { this.WEB_ErrorMsg = value; }
88
get { return WEB_ErrorMsg; }
89
}
90
/// <summary>
91
/// 结果发送列表
92
/// </summary>
93
public string SendList
94
{
95
set { WEB_List = value; }
96
get { return WEB_List; }
97
}
98
}
99
}
100

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

日志记录类:
1
using System;
2
using System.Collections.Generic;
3
using System.Text;
4
using System.IO;
5
6
namespace IDC_SECURITY
7
{
8
public class LOG
9
{
10
private static DateTime HappenTime;
11
12
private static void CheckFileExist(CheckResults Chk)
13
{
14
HappenTime = Chk.ChkTime;
15
string RootPath = MyConfig.GetLogPath();
16
if (!Directory.Exists(RootPath + HappenTime.Year.ToString()))
17
{
18
Directory.CreateDirectory(RootPath + HappenTime.Year.ToString());
19
Directory.CreateDirectory(RootPath + HappenTime.Year.ToString() +
20
"/" + HappenTime.Month.ToString());
21
}
22
else
23
{
24
if (!Directory.Exists(RootPath + HappenTime.Year.ToString() +
25
"/" + HappenTime.Month.ToString()))
26
{
27
Directory.CreateDirectory(RootPath + HappenTime.Year.ToString() +
28
"/" + HappenTime.Month.ToString());
29
}
30
}
31
32
if (!File.Exists(RootPath + HappenTime.Year.ToString() +
33
"/" + HappenTime.Month.ToString() + "/" +
34
HappenTime.ToString("yyyyMMdd") + ".txt"))
35
{
36
FileStream FS =
37
File.Create(RootPath + HappenTime.Year.ToString() +
38
"/" + HappenTime.Month.ToString() + "/" +
39
HappenTime.ToString("yyyyMMdd") + ".txt");
40
FS.Close();
41
}
42
}
43
/// <summary>
44
/// 写入检查结果
45
/// </summary>
46
/// <param name="Chk"></param>
47
public static void WriteCheckResult(CheckResults Chk)
48
{
49
CheckFileExist(Chk);
50
StreamWriter SWT =
51
new StreamWriter(
52
MyConfig.GetLogPath() +
53
Chk.ChkTime.Year.ToString() +
54
"/" + Chk.ChkTime.Month.ToString() +
55
"/" + Chk.ChkTime.ToString("yyyyMMdd") +
56
".txt", true, Encoding.UTF8);
57
58
SWT.WriteLine("[检查]");
59
SWT.WriteLine("[时间:" + Chk.ChkTime.ToString("yyyy年MM月dd日 hh:mm:ss") + "]");
60
SWT.WriteLine("[类型:" + Chk.ChkType.ToString() + "]");
61
SWT.WriteLine("[名称:" + Chk.ChkName + "]");
62
SWT.WriteLine("[结果:" + Chk.ChkResult.ToString() + "]");
63
SWT.WriteLine("\r\n");
64
SWT.Close();
65
}
66
/// <summary>
67
/// 记录短信发送信息
68
/// </summary>
69
/// <param name="LogContent"></param>
70
public static void WriteSmsOpLog(string LogContent, string SendResult)
71
{
72
StreamWriter SWT =
73
new StreamWriter(MyConfig.GetLogPath() +
74
DateTime.Now.Year.ToString() + "/" +
75
DateTime.Now.Month.ToString() + "/" +
76
DateTime.Now.ToString("yyyyMMdd") +
77
".txt", true, Encoding.UTF8);
78
79
SWT.WriteLine("[短信]");
80
SWT.WriteLine("[时间:" +
81
System.DateTime.Now.ToString("yyyy年MM月dd日 hh:mm:ss" + "]"));
82
SWT.WriteLine("[内容:" + LogContent + "]");
83
SWT.WriteLine("[结果:" + SendResult + "]");
84
SWT.WriteLine("\r\n");
85
SWT.Close();
86
}
87
}
88
}

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

短信发送类:(不同设备,程序不同)
1
using System;
2
using System.Collections;
3
using System.ComponentModel;
4
using System.Data;
5
using System.Runtime.InteropServices;
6
using System.Text;
7
using System.Configuration;
8
9
namespace IDC_SECURITY
10
{
11
public class SMS_SEND
12
{
13
基本配置与设置
173
174
public SMS_SEND()
175
{
176
StringBuilder szNeedSndMsg = new StringBuilder(1024);
177
StringBuilder szSndPhNbr = new StringBuilder(30);
178
StringBuilder szNextMsg = new StringBuilder(1024);
179
StringBuilder szRcvPh = new StringBuilder(30);
180
StringBuilder szRcvMsg = new StringBuilder(300);
181
StringBuilder szRcvDateTime = new StringBuilder(30);
182
}
183
/// <summary>
184
/// 打开串口
185
/// </summary>
186
/// <param name="ComName">串口名称</param>
187
/// <returns></returns>
188
private bool OpenComm(string ComName)
189
{
190
//正版授权注册 iErrCode=1 校验正确 iErrCode=-100 错误
191
iErrCode = iSetSerialNo("www.etoneinfo.com", "dfyhJjDkF");
192
//串口名称
193
strTmp = ComName;
194
//打开串口
195
hComm = hOpenComm(strTmp);
196
197
if (!hComm.Equals(null) && (hComm.ToInt32() != 0) &&
198
((UInt32)hComm != INVALID_HANDLE_VALUE))
199
{
200
//自动初始
201
bRet = bAutoInit(hComm, ref CommInfo, iSMSFormat, strErrInfo);
202
203
strTmp = new String(CommInfo.szSCA);
204
iTmp = strTmp.IndexOf('\0');
205
strSCA = new StringBuilder(strTmp, iTmp);
206
207
//打开成功
208
return true;
209
}
210
else
211
{
212
//打开失败
213
return false;
214
}
215
}
216
/// <summary>
217
/// 关闭串口
218
/// </summary>
219
/// <param name="ComName">串口名称</param>
220
/// <returns></returns>
221
private bool CloseComm(string ComName)
222
{
223
bRet = bCloseComm(hComm);
224
if (bRet)
225
{
226
//关闭成功
227
hComm = IntPtr.Zero;
228
return true;
229
}
230
else
231
{
232
//关闭失败
233
return false;
234
}
235
}
236
/// <summary>
237
/// 清空SIM卡
238
/// </summary>
239
/// <returns></returns>
240
private bool CLearSIM()
241
{
242
bRet = bClrSIM(hComm, strErrInfo);
243
if (bRet)
244
{
245
//清空成功
246
return true;
247
}
248
else
249
{
250
//清空失败
251
return 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>
261
public string SendMsg(string MsgContent, string NumToSend, string ComName)
262
{
263
strNextMsg = new StringBuilder(512);
264
iTmp = strNextMsg.Length;
265
strSndPhNbr = new System.Text.StringBuilder(NumToSend);
266
strNeedSndMsg = new System.Text.StringBuilder(MsgContent);
267
OpenComm(ComName);
268
if (hComm.Equals(null) || (hComm.ToInt32() == 0)
269
|| ((UInt32)hComm == INVALID_HANDLE_VALUE))
270
{
271
//串口打开失败
272
return "串口打开失败";
273
}
274
string SndResult = "";
275
while (strNeedSndMsg.Length > 0)
276
{
277
bSndSucc = false;
278
bRet = bSendMsg(hComm, strNeedSndMsg, strSndPhNbr,
279
strSCA, strNextMsg, SMS_FORMAT_PDU, strErrInfo);
280
if (bRet == false) //发送失败
281
{
282
bSndSucc = false;
283
SndResult = "发送失败";
284
break;
285
}
286
else
287
{
288
if (strNextMsg.Length <= 0) //超长部分的待发内容
289
{
290
bSndSucc = true; //发送成功
291
SndResult = "发送成功";
292
}
293
strNeedSndMsg = strNextMsg;
294
strNextMsg = new StringBuilder(512);
295
}
296
}
297
298
if (bSndSucc)
299
{
300
//发送成功
301
CloseComm(ComName);
302
return SndResult;
303
}
304
else
305
{
306
//发送失败
307
CloseComm(ComName);
308
return SndResult;
309
}
310
}
311
}
312
}

2

3

4

5

6

7

8

9

10

11

12

13

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

310

311

312
