public IHttpActionResult GetPackage(HttpRequestMessage request, string id) { string deviceCode; if (request.Headers.Authorization == null || TokenHelper.CheckAuth(request.Headers.Authorization.Parameter, out deviceCode) == false) { return(Content <ApiErrorInfo>(HttpStatusCode.Unauthorized, new ApiErrorInfo() { errcode = (int)ErrorCode.Unauthorized, errmsg = ErrorCodeTransfer.GetErrorString(ErrorCode.Unauthorized) })); } try { TaskManager.RemoveVideoUpdate(id); return(Ok()); } catch (Exception ex) { LogHelper.Error("视频包更新下载确认失败", ex); return(Content <ApiErrorInfo>(HttpStatusCode.InternalServerError, new ApiErrorInfo() { errcode = (int)ErrorCode.ServerException, errmsg = ErrorCodeTransfer.GetErrorString(ErrorCode.ServerException) })); } }
public IHttpActionResult GetSyncConfigTime(HttpRequestMessage request) { string deviceCode; if (TokenHelper.CheckAuth(request.Headers.Authorization.Parameter, out deviceCode) == false) { return(Content <ApiErrorInfo>(HttpStatusCode.Unauthorized, new ApiErrorInfo() { errcode = (int)ErrorCode.Unauthorized, errmsg = ErrorCodeTransfer.GetErrorString(ErrorCode.Unauthorized) })); } try { using (BemEntities db = new BemEntities()) { var config = db.syncconfig.Find(deviceCode); return(Ok(new { synctimeStart = config.SyncBegin, synctimeEnd = config.SyncEnd })); } } catch (Exception ex) { LogHelper.Error("获取名单同步配置失败", ex); return(Content <ApiErrorInfo>(HttpStatusCode.InternalServerError, new ApiErrorInfo() { errcode = (int)ErrorCode.SyncConfigFail, errmsg = "同步时间获取失败" })); } }
public IHttpActionResult GetVideo(HttpRequestMessage request) { string deviceCode = string.Empty; ////检查授权 if (request.Headers.Authorization == null || TokenHelper.CheckAuth(request.Headers.Authorization.Parameter, out deviceCode) == false) { return(Content <ApiErrorInfo>(HttpStatusCode.Unauthorized, new ApiErrorInfo() { errcode = (int)ErrorCode.Unauthorized, errmsg = ErrorCodeTransfer.GetErrorString(ErrorCode.Unauthorized) })); } //检查超时 if (!TokenHelper.IsTokenOnline(deviceCode, DateTime.Now)) { return(Content <ApiErrorInfo>(HttpStatusCode.InternalServerError, new ApiErrorInfo() { errcode = (int)ErrorCode.OverTime, errmsg = ErrorCodeTransfer.GetErrorString(ErrorCode.OverTime) })); } softwareupdate sf = null; using (BemEntities db = new BemEntities()) { if (db.softwareupdate.Where(m => m.type == 1).Count() > 0) { sf = db.softwareupdate.Where(m => m.type == 1).OrderByDescending(m => m.uploadTime).First(); } } if (sf == null) { return(Content <ApiErrorInfo>(HttpStatusCode.NotFound, new ApiErrorInfo() { errcode = (int)ErrorCode.ObjectNotFound, errmsg = ErrorCodeTransfer.GetErrorString(ErrorCode.ObjectNotFound) })); } else { string filePath = System.Web.Hosting.HostingEnvironment.MapPath("~/Content"); string packPath = filePath + "\\video\\" + sf.version; if (!System.IO.File.Exists(packPath)) { return(Content <ApiErrorInfo>(HttpStatusCode.NotFound, new ApiErrorInfo() { errcode = (int)ErrorCode.ObjectNotFound, errmsg = ErrorCodeTransfer.GetErrorString(ErrorCode.ObjectNotFound) })); } string path = string.Format(@"{0}/{1}", FtpHelper.VideoFtpURL, sf.version); FtpPath vf = new FtpPath(); vf.FtpURL = path; return(Ok(vf)); } }
public async Task <IHttpActionResult> GetUpdates(HttpRequestMessage request) { string deviceCode; if (request.Headers.Authorization == null || TokenHelper.CheckAuth(request.Headers.Authorization.Parameter, out deviceCode) == false) { return(Content <ApiErrorInfo>(HttpStatusCode.Unauthorized, new ApiErrorInfo() { errcode = (int)ErrorCode.Unauthorized, errmsg = ErrorCodeTransfer.GetErrorString(ErrorCode.Unauthorized) })); } //检查超时 if (!TokenHelper.IsTokenOnline(deviceCode, DateTime.Now)) { return(Content <ApiErrorInfo>(HttpStatusCode.InternalServerError, new ApiErrorInfo() { errcode = (int)ErrorCode.OverTime, errmsg = ErrorCodeTransfer.GetErrorString(ErrorCode.OverTime) })); } try { LogHelper.Info(string.Format("设备[{0}]开始GetUpdates", deviceCode)); UpdatesJsonObj updatesJsonObj = null; await new TaskFactory().StartNew(delegate() { updatesJsonObj = TaskManager.GetTasks(deviceCode); }); if (updatesJsonObj == null) { return(Content <ApiErrorInfo>(HttpStatusCode.NotFound, new ApiErrorInfo() { errcode = (int)ErrorCode.ObjectNotFound, errmsg = ErrorCodeTransfer.GetErrorString(ErrorCode.ObjectNotFound) })); } return(Ok(updatesJsonObj)); } catch (Exception ex) { LogHelper.Error("获取更新信息失败", ex); return(Content <ApiErrorInfo>(HttpStatusCode.InternalServerError, new ApiErrorInfo() { errcode = (int)ErrorCode.ServerException, errmsg = ErrorCodeTransfer.GetErrorString(ErrorCode.ServerException) })); } }
public IHttpActionResult GetTimeSync(HttpRequestMessage request) { string deviceCode; if (request.Headers.Authorization == null || TokenHelper.CheckAuth(request.Headers.Authorization.Parameter, out deviceCode) == false) { return(Content <ApiErrorInfo>(HttpStatusCode.Unauthorized, new ApiErrorInfo() { errcode = (int)ErrorCode.Unauthorized, errmsg = ErrorCodeTransfer.GetErrorString(ErrorCode.Unauthorized) })); } //检查超时 if (!TokenHelper.IsTokenOnline(deviceCode, DateTime.Now)) { return(Content <ApiErrorInfo>(HttpStatusCode.InternalServerError, new ApiErrorInfo() { errcode = (int)ErrorCode.OverTime, errmsg = ErrorCodeTransfer.GetErrorString(ErrorCode.OverTime) })); } return(Ok(new { serverTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") })); }
public IHttpActionResult GetKeepLive(HttpRequestMessage request) { string deviceCode; if (TokenHelper.CheckAuth(request.Headers.Authorization.Parameter, out deviceCode) == false) { LogHelper.Info(string.Format("设备[{0}]鉴权失败:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), deviceCode)); return(Content <ApiErrorInfo>(HttpStatusCode.Unauthorized, new ApiErrorInfo() { errcode = (int)ErrorCode.Unauthorized, errmsg = ErrorCodeTransfer.GetErrorString(ErrorCode.Unauthorized) })); } if (!TokenHelper.UpdateLiveTime(deviceCode, DateTime.Now)) { LogHelper.Info("设备" + deviceCode + "保活失败:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); LogHelper.Info(string.Format("设备[{0}]设备保活失败", deviceCode)); return(Content <ApiErrorInfo>(HttpStatusCode.InternalServerError, new ApiErrorInfo() { errcode = (int)ErrorCode.OverTime, errmsg = ErrorCodeTransfer.GetErrorString(ErrorCode.OverTime) })); } //检查名单更新列表,和同步时间修改列表; bool list_Updated = false; bool syncTime_Updated = false; bool pack_Updated = false; bool video_Updated = false; //获取是否有名单下发更新 list_Updated = TaskManager.HasListUpdate(deviceCode); //获取同步时间是否有更新 syncTime_Updated = TaskManager.HasConfigUpdate(deviceCode); pack_Updated = TaskManager.HasPackUpdate(deviceCode); video_Updated = TaskManager.HasVideoUpdate(deviceCode); return(Ok(new { haveListUpdate = list_Updated, haveSynctimeUpdate = syncTime_Updated, havePackUpdate = pack_Updated, haveMovUpdate = video_Updated })); }
public IHttpActionResult GetUpdates(HttpRequestMessage request, string id) { string deviceCode; if (request.Headers.Authorization == null || TokenHelper.CheckAuth(request.Headers.Authorization.Parameter, out deviceCode) == false) { return(Content <ApiErrorInfo>(HttpStatusCode.Unauthorized, new ApiErrorInfo() { errcode = (int)ErrorCode.Unauthorized, errmsg = ErrorCodeTransfer.GetErrorString(ErrorCode.Unauthorized) })); } try { LogHelper.Info(string.Format("设备[{0}]GetUpdates完毕", deviceCode)); if (TaskManager.CheckDeleteLegal(deviceCode, id) == true) { //进行清理操作 using (BemEntities db = new BemEntities()) { using (var scope = db.Database.BeginTransaction()) { try { db.Database.ExecuteSqlCommand(string.Format("delete from deviceemployeerelation where Operate={0} and devCode='{1}';", (int)OPERATETYPE.DEBIND, deviceCode));//解除绑定 //var list = (from devRel in db.deviceemployeerelation // join emp in db.employee // on devRel.EmpCode equals emp.EmpCode // where devRel.Operate == 4 // where devRel.DevCode==deviceCode // select emp).ToList(); db.Database.ExecuteSqlCommand(string.Format("delete from deviceemployeerelation where Operate={0} and devCode='{1}';", (int)OPERATETYPE.DELETE, deviceCode)); //解除绑定 db.Database.ExecuteSqlCommand(string.Format("update deviceemployeerelation set Operate=0 where devCode='{0}';", deviceCode)); scope.Commit(); //正常完成,提交事务 TaskManager.RemoveTasks(id); //从任务缓存中移除任务 return(Ok()); } catch (Exception ex) { scope.Rollback(); //发生异常后回滚 LogHelper.Error("更新清理出错", ex); return(Content <ApiErrorInfo>(HttpStatusCode.InternalServerError, new ApiErrorInfo() { errcode = (int)ErrorCode.ServerException, errmsg = ErrorCodeTransfer.GetErrorString(ErrorCode.ServerException) })); } } } } else { return(Content <ApiErrorInfo>(HttpStatusCode.Forbidden, new ApiErrorInfo() { errcode = (int)ErrorCode.IllegalRequest, errmsg = ErrorCodeTransfer.GetErrorString(ErrorCode.IllegalRequest) })); } } catch (Exception ex) { LogHelper.Error("清除更新信息失败", ex); return(Content <ApiErrorInfo>(HttpStatusCode.InternalServerError, new ApiErrorInfo() { errcode = (int)ErrorCode.ServerException, errmsg = ErrorCodeTransfer.GetErrorString(ErrorCode.ServerException) })); } }
public async Task <IHttpActionResult> PostRegRecord(HttpRequestMessage request, RegRecordJsonObj regRecordObj) { string deviceCode; if (TokenHelper.CheckAuth(request.Headers.Authorization.Parameter, out deviceCode) == false) { return(Content <ApiErrorInfo>(HttpStatusCode.Unauthorized, new ApiErrorInfo() { errcode = (int)ErrorCode.Unauthorized, errmsg = ErrorCodeTransfer.GetErrorString(ErrorCode.Unauthorized) })); } //检查超时 if (!TokenHelper.IsTokenOnline(deviceCode, DateTime.Now)) { return(Content <ApiErrorInfo>(HttpStatusCode.InternalServerError, new ApiErrorInfo() { errcode = (int)ErrorCode.OverTime, errmsg = ErrorCodeTransfer.GetErrorString(ErrorCode.OverTime) })); } if (regRecordObj == null) { return(Content <ApiErrorInfo>(HttpStatusCode.BadRequest, new ApiErrorInfo() { errcode = (int)ErrorCode.DataInputFormateError, errmsg = ErrorCodeTransfer.GetErrorString(ErrorCode.DataInputFormateError) })); } try { RegRecord newRecord = new RegRecord(); newRecord.RecordDeviceID = regRecordObj.devCode == null ? string.Empty : regRecordObj.devCode; newRecord.RecordEmpCode = regRecordObj.empCode == null ? string.Empty : regRecordObj.empCode; newRecord.RecordEmpName = regRecordObj.empName == null ? string.Empty : regRecordObj.empName; newRecord.RecordEmpID = regRecordObj.empID == null ? string.Empty : regRecordObj.empID; newRecord.RecordGroupCode = regRecordObj.groupCode == null ? string.Empty : regRecordObj.groupCode; newRecord.RecordGroupName = regRecordObj.groupName == null ? string.Empty : regRecordObj.groupName; newRecord.RecordTime = DateTime.Parse(regRecordObj.recordTime); using (BemEntities db = new BemEntities()) { db.regrecord.Add(newRecord); await db.SaveChangesAsync(); } SaveImage(regRecordObj.empImage1, regRecordObj.empImage2, newRecord.RecordID, newRecord.RecordEmpCode, newRecord.RecordEmpName, newRecord.RecordTime); return(Ok()); } catch (DbEntityValidationException dbex) { LogHelper.Error("数据添加失败" + dbex.EntityValidationErrors.First().ValidationErrors.First().ErrorMessage + "empCode=" + regRecordObj.empCode + "empName" + regRecordObj.empName); return(Content <ApiErrorInfo>(HttpStatusCode.InternalServerError, new ApiErrorInfo() { errcode = (int)ErrorCode.DbError, errmsg = ErrorCodeTransfer.GetErrorString(ErrorCode.DbError) })); } catch (Exception ex) { LogHelper.Error("数据添加失败", ex); return(Content <ApiErrorInfo>(HttpStatusCode.InternalServerError, new ApiErrorInfo() { errcode = (int)ErrorCode.DbError, errmsg = ErrorCodeTransfer.GetErrorString(ErrorCode.DbError) })); } }