Esempio n. 1
0
 private void RefreshReceiveLogs(IEnumerable <ReceiveLogEntity> logs)
 {
     foreach (var log in logs)
     {
         ReceiveLogs.Insert(0, new ReceiveLogModel(log));
     }
 }
Esempio n. 2
0
        private void SetSingalRFuncs()
        {
            connection.On <string>("ReceiveAirports", (jsonAirports) =>
            {
                IEnumerable <AirportStatus> airports = JsonConvert.DeserializeObject <IEnumerable <AirportStatus> >(jsonAirports,
                                                                                                                    new JsonSerializerSettings()
                {
                    ReferenceLoopHandling      = ReferenceLoopHandling.Serialize,
                    PreserveReferencesHandling = PreserveReferencesHandling.Objects
                });

                ReceiveAirports?.Invoke(this, airports);
            });

            connection.On <string>("ReceiveLogs", (jsonLogs) =>
            {
                IEnumerable <CommonPlaneLog> logs = JsonConvert.DeserializeObject <IEnumerable <CommonPlaneLog> >(jsonLogs,
                                                                                                                  new JsonSerializerSettings()
                {
                    ReferenceLoopHandling      = ReferenceLoopHandling.Serialize,
                    PreserveReferencesHandling = PreserveReferencesHandling.Objects
                });

                ReceiveLogs?.Invoke(this, logs);
            });
        }
Esempio n. 3
0
        private async void GetLogs(string file)
        {
            try
            {
                using (FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                {
                    using (StreamReader sr = new StreamReader(fs, Encoding.GetEncoding("utf-8")))
                    {
                        while (sr.Peek() >= 0)
                        {
                            string logLine = await sr.ReadLineAsync();

                            Match match = Regex.Match(logLine, _logPattern, RegexOptions.RightToLeft);
                            if (!match.Success)
                            {
                                continue;
                            }
                            string dateTime  = match.Groups[1].Value;
                            string logMsg    = string.Format("[File]{0}", match.Groups[2].Value);
                            Match  sendMatch = Regex.Match(logMsg, _sendLogPattern, RegexOptions.RightToLeft);
                            if (sendMatch.Success)
                            {
                                string sendFile    = sendMatch.Groups[1].Value;
                                string subscribeIP = sendMatch.Groups[2].Value;
                                string sendState   = sendMatch.Groups[3].Value;
                                SendLogs.Add(new SendLogModel()
                                {
                                    SendFileTime = DateTime.ParseExact(dateTime, "yyyy-MM-dd HH:mm:ss", null), SendFileName = sendFile, SubscribeIP = subscribeIP, SendFileState = sendState
                                });
                            }
                            else
                            {
                                Match receiveMatch = Regex.Match(logMsg, _receiveLogPattern, RegexOptions.RightToLeft);
                                if (!receiveMatch.Success)
                                {
                                    continue;
                                }
                                string receiveFile      = receiveMatch.Groups[1].Value;
                                string monitorIP        = receiveMatch.Groups[2].Value;
                                string monitorDirectory = receiveMatch.Groups[3].Value;
                                string receiveState     = receiveMatch.Groups[4].Value;
                                ReceiveLogs.Add(new ReceiveLogModel()
                                {
                                    ReceiveFileTime = DateTime.ParseExact(dateTime, "yyyy-MM-dd HH:mm:ss", null), ReceiveFileName = receiveFile, MonitorIP = monitorIP, MonitorDirectory = monitorDirectory, ReceiveFileState = receiveState
                                });
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                _logger.Error(string.Format("加载日志异常!异常信息为:{0}", e.Message));
                MessageBox.Show(string.Format("加载日志异常!异常信息为:{0}", e.Message), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }