// 调用指定摄像头数据源的清理冗余数据 public static void ClearCameraSource(CameraSource cam, int timeSpanLimit = 5) { IUserLog log = new UserLog(); try { // 获取当前摄像头的全部数据记录 using (IRepository repo = new Repository()) { var list = repo.Query <TruckCamRecord>(x => x.CamNo.Equals(cam.CamNo)).FindAll(x => !string.IsNullOrEmpty(x.License)); if (list.Count > 0) { var query = (from t in list group t by t.License into g orderby g.Count() descending select new { License = g.Key, Nums = g.Count() }) .ToList().FindAll(x => x.Nums > 1); if (query.Count > 0) { var countClear = 0; foreach (var instance in query) { var result = list.GetRedundantTruckRecords(instance.License, instance.Nums, timeSpanLimit); //var listDelete = list.FindAll(x => result.Exists(t => t.Equals(x))); if (result.Count > 0) { foreach (var del in result) { countClear += repo.Delete(del); } } } if (countClear > 0) { // 记录成功日志 var msg = new { camNo = cam.CamNo, countClear, //lastSyncRecordTime = cam.LastSyncTime.ToString("yyyyMMdd HH:mm:ss") }; log.Info(msg.ToJson()); } } } } } catch (Exception ex) { log.Error(ex); } }
// 调用指定摄像头数据源到目标库 public static void SyncCameraSource(CameraSource cam) { IUserLog log = new UserLog(); try { // 获取需要同步的集卡违章数据,已按抓拍时间升序排列 var list = GetTruckRecordsByCamSource(cam); if (list.Count > 0) { using (IRepository repo = new Repository()) { // 同步到oracle库中,返回成功记录数 var countInsert = list.AsEnumerable().Insert(); // 获取最后记录的时间戳 cam.LastSyncTime = list.Last().PicTime; repo.Save(cam); CameraSource.Cache.RefreshCache(); // 记录成功日志 var msg = new { camNo = cam.CamNo, countInsert, lastSyncRecordTime = cam.LastSyncTime.ToString("yyyyMMdd HH:mm:ss") }; log.Info(msg.ToJson()); } } } catch (Exception ex) { log.Error(ex); } }
public void Execute(object state) { var logInfo = new LogInfo { MethodInstance = MethodBase.GetCurrentMethod(), ThreadInstance = Thread.CurrentThread }; try { _log.Info("Scheduler Start: (OfficialSync)", logInfo); var rand = new Random(Guid.NewGuid().GetHashCode()); var result = rand.Next(0, 900); var season = "1617"; if (result < 80) { var member = GetUnSyncMemberByRandom(); if (member != null) { var success = SyncOfficialMemberInfo(member); // logger the result of Official Synchronization ILog uLog = new UserLog(); var logPara = new LogInfo { MethodInstance = MethodBase.GetCurrentMethod(), ThreadInstance = Thread.CurrentThread, UserClient = new UserClientInfo { UserID = member.AcnID, UserName = member.AcnName, UserIP = "127.0.0.1", UserBrowser = string.Empty, UserOS = string.Empty } }; if (success) { member.OfficialSync = season; _repo.Update(member); uLog.Info($"官方会员信息同步成功 (随机码:{result}, {season}会员:{member.Name})", logPara); } else { uLog.Error($"官方会员信息同步失败 (随机码:{result}, {season}会员:{member.Name})", logPara); } } } _log.Info($"Scheduler End: (OfficialSync ({result}))", logInfo); } catch (Exception ex) { _log.Warn(ex, logInfo); } }