Esempio n. 1
0
 public Task StartAsync(CancellationToken cancellationToken)
 {
     try
     {
         ConsumerFactory
         .Subscribe((ushort)JT808.Protocol.Enums.JT808MsgId.位置信息汇报)
         .OnMessage((msg) =>
         {
             try
             {
                 _hubContext.Clients.All.SendAsync("ReceiveMessage", $"Home page loaded at: {DateTime.Now}");
                 _hubContext.Clients.All.SendAsync("ReceiveMessage", msg.data.ToHexString());
             }
             catch (Exception ex)
             {
                 logger.LogError(ex, "Error");
             }
         });
     }
     catch (Exception ex)
     {
         logger.LogError(ex, "Error");
     }
     return(Task.CompletedTask);
 }
 public Task StartAsync(CancellationToken cancellationToken)
 {
     ConsumerFactory
     .Subscribe((ushort)JT808.Protocol.Enums.JT808MsgId.位置信息汇报)
     .OnMessage((msg) =>
     {
         logger.LogDebug($"{msg.Key},{ msg.data.ToHexString()}");
     });
     return(Task.CompletedTask);
 }
Esempio n. 3
0
 public Task StartAsync(CancellationToken cancellationToken)
 {
     try
     {
         ConsumerFactory
         .Subscribe(PubSubConstants.UnificationPushToWebSocket)
         .OnMessage((msg) =>
         {
             try
             {
                 _hubContext.Clients.All.SendAsync("ReceiveMessage", msg.Key, Encoding.UTF8.GetString(msg.data));
             }
             catch (Exception ex)
             {
                 logger.LogError(ex, "Error");
             }
         });
     }
     catch (Exception ex)
     {
         logger.LogError(ex, "Error");
     }
     return(Task.CompletedTask);
 }
        public Task StartAsync(CancellationToken cancellationToken)
        {
            try
            {
                Task.Run(() => {
                    while (!cancellationToken.IsCancellationRequested)
                    {
                        if (CurrentTime.HasValue)
                        {
                            if (CurrentTime.Value < DateTime.Now)
                            {
                                CurrentTime = null;
                                optionsMonitor.CurrentValue.MonitoringStatus = false;
                                var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "LogMonitioringOptions.json");
                                if (!File.Exists(path))
                                {
                                    File.Create(path).Dispose();
                                    using (StreamWriter sw = new StreamWriter(path))
                                    {
                                        JObject jObject = new JObject();
                                        jObject.Add("LogMonitioringOptions", JToken.FromObject(optionsMonitor.CurrentValue));
                                        sw.WriteLine(jObject.ToString(Formatting.Indented));
                                    }
                                }
                                else
                                {
                                    using (StreamWriter sw = new StreamWriter(path))
                                    {
                                        JObject jObject = new JObject();
                                        jObject.Add("LogMonitioringOptions", JToken.FromObject(optionsMonitor.CurrentValue));
                                        sw.WriteLine(jObject.ToString(Formatting.Indented));
                                    }
                                }
                            }
                            else
                            {
#if DEBUG
                                Thread.Sleep(10000);
#else
                                Thread.Sleep(36000);
#endif
                            }
                        }
                        else
                        {
#if DEBUG
                            Thread.Sleep(10000);
#else
                            Thread.Sleep(36000);
#endif
                        }
                    }
                }, cancellationToken);

                ConsumerFactory
                .Subscribe(DispatcherConstants.DeviceMonitoringTopic)
                .OnMessage((msg) =>
                {
                    try
                    {
                        // 是否需要监控
                        if (optionsMonitor.CurrentValue.MonitoringStatus)
                        {
                            // 是不是第一次进来
                            if (!CurrentTime.HasValue)
                            {    //监控多长时间
#if DEBUG
                                CurrentTime = DateTime.Now.AddSeconds(optionsMonitor.CurrentValue.MonitoringTime);
#else
                                CurrentTime = DateTime.Now.AddHours(optionsMonitor.CurrentValue.MonitoringTime);
#endif
                            }
                            var keys = optionsMonitor.CurrentValue.Data.Split(',').ToList();
                            if (keys.Contains("all"))
                            {       //输出所有设备日志
                                LogMonitoringLogger.LogDebug(msg.Key + "," + msg.data.ToHexString());
                            }
                            else
                            {
                                if (keys.Contains(msg.Key))
                                {
                                    LogMonitoringLogger.LogDebug(msg.Key + "," + msg.data.ToHexString());
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.LogError(ex, "Error");
                    }
                });
            }
            catch (Exception ex)
            {
                logger.LogError(ex, "Error");
            }
            //Task.Run(()=> {
            //    while (true)
            //    {
            //        logger.LogDebug(JsonConvert.SerializeObject(optionsMonitor.CurrentValue));
            //        Thread.Sleep(5000);
            //    }
            //});
            return(Task.CompletedTask);
        }