Exemple #1
0
        /// <summary>
        /// 声光报警联动动作控制
        /// </summary>
        /// <param name="ledControl"></param>
        /// <returns></returns>
        public HttpRequestResult SendSoundLightAction(SoundLightControl ledControl)
        {
            //if (ASCS == null)
            //    throw new Exception("请配置哨位中心服务!");
            string url = string.Format(@"http://{0}:{1}/ASCS/LinkageLedSound",
                                       ASCS.EndPoints[0].IPAddress, ASCS.EndPoints[0].Port);
            var result = HttpClientHelper.Post <SoundLightControl>(ledControl, url);

            return(result);
        }
Exemple #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);
            }
        }
        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);
        }
Exemple #4
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);
            }
        }