예제 #1
0
 public IActionResult Publish([FromBody] AlarmLog alarmLog)
 {
     alarmLog.IsForwardAlarm = true;
     alarmLog.TimeCreated    = DateTime.Now;
     MQPulish.PublishMessage("AlarmLog", alarmLog);
     return(Ok());
 }
예제 #2
0
 public IActionResult NotifySynchronousSensing([FromBody] SynchronousSensing model)
 {
     //广播消息
     MQPulish.PublishMessage("SynchronousSensing", model);
     //并转发消息到下级
     return(new ObjectResult("Ok"));
 }
예제 #3
0
        /// <summary>
        /// 转发报警到上级
        /// </summary>
        /// <param name="alarmLog"></param>
        private void ForwardAlarmToTopOrganization(AlarmLog alarmLog)
        {
            Task.Run(() =>
            {
                using (var db = new AllInOneContext.AllInOneContext())
                {
                    string error             = "";
                    var topApplicationCenter = db.Organization.Include(t => t.Center).
                                               OrderBy(t => t.OrganizationFullName).
                                               Select(t => t.Center).
                                               FirstOrDefault();

                    if (topApplicationCenter != null &&
                        topApplicationCenter.EndPoints != null &&
                        topApplicationCenter.EndPoints.Count > 0)
                    {
                        _logger.LogInformation("开始推送{1}发生的{2}报警消息到上级系统...", alarmLog.AlarmSource.IPDeviceName, alarmLog.AlarmType.SystemOptionName);
                        EndPointInfo endPoint = topApplicationCenter.EndPoints.First();
                        string url            = string.Format("http://{0}:{1}/Alarm/AlarmLog/Publish", endPoint.IPAddress, endPoint.Port);
                        _logger.LogInformation("推送URL:{0}...", url);
                        var result = HttpClientHelper.Post <AlarmLog>(alarmLog, url, false);
                        if (result.Success)
                        {
                            alarmLog.UploadStatus = 1;
                            db.SaveChanges();
                            _logger.LogInformation("报警消息推送到上级系统成功");
                        }
                        else
                        {
                            _logger.LogInformation("报警消息推送到上级系统失败,原因:{0},将推送添加到报警转发队列", result);
                            ForwardAlarmLogTask.Instance.ForwardAlarmLog(alarmLog);
                        }
                    }
                    else
                    {
                        error = "未配置上级应用服务";
                    }

                    if (!string.IsNullOrEmpty(error))
                    {
                        error = string.Format("由于{0},推送{1}发生的{2}报警消息到上级系统失败!", error,
                                              alarmLog.AlarmSource.IPDeviceName, alarmLog.AlarmType.SystemOptionName);
                        ForwardAlarmLogError forwardErr = new ForwardAlarmLogError()
                        {
                            ErrorDesc  = error,
                            CreateTime = DateTime.Now
                        };
                        MQPulish.PublishMessage("ForwardAlarmLogError", forwardErr);  //改为提示.....
                    }
                }
            });
        }
예제 #4
0
 public override void Stop()
 {
     try
     {
         _logger.LogInformation("停止实时视频预览Begin....");
         MQPulish.PublishMessage("StopRealPlayAction", "");
         _logger.LogInformation("停止实时视频预览End....");
     }
     catch (Exception ex)
     {
         _logger.LogError("执行实时视频预览异常:Message:{0}\r\nStackTrace:{1}", ex.Message, ex.StackTrace);
     }
 }
예제 #5
0
        public IActionResult Add([FromBody] AlarmProcessed processInfo)
        {
            if (processInfo == null)
            {
                return(BadRequest());
            }
            using (var db = new AllInOneContext.AllInOneContext())
            {
                try
                {
                    _logger.LogInformation("开始添加报警处理意见...");
                    db.AlarmProcessed.Add(processInfo);
                    db.SaveChanges();

                    //推送处理结果到上级服务
                    //获取上级服务器的依据:按组织机构长地址排序,取第一个组织机构的应用中心信息
                    var topApplicationCenter = db.Organization.Include(t => t.Center).
                                               OrderBy(t => t.OrganizationFullName).
                                               Select(t => t.Center).
                                               FirstOrDefault();
                    if (topApplicationCenter != null && topApplicationCenter.EndPoints != null && topApplicationCenter.EndPoints.Count > 0)
                    {
                        _logger.LogInformation("发送报警处理到上级平台...");
                        EndPointInfo endPoint = topApplicationCenter.EndPoints.First();
                        string       url      = string.Format("http://{0}:{1}/Alarm/AlarmProcessed/Publish", endPoint.IPAddress, endPoint.Port);
                        var          result   = HttpClientHelper.Post <AlarmProcessed>(processInfo, url);
                        _logger.LogInformation("发送报警处理到上级平台...result:{0}", result);
                    }
                    else
                    {
                        Console.WriteLine("未配置上级应用服务,未能完成发送报警处理到上级系统");
                    }

                    //本地广播报警处理消息
                    _logger.LogInformation("广播报警处理消息");
                    MQPulish.PublishMessage("AlarmProcess", processInfo);

                    _logger.LogInformation("完成添加报警处理意见...");
                    return(CreatedAtRoute("GetById", processInfo));
                }
                catch (Exception ex)
                {
                    _logger.LogError("添加报警处理意见异常,Message:{0}\r\n,StackTrace{1}", ex.Message, ex.StackTrace);
                    return(BadRequest(ex));
                }
            }
        }
예제 #6
0
        ///// <summary>
        ///// 获取查勤进度
        ///// </summary>
        ///// <returns></returns>
        //[HttpGet]
        //[Route("~/Paps/dutyCheckLog/organizationId={organizationId}")]
        //public IActionResult GetDutyCheckLogByProcess(Guid organizationId)
        //{
        //    using (var db = new AllInOneContext.AllInOneContext())
        //    {
        //        DutyCheckLog data = db.DutyCheckLog
        //                            .Include(t => t.Apprise).ThenInclude(t => t.AppraiseICO)
        //                            .Include(t => t.Apprise).ThenInclude(t => t.AppraiseType)
        //                            .Include(t => t.DutyCheckOperation).ThenInclude(t => t.Attachments).ThenInclude(t => t.Attachment)
        //                            .Include(t => t.DutyCheckOperation).ThenInclude(t => t.Attachments).ThenInclude(t => t.AttachmentType)
        //                            .Include(t => t.DutyCheckSiteSchedule).ThenInclude(t => t.CheckDutySite)
        //                            .Include(t => t.DutyCheckSiteSchedule).ThenInclude(t => t.CheckMan)
        //                            .Include(t => t.DutyCheckStaff)
        //                            .Include(t => t.Organization)
        //                            .Include(t => t.RecordType)
        //                            .Include(t => t.Status)
        //                            .FirstOrDefault(
        //                            p => p.OrganizationId.Equals(organizationId)
        //                            && );
        //        if (data == null)
        //        {
        //            return NoContent();
        //        }

        //        return new ObjectResult(data);
        //    }
        //}


        /// <summary>
        /// 检查查勤进度
        /// </summary>
        private void CheckPackageProcess(Guid organizationId)
        {
            try
            {
                if (organizationId == null || organizationId == new Guid())
                {
                    return;
                }

                using (var db = new AllInOneContext.AllInOneContext())
                {
                    DutyCheckPackage package = db.DutyCheckPackage
                                               .Include(t => t.DutyCheckPackLogs).ThenInclude(t => t.DutyCheckLog).ThenInclude(t => t.Status)
                                               .FirstOrDefault(p => p.StartTime <= DateTime.Now && p.EndTime >= DateTime.Now);
                    if (package == null)
                    {
                        MQPulish.PublishMessage("DutyCheckPackageProcess", new DutyCheckPackageProcess {
                            ProcessStatus = 0, Description = "尚未开始"
                        });
                        return;
                    }

                    var endLogs = package.DutyCheckPackLogs.Where(p => p.DutyCheckLog.Status.SystemOptionCode.Equals("16000003")).Count();
                    int status  = 0;
                    if (endLogs > 0)
                    {
                        status = 2;
                    }
                    DutyCheckPackageProcess process = new DutyCheckPackageProcess
                    {
                        Description   = "",
                        EndTime       = package.EndTime,
                        StartTime     = package.StartTime,
                        Total         = package.DutyCheckPackLogs.Count(),
                        CompetedCount = endLogs,
                        ProcessStatus = status
                    };

                    MQPulish.PublishMessage("DutyCheckPackageProcess", process);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(string.Format("根据组织机构ID获取查勤进度状态:Message:{0}\r\n,StackTrace:{1}", ex.Message, ex.StackTrace));
            }
        }
예제 #7
0
        public IActionResult BroadcastCircular([FromBody] Circular Circular)
        {
            if (Circular == null)
            {
                return(BadRequest("Circular object can not be null!"));
            }

            using (var db = new AllInOneContext.AllInOneContext())
            {
                try
                {
                    MQPulish.PublishMessage("Circular", Circular);
                    return(CreatedAtAction("", Circular));
                }
                catch (Exception ex)
                {
                    return(BadRequest(new ApplicationException {
                        ErrorCode = "Unknown", ErrorMessage = ex.Message
                    }));
                }
            }
        }
예제 #8
0
        public IActionResult BroadcastFeedback([FromBody] Feedback Feedback)
        {
            if (Feedback == null)
            {
                return(BadRequest("Feedback object can not be null!"));
            }

            using (var db = new AllInOneContext.AllInOneContext())
            {
                try
                {
                    MQPulish.PublishMessage("Feedback", Feedback);
                    return(CreatedAtAction("", Feedback));
                }
                catch (Exception ex)
                {
                    return(BadRequest(new ApplicationException {
                        ErrorCode = "Unknown", ErrorMessage = ex.Message
                    }));
                }
            }
        }
예제 #9
0
 //http://localhost:5001/IPDevice/deviceStatus?deviceInfoId=7d57976c-a472-8a47-81d4-0005d4dff4ec&StatusId=A0002016-E009-B019-E001-ABCD13800002
 public IActionResult UpdateDeviceStatus(Guid deviceInfoId, Guid statusId)
 {
     using (var db = new AllInOneContext.AllInOneContext())
     {
         try
         {
             //SystemOption statusOptions = db.SystemOption.FirstOrDefault(t => t.SystemOptionCode.Equals(statusId));
             //if (statusOptions == null)
             //    return BadRequest(new ApplicationException() { ErrorCode = "Unknow", ErrorMessage = "未定义设备状态" });
             var device = db.IPDeviceInfo.FirstOrDefault(t => t.IPDeviceInfoId.Equals(deviceInfoId));
             if (device != null && !device.StatusId.Equals(statusId))
             {
                 device.StatusId = statusId;
                 db.IPDeviceInfo.Update(device);
                 //status history
                 DeviceStatusHistory statusHis = new DeviceStatusHistory()
                 {
                     DeviceStatusHistoryId = Guid.NewGuid(),
                     DeviceInfoId          = deviceInfoId,
                     StatusId   = statusId,
                     CreateTime = DateTime.Now
                 };
                 db.DeviceStatusHistory.Add(statusHis);
                 db.SaveChanges();
                 MQPulish.PublishMessage("DeviceStatus", statusHis);
             }
             return(Ok());
         }
         catch (Exception ex)
         {
             _logger.LogError("更新设备状态异常:Message:{0}\r\nStackTrace:{1}", ex.Message, ex.StackTrace);
             return(BadRequest(new ApplicationException()
             {
                 ErrorCode = "Unknow", ErrorMessage = ex.Message
             }));
         }
     }
 }
예제 #10
0
 public override void Execute()
 {
     try
     {
         _logger.LogInformation("执行实时视频预览Begin....");
         //string ids = "";
         //m_actionArgument.ForEach(t => ids += "ids[]=" + t.VideoDeviceId + "&");
         //ids = ids.Substring(0, ids.Length - 1);
         string ids = JsonConvert.SerializeObject(m_actionArgument.Select(t => t.VideoDeviceId).ToList());
         string url = string.Format("{0}/Surveillance/Camera/ids={1}", GlobalSetting.AppServerBaseUrl, ids);
         IEnumerable <CameraView> cams       = HttpClientHelper.Get <CameraView>(url);
         List <RealPlayParam>     playParams = new List <RealPlayParam>();
         m_actionArgument.ForEach(t =>
         {
             CameraView cam     = cams.First(f => f.IPDeviceId.Equals(t.VideoDeviceId));
             RealPlayParam rvpp = new RealPlayParam()
             {
                 CameraView   = cam,
                 Snapshot     = t.ScreenShot,
                 StreamType   = (VideoStream)t.StreamType,
                 PresetSiteNo = t.PresetSiteNo
             };
             playParams.Add(rvpp);
         });
         MQRealPlayAction playRequest = new MQRealPlayAction()
         {
             Cameras    = playParams,
             AlarmLogId = PlanTrigger != null && PlanTrigger.AlarmLogId != null ? PlanTrigger.AlarmLogId.Value : Guid.Empty,
         };
         MQPulish.PublishMessage("ExecuteRealPlayAction", playRequest);
         _logger.LogInformation("执行实时视频预览End....");
     }
     catch (Exception ex)
     {
         _logger.LogError("执行实时视频预览异常:Message:{0}\r\nStackTrace:{1}", ex.Message, ex.StackTrace);
     }
 }
예제 #11
0
 public IActionResult publish([FromBody] ServiceEventLog eventLog)
 {
     MQPulish.PublishMessage("ServiceEventLog", eventLog);
     return(Ok());
 }
예제 #12
0
        private void Run()
        {
            while (WaitHandle.WaitAny(m_WaitHandles) == 0)
            {
                if (m_alarmLogQueue.Count == 0)
                {
                    m_queueThreadSemaphore.Reset();
                }

                //出列,处理
                AlarmLog alarmLog  = null;
                bool     dequeueOk = m_alarmLogQueue.TryDequeue(out alarmLog);
                if (dequeueOk)
                {
                    //报警联动
                    using (var db = new AllInOneContext.AllInOneContext())
                    {
                        try
                        {
                            var setting = GetAlarmSetting(db, alarmLog);
                            if (setting != null)
                            {
                                int code = 0;
                                if (Int32.TryParse(setting.AlarmSource.Organization.OrganizationCode, out code))
                                {
                                    setting.AlarmSource.IPDeviceCode = code;
                                }
                                Plan plan = null;
                                DeviceAlarmStatus status = null;
                                //本地广播报警消息
                                MQPulish.PublishMessage("AlarmLog", alarmLog);
                                if (alarmLog.AlarmStatusId.Equals(Guid.Parse("A0002016-E009-B019-E001-ABCD13100001"))) //执行预案,状态未确认
                                {
                                    if (ScheduleUtility.IsValidSchedule(setting.Schedule, DateTime.Now))               //符合当前排班的情况
                                    {
                                        ////本地广播报警消息
                                        //MQPulish.PublishMessage("AlarmLog", alarmLog);
                                        plan = db.Plan.Include(t => t.Actions).ThenInclude(t => t.PlanActions).ThenInclude(t => t.Action).FirstOrDefault(t => t.PlanId.Equals(setting.BeforePlanId));
                                    }
                                }
                                else if (alarmLog.AlarmStatusId.Equals(Guid.Parse("A0002016-E009-B019-E001-ABCD13100002")))  //执行应急预案
                                {
                                    //预案确认
                                    plan = db.Plan.Include(t => t.Actions).ThenInclude(t => t.PlanActions).ThenInclude(t => t.Action).FirstOrDefault(t => t.PlanId.Equals(setting.EmergencyPlanId));

                                    //哨位报警,确认需推送报警确认/取消到哨位中心服务
                                    status = GetDeviceAlarmStatus(db, setting, true);
                                }
                                else if (alarmLog.AlarmStatusId.Equals(Guid.Parse("A0002016-E009-B019-E001-ABCD13100003"))) //报警取消,停止联动动作
                                {
                                    //哨位报警,取消需推送报警确认/取消到哨位中心服务
                                    status = GetDeviceAlarmStatus(db, setting, false);
                                    StopPlan(setting);
                                }
                                else if (alarmLog.AlarmStatusId.Equals(Guid.Parse("A0002016-E009-B019-E001-ABCD13100004"))) //停止联动动作,已关闭
                                {
                                    status = GetDeviceAlarmStatus(db, setting, false);
                                    StopPlan(setting);
                                }

                                //找到满足条件的预案,发送到任务服务,启动预案
                                if (plan != null)
                                {
                                    plan.PlanTrigger = new PlanTriggerSource()
                                    {
                                        AlarmSource     = setting.AlarmSource,
                                        AlarmType       = setting.AlarmType,
                                        BeforePlanId    = setting.BeforePlanId,
                                        EmergencyPlanId = setting.EmergencyPlanId,
                                        AlarmLogId      = alarmLog.AlarmLogId
                                    };
                                    StartPlan(plan);
                                }
                                if (status != null)
                                {
                                    SendAlarmStatusToASCS(status, setting.AlarmSource.OrganizationId);
                                }
                            }
                            else
                            {
                                _logger.LogInformation("未配置报警,没有任务联动响应!!!!");
                            }
                        }
                        catch (Exception ex)
                        {
                            _logger.LogError("报警处理异常,Message:{0}\r\nStackTrace:{1}", ex.Message, ex.StackTrace);
                        }
                    }
                }
            }
        }
예제 #13
0
 public IActionResult publish([FromBody] AlarmLog alarmLog)
 {
     MQPulish.PublishMessage("ForwardAlarmProcessed", alarmLog);
     return(Ok());
 }
예제 #14
0
        public void Run()
        {
            Task.Factory.StartNew(() =>
            {
                _logger.LogInformation("Start forward alarmlog task......");
                while (true)
                {
                    if (m_alarmLogList.Count == 0)
                    {
                        m_forwardWaiter.WaitOne(-1);
                    }
                    using (var db = new AllInOneContext.AllInOneContext())
                    {
                        //默认第一个为本地应用中心节点()
                        var topApplicationCenter = db.Organization.Include(t => t.Center).
                                                   OrderBy(t => t.OrganizationFullName).Select(t => t.Center).
                                                   FirstOrDefault();

                        if (topApplicationCenter == null || topApplicationCenter.EndPoints == null || topApplicationCenter.EndPoints.Count == 0)
                        {
                            _logger.LogInformation("未配置上级服务器IP,报警上传等待10 min后再检测......");
                            m_forwardWaiter.WaitOne(10 * 60000);
                            continue;
                        }

                        EndPointInfo endPoint = topApplicationCenter.EndPoints.First();
                        string url            = string.Format("http://{0}:{1}/Alarm/AlarmLog/Publish", endPoint.IPAddress, endPoint.Port);
                        //上传报警记录
                        string error = "";
                        lock (m_logLockObj)
                        {
                            for (int i = m_alarmLogList.Count - 1; i >= 0; i--)
                            {
                                AlarmLog log = m_alarmLogList[i];
                                if (log.UploadCount < 10)
                                {
                                    var result = HttpClientHelper.Post <AlarmLog>(log, url);
                                    if (result.Success)
                                    {
                                        log.UploadStatus = 1;  //上传完成
                                    }
                                    else
                                    {
                                        log.UploadCount++;
                                    }
                                    db.AlarmLog.Update(log);
                                    db.SaveChanges();
                                    m_alarmLogList.RemoveAt(i);
                                }
                                else if (log.UploadCount == 10)
                                {
                                    //上传次数达到10次,记录....
                                    log.UploadCount++;
                                    db.AlarmLog.Update(log);
                                    db.SaveChanges();
                                    m_alarmLogList.Remove(log);
                                    //广播消息
                                    error = string.Format("多次尝试推送报警失败,取消推送{0}发生的{1}报警消息到上级系统!",
                                                          log.AlarmSource.IPDeviceName, log.AlarmType.SystemOptionName);
                                    ForwardAlarmLogError forwardErr = new ForwardAlarmLogError()
                                    {
                                        ErrorDesc  = error,
                                        CreateTime = DateTime.Now
                                    };
                                    MQPulish.PublishMessage("ForwardAlarmLogError", forwardErr);
                                }
                            }
                        }
                    }
                    // m_uploadWaiter.WaitOne(10 * 1000);
                }
            });
        }