Esempio n. 1
0
        /// <summary>
        /// 删除哨位终端数据
        /// </summary>
        /// <param name="fp"></param>
        /// <param name="db"></param>
        private void DeleteSentinelFingerInfo(AllInOneContext.AllInOneContext db, Sentinel sen)
        {
            //移除已下发到位台的指纹
            var sentinelFingers = db.Set <SentinelFingerPrintMapping>().Where(t => t.SentinelId.Equals(sen.SentinelId)).ToList();

            if (sentinelFingers != null && sentinelFingers.Count > 0)
            {
                Guid ascsServerType = Guid.Parse("A0002016-E009-B019-E001-ABCD11300206");
                var  service        = db.ServiceInfo.Include(t => t.ServerInfo).
                                      FirstOrDefault(t => t.ServiceTypeId.Equals(ascsServerType) && t.ServerInfo.OrganizationId.Equals(sen.DeviceInfo.OrganizationId));

                if (service != null)
                {
                    Task.Run(() =>
                    {
                        try
                        {
                            _logger.LogInformation("清除哨位指纹 Begin...");
                            ASCSApi ascs     = new ASCSApi(service);
                            var sentinelCode = Int32.Parse(sen.DeviceInfo.Organization.OrganizationCode);
                            var r            = ascs.CleanFinger(sentinelCode, 0);
                            db.Set <SentinelFingerPrintMapping>().RemoveRange(sentinelFingers);
                            _logger.LogInformation("清除哨位指纹End,结果:{0}...", r.Success);
                        }
                        catch (Exception ex)
                        {
                            _logger.LogError("清除哨位指纹结果异常:{0}\r\n{1}", ex.Message, ex.StackTrace);
                        }
                    });
                }
            }
        }
Esempio n. 2
0
        public override void Execute()
        {
            return;

            try
            {
                _logger.LogInformation("执行开启警灯动作 {0} Begin....", PlanId);
                //获取声光报警设备,并按组织机构分组
                string url = string.Format("{0}/Resources/IPDevice/systemOptionId={1}", GlobalSetting.AppServerBaseUrl, "A0002016-E009-B019-E001-ABCD11000006");
                IEnumerable <IPDeviceInfo> soundLightDevices = HttpClientHelper.Get <IPDeviceInfo>(url);
                var soundLightDeviceGroup = soundLightDevices.Join(m_actionArgumentList, p => p.IPDeviceInfoId, q => q.SoundLightDeviceId, (p, q) =>
                                                                   new { Device = p, Argument = q }).GroupBy(t => t.Device.OrganizationId);

                foreach (var sg in soundLightDeviceGroup)
                {
                    var service = TaskUtility.GetASCService(sg.Key);
                    if (service != null)
                    {
                        //判断是否有报警
                        ASCSApi ascs = new ASCSApi(service);
                        foreach (var device in sg)
                        {
                            int ledbitmask   = 0x80;
                            var sentinelCode = -1;
                            if (PlanTrigger != null)
                            {
                                if (AlarmLightDictionry.ContainsKey(PlanTrigger.AlarmType.SystemOptionId))
                                {
                                    ledbitmask = AlarmLightDictionry[PlanTrigger.AlarmType.SystemOptionId];
                                }
                            }
                            SoundLightControl action = new SoundLightControl()
                            {
                                DeviceCode   = device.Device.IPDeviceCode,
                                Message      = string.Empty,
                                Ledbitmask   = ledbitmask,
                                Audio        = string.Empty,
                                SentinelCode = sentinelCode //PlanTrigger.AlarmSource.IPDeviceCode
                            };
                            ascs.SendSoundLightAction(action);
                        }
                    }
                    else
                    {
                        _logger.LogInformation("取消开启警灯动作执行,找不到设备对应的哨位中心服务!!!");
                    }
                }
                _logger.LogInformation("执行开启警灯动作 {0} End ....", PlanId);
            }
            catch (Exception ex)
            {
                _logger.LogError("执行开启警灯报动作异常:{0}\r\n{1}", ex.Message, ex.StackTrace);
            }
        }
Esempio n. 3
0
        public override void Execute()
        {
            //获取哨位设备,并按组织机构分组
            try
            {
                _logger.LogInformation("执行开启喊话动作!!!");
                string url = string.Format("{0}/Resources/IPDevice/systemOptionId={1}", GlobalSetting.AppServerBaseUrl, "A0002016-E009-B019-E001-ABCD11000004");
                IEnumerable <IPDeviceInfo> sentinels = HttpClientHelper.Get <IPDeviceInfo>(url);
                var sentinelGroup = sentinels.Join(m_actionArgumentList, p => p.IPDeviceInfoId, q => q.SentinelId, (p, q) => p).GroupBy(t => t.OrganizationId);

                ////获取哨位中心服务
                //url = string.Format("{0}/Resources/Service/ServiceTypeId={1}", GlobalSetting.AppServerBaseUrl, "A0002016-E009-B019-E001-ABCD11300206");
                //IEnumerable<ServiceInfo> services = HttpClientHelper.Get<ServiceInfo>(url);

                //url = string.Format("{0}//Infrastructure/Organization/isorganizationtype=false", GlobalSetting.AppServerBaseUrl);
                //IEnumerable<Organization> orgs = HttpClientHelper.Get<Organization>(url);
                foreach (var sg in sentinelGroup)
                {
                    //var deviceOrg = orgs.FirstOrDefault(t => t.OrganizationId.Equals(sg.Key));
                    //ServiceInfo ascs = services.FirstOrDefault(t => t.ServerInfo.OrganizationId.Equals(deviceOrg.ParentOrganizationId) ||
                    //        t.ServerInfo.OrganizationId.Equals(sg.Key));
                    var ascs = TaskUtility.GetASCService(sg.Key);
                    if (ascs != null)
                    {
                        foreach (var device in sg)
                        {
                            var sentinelCode = 0;
                            if (Int32.TryParse(device.Organization.OrganizationCode, out sentinelCode))
                            {
                                device.IPDeviceCode = sentinelCode;
                            }
                            SentinelShout shout = new SentinelShout()
                            {
                                DeviceId     = device.IPDeviceInfoId,
                                SentinelCode = sentinelCode, //device.IPDeviceCode,
                                Open         = true
                            };

                            ASCSApi api = new ASCSApi(ascs);
                            api.Shout(shout);
                        }
                    }
                }
                _logger.LogInformation("执行启动喊话动作完成!!!");
            }
            catch (Exception ex)
            {
                _logger.LogError("执行启动喊话动作异常:{0}\r\n{1}", ex.Message, ex.StackTrace);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 停止声光报警动作
        /// 停止当前预案动作,然后恢复上一预案动作
        /// </summary>
        /// <param name="plan"></param>
        public static void Stop(Plan plan)
        {
            var actionId      = plan.PlanTrigger != null ? plan.PlanTrigger.AlarmLogId.Value : plan.PlanId;
            var outTimeAction = s_SoundLightActionRecords.FirstOrDefault(t => t.ActionId.Equals(actionId));

            if (outTimeAction != null && outTimeAction.Actions != null && outTimeAction.Actions.Count > 0)
            {
                _logger.LogInformation("停止声光报警动作 Begin...");
                ASCSApi    api = null;
                List <int> soundLightDeviceCode = new List <int>();
                foreach (var action in outTimeAction.Actions)
                {
                    action.SoundLightControl.Audio      = string.Empty;
                    action.SoundLightControl.Ledbitmask = 0;
                    action.SoundLightControl.Message    = string.Empty;
                    api = new ASCSApi(action.Ascs);
                    _logger.LogInformation("下发停止声光报警联动协议: \r\n:{0}", JsonUtility.CamelCaseSerializeObject(action.SoundLightControl));
                    api.SendSoundLightAction(action.SoundLightControl);
                    soundLightDeviceCode.Add(action.SoundLightControl.DeviceCode);
                }
                LedDisplay ledDisopay = new LedDisplay()
                {
                    Flag         = 2,
                    Text         = string.Empty,
                    TerminalCode = soundLightDeviceCode.ToArray()
                };
                _logger.LogInformation("下发恢复声光报警时间显示: \r\n:{0}", JsonUtility.CamelCaseSerializeObject(ledDisopay));
                api.ControLedDisplayl(ledDisopay);
                s_SoundLightActionRecords.Remove(outTimeAction);
                _logger.LogInformation("停止声光报警动作 End...");

                //执行下动作
                if (s_SoundLightActionRecords.Count > 0)
                {
                    _logger.LogInformation("恢复播放上一声光报警动作 begin!!");
                    var record = s_SoundLightActionRecords.Last();
                    foreach (var action in record.Actions)
                    {
                        api = new ASCSApi(action.Ascs);
                        api.SendSoundLightAction(action.SoundLightControl);
                    }
                    _logger.LogInformation("恢复播放上一声光报警动作 end!!");
                }
                else
                {
                    _logger.LogInformation("当前没有要恢复的声光报警动作");
                }
            }
        }
Esempio n. 5
0
        //public override void Execute()
        //{
        //    //获取哨位设备,并按组织机构分组
        //    try
        //    {
        //        _logger.LogInformation("执行打开子弹箱动作 {0} Begin...",PlanId);
        //        string url = string.Format("{0}/Resources/IPDevice/systemOptionId={1}", GlobalSetting.AppServerBaseUrl, "A0002016-E009-B019-E001-ABCD11000004");
        //        IEnumerable<IPDeviceInfo> sentinels = HttpClientHelper.Get<IPDeviceInfo>(url);
        //        var sentinelGroup = sentinels.Join(m_actionArgumentList, p => p.IPDeviceInfoId, q => q.SentinelId, (p, q) => p).GroupBy(t => t.OrganizationId);

        //        ////获取哨位中心服务
        //        //url = string.Format("{0}/Resources/Service/ServiceTypeId={1}", GlobalSetting.AppServerBaseUrl, "A0002016-E009-B019-E001-ABCD11300206");
        //        //IEnumerable<ServiceInfo> services = HttpClientHelper.Get<ServiceInfo>(url);

        //        //url = string.Format("{0}//Infrastructure/Organization/isorganizationtype=false", GlobalSetting.AppServerBaseUrl);
        //        //IEnumerable<Organization> orgs = HttpClientHelper.Get<Organization>(url);

        //        foreach (var sg in sentinelGroup)
        //        {
        //            //var deviceOrg = orgs.FirstOrDefault(t => t.OrganizationId.Equals(sg.Key));
        //            //ServiceInfo ascs = services.FirstOrDefault(t => t.ServerInfo.OrganizationId.Equals(deviceOrg.ParentOrganizationId) ||
        //            //        t.ServerInfo.OrganizationId.Equals(sg.Key));
        //            var ascs = TaskUtility.GetASCService(sg.Key);
        //            if (ascs != null)
        //            {
        //                List<CartidgeBoxStatus> statuses = new List<CartidgeBoxStatus>();

        //                foreach (var device in sg)
        //                {
        //                    var sentinelCode = 0;
        //                    if (Int32.TryParse(device.Organization.OrganizationCode, out sentinelCode))
        //                        device.IPDeviceCode = sentinelCode;
        //                    CartidgeBoxStatus status = new CartidgeBoxStatus()
        //                    {
        //                        DeviceId = device.IPDeviceInfoId,
        //                        SentinelCode = sentinelCode, //device.IPDeviceCode,
        //                        BulletBoxStatus = true
        //                    };
        //                    statuses.Add(status);
        //                }
        //                _logger.LogInformation("下发打开子弹箱 Begin :{0}", JsonUtility.CamelCaseSerializeObject(statuses));
        //                ASCSApi api = new ASCSApi(ascs);
        //                api.CatridgeBoxStatus(statuses);
        //                _logger.LogInformation("下发打开子弹箱 End...");
        //            }
        //        }
        //        _logger.LogInformation("执行打开子弹箱动作 {0} End...",PlanId);
        //    }
        //    catch (Exception ex)
        //    {
        //        _logger.LogError("执行打开子弹箱动作异常:{0}\r\n{1}", ex.Message, ex.StackTrace);
        //    }
        //}

        public override void Execute()
        {
            //获取哨位设备,并按组织机构分组
            try
            {
                _logger.LogInformation("执行打开子弹箱动作 {0} Begin...", PlanId);

                var sentinels = TaskUtility.s_cacheDeviceList;
                if (sentinels == null || sentinels.Count == 0)
                {
                    string url = string.Format("{0}/Resources/IPDevice/systemOptionId={1}", GlobalSetting.AppServerBaseUrl, "A0002016-E009-B019-E001-ABCD11000004");
                    sentinels = HttpClientHelper.Get <IPDeviceInfo>(url).ToList();
                }
                var sentinelIpdevices = sentinels.Join(m_actionArgumentList, p => p.IPDeviceInfoId, q => q.SentinelId, (p, q) => p).ToList();

                var ascs = TaskUtility.GetDefaultASCService();

                if (ascs != null)
                {
                    List <CartidgeBoxStatus> statuses = new List <CartidgeBoxStatus>();
                    foreach (var device in sentinelIpdevices)
                    {
                        var sentinelCode = 0;
                        if (Int32.TryParse(device.Organization.OrganizationCode, out sentinelCode))
                        {
                            device.IPDeviceCode = sentinelCode;
                        }
                        CartidgeBoxStatus status = new CartidgeBoxStatus()
                        {
                            DeviceId        = device.IPDeviceInfoId,
                            SentinelCode    = sentinelCode,
                            BulletBoxStatus = true
                        };
                        statuses.Add(status);
                    }
                    _logger.LogInformation("下发打开子弹箱 Begin :{0}", JsonUtility.CamelCaseSerializeObject(statuses));
                    ASCSApi api = new ASCSApi(ascs);
                    api.CatridgeBoxStatus(statuses);
                    _logger.LogInformation("下发打开子弹箱 End...");
                }
                _logger.LogInformation("执行打开子弹箱动作 {0} End...", PlanId);
            }
            catch (Exception ex)
            {
                _logger.LogError("执行打开子弹箱动作异常:{0}\r\n{1}", ex.Message, ex.StackTrace);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// 发送报警状态到哨位中心服务
        /// </summary>
        /// <param name="db"></param>
        /// <param name="status"></param>
        /// <param name="deviceOrgId"></param>
        private void SendAlarmStatusToASCS(DeviceAlarmStatus status, Guid deviceOrgId)
        {
            Task.Run(new Action(() =>
            {
                using (var db = new AllInOneContext.AllInOneContext())
                {
                    _logger.LogInformation("推送报警状态到哨位心...");
                    Guid ascsServerType = Guid.Parse("A0002016-E009-B019-E001-ABCD11300206");

                    //哨位台挂在哨位节点上面
                    var org     = db.Organization.FirstOrDefault(t => t.OrganizationId.Equals(deviceOrgId));
                    var service = db.ServiceInfo.Include(t => t.ServerInfo).
                                  FirstOrDefault(t => t.ServiceTypeId.Equals(ascsServerType) && (
                                                     t.ServerInfo.OrganizationId.Equals(org.ParentOrganizationId) || t.ServerInfo.OrganizationId.Equals(deviceOrgId)));

                    //var service = new ServiceInfo() {
                    //    EndPointsJson = "[{\"IPAddress\":\"192.168.18.76\",\"Port\":5002}]"
                    //};
                    if (service != null)
                    {
                        try
                        {
                            ASCSApi ascs = new ASCSApi(service);
                            var r        = ascs.SendDeviceAlarmStatus(status);
                            _logger.LogInformation("推送报警状态到哨位中心结果:{0}...", r.Success);
                        }
                        catch (Exception ex)
                        {
                            _logger.LogError("发送报警状态到哨位中心异常:{0}\r\n{1}", ex.Message, ex.StackTrace);
                        }
                        return;
                    }
                }
                _logger.LogInformation("未配置哨位中心服务,取消推送....");
            }));
        }
Esempio n. 7
0
        public override void Execute()
        {
            return;

            _logger.LogInformation("执行语言播报联动动作 {0} Begin.....", PlanId);
            try
            {
                //获取声光报警设备,并按组织机构分组
                string url = string.Format("{0}/Resources/IPDevice/systemOptionId={1}", GlobalSetting.AppServerBaseUrl, "A0002016-E009-B019-E001-ABCD11000006");
                IEnumerable <IPDeviceInfo> soundLightDevices = HttpClientHelper.Get <IPDeviceInfo>(url);
                var soundLightDeviceGroup = soundLightDevices.Join(m_actionArgumentList, p => p.IPDeviceInfoId, q => q.SoundLightDeviceId, (p, q) =>
                                                                   new { Device = p, Argument = q }).GroupBy(t => t.Device.OrganizationId);

                ////获取哨位中心服务
                //url = string.Format("{0}/Resources/Service/ServiceTypeId={1}", GlobalSetting.AppServerBaseUrl, "A0002016-E009-B019-E001-ABCD11300206");
                //IEnumerable<ServiceInfo> services = HttpClientHelper.Get<ServiceInfo>(url);

                //url = string.Format("{0}//Infrastructure/Organization/isorganizationtype=false", GlobalSetting.AppServerBaseUrl);
                //IEnumerable<Organization> orgs = HttpClientHelper.Get<Organization>(url);
                foreach (var sg in soundLightDeviceGroup)
                {
                    //var deviceOrg = orgs.FirstOrDefault(t => t.OrganizationId.Equals(sg.Key));
                    //ServiceInfo service = services.FirstOrDefault(t => t.ServerInfo.OrganizationId.Equals(deviceOrg.ParentOrganizationId) ||
                    //        t.ServerInfo.OrganizationId.Equals(sg.Key));
                    var service = TaskUtility.GetASCService(sg.Key);

                    if (service != null)
                    {
                        ASCSApi ascs = new ASCSApi(service);
                        foreach (var device in sg)
                        {
                            string audioFile    = device.Argument.AudioFile;
                            int    sentinelCode = -1;
                            if (PlanTrigger != null)
                            {
                                sentinelCode = PlanTrigger.AlarmSource.IPDeviceCode;//Int32.Parse(PlanTrigger.AlarmSource.Organization.OrganizationCode);
                                if (PlanId.Equals(PlanTrigger.EmergencyPlanId))
                                {
                                    audioFile = string.Format("sound/{0}处置/{1}号哨{2}处置.wav", PlanTrigger.AlarmType.SystemOptionName,
                                                              sentinelCode /*PlanTrigger.AlarmSource.IPDeviceCode*/, PlanTrigger.AlarmType.SystemOptionName);
                                }
                                else if (PlanId.Equals(PlanTrigger.BeforePlanId))
                                {
                                    audioFile = string.Format("sound/{0}一级/{1}号哨发生犯人{2}.wav", PlanTrigger.AlarmType.SystemOptionName,
                                                              sentinelCode /*PlanTrigger.AlarmSource.IPDeviceCode*/, PlanTrigger.AlarmType.SystemOptionName);
                                }
                            }
                            //audioFile = device.Argument.AudioFile;
                            SoundLightControl action = new SoundLightControl()
                            {
                                DeviceCode   = device.Device.IPDeviceCode,
                                Message      = string.Empty,
                                Ledbitmask   = -1,
                                Audio        = audioFile,
                                SentinelCode = sentinelCode
                            };
                            _logger.LogInformation("下发语音播报:{0}", JsonUtility.CamelCaseSerializeObject(action));
                            ascs.SendSoundLightAction(action);
                            _logger.LogInformation("下发语音播报完成");
                        }
                    }
                    else
                    {
                        _logger.LogInformation("找不到设备对应的哨位中心服务,取消播报音频!!!");
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogError("执行语音播报动作异常:{0}\r\n{1}", ex.Message, ex.StackTrace);
            }
            _logger.LogInformation("执行语言播报联动动作 {0} End.....", PlanId);
        }
Esempio n. 8
0
        public override void Execute()
        {
            return;

            try
            {
                _logger.LogInformation("执行LED消息推送动作 {0} Begin.....", PlanId);
                //获取声光报警设备,并按组织机构分组
                string url = string.Format("{0}/Resources/IPDevice/systemOptionId={1}", GlobalSetting.AppServerBaseUrl, "A0002016-E009-B019-E001-ABCD11000006");
                IEnumerable <IPDeviceInfo> soundLightDevices = HttpClientHelper.Get <IPDeviceInfo>(url);
                var soundLightDeviceGroup = soundLightDevices.Join(m_actionArgumentList, p => p.IPDeviceInfoId, q => q.SoundLightDeviceId, (p, q) => new { Device = p, Message = q.LedText }).GroupBy(t => t.Device.OrganizationId);

                //获取哨位中心服务
                //url = string.Format("{0}/Resources/Service/ServiceTypeId={1}", GlobalSetting.AppServerBaseUrl, "A0002016-E009-B019-E001-ABCD11300206");
                //IEnumerable<ServiceInfo> services = HttpClientHelper.Get<ServiceInfo>(url);

                //url = string.Format("{0}//Infrastructure/Organization/isorganizationtype=false", GlobalSetting.AppServerBaseUrl);
                //IEnumerable<Organization> orgs = HttpClientHelper.Get<Organization>(url);
                foreach (var sg in soundLightDeviceGroup)
                {
                    //var deviceOrg = orgs.FirstOrDefault(t => t.OrganizationId.Equals(sg.Key));
                    //ServiceInfo service = services.FirstOrDefault(t => t.ServerInfo.OrganizationId.Equals(deviceOrg.ParentOrganizationId) ||
                    //        t.ServerInfo.OrganizationId.Equals(sg.Key));
                    var service = TaskUtility.GetASCService(sg.Key);
                    if (service != null)
                    {
                        //判断是否有报警
                        ASCSApi ascs = new ASCSApi(service);
                        foreach (var device in sg)
                        {
                            string message = device.Message;
                            if (PlanTrigger != null)
                            {
                                var alarmTextObj = TaskUtility.SoundlightConfigList.FirstOrDefault(t => t.AlarmTypeId.Equals(PlanTrigger.AlarmType.SystemOptionId));
                                var alarmdesc    = alarmTextObj != null ? alarmTextObj.Description : "";
                                if (PlanId.Equals(PlanTrigger.BeforePlanId))
                                {
                                    message = string.Format("{0}{1},各小组请注意观察!", PlanTrigger.AlarmSource.IPDeviceName, alarmdesc);
                                }
                                else if (PlanId.Equals(PlanTrigger.EmergencyPlanId))
                                {
                                    message = string.Format("{0}{1},各小组按预案处置!", alarmdesc);
                                }
                            }

                            //message = "\0"; //清空
                            _logger.LogInformation("推送消息 Begin ....发送[{0}]到{1}", message, device.Device.IPDeviceName);
                            PushMessage msg = new PushMessage()
                            {
                                DeviceCode = device.Device.IPDeviceCode,
                                Message    = message
                            };
                            ascs.PushMessage(msg);
                            _logger.LogInformation("推送消息 End");
                        }
                        _logger.LogInformation("执行LED消息推送动作 {0} End.....", PlanId);
                    }
                    else
                    {
                        _logger.LogInformation("未配置哨位中心服务,取消推送消息");
                    }
                }
            }catch (Exception ex)
            {
                _logger.LogError("执行文字推送动作异常:{0}\r\n{1}", ex.Message, ex.StackTrace);
            }
        }
Esempio n. 9
0
        ///// <summary>
        ///// 更新指纹
        ///// </summary>
        ///// <param name="figure"></param>
        ///// <returns></returns>
        //[HttpPut]
        //[Route("~/Infrastructure/Staff/fingerprint")]
        //public IActionResult UpdateFingerprint([FromBody]Fingerprint figure)
        //{
        //    try
        //    {
        //        using (var db = new AllInOneContext.AllInOneContext())
        //        {
        //            db.Set<Fingerprint>().Update(figure);
        //            db.SaveChanges();
        //            return new NoContentResult();
        //        }
        //    }
        //    catch (DbUpdateException dbEx)
        //    {
        //        return BadRequest(new ApplicationException { ErrorCode = "DBUpdate", ErrorMessage = "数据保存异常:" + dbEx.Message });
        //    }
        //    catch (Exception ex)
        //    {
        //        return BadRequest(new ApplicationException { ErrorCode = "Unknown", ErrorMessage = ex.Message });
        //    }
        //}

        ///// <summary>
        ///// 删除指纹
        ///// </summary>
        ///// <param name="id"></param>
        ///// <returns></returns>
        //[HttpDelete]
        //[Route("~/Infrastructure/Staff/fingerprint/id={id}")]
        //public IActionResult DeleteFingerprint(Guid id)
        //{
        //    try
        //    {
        //        using (var db = new AllInOneContext.AllInOneContext())
        //        {
        //            var fp = db.Set<Fingerprint>().FirstOrDefault(t => t.FingerprintId.Equals(id));
        //            if (fp != null)
        //            {
        //                //查找关联的哨位,删除下发记录
        //                DeleteFingerDispatch(fp, db);

        //                //删除数据库中记录
        //                db.Set<Fingerprint>().Remove(fp);
        //                db.SaveChanges();
        //                return new NoContentResult();
        //            }
        //            else
        //                return NotFound();
        //        }
        //    }
        //    catch (DbUpdateException dbEx)
        //    {
        //        return BadRequest(new ApplicationException { ErrorCode = "DBUpdate", ErrorMessage = "数据保存异常:" + dbEx.Message });
        //    }
        //    catch (Exception ex)
        //    {
        //        return BadRequest(new ApplicationException { ErrorCode = "Unknown", ErrorMessage = ex.Message });
        //    }
        //}

        /// <summary>
        /// 删除哨位终端数据
        /// </summary>
        /// <param name="fp"></param>
        /// <param name="db"></param>
        private void DeleteFingerDispatch(Fingerprint fp, AllInOneContext.AllInOneContext db)
        {
            //var sentinels = db.Sentinel.Include(t => t.DeviceInfo).Include(t => t.FingerDispatch).ToList().Where(t => t.FingerDispatch != null
            //           && t.FingerDispatch.Exists(f => f.FingerprintId.Equals(fp.FingerprintId))).ToList();
            //foreach (var sen in sentinels)
            //{
            //    //调用哨位所在
            //    Guid ascsServerType = Guid.Parse("A0002016-E009-B019-E001-ABCD11300206");
            //    var service = db.ServiceInfo.Include(t => t.ServerInfo).
            //        FirstOrDefault(t => t.ServiceTypeId.Equals(ascsServerType) && t.ServerInfo.OrganizationId.Equals(sen.DeviceInfo.OrganizationId));

            //    if (service != null)
            //    {
            //        try
            //        {
            //            ASCSApi ascs = new ASCSApi(service);
            //            var r = ascs.CleanFinger(sen.DeviceInfo.IPDeviceCode, fp.FingerprintNo);
            //            //移除已下发到位台的指纹
            //            db.Set<SentinelFingerPrintMapping>().RemoveRange(
            //                db.Set<SentinelFingerPrintMapping>().Where(t => t.FingerprintId.Equals(fp.FingerprintId)));
            //            _logger.LogInformation("删除下发到哨位的指纹结果:{0}...", r.Success);
            //        }
            //        catch (Exception ex)
            //        {
            //            _logger.LogError("删除下发到哨位的指纹异常:{0}\r\n{1}", ex.Message, ex.StackTrace);
            //        }
            //        return;
            //    }
            //}

            //获取下发了该指纹的哨位台
            var sentinels = db.SentinelFingerPrintMapping.Include(t => t.Sentinel).ThenInclude(t => t.DeviceInfo)
                            .ThenInclude(t => t.Organization)
                            .Where(t => t.FingerprintId.Equals(fp.FingerprintId)).ToList().Select(t => t.Sentinel).ToList();

            foreach (var sen in sentinels)
            {
                Guid ascsServerType = Guid.Parse("A0002016-E009-B019-E001-ABCD11300206");
                var  deviceOrg      = db.Organization.FirstOrDefault(t => t.OrganizationId.Equals(sen.DeviceInfo.OrganizationId));
                var  service        = db.ServiceInfo.Include(t => t.ServerInfo).
                                      FirstOrDefault(t => t.ServiceTypeId.Equals(ascsServerType) && (t.ServerInfo.OrganizationId.Equals(deviceOrg.ParentOrganizationId) ||
                                                                                                     t.ServerInfo.OrganizationId.Equals(deviceOrg.OrganizationId)));

                if (service != null)
                {
                    try
                    {
                        ASCSApi ascs = new ASCSApi(service);
                        //var sentinelCode = Int32.Parse(sen.DeviceInfo.Organization.OrganizationCode);
                        //var r = ascs.CleanFinger(sentinelCode, fp.FingerprintNo);
                        var r = ascs.CleanFinger(sen.DeviceInfo.IPDeviceCode, fp.FingerprintNo);
                        //移除已下发到位台的指纹
                        db.SentinelFingerPrintMapping.RemoveRange(
                            db.SentinelFingerPrintMapping.Where(t => t.FingerprintId.Equals(fp.FingerprintId)).ToList());
                        _logger.LogInformation("删除下发到哨位的指纹结果:{0}...", r.Success);
                    }
                    catch (Exception ex)
                    {
                        _logger.LogError("删除下发到哨位的指纹异常:{0}\r\n{1}", ex.Message, ex.StackTrace);
                    }
                    return;
                }
            }
        }
Esempio n. 10
0
        ///// <summary>
        /////  执行声光联动动作
        ///// </summary>
        ///// <param name="plan"></param>
        //public static void Execute(Plan plan)
        //{
        //    try
        //    {
        //        var planId = plan.PlanId;
        //        var planTrigger = plan.PlanTrigger;
        //        _logger.LogInformation("执行声光报警联动动作 Begin .....");

        //        RemoveBeforePlanAction(plan);

        //        //获取声光报警设备,并按组织机构分组
        //        if (SoundLightActionHash.ContainsKey(planId))
        //        {
        //            var arguments = SoundLightActionHash[planId] as List<SoundLightArgument>;
        //            if (arguments.Count == 0)
        //                return;
        //            _logger.LogInformation("声光报警器按组织机构分组 Begin .....");
        //            string url = string.Format("{0}/Resources/IPDevice/systemOptionId={1}", GlobalSetting.AppServerBaseUrl, "A0002016-E009-B019-E001-ABCD11000006");
        //            IEnumerable<IPDeviceInfo> soundLightDevices = HttpClientHelper.Get<IPDeviceInfo>(url);
        //            var soundLightDeviceGroup = soundLightDevices.Join(arguments, p => p.IPDeviceInfoId, q => q.SoundLightDeviceId, (p, q) =>new { Device = p, Argument = q }).
        //                GroupBy(t => t.Device.OrganizationId);
        //            _logger.LogInformation("声光报警器按组织机构分组 End .....");

        //            List<SoundLightActionEx> actions = new List<SoundLightActionEx>(); //缓存执行的动作
        //            foreach (var sg in soundLightDeviceGroup)
        //            {
        //                var service = TaskUtility.GetASCService(sg.Key);
        //                if (service != null)
        //                {
        //                    //判断是否有报警
        //                    ASCSApi ascs = new ASCSApi(service);
        //                    foreach (var device in sg)
        //                    {
        //                        string message = "";
        //                        int sentinelCode = -1;
        //                        if (planTrigger != null && planTrigger.AlarmSource != null && planTrigger.AlarmSource.Organization != null)
        //                        {
        //                            Int32.TryParse(planTrigger.AlarmSource.Organization.OrganizationCode, out sentinelCode);
        //                        }

        //                        ///哨位节点名称
        //                        //推送文字
        //                        if (device.Argument.PushMessage)
        //                        {
        //                            if (!string.IsNullOrEmpty(device.Argument.Message))
        //                                message = device.Argument.Message;
        //                            else
        //                            {
        //                                if (planTrigger != null)
        //                                {
        //                                    string sentinelNodeName = planTrigger.AlarmSource.Organization.OrganizationShortName;
        //                                    message = GetPushText(planId, planTrigger, sentinelNodeName);
        //                                }
        //                            }
        //                        }
        //                        _logger.LogInformation("推送消息内容[{0}]到{1}", message, device.Device.IPDeviceName);

        //                        //开启警灯
        //                        int ledbitmask = 0;
        //                        if (device.Argument.TurnonLightAction)
        //                        {
        //                            if (planTrigger != null)
        //                            {
        //                                var soundlightCfg = TaskUtility.SoundlightConfigList.FirstOrDefault(t => t.AlarmTypeId.Equals(planTrigger.AlarmType.SystemOptionId));
        //                                if (soundlightCfg != null)
        //                                    ledbitmask = soundlightCfg.Ledbitmask;
        //                            }
        //                            else
        //                                ledbitmask = 0x80;
        //                        }
        //                        //语音推送
        //                        string audioFile = "";
        //                        if (device.Argument.AudioAction)
        //                        {
        //                            audioFile = device.Argument.AudioFile;
        //                            if (planTrigger != null)
        //                                audioFile = GetAudioFile(planId, planTrigger);
        //                        }

        //                        SoundLightControl startAction = new SoundLightControl()
        //                        {
        //                            DeviceCode = device.Device.IPDeviceCode,
        //                            Message = message,
        //                            Ledbitmask = ledbitmask,
        //                            Audio = audioFile,
        //                            SentinelCode = sentinelCode //planTrigger.AlarmSource.IPDeviceCode
        //                        };
        //                        _logger.LogInformation("下发声光报警联动动作: Begin");
        //                        ascs.SendSoundLightAction(startAction);
        //                        _logger.LogInformation("启动动作 \r\n:{0}", JsonUtility.CamelCaseSerializeObject(startAction));
        //                        actions.Add(new SoundLightActionEx() {
        //                            Ascs = service,
        //                            SoundLightControl = startAction
        //                        });
        //                        _logger.LogInformation("下发声光报警联动动作: End ");
        //                    }
        //                }
        //                else
        //                    _logger.LogInformation("未配置哨位中心服务,取消声光报警联动");
        //            }
        //            //保存执行动作
        //            s_SoundLightActionRecords.Add(new SoundLightActionRecord()
        //            {
        //                ActionId = plan.PlanTrigger != null ? plan.PlanTrigger.AlarmLogId.Value : plan.PlanId,
        //                Actions = actions
        //            });
        //            _logger.LogInformation("执行声光报警联动动作 End .....");
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        _logger.LogError("执行声光报警动作异常:{0}\r\n{1}", ex.Message, ex.StackTrace);
        //    }
        //}

        /// <summary>
        ///  执行声光联动动作
        /// </summary>
        /// <param name="plan"></param>
        public static void Execute(Plan plan)
        {
            try
            {
                var planId      = plan.PlanId;
                var planTrigger = plan.PlanTrigger;
                _logger.LogInformation("执行声光报警联动动作 Begin .....");

                RemoveBeforePlanAction(plan);

                //获取声光报警设备,并按组织机构分组
                if (SoundLightActionHash.ContainsKey(planId))
                {
                    var arguments = SoundLightActionHash[planId] as List <SoundLightArgument>;
                    if (arguments.Count > 0)
                    {
                        _logger.LogInformation("获取声光报警器设备信息 Begin .....");
                        IEnumerable <IPDeviceInfo> soundLightDevices = soundLightDevices = TaskUtility.s_cacheDeviceList;
                        if (soundLightDevices == null || soundLightDevices.Count() == 0)
                        {
                            string url = string.Format("{0}/Resources/IPDevice/systemOptionId={1}", GlobalSetting.AppServerBaseUrl, "A0002016-E009-B019-E001-ABCD11000006");
                            soundLightDevices = HttpClientHelper.Get <IPDeviceInfo>(url);
                        }
                        var soundLightDeviceViewList = soundLightDevices.Join(arguments, p => p.IPDeviceInfoId, q => q.SoundLightDeviceId, (p, q) =>
                                                                              new { Device = p, Argument = q }).ToList();
                        _logger.LogInformation("获取声光报警器设备信息 End .....");

                        List <SoundLightActionEx> actions = new List <SoundLightActionEx>(); //缓存执行的动作
                        var service = TaskUtility.GetDefaultASCService();
                        if (service != null)
                        {
                            ASCSApi ascs         = new ASCSApi(service);
                            int     sentinelCode = -1;
                            if (planTrigger != null && planTrigger.AlarmSource != null && planTrigger.AlarmSource.Organization != null)
                            {
                                Int32.TryParse(planTrigger.AlarmSource.Organization.OrganizationCode, out sentinelCode);
                            }
                            foreach (var device in soundLightDeviceViewList)
                            {
                                string message    = "";
                                int    ledbitmask = 0;
                                string audioFile  = "";
                                if (planTrigger != null)
                                {
                                    //推送文字
                                    if (!string.IsNullOrEmpty(device.Argument.Message))
                                    {
                                        message = device.Argument.Message;
                                    }
                                    else
                                    {
                                        string sentinelNodeName = planTrigger.AlarmSource.Organization.OrganizationShortName;
                                        message = GetPushText(planId, planTrigger, sentinelNodeName);
                                    }
                                    //警灯
                                    var soundlightCfg = TaskUtility.SoundlightConfigList.FirstOrDefault(t => t.AlarmTypeId.Equals(planTrigger.AlarmType.SystemOptionId));
                                    if (soundlightCfg != null)
                                    {
                                        ledbitmask = soundlightCfg.Ledbitmask;
                                    }
                                    else
                                    {
                                        ledbitmask = 0x80; //其他报警打开所有灯
                                    }
                                    //播报语音
                                    audioFile = GetAudioFile(planId, planTrigger);
                                }
                                else
                                {
                                    ledbitmask = 0x80;
                                    audioFile  = device.Argument.AudioFile;
                                }

                                _logger.LogInformation("Before :audio:{0}", audioFile);
                                SoundLightControl startAction = new SoundLightControl()
                                {
                                    DeviceCode   = device.Device.IPDeviceCode,
                                    Message      = device.Argument.PushMessage ? message : string.Empty,
                                    Ledbitmask   = device.Argument.TurnonLightAction ? ledbitmask : 0,
                                    Audio        = device.Argument.AudioAction ? audioFile : string.Empty,
                                    SentinelCode = sentinelCode
                                };

                                _logger.LogInformation("下发声光报警联动动作: Begin");
                                ascs.SendSoundLightAction(startAction);
                                actions.Add(new SoundLightActionEx()
                                {
                                    Ascs = service,
                                    SoundLightControl = startAction
                                });
                                _logger.LogInformation("下发声光报警联动动作: End ");
                            }
                            //保存执行动作
                            s_SoundLightActionRecords.Add(new SoundLightActionRecord()
                            {
                                ActionId = plan.PlanTrigger != null ? plan.PlanTrigger.AlarmLogId.Value : plan.PlanId,
                                Actions  = actions
                            });
                        }
                        else
                        {
                            _logger.LogInformation("未配置哨位中心服务,取消声光报警联动");
                        }
                    }
                }
                _logger.LogInformation("执行声光报警联动动作 End .....");
            }
            catch (Exception ex)
            {
                _logger.LogError("执行声光报警动作异常:{0}\r\n{1}", ex.Message, ex.StackTrace);
            }
        }