private void RefreshSendLogs(IEnumerable <SendLogEntity> logs) { foreach (var log in logs) { SendLogs.Insert(0, new SendLogModel(log)); } }
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); } }
public virtual UpdateLogEntity GetAttachmentLog(User user) { var log = SendLogs.FirstOrDefault(l => l.User == user); if (log == null) { return(null); } return(log.Update); }
static void Main(string[] args) { ReturnAnswer returnAnswer = new ReturnAnswer(); //Initialize connection bool tmp = true; Console.WriteLine("IP:"); Connection connection = new Connection(); while (tmp) { var IP = Console.ReadLine(); try { connection.init(IP, 8001, returnAnswer); tmp = false; } catch (Exception) { Console.WriteLine("Wrong IP!"); } } //Initailize commands Command create = new Create(connection, returnAnswer); Command sendupdate = new SendUpdate(connection, returnAnswer); Command reciveupdate = new ReciveUpdate(connection, returnAnswer); Command getlastimage = new GetLastImage(connection, returnAnswer); Command checktopicality = new CheckTopicality(connection, returnAnswer); Command getlastest = new GetLastest(connection, returnAnswer); Command list = new List(connection, returnAnswer); Command checkmemory = new CheckMemory(connection, returnAnswer); Command exist = new Exist(connection, returnAnswer); Command sendlogs = new SendLogs(connection, returnAnswer); Command set = new Set(connection, returnAnswer); Command checksettings = new CheckSettings(connection, returnAnswer); Command recivesettings = new ReciveSettings(connection, returnAnswer); //Make a one-way list create.SetNext(sendupdate); sendupdate.SetNext(reciveupdate); reciveupdate.SetNext(getlastimage); getlastimage.SetNext(checktopicality); checktopicality.SetNext(getlastest); getlastest.SetNext(list); list.SetNext(checkmemory); checkmemory.SetNext(exist); exist.SetNext(sendlogs); sendlogs.SetNext(set); set.SetNext(checksettings); checksettings.SetNext(recivesettings); string insert; do { connection.Connect(); insert = connection.Recive(); Console.WriteLine(insert); create.Next(insert); } while (insert != "exit"); }