109,897
社区成员




using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using System.Data.SqlClient;
using System.Data;
namespace EOSS
{
class Program
{
System.Data.DataSet box; //公用的dataset,用来存放处理后,准备入库的数据。再每10秒钟将box里的数据插入数据库。
System.Data.DataSet snmpconfig; //通过查询数据库中snmpconfig表,每小时取一次。
System.Data.DataSet telnetconfig; //通过查询数据库中telnetconfig表,每小时取一次。
static void Main(string[] args)
{
System.Timers.Timer TH = new System.Timers.Timer();//每小时用的定时器
//TH.Elapsed += new System.Timers.ElapsedEventHandler(onTimer);//这行出错 “错误 10 非静态的字段、方法或属性“EOSS.Program.onTimer(object, System.Timers.ElapsedEventArgs)”要求对象引用 ”
TH.Interval = 6000;
TH.AutoReset = true;//设置是执行一次(false)还是一直执行(true);
TH.Enabled = true;//是否执行System.Timers.Timer.Elapsed事件;
TH.Start();
Timer T10 = new Timer(boxtodatabase,null,0,60000);//10秒钟调用一次,将box中的内容插入数据库。
while (true)
{
//这里完全不知道 怎么写了,
}
}
private static void boxtodatabase(object state)//执行将box中数据放入数据库
{
SqlDataAdapter boxda = new SqlDataAdapter();
boxda.Update();//不写了,具体的
}
protected void onTimer(object sender, System.Timers.ElapsedEventArgs e) //每1小时取查询数据库中两个config表,
{
string snmpconfigtxt = "select * from snmpconfig";
SqlCommand cmd1 = new SqlCommand(snmpconfigtxt);
SqlDataAdapter sda1 = new SqlDataAdapter();
sda1.Fill(snmpconfig);
//下面是取telnetconfig的,同上不写了。
////
////
}
private string snmp1() //将snmp取到的字符返回。
{
//这个我写好了。
return null;
}
private string telnet1() //将telnet截取的字符返回。
{
//这个我也写好了。
return null;
}
private void snmptobox(string s) //snmp 字符处理后放入 box
{
foreach (DataRow sc in snmpconfig.Tables[0].Rows)
{
if (s == sc["告警名称"])
{
DataRow newb = box.Tables[0].NewRow();
newb["告警信息"] = s;
box.Tables[0].Rows.Add(newb);
//向box插入一条匹配的告警信息。
}
}
}
}
}
ThreadPool.QueueUserWorkItem(h =>
{
while (true)
{
//这里写入
Thread.Sleep(10000);
}
});
ThreadPool.QueueUserWorkItem(h =>
{
while (true)
{
//这里写入
Thread.Sleep(10000);
}
}
});