public override string GetAlarmInfo() { try { MemoryStream ms = new MemoryStream(); AlarmImage.Save(ms, ImageFormat.Jpeg); StringBuilder sb = new StringBuilder(SystemContext.Name + "<SystemContext>"); sb.Append(Monitor.Name + "<Monitor><MonitorAlarm>"); sb.Append(ID + "<ID>"); sb.Append(Sender + "<Sender>"); sb.Append(Desc + "<Desc>"); sb.Append((int)EventType + "<EventType>"); sb.Append((int)GuardLevel + "<GuardLevel>"); sb.Append(AreaIndex + "<AreaIndex>"); sb.Append((int)AreaType + "<AreaType>"); sb.Append((ushort)AlertOpt + "<AlertOpt>"); sb.Append(AlarmTime.ToLongDateString() + " " + AlarmTime.ToLongTimeString() + "<AlarmTime>"); sb.Append(Convert.ToBase64String(ms.GetBuffer()) + "<AlarmImage></MonitorAlarm>"); return(sb.ToString()); } catch (Exception e) { return(e.Message); } }
/// <summary> /// 获取二次解析图片 /// </summary> public static List <AlarmImage> GetSecondAnalysisImage(List <Int64> ids) { if ((ids == null) && (ids.Count <= 0)) { return(null); } IDbHelper connection = DBConnection.Instance.GetConnection(); if (connection == null) { return(null); } String sqlString = @"SELECT id as alarmId, image as imagePath FROM alarm WHERE "; foreach (Int64 id in ids) { sqlString = String.Format("{0} id={1} OR", sqlString, id); } sqlString = sqlString.Substring(0, sqlString.Length - 2); try { DataTable dt = DbFactory.Instance.CreateSqlHelper(connection, sqlString) .ToDataTable(); if ((dt == null) || (dt.Rows.Count <= 0)) { return(null); } List <AlarmImage> imageList = new List <AlarmImage>(); foreach (DataRow dr in dt.Rows) { Int64 alarmId = Int64.Parse(dr["alarmId"].ToString()); String path = dr["imagePath"].ToString(); // 取出图片所有数据 Byte[] bytes = Utils.GetBytesByImagePath(path); if (bytes == null) { continue; } AlarmImage image = new AlarmImage(); image.mImage = Convert.ToBase64String(bytes); image.mAlarmId = alarmId; imageList.Add(image); } return(imageList); } catch (Exception e) { Tracker.LogE(e); return(null); } finally { DBConnection.Instance.ReturnDBConnection(connection); } }