private void timerTreeViewRecover_Tick(object sender, EventArgs e) { try { // Now lock in case the timer is overlapping ! lock (this) { //read out of the file until the EOF while (LiveLog.LogQueueRecover.Any()) { LiveLog.LogString log = LiveLog.LogQueueRecover.Dequeue(); if (!log.Message.Contains("[recovered ")) { continue; // this is not the line you seek } // use regex to parse log line and get the FilePath string regexPattern = @"(?<LogEntryTimestamp>\d\d\d\d-\d\d-\d\d\s\d\d:\d\d:\d\d.\d\d\d\d).*\[recovered\s(?<FilePath>.*)\].*"; Match matches = Regex.Match(log.Message, regexPattern, RegexOptions.Singleline); if (!matches.Success) { // nothing to do, the string did not match regex but it contained "[recoverable ", odd Group logEntryTimestamp = matches.Groups["FilePath"]; if (!logEntryTimestamp.Success) { return; // paranoid, just check } Log.Instance.Error($"Unable to retrieve the recovered file path from log entry at '{logEntryTimestamp.Value}'"); return; } Group groupFilePath = matches.Groups["FilePath"]; if (!groupFilePath.Success || string.IsNullOrEmpty(groupFilePath.Value)) { return; // nothing to do, path is an empty string } string filePath = groupFilePath.Value; TreeNode[] node = treeView1.Nodes.Find($"/{filePath}", false); if (node.Length <= 0) { continue; } node[0].Text = $@"{node[0].Name} (RECOVERED)"; node[0].BackColor = Color.Green; } if (!liveRunLogControl.ActionWorker.IsBusy && !LiveLog.LogQueueRecover.Any()) { //SetRecoveryButtonEnableState(); timerTreeViewRecover.Enabled = false; } } } catch { // ignored } }
private void timerTreeViewFill_Tick(object sender, EventArgs e) { try { lock (this) { for (int i = 0; i < 10; i++) { while (LiveLog.LogQueueRecover.Any()) { LiveLog.LogString log = LiveLog.LogQueueRecover.Dequeue(); if (!log.Message.Contains("[recoverable ")) { continue; // this is not the line you seek } // use regex to parse log line and get the FilePath string regexPattern = @"(?<LogEntryTimestamp>\d\d\d\d-\d\d-\d\d\s\d\d:\d\d:\d\d.\d\d\d\d).*\[recoverable\s(?<FilePath>.*)\].*"; Match matches = Regex.Match(log.Message, regexPattern, RegexOptions.Singleline); if (!matches.Success) { // nothing to do, the string did not match regex but it contained "[recoverable ", odd Group logEntryTimestamp = matches.Groups["FilePath"]; if (!logEntryTimestamp.Success) { return; // paranoid, just check } Log.Error($@"Unable to retrieve the recoverable file path from log entry at '{logEntryTimestamp.Value}'"); return; } Group groupFilePath = matches.Groups["FilePath"]; if (!groupFilePath.Success || string.IsNullOrEmpty(groupFilePath.Value)) { return; // nothing to do, path is an empty string } string filePath = groupFilePath.Value; treeView1.Invoke(new Action(() => treeView1.Nodes.Add($"/{filePath}", $"/{filePath}"))); } } if (liveRunLogControl.ActionWorker.IsBusy || LiveLog.LogQueueRecover.Any()) { return; // more items to dequeue } SetButtonsEnabledState(true); timerTreeViewFill.Enabled = false; } } catch { // ignored } }
private void timerScantillaTimer_Tick(object sender, EventArgs e) { try { // Now lock in case the timer is overlapping ! lock (this) { if (!ActionWorker.IsBusy) { timerScantilla.Enabled = false; } if (!LiveLog.LogQueueCommon.Any()) { return; } while (LiveLog.LogQueueCommon.Any()) { LiveLog.LogString log = LiveLog.LogQueueCommon.Dequeue(); if (!checkBoxDisplayOutput.Checked) { continue; } scintilla.AppendText($"{log.Message}{Environment.NewLine}"); } // scroll to the bottom int scintillaTextLength = scintilla.TextLength; scintilla.ScrollRange(scintillaTextLength, scintillaTextLength); } } catch { // ignored } }