Esempio n. 1
0
        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)
                }));
            }
        }
Esempio n. 2
0
        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 = "同步时间获取失败"
                }));
            }
        }
Esempio n. 3
0
        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));
            }
        }
Esempio n. 4
0
        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)
                }));
            }
        }
Esempio n. 5
0
        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") }));
        }
Esempio n. 6
0
        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 }));
        }
Esempio n. 7
0
        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)
                }));
            }
        }
Esempio n. 8
0
 public async Task <IHttpActionResult> PostRecords(RecordsQuery queryItem)
 {
     try
     {
         if (queryItem == null)
         {
             return(Content <ApiErrorInfo>(HttpStatusCode.BadRequest, new ApiErrorInfo()
             {
                 errcode = (int)ErrorCode.DataInputFormateError, errmsg = ErrorCodeTransfer.GetErrorString(ErrorCode.DataInputFormateError)
             }));
         }
         DateTime dt1 = DateTime.Now;
         DateTime dt2 = DateTime.Now;
         if (DateTime.TryParse(queryItem.startTime, out dt1) == false || DateTime.TryParse(queryItem.endTime, out dt2) == false)
         {
             return(Content <ApiErrorInfo>(HttpStatusCode.BadRequest, new ApiErrorInfo()
             {
                 errcode = (int)ErrorCode.DataInputFormateError, errmsg = ErrorCodeTransfer.GetErrorString(ErrorCode.DataInputFormateError)
             }));
         }
         if ((dt2 - dt1).TotalDays > 60)
         {
             return(Content <ApiErrorInfo>(HttpStatusCode.InternalServerError, new ApiErrorInfo()
             {
                 errcode = (int)ErrorCode.QueryExceed, errmsg = ErrorCodeTransfer.GetErrorString(ErrorCode.QueryExceed)
             }));
         }
         using (BemEntities db = new BemEntities())
         {
             var recordsList = from record in db.regrecord
                               join dev in db.clientdevice
                               on record.RecordDeviceID equals dev.DevCode
                               where record.RecordTime >= dt1 && record.RecordTime <= dt2
                               select new
             {
                 empName        = record.RecordEmpName,
                 empCode        = record.RecordEmpCode,
                 empID          = record.RecordEmpID,
                 departmentName = record.RecordGroupName,
                 departmentCode = record.RecordGroupCode,
                 recordTime     = record.RecordTime,
                 deviceCode     = record.RecordDeviceID,
                 deviceName     = dev.DevName
             };
             if (!string.IsNullOrEmpty(queryItem.empCode))
             {
                 recordsList = recordsList.Where(m => m.empCode == queryItem.empCode);
             }
             if (!string.IsNullOrEmpty(queryItem.deviceCode))
             {
                 recordsList = recordsList.Where(m => m.deviceCode == queryItem.deviceCode);
             }
             if (!string.IsNullOrEmpty(queryItem.departmentCode))
             {
                 recordsList = recordsList.Where(m => m.departmentCode == queryItem.departmentCode);
             }
             var contentList = recordsList.OrderBy(m => m.recordTime).ToList();
             if (contentList.Count > 0)
             {
                 return(Ok(contentList));
             }
             else
             {
                 return(Content <ApiErrorInfo>(HttpStatusCode.NoContent, new ApiErrorInfo()
                 {
                     errcode = (int)ErrorCode.ObjectNotFound, errmsg = ErrorCodeTransfer.GetErrorString(ErrorCode.ObjectNotFound)
                 }));
             }
         }
     }
     catch (Exception ex)
     {
         LogHelper.Error("查询原始记录出错", ex);
         return(Content <ApiErrorInfo>(HttpStatusCode.InternalServerError, new ApiErrorInfo()
         {
             errcode = (int)ErrorCode.DbError, errmsg = ErrorCodeTransfer.GetErrorString(ErrorCode.DbError)
         }));
     }
 }
Esempio n. 9
0
        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)
                }));
            }
        }