private void StartWatchingFile(string file) { new Thread(() => { bool isWatching = true; while (isWatching) { ReverseTextReader reader = new ReverseTextReader(_clientFileStream, Encoding.UTF8); string line = reader.ReadLine(); //last line always a new line line = reader.ReadLine(); Regex pattern = new Regex($"{_characterName}.*is now level (\\d*)"); Match match = pattern.Match(line); if (match.Success) { string level = match.Groups[1].Value; Application.Current.Dispatcher.Invoke(new Action(() => { characterLevel.Text = level; })); } Thread.Sleep(1000); } }) { IsBackground = true }.Start(); }
// Define the event handlers. private void OnClientTxtChanged(object source, FileSystemEventArgs e) { // Specify what is done when a file is changed, created, or deleted. //Console.WriteLine("File: " + e.FullPath + " " + e.ChangeType); ReverseTextReader reader = new ReverseTextReader(_clientFileStream, Encoding.UTF8); //while (!reader.EndOfStream) //{ //read last line string line = reader.ReadLine(); //last line always a new line line = reader.ReadLine(); Regex pattern = new Regex($"{_characterName}.*is now level (\\d*)"); Match match = pattern.Match(line); if (match.Success) { string level = match.Groups[1].Value; Application.Current.Dispatcher.Invoke(new Action(() => { characterLevel.Text = level; })); } //inStream.Close(); // } }
private static void Tick(object state) { if (_isRunning) { return; } _isRunning = true; try { Parallel.ForEach(_settings.RelayChannels, relay => { var file = Directory .EnumerateFiles(_settings.EveLogsFolder, $"{relay.EveChannelName}*", SearchOption.TopDirectoryOnly).Aggregate((agg, next) => Directory.GetLastWriteTime(next) > Directory.GetLastWriteTime(agg) ? next : agg); if (string.IsNullOrEmpty(file)) { return; } if (relay.Pool.Count == 0) { using (var reader = new ReverseTextReader(file, Encoding.Unicode)) { relay.Pool.AddRange(reader.Take(5)); } return; } using (var reader = new ReverseTextReader(file, Encoding.Unicode)) { foreach (var line in reader.Take(5)) { if (!line.StartsWith('[') || relay.Pool.Contains(line)) { continue; } var newLine = line; //change time try { var end = line.IndexOf(']', 1); var dt = DateTime.Parse(line.Substring(1, end - 2).Trim()); var msg = line.Substring(end + 1, line.Length - end - 1).Trim(); //startswith if (relay.RelayStartsWithText.Count > 0 && !relay.RelayStartsWithText.Any(a => msg.ToLower().StartsWith(a.ToLower()))) { continue; } if (relay.RelayContainsText.Count > 0 && !relay.RelayContainsText.Any(a => msg.ToLower().Contains(a.ToLower()))) { continue; } if (relay.FilterChatContainsText.Any(a => msg.ToLower().Contains(a.ToLower()))) { continue; } newLine = $"[{dt.ToString(relay.DateFormat)}] {msg}"; } catch { //ignore } Console.WriteLine($"SEND->[{relay.EveChannelName}]: {newLine}"); lock (Locker) { relay.Pool.Add(line); if (relay.Pool.Count > 10) { relay.Pool.RemoveAt(0); } } if (!SendMessage(relay, newLine).GetAwaiter().GetResult()) { Console.WriteLine(""); } } } }); } finally { _isRunning = false; } }