private bool loadLocalConfig() { try { connectStr = ConfigWorker.GetConfigValue("connectString"); if (connectStr == string.Empty) { MessageBox.Show("数据库连接字符串不能为空"); return(false); } string alarmalarmFilterStr = ConfigWorker.GetConfigValue("alarmFilter"); string[] alarmFilterArray = alarmalarmFilterStr.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); foreach (string alarmFilter in alarmFilterArray) { if (alarmFilter.Contains(":") == false) { continue; } string[] alarmFilterItem = alarmFilter.Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries); eventDic.Add(alarmFilterItem[1], alarmFilterItem[0]); } return(true); } catch (Exception ex) { MessageBox.Show("读取本地配置错误"); return(false); } }
/// <summary> /// 查询人员表的信息 /// </summary> /// <param name="v1"></param> /// <param name="v2"></param> /// <returns></returns> private static string SelePersonTable(string perCode, int index) { string strConn = ConfigWorker.GetConfigValue("connectString"); //strConn = "server=127.0.0.1;database=CEMData;uid=sa;pwd=qq.123456"; string code = string.Format("'{0}'", perCode); string perTable = ConfigWorker.GetConfigValue("perTableName"); string sql = string.Format("select * from {0} where per_ser = {1}", perTable, code); SqlDataAdapter da = new SqlDataAdapter(sql, strConn); string str = ""; try { DataSet ds = new DataSet(); da.Fill(ds); int len = ds.Tables[0].Rows.Count; for (int i = 0; i < len; i++) { str = ds.Tables[0].Rows[i].ItemArray[index].ToString(); } } catch (Exception ex) { FileWorker.LogHelper.WriteLog("解析数据失败," + ex.Message); str = ""; } return(str); }
///定时任务 private void initJob() { try { if (scheduler == null && job == null) { scheduler = StdSchedulerFactory.GetDefaultScheduler(); JobWorker.form = this; job = JobBuilder.Create <JobWorker>().WithIdentity("connectJob", "jobs").Build(); //ITrigger trigger = TriggerBuilder.Create().WithIdentity("connectTrigger", "triggers").StartAt(DateTimeOffset.Now.AddSeconds(1)) // .WithSimpleSchedule(x => x.WithIntervalInSeconds(60).RepeatForever()).Build(); string time = ConfigWorker.GetConfigValue("timeTask"); ITrigger trigger = TriggerBuilder.Create().WithIdentity("connectTrigger", "triggers").StartAt(DateTimeOffset.Now.AddSeconds(1)) .WithCronSchedule(time).Build(); scheduler.ScheduleJob(job, trigger);//把作业,触发器加入调度器。 jobKey = job.Key; //scheduler.DeleteJob } scheduler.Start(); } catch (Exception ex) { FileWorker.LogHelper.WriteLog("定时任务异常:" + ex.Message); } }
/// <summary> /// 查询设备表的信息 /// </summary> /// <param name="doorCode"></param> /// <returns></returns> private static string SeleSql(string doorCode) { string strConn = ConfigWorker.GetConfigValue("connectString"); //strConn = "server=127.0.0.1;database=CEMData;uid=sa;pwd=qq.123456"; string code = string.Format("'{0}'", doorCode); string tableName = ConfigWorker.GetConfigValue("devTableName"); string sql = string.Format("select DoorName from {1} where dev_addr = {0} group by DoorName", code, tableName); string arr = ""; try { DataSet ds = null; using (SqlDataAdapter da = new SqlDataAdapter(sql, strConn)) { ds = new DataSet(); da.Fill(ds); } int len = ds.Tables[0].Rows[0].ItemArray.Length; for (int i = 0; i < len; i++) { arr = arr + ds.Tables[0].Rows[0].ItemArray[0]; } } catch (Exception ex) { FileWorker.LogHelper.WriteLog("解析数据失败," + ex.Message); } return(arr); }
public static ResourStateEntity parseState(List <string> devList) { ResourStateEntity stateEntity = null; try { stateEntity = new ResourStateEntity(); #region meta stateEntity.meta.eventType = "MJ_EQUINFO_UE"; stateEntity.meta.msgType = "EQU"; stateEntity.meta.receiver = ""; stateEntity.meta.recvSequence = ""; stateEntity.meta.recvTime = ""; stateEntity.meta.sender = "MJ"; stateEntity.meta.sendTime = DateTime.Now.ToString("yyyyMMddHHmmss"); stateEntity.meta.sequence = ""; #endregion #region body stateEntity.body.equCode = devList[1]; stateEntity.body.equName = devList[2]; stateEntity.body.resClassCode = "RC01"; stateEntity.body.resClassName = "安保资源"; stateEntity.body.airportIata = ConfigWorker.GetConfigValue("airportIata"); stateEntity.body.airportName = ConfigWorker.GetConfigValue("airportName"); #endregion } catch (Exception ex) { FileWorker.LogHelper.WriteLog("解析设备状态失败," + ex.Message); } return(stateEntity); }
/// <summary> /// 定时查询数据 /// </summary> public void cyclicWork() { string strConn = ConfigWorker.GetConfigValue("connectString"); //strConn = "server=127.0.0.1;database=CEMData;uid=sa;pwd=qq.123456"; string tableName = ConfigWorker.GetConfigValue("devTableName"); string sql = string.Format("select DoorID,dev_addr,DoorName from {0} ", tableName); FileWorker.LogHelper.WriteLog("定时查询设备信息"); try { DataSet ds = null; using (SqlDataAdapter da = new SqlDataAdapter(sql, strConn)) { ds = new DataSet(); da.Fill(ds); } foreach (DataRow item in ds.Tables[0].Rows) { List <string> devList = new List <string>(); devList.Add(item.ItemArray[0].ToString()); devList.Add(item.ItemArray[1].ToString()); devList.Add(item.ItemArray[2].ToString()); ResourStateEntity accessEnt = StateParseTool.parseState(devList); string jsonMess = accessEnt.toJson(); KafkaWorker.sendDeviceMessage(jsonMess); } } catch (Exception e) { FileWorker.LogHelper.WriteLog("解析设备信息表失败:" + e.Message); } }
private void Form1_Shown(object sender, EventArgs e) { localIp = ConfigWorker.GetConfigValue("localIp"); string localPortStr = ConfigWorker.GetConfigValue("localPort"); serverIp = ConfigWorker.GetConfigValue("serverIp"); string serverPortStr = ConfigWorker.GetConfigValue("serverPort"); if (int.TryParse(localPortStr, out localPort) == false) { FileWorker.LogHelper.WriteLog("本地端口设置不正确"); MessageBox.Show("本地端口设置不正确"); return; } else if (int.TryParse(serverPortStr, out serverPort) == false) { FileWorker.LogHelper.WriteLog("服务器端口设置不正确"); MessageBox.Show("服务器端口设置不正确"); return; } else { startListener(); } }
private void loadLocalConfig() { try { watchName = ConfigWorker.GetConfigValue("watchName"); interval = int.Parse(ConfigWorker.GetConfigValue("interval")); lease = double.Parse(ConfigWorker.GetConfigValue("lease")); airportIata = ConfigWorker.GetConfigValue("airportIata"); airportName = ConfigWorker.GetConfigValue("airportName"); string alarmFilterRule = ConfigWorker.GetConfigValue("alarmFilterRule"); foreach (string filterRule in alarmFilterRule.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries)) { string eventCode = filterRule.Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries)[0]; string sodbCode = filterRule.Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries)[1]; string alarmNameCode = sodbCode.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries)[0]; string alarmName = sodbCode.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries)[1]; alarmRuleDic.Add(eventCode, new Tuple <string, string>(alarmNameCode, alarmName)); } FileWorker.LogHelper.WriteLog("配置加载完成"); } catch (Exception ex) { MessageBox.Show("配置文件设置不正确" + ex.Message); } }
static FileWorker() { txtFilePath = ConfigWorker.GetConfigValue("logPath"); if (!System.IO.Directory.Exists(txtFilePath)) { System.IO.Directory.CreateDirectory(txtFilePath);//不存在就创建目录 } }
public SqlServerWorker() { try { connStr = ConfigWorker.GetConfigValue("connectString"); conn = new SqlConnection(connStr); } catch (Exception ex) { throw ex; } }
static SqlServerHelper() { SqlConnectionStringBuilder scsb = new SqlConnectionStringBuilder(); scsb.DataSource = ConfigWorker.GetConfigValue("sqlserverIp"); scsb.IntegratedSecurity = true; scsb.InitialCatalog = ConfigWorker.GetConfigValue("sqlserverDbName"); scsb.UserID = ConfigWorker.GetConfigValue("sqlserverUser"); scsb.Password = ConfigWorker.GetConfigValue("sqlserverPassword"); imagePath = ConfigWorker.GetConfigValue("imagePath"); sqlconStr = scsb.ConnectionString; }
private void Form1_Load(object sender, EventArgs e) { user = ConfigWorker.GetConfigValue("user"); password = ConfigWorker.GetConfigValue("password"); hostname = ConfigWorker.GetConfigValue("hostname"); serverIp = ConfigWorker.GetConfigValue("serverIp"); localIp = ConfigWorker.GetConfigValue("localIp"); port = ConfigWorker.GetConfigValue("port"); thread = new Thread(new ThreadStart(startListener)); threadPerson = new Thread(new ThreadStart(KafkaWorker.startGetMessage)); KafkaWorker.OnGetMessage += KafkaWorker_OnGetMessage; }
private bool loadConfig() { try { remoteIp = ConfigWorker.GetConfigValue("remoteIp"); remotePort = int.Parse(ConfigWorker.GetConfigValue("remotePort")); return(true); } catch (Exception) { return(false); } }
private void cbb_user_Leave(object sender, EventArgs e) { string userId = cbb_user.Text.Trim(); string password = ConfigWorker.GetConfigValue(userId); txt_password.Text = password; if (string.IsNullOrEmpty(password)) { cb_remindPwd.Checked = false; } else { cb_remindPwd.Checked = true; } }
private Dictionary <string, string> GetConfigMess() { Dictionary <string, string> dict = new Dictionary <string, string>(); string str = ConfigWorker.GetConfigValue("alarmMessage"); string[] keyPair = str.Split(new char[] { ',' }); for (int i = 0; i < keyPair.Length; i++) { string[] item = keyPair[i].Split(new char[] { ':' }); if (item.Length >= 2) { dict.Add(item[0], item[1]); } } return(dict); }
private bool loadLocalConfig() { try { videoUrl = ConfigWorker.GetConfigValue("videoUrl"); videoPort = uint.Parse(ConfigWorker.GetConfigValue("videoPort")); videoUser = ConfigWorker.GetConfigValue("videoUser"); videoPwd = ConfigWorker.GetConfigValue("videoPwd"); return(true); } catch (Exception ex) { FileWorker.LogHelper.WriteLog("读取本地配置文件出现异常" + ex.Message); return(false); } }
public static DeviceStateEntity parseDeviceState(string devId, string state) { DeviceStateEntity deviceStateEntity = null; try { deviceStateEntity = new DeviceStateEntity(); deviceStateEntity.meta.eventType = "SVMS_EQU_STATUS_UE"; deviceStateEntity.meta.msgType = "EQU_STATUS"; deviceStateEntity.meta.receiver = ""; deviceStateEntity.meta.recvSequence = ""; deviceStateEntity.meta.recvTime = ""; deviceStateEntity.meta.sender = "MJ"; deviceStateEntity.meta.sendTime = DateTime.Now.ToString("yyyyMMddHHmmss"); deviceStateEntity.meta.sequence = Guid.NewGuid().ToString();; //string pattern = "[\\[ \\] \\^ \\-_*×――(^)$%~!@#$…&%¥—+<>《》!!???::•`·、。,;,;\"‘’“”-]"; //string channelID = Regex.Replace(devArr[1], pattern, "").Split(new char[] { '=' })[1]; //string channelStatus = Regex.Replace(devArr[4], pattern, "").Split(new char[] { '=' })[1]; deviceStateEntity.body.equCode = devId; if (state == "离线") { deviceStateEntity.body.timeStateId = "ES02"; deviceStateEntity.body.timeStateName = "离线"; } else if (state == "上线") { deviceStateEntity.body.timeStateId = "ES01"; deviceStateEntity.body.timeStateName = "在线"; } else { deviceStateEntity.body.timeStateId = "ES03"; deviceStateEntity.body.timeStateName = "故障"; } deviceStateEntity.body.operateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); deviceStateEntity.body.airportIata = ConfigWorker.GetConfigValue("airportIata"); deviceStateEntity.body.airportName = ConfigWorker.GetConfigValue("airportName"); } catch (Exception ex) { FileWorker.LogHelper.WriteLog("解析设备状态失败," + ex.Message); } return(deviceStateEntity); }
public static DeviceStateEntity parseDeviceState(string stateId, string eventType) { DeviceStateEntity deviceStateEntity = null; try { deviceStateEntity = new DeviceStateEntity(); deviceStateEntity.meta.eventType = "ACS_EQUINFO_UE"; deviceStateEntity.meta.msgType = "EQU_STATUS"; deviceStateEntity.meta.receiver = ""; deviceStateEntity.meta.recvSequence = ""; deviceStateEntity.meta.recvTime = ""; deviceStateEntity.meta.sender = "MJ"; deviceStateEntity.meta.sendTime = DateTime.Now.ToString("yyyyMMddHHmmss"); deviceStateEntity.meta.sequence = ""; deviceStateEntity.body.equCode = stateId; if (eventType == "903")//903---ES02---离线---开门 { deviceStateEntity.body.timeStateId = "ES02"; deviceStateEntity.body.timeStateName = "开门"; } else if (eventType == "10903")//10903---ES01---在线---关门 { deviceStateEntity.body.timeStateId = "ES01"; deviceStateEntity.body.timeStateName = "关门"; } else { deviceStateEntity.body.timeStateId = "ES03"; deviceStateEntity.body.timeStateName = "故障"; } deviceStateEntity.body.operateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); deviceStateEntity.body.airportIata = ConfigWorker.GetConfigValue("airportIata"); deviceStateEntity.body.airportName = ConfigWorker.GetConfigValue("airportName"); } catch (Exception ex) { FileWorker.LogHelper.WriteLog("解析设备状态失败," + ex.Message); } return(deviceStateEntity); }
public static AlarmEntity parseAlarm(string[] messCollection, Dictionary <string, string> alarmCollection) { AlarmEntity alarmEntity = null; try { alarmEntity = new AlarmEntity(); alarmEntity.meta.eventType = "MJ_ALARM"; alarmEntity.meta.msgType = "ALARM"; alarmEntity.meta.receiver = ""; alarmEntity.meta.recvSequence = ""; alarmEntity.meta.recvTime = ""; alarmEntity.meta.sender = "MJALARM"; alarmEntity.meta.sendTime = DateTime.Now.ToString("yyyyMMddHHmmss"); alarmEntity.meta.sequence = ""; alarmEntity.body.alarmClassCode = "AC02"; alarmEntity.body.alarmClassName = "门禁报警事件"; //alarmEntity.body.alarmTime = DateTime.Parse(alarmInfo.sEventTime).ToString("yyyy-MM-dd HH:mm:ss"); //alarmEntity.body.alarmEquCode = alarmInfo.sEventLocation; //alarmEntity.body.alarmName = alarmInfo.sEventName; //alarmEntity.body.alarmNameCode = alarmTypeCode; alarmEntity.body.alarmStateCode = "AS01"; alarmEntity.body.alarmStateName = "未解除"; alarmEntity.body.airportIata = ConfigWorker.GetConfigValue("airportIata"); alarmEntity.body.airportName = ConfigWorker.GetConfigValue("airportName"); alarmEntity.body.alarmTime = messCollection[6]; alarmEntity.body.alarmEquCode = messCollection[8]; alarmEntity.body.alarmNameCode = messCollection[9]; alarmEntity.body.alarmName = alarmCollection[messCollection[9]]; } catch (Exception ex) { FileWorker.LogHelper.WriteLog("解析报警失败," + ex.Message); } return(alarmEntity); }
static BaseParseTool() { airportIata = ConfigWorker.GetConfigValue("airportIata"); airportName = ConfigWorker.GetConfigValue("airportName"); }