-
Notifications
You must be signed in to change notification settings - Fork 186
Expand file tree
/
Copy pathLogWindow.cs
More file actions
7773 lines (6682 loc) · 251 KB
/
LogWindow.cs
File metadata and controls
7773 lines (6682 loc) · 251 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System.ComponentModel;
using System.Globalization;
using System.Runtime.Versioning;
using System.Text;
using System.Text.RegularExpressions;
using LogExpert.Core.Callback;
using LogExpert.Core.Classes;
using LogExpert.Core.Classes.Bookmark;
using LogExpert.Core.Classes.Columnizer;
using LogExpert.Core.Classes.Filter;
using LogExpert.Core.Classes.Highlight;
using LogExpert.Core.Classes.Log;
using LogExpert.Core.Classes.Persister;
using LogExpert.Core.Config;
using LogExpert.Core.Entities;
using LogExpert.Core.EventArguments;
using LogExpert.Core.Interface;
using LogExpert.Dialogs;
using LogExpert.Entities;
using LogExpert.Extensions;
using LogExpert.UI.Dialogs;
using LogExpert.UI.Entities;
using LogExpert.UI.Extensions;
using LogExpert.UI.Interface;
using NLog;
using WeifenLuo.WinFormsUI.Docking;
//using static LogExpert.PluginRegistry.PluginRegistry; //TODO: Adjust the instance name so using static can be used.
namespace LogExpert.UI.Controls.LogWindow;
//TODO: Implemented 4 interfaces explicitly. Find them by searching: ILogWindow.<method name>
[SupportedOSPlatform("windows")]
internal partial class LogWindow : DockContent, ILogPaintContextUI, ILogView, ILogWindow
{
#region Fields
private const int SPREAD_MAX = 99;
private const int PROGRESS_BAR_MODULO = 1000;
private const int FILTER_ADVANCED_SPLITTER_DISTANCE = 110;
private static readonly Logger _logger = LogManager.GetCurrentClassLogger();
private readonly Image _advancedButtonImage;
private readonly object _bookmarkLock = new();
private readonly BookmarkDataProvider _bookmarkProvider = new();
private readonly IList<IBackgroundProcessCancelHandler> _cancelHandlerList = [];
private readonly object _currentColumnizerLock = new();
private readonly object _currentHighlightGroupLock = new();
private readonly EventWaitHandle _externaLoadingFinishedEvent = new ManualResetEvent(false);
private readonly IList<FilterPipe> _filterPipeList = [];
private readonly Dictionary<Control, bool> _freezeStateMap = [];
private readonly GuiStateArgs _guiStateArgs = new();
private readonly List<int> _lineHashList = [];
private readonly EventWaitHandle _loadingFinishedEvent = new ManualResetEvent(false);
private readonly EventWaitHandle _logEventArgsEvent = new ManualResetEvent(false);
private readonly List<LogEventArgs> _logEventArgsList = [];
private readonly Task _logEventHandlerTask;
//private readonly Thread _logEventHandlerThread;
private readonly Image _panelCloseButtonImage;
private readonly Image _panelOpenButtonImage;
private readonly LogTabWindow.LogTabWindow _parentLogTabWin;
private readonly ProgressEventArgs _progressEventArgs = new();
private readonly object _reloadLock = new();
private readonly Image _searchButtonImage;
private readonly StatusLineEventArgs _statusEventArgs = new();
private readonly object _tempHighlightEntryListLock = new();
private readonly Task _timeShiftSyncTask;
private readonly CancellationTokenSource cts = new();
//private readonly Thread _timeShiftSyncThread;
private readonly EventWaitHandle _timeShiftSyncTimerEvent = new ManualResetEvent(false);
private readonly EventWaitHandle _timeShiftSyncWakeupEvent = new ManualResetEvent(false);
private readonly TimeSpreadCalculator _timeSpreadCalc;
private readonly object _timeSyncListLock = new();
private ColumnCache _columnCache = new();
private ILogLineColumnizer _currentColumnizer;
//List<HilightEntry> currentHilightEntryList = new List<HilightEntry>();
private HighlightGroup _currentHighlightGroup = new();
private SearchParams _currentSearchParams;
private string[] _fileNames;
private List<int> _filterHitList = [];
private FilterParams _filterParams = new();
private int _filterPipeNameCounter;
private List<int> _filterResultList = [];
private ILogLineColumnizer _forcedColumnizer;
private ILogLineColumnizer _forcedColumnizerForLoading;
private bool _isDeadFile;
private bool _isErrorShowing;
private bool _isLoadError;
private bool _isLoading;
private bool _isMultiFile;
private bool _isSearching;
private bool _isTimestampDisplaySyncing;
private List<int> _lastFilterLinesList = [];
private int _lineHeight;
private LogfileReader _logFileReader;
private MultiFileOptions _multiFileOptions = new();
private bool _noSelectionUpdates;
private PatternArgs _patternArgs = new();
private PatternWindow _patternWindow;
private ReloadMemento _reloadMemento;
private int _reloadOverloadCounter;
private SortedList<int, RowHeightEntry> _rowHeightList = [];
private int _selectedCol; // set by context menu event for column headers only
private bool _shouldCallTimeSync;
private bool _shouldCancel;
private bool _shouldTimestampDisplaySyncingCancel;
private bool _showAdvanced;
private List<HighlightEntry> _tempHighlightEntryList = [];
private int _timeShiftSyncLine;
private bool _waitingForClose;
#endregion
#region cTor
[SupportedOSPlatform("windows")]
public LogWindow (LogTabWindow.LogTabWindow parent, string fileName, bool isTempFile, bool forcePersistenceLoading, IConfigManager configManager)
{
SuspendLayout();
//HighDPI Functionality must be called before all UI Elements are initialized, to make sure they work as intended
AutoScaleDimensions = new SizeF(96F, 96F);
AutoScaleMode = AutoScaleMode.Dpi;
InitializeComponent();
CreateDefaultViewStyle();
columnNamesLabel.Text = string.Empty; // no filtering on columns by default
_parentLogTabWin = parent;
IsTempFile = isTempFile;
ConfigManager = configManager; //TODO: This should be changed to DI
//Thread.CurrentThread.Name = "LogWindowThread";
ColumnizerCallbackObject = new ColumnizerCallback(this);
FileName = fileName;
ForcePersistenceLoading = forcePersistenceLoading;
dataGridView.CellValueNeeded += OnDataGridViewCellValueNeeded;
dataGridView.CellPainting += OnDataGridViewCellPainting;
filterGridView.CellValueNeeded += OnFilterGridViewCellValueNeeded;
filterGridView.CellPainting += OnFilterGridViewCellPainting;
filterListBox.DrawMode = DrawMode.OwnerDrawVariable;
filterListBox.MeasureItem += MeasureItem;
Closing += OnLogWindowClosing;
Disposed += OnLogWindowDisposed;
Load += OnLogWindowLoad;
_timeSpreadCalc = new TimeSpreadCalculator(this);
timeSpreadingControl.TimeSpreadCalc = _timeSpreadCalc;
timeSpreadingControl.LineSelected += OnTimeSpreadingControlLineSelected;
tableLayoutPanel1.ColumnStyles[1].SizeType = SizeType.Absolute;
tableLayoutPanel1.ColumnStyles[1].Width = 20;
tableLayoutPanel1.ColumnStyles[0].SizeType = SizeType.Percent;
tableLayoutPanel1.ColumnStyles[0].Width = 100;
_parentLogTabWin.HighlightSettingsChanged += OnParentHighlightSettingsChanged;
SetColumnizer(PluginRegistry.PluginRegistry.Instance.RegisteredColumnizers[0]);
_patternArgs.MaxMisses = 5;
_patternArgs.MinWeight = 1;
_patternArgs.MaxDiffInBlock = 5;
_patternArgs.Fuzzy = 5;
//InitPatternWindow();
//this.toolwinTabControl.TabPages.Add(this.patternWindow);
//this.toolwinTabControl.TabPages.Add(this.bookmarkWindow);
_filterParams = new FilterParams();
foreach (var item in configManager.Settings.FilterHistoryList)
{
_ = filterComboBox.Items.Add(item);
}
filterComboBox.DropDownHeight = filterComboBox.ItemHeight * configManager.Settings.Preferences.MaximumFilterEntriesDisplayed;
AutoResizeFilterBox();
filterRegexCheckBox.Checked = _filterParams.IsRegex;
filterCaseSensitiveCheckBox.Checked = _filterParams.IsCaseSensitive;
filterTailCheckBox.Checked = _filterParams.IsFilterTail;
splitContainerLogWindow.Panel2Collapsed = true;
advancedFilterSplitContainer.SplitterDistance = FILTER_ADVANCED_SPLITTER_DISTANCE;
_timeShiftSyncTask = new Task(SyncTimestampDisplayWorker, cts.Token);
_timeShiftSyncTask.Start();
_logEventHandlerTask = new Task(LogEventWorker, cts.Token);
_logEventHandlerTask.Start();
//this.filterUpdateThread = new Thread(new ThreadStart(this.FilterUpdateWorker));
//this.filterUpdateThread.Start();
_advancedButtonImage = advancedButton.Image;
_searchButtonImage = filterSearchButton.Image;
filterSearchButton.Image = null;
dataGridView.EditModeMenuStrip = editModeContextMenuStrip;
markEditModeToolStripMenuItem.Enabled = true;
_panelOpenButtonImage = Resources.Arrow_menu_open;
_panelCloseButtonImage = Resources.Arrow_menu_close;
var settings = configManager.Settings;
if (settings.AppBounds.Right > 0)
{
Bounds = settings.AppBounds;
}
_waitingForClose = false;
dataGridView.Enabled = false;
dataGridView.ColumnDividerDoubleClick += OnDataGridViewColumnDividerDoubleClick;
ShowAdvancedFilterPanel(false);
filterKnobBackSpread.MinValue = 0;
filterKnobBackSpread.MaxValue = SPREAD_MAX;
filterKnobBackSpread.ValueChanged += OnFilterKnobControlValueChanged;
filterKnobForeSpread.MinValue = 0;
filterKnobForeSpread.MaxValue = SPREAD_MAX;
filterKnobForeSpread.ValueChanged += OnFilterKnobControlValueChanged;
fuzzyKnobControl.MinValue = 0;
fuzzyKnobControl.MaxValue = 10;
//PreferencesChanged(settings.preferences, true);
AdjustHighlightSplitterWidth();
ToggleHighlightPanel(false); // hidden
_bookmarkProvider.BookmarkAdded += OnBookmarkProviderBookmarkAdded;
_bookmarkProvider.BookmarkRemoved += OnBookmarkProviderBookmarkRemoved;
_bookmarkProvider.AllBookmarksRemoved += OnBookmarkProviderAllBookmarksRemoved;
ResumeLayout();
}
#endregion
#region Delegates
// used for filterTab restore
public delegate void FilterRestoreFx (LogWindow newWin, PersistenceData persistenceData);
public delegate void RestoreFiltersFx (PersistenceData persistenceData);
public delegate bool ScrollToTimestampFx (DateTime timestamp, bool roundToSeconds, bool triggerSyncCall);
public delegate void TailFollowedEventHandler (object sender, EventArgs e);
#endregion
#region Events
public event EventHandler<LogEventArgs> FileSizeChanged;
public event EventHandler<ProgressEventArgs> ProgressBarUpdate;
public event EventHandler<StatusLineEventArgs> StatusLineEvent;
public event EventHandler<GuiStateArgs> GuiStateUpdate;
public event TailFollowedEventHandler TailFollowed;
public event EventHandler<EventArgs> FileNotFound;
public event EventHandler<EventArgs> FileRespawned;
public event EventHandler<FilterListChangedEventArgs> FilterListChanged;
public event EventHandler<CurrentHighlightGroupChangedEventArgs> CurrentHighlightGroupChanged;
public event EventHandler<EventArgs> BookmarkAdded;
public event EventHandler<EventArgs> BookmarkRemoved;
public event EventHandler<BookmarkEventArgs> BookmarkTextChanged;
public event EventHandler<ColumnizerEventArgs> ColumnizerChanged;
public event EventHandler<SyncModeEventArgs> SyncModeChanged;
#endregion
#region Properties
public Color BookmarkColor { get; set; } = Color.FromArgb(165, 200, 225);
public ILogLineColumnizer CurrentColumnizer
{
get => _currentColumnizer;
private set
{
lock (_currentColumnizerLock)
{
_currentColumnizer = value;
_logger.Debug($"Setting columnizer {_currentColumnizer.GetName()} ");
}
}
}
[SupportedOSPlatform("windows")]
public bool ShowBookmarkBubbles
{
get => _guiStateArgs.ShowBookmarkBubbles;
set
{
_guiStateArgs.ShowBookmarkBubbles = dataGridView.PaintWithOverlays = value;
dataGridView.Refresh();
}
}
public int CurrentLineNum => dataGridView.CurrentRow == null
? -1
: dataGridView.CurrentRow.Index;
public string FileName { get; private set; }
public string SessionFileName { get; set; }
public bool IsMultiFile
{
get => _isMultiFile;
private set => _guiStateArgs.IsMultiFileActive = _isMultiFile = value;
}
public bool IsTempFile { get; }
private readonly IConfigManager ConfigManager;
public string TempTitleName { get; set; } = "";
internal FilterPipe FilterPipe { get; set; }
public string Title => IsTempFile
? TempTitleName
: FileName;
public ColumnizerCallback ColumnizerCallbackObject { get; }
public bool ForcePersistenceLoading { get; set; }
public string ForcedPersistenceFileName { get; set; }
public Preferences Preferences => _parentLogTabWin.Preferences;
public string GivenFileName { get; set; }
public TimeSyncList TimeSyncList { get; private set; }
public bool IsTimeSynced => TimeSyncList != null;
protected EncodingOptions EncodingOptions { get; set; }
public IBookmarkData BookmarkData => _bookmarkProvider;
public Font MonospacedFont { get; private set; }
public Font NormalFont { get; private set; }
public Font BoldFont { get; private set; }
LogfileReader ILogWindow.LogFileReader => _logFileReader;
//public event EventHandler<EventArgs> ILogWindow.FileSizeChanged
//{
// add => FileSizeChanged += new EventHandler<LogEventArgs>(value);
// remove => FileSizeChanged -= new EventHandler<LogEventArgs>(value);
//}
//event EventHandler ILogWindow.TailFollowed
//{
// add => TailFollowed += new TailFollowedEventHandler(value);
// remove => TailFollowed -= new TailFollowedEventHandler(value);
//}
#endregion
#region Public methods
public ILogLine GetLogLine (int lineNum)
{
return _logFileReader.GetLogLine(lineNum);
}
public ILogLine GetLogLineWithWait (int lineNum)
{
return _logFileReader.GetLogLineWithWait(lineNum).Result;
}
public Bookmark GetBookmarkForLine (int lineNum)
{
return _bookmarkProvider.GetBookmarkForLine(lineNum);
}
#endregion
#region Internals
internal IColumnizedLogLine GetColumnsForLine (int lineNumber)
{
return _columnCache.GetColumnsForLine(_logFileReader, lineNumber, CurrentColumnizer, ColumnizerCallbackObject);
//string line = this.logFileReader.GetLogLine(lineNumber);
//if (line != null)
//{
// string[] cols;
// this.columnizerCallback.LineNum = lineNumber;
// cols = this.CurrentColumnizer.SplitLine(this.columnizerCallback, line);
// return cols;
//}
//else
//{
// return null;
//}
}
[SupportedOSPlatform("windows")]
internal void RefreshAllGrids ()
{
dataGridView.Refresh();
filterGridView.Refresh();
}
[SupportedOSPlatform("windows")]
internal void ChangeMultifileMask ()
{
MultiFileMaskDialog dlg = new(this, FileName)
{
Owner = this,
MaxDays = _multiFileOptions.MaxDayTry,
FileNamePattern = _multiFileOptions.FormatPattern
};
if (dlg.ShowDialog() == DialogResult.OK)
{
_multiFileOptions.FormatPattern = dlg.FileNamePattern;
_multiFileOptions.MaxDayTry = dlg.MaxDays;
if (IsMultiFile)
{
Reload();
}
}
}
[SupportedOSPlatform("windows")]
internal void ToggleColumnFinder (bool show, bool setFocus)
{
_guiStateArgs.ColumnFinderVisible = show;
if (show)
{
columnComboBox.AutoCompleteMode = AutoCompleteMode.Suggest;
columnComboBox.AutoCompleteSource = AutoCompleteSource.CustomSource;
columnComboBox.AutoCompleteCustomSource = [.. CurrentColumnizer.GetColumnNames()];
if (setFocus)
{
_ = columnComboBox.Focus();
}
}
else
{
_ = dataGridView.Focus();
}
tableLayoutPanel1.RowStyles[0].Height = show ? 28 : 0;
}
#endregion
#region Overrides
protected override string GetPersistString ()
{
return "LogWindow#" + FileName;
}
#endregion
[SupportedOSPlatform("windows")]
private void OnButtonSizeChanged (object sender, EventArgs e)
{
if (sender is Button button && button.Image != null)
{
button.ImageAlign = ContentAlignment.MiddleCenter;
button.Image = new Bitmap(button.Image, new Size(button.Size.Height, button.Size.Height));
}
}
// used for external wait fx WaitForLoadFinished()
private delegate void SelectLineFx (int line, bool triggerSyncCall);
private Action<FilterParams, List<int>, List<int>, List<int>> FilterFxAction;
//private delegate void FilterFx(FilterParams filterParams, List<int> filterResultLines, List<int> lastFilterResultLines, List<int> filterHitList);
private delegate void UpdateProgressBarFx (int lineNum);
private delegate void SetColumnizerFx (ILogLineColumnizer columnizer);
private delegate void WriteFilterToTabFinishedFx (FilterPipe pipe, string namePrefix, PersistenceData persistenceData);
private delegate void SetBookmarkFx (int lineNum, string comment);
private delegate void FunctionWith1BoolParam (bool arg);
private delegate void PatternStatisticFx (PatternArgs patternArgs);
private delegate void ActionPluginExecuteFx (string keyword, string param, ILogExpertCallback callback, ILogLineColumnizer columnizer);
private delegate void PositionAfterReloadFx (ReloadMemento reloadMemento);
private delegate void AutoResizeColumnsFx (BufferedDataGridView gridView);
private delegate bool BoolReturnDelegate ();
// =================== ILogLineColumnizerCallback ============================
#if DEBUG
[SupportedOSPlatform("windows")]
internal void DumpBufferInfo ()
{
var currentLineNum = dataGridView.CurrentCellAddress.Y;
_logFileReader.LogBufferInfoForLine(currentLineNum);
}
internal void DumpBufferDiagnostic ()
{
_logFileReader.LogBufferDiagnostic();
}
#endif
[SupportedOSPlatform("windows")]
void ILogWindow.SelectLine (int lineNum, bool triggerSyncCall, bool shouldScroll)
{
SelectLine(lineNum, triggerSyncCall, shouldScroll);
}
[SupportedOSPlatform("windows")]
void ILogWindow.AddTempFileTab (string fileName, string title)
{
AddTempFileTab(fileName, title);
}
[SupportedOSPlatform("windows")]
void ILogWindow.WritePipeTab (IList<LineEntry> lineEntryList, string title)
{
WritePipeTab(lineEntryList, title);
}
#region Event Handlers
[SupportedOSPlatform("windows")]
private void AutoResizeFilterBox ()
{
filterSplitContainer.SplitterDistance = filterComboBox.Left + filterComboBox.GetMaxTextWidth();
}
#region Events handler
protected void OnProgressBarUpdate (ProgressEventArgs e)
{
ProgressBarUpdate?.Invoke(this, e);
}
protected void OnStatusLine (StatusLineEventArgs e)
{
StatusLineEvent?.Invoke(this, e);
}
protected void OnGuiState (GuiStateArgs e)
{
GuiStateUpdate?.Invoke(this, e);
}
protected void OnTailFollowed (EventArgs e)
{
TailFollowed?.Invoke(this, e);
}
protected void OnFileNotFound (EventArgs e)
{
FileNotFound?.Invoke(this, e);
}
protected void OnFileRespawned (EventArgs e)
{
FileRespawned?.Invoke(this, e);
}
protected void OnFilterListChanged (LogWindow source)
{
FilterListChanged?.Invoke(this, new FilterListChangedEventArgs(source));
}
protected void OnCurrentHighlightListChanged ()
{
CurrentHighlightGroupChanged?.Invoke(this, new CurrentHighlightGroupChangedEventArgs(this, _currentHighlightGroup));
}
protected void OnBookmarkAdded ()
{
BookmarkAdded?.Invoke(this, EventArgs.Empty);
}
protected void OnBookmarkRemoved ()
{
BookmarkRemoved?.Invoke(this, EventArgs.Empty);
}
protected void OnBookmarkTextChanged (Bookmark bookmark)
{
BookmarkTextChanged?.Invoke(this, new BookmarkEventArgs(bookmark));
}
protected void OnColumnizerChanged (ILogLineColumnizer columnizer)
{
ColumnizerChanged?.Invoke(this, new ColumnizerEventArgs(columnizer));
}
protected void OnRegisterCancelHandler (IBackgroundProcessCancelHandler handler)
{
lock (_cancelHandlerList)
{
_cancelHandlerList.Add(handler);
}
}
protected void OnDeRegisterCancelHandler (IBackgroundProcessCancelHandler handler)
{
lock (_cancelHandlerList)
{
_ = _cancelHandlerList.Remove(handler);
}
}
[SupportedOSPlatform("windows")]
private void OnLogWindowLoad (object sender, EventArgs e)
{
var setLastColumnWidth = _parentLogTabWin.Preferences.SetLastColumnWidth;
var lastColumnWidth = _parentLogTabWin.Preferences.LastColumnWidth;
var fontName = _parentLogTabWin.Preferences.FontName;
var fontSize = _parentLogTabWin.Preferences.FontSize;
PreferencesChanged(fontName, fontSize, setLastColumnWidth, lastColumnWidth, true, SettingsFlags.GuiOrColors);
}
[SupportedOSPlatform("windows")]
private void OnLogWindowDisposed (object sender, EventArgs e)
{
_waitingForClose = true;
_parentLogTabWin.HighlightSettingsChanged -= OnParentHighlightSettingsChanged;
_logFileReader?.DeleteAllContent();
FreeFromTimeSync();
}
[SupportedOSPlatform("windows")]
private void OnLogFileReaderLoadingStarted (object sender, LoadFileEventArgs e)
{
_ = Invoke(LoadingStarted, e);
}
[SupportedOSPlatform("windows")]
private void OnLogFileReaderFinishedLoading (object sender, EventArgs e)
{
//Thread.CurrentThread.Name = "FinishedLoading event thread";
_logger.Info(CultureInfo.InvariantCulture, "Finished loading.");
_isLoading = false;
_isDeadFile = false;
if (!_waitingForClose)
{
_ = Invoke(new MethodInvoker(LoadingFinished));
_ = Invoke(new MethodInvoker(LoadPersistenceData));
_ = Invoke(new MethodInvoker(SetGuiAfterLoading));
_ = _loadingFinishedEvent.Set();
_ = _externaLoadingFinishedEvent.Set();
_timeSpreadCalc.SetLineCount(_logFileReader.LineCount);
if (_reloadMemento != null)
{
_ = Invoke(new PositionAfterReloadFx(PositionAfterReload), _reloadMemento);
}
if (filterTailCheckBox.Checked)
{
_logger.Info(CultureInfo.InvariantCulture, "Refreshing filter view because of reload.");
_ = Invoke(new MethodInvoker(FilterSearch)); // call on proper thread
}
HandleChangedFilterList();
}
_reloadMemento = null;
}
[SupportedOSPlatform("windows")]
private void OnLogFileReaderFileNotFound (object sender, EventArgs e)
{
if (!IsDisposed && !Disposing)
{
_logger.Info(CultureInfo.InvariantCulture, "Handling file not found event.");
_isDeadFile = true;
_ = BeginInvoke(new MethodInvoker(LogfileDead));
}
}
[SupportedOSPlatform("windows")]
private void OnLogFileReaderRespawned (object sender, EventArgs e)
{
_ = BeginInvoke(new MethodInvoker(LogfileRespawned));
}
[SupportedOSPlatform("windows")]
private void OnLogWindowClosing (object sender, CancelEventArgs e)
{
if (Preferences.AskForClose)
{
if (MessageBox.Show("Sure to close?", "LogExpert", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
e.Cancel = true;
return;
}
}
_ = SavePersistenceData(false);
CloseLogWindow();
}
[SupportedOSPlatform("windows")]
private void OnDataGridViewColumnDividerDoubleClick (object sender, DataGridViewColumnDividerDoubleClickEventArgs e)
{
e.Handled = true;
AutoResizeColumns(dataGridView);
}
/**
* Event handler for the Load event from LogfileReader
*/
[SupportedOSPlatform("windows")]
private void OnLogFileReaderLoadFile (object sender, LoadFileEventArgs e)
{
if (e.NewFile)
{
_logger.Info(CultureInfo.InvariantCulture, "File created anew.");
// File was new created (e.g. rollover)
_isDeadFile = false;
UnRegisterLogFileReaderEvents();
dataGridView.CurrentCellChanged -= OnDataGridViewCurrentCellChanged;
MethodInvoker invoker = ReloadNewFile;
_ = BeginInvoke(invoker);
//Thread loadThread = new Thread(new ThreadStart(ReloadNewFile));
//loadThread.Start();
_logger.Debug(CultureInfo.InvariantCulture, "Reloading invoked.");
}
else if (_isLoading)
{
_ = BeginInvoke(UpdateProgress, e);
}
}
private void OnFileSizeChanged (object sender, LogEventArgs e)
{
//OnFileSizeChanged(e); // now done in UpdateGrid()
_logger.Info(CultureInfo.InvariantCulture, "Got FileSizeChanged event. prevLines:{0}, curr lines: {1}", e.PrevLineCount, e.LineCount);
// - now done in the thread that works on the event args list
//if (e.IsRollover)
//{
// ShiftBookmarks(e.RolloverOffset);
// ShiftFilterPipes(e.RolloverOffset);
//}
//UpdateGridCallback callback = new UpdateGridCallback(UpdateGrid);
//this.BeginInvoke(callback, new object[] { e });
lock (_logEventArgsList)
{
_logEventArgsList.Add(e);
_ = _logEventArgsEvent.Set();
}
}
[SupportedOSPlatform("windows")]
private void OnDataGridViewCellValueNeeded (object sender, DataGridViewCellValueEventArgs e)
{
var startCount = CurrentColumnizer?.GetColumnCount() ?? 0;
e.Value = GetCellValue(e.RowIndex, e.ColumnIndex);
// The new column could be find dynamically.
// Only support add new columns for now.
// TODO: Support reload all columns?
if (CurrentColumnizer != null && CurrentColumnizer.GetColumnCount() > startCount)
{
for (var i = startCount; i < CurrentColumnizer.GetColumnCount(); i++)
{
var colName = CurrentColumnizer.GetColumnNames()[i];
_ = dataGridView.Columns.Add(PaintHelper.CreateTitleColumn(colName));
}
}
}
[SupportedOSPlatform("windows")]
private void OnDataGridViewCellValuePushed (object sender, DataGridViewCellValueEventArgs e)
{
if (!CurrentColumnizer.IsTimeshiftImplemented())
{
return;
}
var line = _logFileReader.GetLogLine(e.RowIndex);
var offset = CurrentColumnizer.GetTimeOffset();
CurrentColumnizer.SetTimeOffset(0);
ColumnizerCallbackObject.SetLineNum(e.RowIndex);
var cols = CurrentColumnizer.SplitLine(ColumnizerCallbackObject, line);
CurrentColumnizer.SetTimeOffset(offset);
if (cols.ColumnValues.Length <= e.ColumnIndex - 2)
{
return;
}
var oldValue = cols.ColumnValues[e.ColumnIndex - 2].FullValue;
var newValue = (string)e.Value;
//string oldValue = (string) this.dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
CurrentColumnizer.PushValue(ColumnizerCallbackObject, e.ColumnIndex - 2, newValue, oldValue);
dataGridView.Refresh();
TimeSpan timeSpan = new(CurrentColumnizer.GetTimeOffset() * TimeSpan.TicksPerMillisecond);
var span = timeSpan.ToString();
var index = span.LastIndexOf('.');
if (index > 0)
{
span = span[..(index + 4)];
}
SetTimeshiftValue(span);
SendGuiStateUpdate();
}
[SupportedOSPlatform("windows")]
private void OnDataGridViewRowHeightInfoNeeded (object sender, DataGridViewRowHeightInfoNeededEventArgs e)
{
e.Height = GetRowHeight(e.RowIndex);
}
[SupportedOSPlatform("windows")]
private void OnDataGridViewCurrentCellChanged (object sender, EventArgs e)
{
if (dataGridView.CurrentRow != null)
{
_statusEventArgs.CurrentLineNum = dataGridView.CurrentRow.Index + 1;
SendStatusLineUpdate();
if (syncFilterCheckBox.Checked)
{
SyncFilterGridPos();
}
if (CurrentColumnizer.IsTimeshiftImplemented() && Preferences.TimestampControl)
{
SyncTimestampDisplay();
}
//MethodInvoker invoker = new MethodInvoker(DisplayCurrentFileOnStatusline);
//invoker.BeginInvoke(null, null);
}
}
private void OnDataGridViewCellEndEdit (object sender, DataGridViewCellEventArgs e)
{
StatusLineText(string.Empty);
}
[SupportedOSPlatform("windows")]
private void OnEditControlKeyUp (object sender, KeyEventArgs e)
{
UpdateEditColumnDisplay((DataGridViewTextBoxEditingControl)sender);
}
[SupportedOSPlatform("windows")]
private void OnEditControlKeyPress (object sender, KeyPressEventArgs e)
{
UpdateEditColumnDisplay((DataGridViewTextBoxEditingControl)sender);
}
[SupportedOSPlatform("windows")]
private void OnEditControlClick (object sender, EventArgs e)
{
UpdateEditColumnDisplay((DataGridViewTextBoxEditingControl)sender);
}
[SupportedOSPlatform("windows")]
private void OnEditControlKeyDown (object sender, KeyEventArgs e)
{
UpdateEditColumnDisplay((DataGridViewTextBoxEditingControl)sender);
}
[SupportedOSPlatform("windows")]
private void OnDataGridViewPaint (object sender, PaintEventArgs e)
{
if (ShowBookmarkBubbles)
{
AddBookmarkOverlays();
}
}
// ======================================================================================
// Filter Grid stuff
// ======================================================================================
[SupportedOSPlatform("windows")]
private void OnFilterSearchButtonClick (object sender, EventArgs e)
{
FilterSearch();
}
[SupportedOSPlatform("windows")]
private void OnFilterGridViewCellPainting (object sender, DataGridViewCellPaintingEventArgs e)
{
var gridView = (BufferedDataGridView)sender;
CellPainting(gridView.Focused, e.RowIndex, e.ColumnIndex, true, e);
}
[SupportedOSPlatform("windows")]
private void OnFilterGridViewCellValueNeeded (object sender, DataGridViewCellValueEventArgs e)
{
if (e.RowIndex < 0 || e.ColumnIndex < 0 || _filterResultList.Count <= e.RowIndex)
{
e.Value = string.Empty;
return;
}
var lineNum = _filterResultList[e.RowIndex];
e.Value = GetCellValue(lineNum, e.ColumnIndex);
}
[SupportedOSPlatform("windows")]
private void OnFilterGridViewRowHeightInfoNeeded (object sender, DataGridViewRowHeightInfoNeededEventArgs e)
{
e.Height = _lineHeight;
}
[SupportedOSPlatform("windows")]
private void OnFilterComboBoxKeyDown (object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
FilterSearch();
}
}
[SupportedOSPlatform("windows")]
private void OnFilterGridViewColumnDividerDoubleClick (object sender,
DataGridViewColumnDividerDoubleClickEventArgs e)
{
e.Handled = true;
AutoResizeColumnsFx fx = AutoResizeColumns;
_ = BeginInvoke(fx, filterGridView);
}
[SupportedOSPlatform("windows")]
private void OnFilterGridViewCellDoubleClick (object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 0)
{
ToggleBookmark();
return;
}
if (filterGridView.CurrentRow != null && e.RowIndex >= 0)
{