public Bitmap ReadFrame(GroupInfo group, AlarmInfo alarm) { string root = FileConfigReader.SingleConfig[group.Area, group.Device]["event"]; if (root == string.Empty) return null; string alarmFile = FilePath.GetDateTimePathTimeFile(root, group.Area, group.Device, new DateTime(alarm.GroupID), alarm.AlarmTime, "jpg"); if (!File.Exists(alarmFile)) return null; return new Bitmap(alarmFile); }
public bool WriteAlarm(GroupInfo group, AlarmInfo alarm, Bitmap frame) { IConfigReader _config = FileConfigReader.SingleConfig; string root = _config[group.Area, group.Device]["event"]; if (root == string.Empty) return false; string groupPath = FilePath.GetDateTimePath(root, group.Area, group.Device, group.GroupTime); //若报警组目录不存在,则创建该目录 if (!Directory.Exists(groupPath)) Directory.CreateDirectory(groupPath); string alarmFile = FilePath.GetDateTimePathTimeFile(root, group.Area, group.Device, group.GroupTime, alarm.AlarmTime, "alarm"); string frameFile = FilePath.GetDateTimePathTimeFile(root, group.Area, group.Device, group.GroupTime, alarm.AlarmTime, "jpg"); try { frame.Save(frameFile); } catch { return false; } FileInfo fiAlarm = new FileInfo(alarmFile); using (StreamWriter swAlarm = File.CreateText(fiAlarm.FullName)) { //存储报警 { swAlarm.WriteLine(alarm.GroupID); swAlarm.WriteLine(alarm.FrameIndex); swAlarm.WriteLine(alarm.AlarmID); int regionLength = Math.Min(alarm.AlarmRegion.Length, alarm.AlarmRegionType.Length); for (int i = 0; i < regionLength; i++) { swAlarm.WriteLine(string.Format("{0},{1},{2},{3},{4}", alarm.AlarmRegion[i].X, alarm.AlarmRegion[i].Y, alarm.AlarmRegion[i].Width, alarm.AlarmRegion[i].Height, (int)alarm.AlarmRegionType[i] )); } } } return true; }
public GroupInfo[] ReadGroups(string area, string device, DateTime date) { string root = FileConfigReader.SingleConfig[area, device]["event"]; if (root == string.Empty) return new GroupInfo[0] ; List<GroupInfo> groups = new List<GroupInfo>(); //获取指定日期的报警组列表 DirectoryInfo di = new DirectoryInfo(FilePath.GetDatePath(root, area, device, date)); if (!di.Exists) return new GroupInfo[0]; DirectoryInfo[] diGroups = di.GetDirectories(); foreach (DirectoryInfo diGroup in diGroups) { FileInfo[] fiGroups = diGroup.GetFiles("*.group"); if (fiGroups.Length == 0) continue; using (StreamReader srGroup = new StreamReader(fiGroups[0].FullName)) {//读取所有报警信息 long groupID; if (!long.TryParse(srGroup.ReadLine(), out groupID)) continue; string groupArea = srGroup.ReadLine(); string groupDevice = srGroup.ReadLine(); short horizon; if (!short.TryParse(srGroup.ReadLine(), out horizon)) continue; short vertical; if (!short.TryParse(srGroup.ReadLine(), out vertical)) continue; int analyzeCount; if (!int.TryParse(srGroup.ReadLine(), out analyzeCount)) continue; int eventOperate; if (!int.TryParse(srGroup.ReadLine(), out eventOperate)) continue; string[] alarmIDs = srGroup.ReadToEnd().Split(new char[]{'\r','\n'}, StringSplitOptions.RemoveEmptyEntries); GroupInfo group = new GroupInfo(groupID,groupArea,groupDevice,horizon,vertical,analyzeCount); long alarmID; //DateTime groupTime = new DateTime(groupID); foreach (string id in alarmIDs) { if (!long.TryParse(id, out alarmID)) continue; DateTime alarmTime = new DateTime(alarmID); //获取指定报警信息路径 string alarmFile = FilePath.GetDateTimePathTimeFile(root, area, device, group.GroupTime, alarmTime, "alarm"); if (!File.Exists(alarmFile)) continue; using (StreamReader srAlarm = new StreamReader(alarmFile)) { long groupid; if (!long.TryParse(srAlarm.ReadLine(), out groupid) || groupid != groupID) continue; int frameIndex; if (!int.TryParse(srAlarm.ReadLine(), out frameIndex)) continue; long alarmid; if (!long.TryParse(srAlarm.ReadLine(), out alarmid) || alarmid != alarmID) continue; string[] regionAndType = srAlarm.ReadToEnd().Split('\n'); Rectangle[] regions = new Rectangle[regionAndType.Length]; int[] regionTypes = new int[regionAndType.Length]; for (int i = 0; i < regionAndType.Length; i++) { string[] XYWHT = regionAndType[i].Split(','); if (XYWHT.Length != 5) continue; int x, y, w, h, t; if (!int.TryParse(XYWHT[0], out x)) continue; if (!int.TryParse(XYWHT[1], out y)) continue; if (!int.TryParse(XYWHT[2], out w)) continue; if (!int.TryParse(XYWHT[3], out h)) continue; if (!int.TryParse(XYWHT[4], out t)) continue; regions[i] = new Rectangle(x, y, w, h); regionTypes[i] = t; } AlarmInfo alarm = new AlarmInfo(groupid, frameIndex, alarmid, regions, regionTypes); group.Add(alarm); } } groups.Add(group); } } return groups.ToArray(); }
void analyzeStrategy_AnalyzeAlarm(object sender, IAnalyze.EventArgsAnalyzeAlarm e) { if (this.group != null) { AlarmInfo alarm = new AlarmInfo(this.group.GroupTime, e.FrameIndex, e.AlarmTime, e.AlarmRegion, e.AlarmRegionType); //保存报警 if (this.alarmWriter.WriteAlarm(this.group, alarm, e.AlarmFrame)) { //添加报警 if (this.group!= null) this.group.Add(alarm); OnAnalyzeAlarm(new AlarmEventArgs(this.group, alarm), e.AlarmFrame); } e.AlarmFrame.Dispose(); } }
public AlarmEventArgs(GroupInfo group, AlarmInfo alarm) { this.Group = group; this.Alarm = alarm; }
/// <summary> /// 向报警帧组ID中加入一个报警信息 /// </summary> /// <param name="id">报警帧ID</param> /// <param name="eventInfo">报警信息</param> public void Add(AlarmInfo alarm) { long id = alarm.AlarmTime.Ticks; if (!this.alarmInfos.ContainsKey(id)) { this.alarmInfos.Add(id, alarm); this.alarmIDs.Add(id); } }