Ejemplo n.º 1
0
        /// <summary>
        /// 设备信息变更通知
        /// </summary>
        /// <param name="caller">群呼号</param>
        /// <returns></returns>
        public HttpRequestResult NotifyDeviceInfoChange(DeviceInfoChange notify)
        {
            //if (ASCS == null)
            //    throw new Exception("请配置哨位中心服务!");
            _logger.LogInformation("设备消息变化通知Begin, Protocol:\r\n{0}", JsonUtility.CamelCaseSerializeObject(notify));
            string url = string.Format(@"http://{0}:{1}/ASCS/DeviceInfo",
                                       ASCS.EndPoints[0].IPAddress, ASCS.EndPoints[0].Port);
            var result = HttpClientHelper.Post <DeviceInfoChange>(notify, url);

            _logger.LogInformation("设备消息变化通知End...");
            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 地图数据同步
        /// </summary>
        /// <param name="mapInfo"></param>
        /// <returns></returns>
        public HttpRequestResult SyncSentinelMap(SentinelMapInfo mapInfo)
        {
            //if (ASCS == null)
            //    throw new Exception("请配置哨位中心服务!");
            string url = string.Format(@"http://{0}:{1}/ASCS/MapInfo",
                                       ASCS.EndPoints[0].IPAddress, ASCS.EndPoints[0].Port);

            _logger.LogInformation("哨位地图同步Begin.\r\nUrl:{0}.\r\nProtocol:{1}", url, JsonUtility.CamelCaseSerializeObject(mapInfo));
            var result = HttpClientHelper.Post <SentinelMapInfo>(mapInfo, url, Encoding.GetEncoding("gb2312"));

            _logger.LogInformation("哨位地图同步End ,return {0}", result);
            return(result);
        }
Ejemplo n.º 3
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("当前没有要恢复的声光报警动作");
                }
            }
        }
Ejemplo n.º 4
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);
            }
        }
Ejemplo n.º 5
0
        public static HttpRequestResult Post <T>(T newObj, string url, Encoding encoding, bool camelCase = true)
        {
            //using (var httpClient = new HttpClient())
            //{
            //    httpClient.DefaultRequestHeaders.Clear();
            //    httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            //    httpClient.DefaultRequestHeaders.AcceptCharset.Add(new StringWithQualityHeaderValue("utf-8"));
            //    string body = "";
            //    if (camelCase)
            //        body = JsonUtility.CamelCaseSerializeObject(newObj);
            //    else
            //        body = JsonConvert.SerializeObject(newObj);
            //    var content = new StringContent(body, encoding, "application/json");
            //    var response = httpClient.PostAsync(url, content);
            //    if (response.Result.IsSuccessStatusCode)
            //    {
            //        Console.WriteLine("Post Ok....");
            //        responseContent = response.Result.Content.ReadAsStringAsync().Result;
            //        return true;
            //    }
            //    else
            //    {
            //        responseContent = response.Result.ReasonPhrase;
            //        Console.WriteLine("Post Error ....StatusCode:{0},", response.Result.StatusCode);
            //        return false;
            //    }
            //}

            s_logger.LogInformation("Http Post {0} begin", url);
            string body = camelCase ? JsonUtility.CamelCaseSerializeObject(newObj) : JsonConvert.SerializeObject(newObj);

            s_logger.LogInformation("Http Post Json序列化:{0}", body);
            var content = new StringContent(body, encoding, "application/json");
            var r       = s_httpClient.PostAsync(url, content).ContinueWith <HttpRequestResult>(
                (Task <HttpResponseMessage> task) =>
            {
                var response = task.Result;
                s_logger.LogInformation("Http Post 响应完成,结果{0},Return Code{1}", response.IsSuccessStatusCode, response.StatusCode);
                return(GetHttpRequestMessage(response));
            });

            return(r.Result);
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 子弹箱控制
        /// </summary>
        /// <param name="cartidges"></param>
        /// <returns></returns>
        public HttpRequestResult CatridgeBoxStatus(List <CartidgeBoxStatus> cartidges)
        {
            //if (ASCS == null)
            //    throw new Exception("请配置哨位中心服务!");
            string url = string.Format(@"http://{0}:{1}/ASCS/BulletBoxStatus", ASCS.EndPoints[0].IPAddress, ASCS.EndPoints[0].Port);

            _logger.LogInformation("子弹箱控制 Begin, \r\nUrl:{0}\r\nProtocol:{1}...", url, JsonUtility.CamelCaseSerializeObject(cartidges));
            var result = HttpClientHelper.Post <List <CartidgeBoxStatus> >(cartidges, url);

            _logger.LogInformation("子弹箱控制 End,Return {0}", result);
            return(result);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 确认/取消哨位报警
        /// </summary>
        /// <returns></returns>
        public HttpRequestResult SendDeviceAlarmStatus(DeviceAlarmStatus status)
        {
            string url = string.Format(@"http://{0}:{1}/ASCS/SentinelAlarmStatus", ASCS.EndPoints[0].IPAddress, ASCS.EndPoints[0].Port);

            _logger.LogInformation("发送报警状态确认 Begin.\r\nUrl:{0},\r\n Protocol:{1}...", url, JsonUtility.CamelCaseSerializeObject(status));
            var result = HttpClientHelper.Put(status, url);

            _logger.LogInformation("发送报警状态确认 End,retur {0}...", result);
            return(result);
        }
Ejemplo n.º 9
0
 /// <summary>
 /// LED 文字显示控制
 /// </summary>
 /// <param name="ledDisplay"></param>
 /// <returns></returns>
 public HttpRequestResult ControLedDisplayl(LedDisplay ledDisplay)
 {
     //if (ASCS == null)
     //    throw new Exception("请配置哨位中心服务!");
     try
     {
         string url = string.Format(@"http://{0}:{1}/ASCS/LedDisplay  ",
                                    ASCS.EndPoints[0].IPAddress, ASCS.EndPoints[0].Port);
         _logger.LogInformation("LED文字显示控制 Begin.\r\nUrl:{0}.\r\nProtocol:{1}", url, JsonUtility.CamelCaseSerializeObject(ledDisplay));
         var result = HttpClientHelper.Post <LedDisplay>(ledDisplay, url, Encoding.GetEncoding("gb2312"));
         _logger.LogInformation("LED文字显示控制 End ,return {0}", result);
         return(result);
     }
     catch (Exception ex)
     {
         return(new HttpRequestResult()
         {
             Success = false, ResultText = ex.Message
         });
     }
 }
Ejemplo n.º 10
0
        /// <summary>
        /// 分发指纹
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public HttpRequestResult DispatchFinger(DispatchFigureInfo info)
        {
            //if (ASCS == null)
            //    throw new Exception("请配置哨位中心服务!");
            string url = string.Format(@"http://{0}:{1}/ASCS/FingerDispatch", ASCS.EndPoints[0].IPAddress, ASCS.EndPoints[0].Port);

            _logger.LogInformation("指纹下发 Begin, \r\nUrl:{0}\r\nProtocol:{1}...", url, JsonUtility.CamelCaseSerializeObject(info));
            var result = HttpClientHelper.Post <DispatchFigureInfo>(info, url);

            _logger.LogInformation("指纹下发 End,Result:{0}", result);
            return(result);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 消息发布
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public HttpRequestResult PushMessage(PushMessage message)
        {
            //if (ASCS == null)
            //    throw new Exception("请配置哨位中心服务!");
            string url = string.Format(@"http://{0}:{1}/ASCS/SendMsgToDevice", ASCS.EndPoints[0].IPAddress, ASCS.EndPoints[0].Port);

            _logger.LogInformation("发送LED文字消息 Begin, \r\nUrl:{0}\r\nProtocol:{1}...", url, JsonUtility.CamelCaseSerializeObject(message));
            var result = HttpClientHelper.Post <PushMessage>(message, url);

            _logger.LogInformation("发送LED文字消息 End...,return {0}", result);
            return(result);
        }