Skip to content

Commit e68207a

Browse files
authored
Merge pull request #522 from LogExperts/logtabwindowrefactor
a few fixes
2 parents 5bf8015 + a955b61 commit e68207a

31 files changed

+1844
-499
lines changed
Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Text;
4-
51
namespace ColumnizerLib;
62

73
/// <summary>
8-
/// Implement this interface to execute a self defined action when LogExpert detects a
4+
/// Implement this interface to execute a self defined action when LogExpert detects a
95
/// keyword on incomig log file content.
106
/// These kind of plugins can be used in the "Highlight and Action Triggers" dialog.
117
/// </summary>
@@ -21,30 +17,30 @@ public interface IKeywordAction
2117
/// <param name="keyword">The keyword which triggered the call.</param>
2218
/// <param name="param">The parameter configured for the plugin launch (in the Highlight dialog).</param>
2319
/// <param name="callback">A callback which can be used by the plugin.</param>
24-
/// <param name="columnizer">The current columnizer. Can be used to obtain timestamps
20+
/// <param name="columnizer">The current columnizer. Can be used to obtain timestamps
2521
/// (if supported by Columnizer) or to split the log line into fields.</param>
2622
/// <remarks>
27-
/// This method is called in a background thread from the process' thread pool (using BeginInvoke()).
23+
/// This method is called in a background thread from the process' thread pool (using BeginInvoke()).
2824
/// So you cannot rely on state information retrieved by the given callback. E.g. the line count
2925
/// may change during the execution of the method. The only exception from this rule is the current line number
3026
/// retrieved from the callback. This is of course the line number of the line that has triggered
3127
/// the keyword match.
3228
/// </remarks>
33-
void Execute(string keyword, string param, ILogExpertCallback callback, ILogLineMemoryColumnizer columnizer);
29+
void Execute (string keyword, string param, ILogExpertCallbackMemory callback, ILogLineMemoryColumnizer columnizer);
3430

3531
/// <summary>
36-
/// Return the name of your plugin here. The returned name is used for displaying the plugin list
32+
/// Return the name of your plugin here. The returned name is used for displaying the plugin list
3733
/// in the settings.
3834
/// </summary>
3935
/// <returns>The name of the plugin.</returns>
40-
string GetName();
36+
string GetName ();
4137

4238
/// <summary>
4339
/// Return a description of your plugin here. E.g. a short explanation of parameters. The descriptions
4440
/// will be displayed in the plugin chooser dialog which is used by the Highlight settings.
4541
/// </summary>
4642
/// <returns>The description of the plugin.</returns>
47-
string GetDescription();
43+
string GetDescription ();
4844

4945
#endregion
5046
}

src/CsvColumnizer/CsvColumnizer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public void Selected (ILogLineMemoryColumnizerCallback callback)
187187
_columnList.Clear();
188188
var line = _config.HasFieldNames
189189
? _firstLine
190-
: callback.GetLogLine(0);
190+
: callback.GetLogLineMemory(0);
191191

192192
if (line != null)
193193
{

src/DefaultPlugins/ProcessLauncher.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System;
21
using System.Diagnostics;
32

43
using ColumnizerLib;
@@ -15,9 +14,9 @@ internal class ProcessLauncher : IKeywordAction
1514

1615
#region IKeywordAction Member
1716

18-
private readonly object _callbackLock = new();
17+
private readonly Lock _callbackLock = new();
1918

20-
public void Execute (string keyword, string param, ILogExpertCallback callback, ILogLineMemoryColumnizer columnizer)
19+
public void Execute (string keyword, string param, ILogExpertCallbackMemory callback, ILogLineMemoryColumnizer columnizer)
2120
{
2221
var start = 0;
2322
int end;
@@ -46,16 +45,16 @@ public void Execute (string keyword, string param, ILogExpertCallback callback,
4645
parameters = parameters.Replace("%K", keyword, StringComparison.Ordinal);
4746

4847
var lineNumber = callback.LineNum; //Line Numbers start at 0, but are displayed (+1)
49-
var logline = callback.GetLogLine(lineNumber).FullLine;
50-
parameters = parameters.Replace("%L", string.Empty + lineNumber, System.StringComparison.Ordinal);
48+
var logline = callback.GetLogLineMemory(lineNumber).FullLine;
49+
parameters = parameters.Replace("%L", string.Empty + lineNumber, StringComparison.Ordinal);
5150
parameters = parameters.Replace("%T", callback.GetTabTitle(), StringComparison.Ordinal);
52-
parameters = parameters.Replace("%C", logline, StringComparison.Ordinal);
51+
parameters = parameters.Replace("%C", logline.ToString(), StringComparison.Ordinal);
5352

5453
Process explorer = new();
5554
explorer.StartInfo.FileName = procName;
5655
explorer.StartInfo.Arguments = parameters;
5756
explorer.StartInfo.UseShellExecute = false;
58-
explorer.Start();
57+
_ = explorer.Start();
5958
}
6059
}
6160

src/FlashIconHighlighter/FlashIconHighlighter.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,14 @@
77
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
88
<OutputPath>$(SolutionDir)..\bin\$(Configuration)\plugins</OutputPath>
99
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
10+
<AssemblyTitle>FlashIconHighlighter</AssemblyTitle>
11+
<RootNamespace>FlashIconHighlighter</RootNamespace>
1012
</PropertyGroup>
1113

14+
<ItemGroup>
15+
<PackageReference Include="Vanara.PInvoke.User32" />
16+
</ItemGroup>
17+
1218
<ItemGroup>
1319
<ProjectReference Include="..\ColumnizerLib\ColumnizerLib.csproj" />
1420
</ItemGroup>

src/FlashIconHighlighter/FlashIconPlugin.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
using System;
21
using System.Runtime.InteropServices;
32
using System.Runtime.Versioning;
4-
using System.Windows.Forms;
53

64
using ColumnizerLib;
75

6+
using static Vanara.PInvoke.User32;
7+
88
[assembly: SupportedOSPlatform("windows")]
99
namespace FlashIconHighlighter;
1010

@@ -18,29 +18,33 @@ internal class FlashIconPlugin : IKeywordAction
1818

1919
#region IKeywordAction Member
2020

21-
public void Execute (string keyword, string param, ILogExpertCallback callback, ILogLineMemoryColumnizer columnizer)
21+
public void Execute (string keyword, string param, ILogExpertCallbackMemory callback, ILogLineMemoryColumnizer columnizer)
2222
{
2323
var openForms = Application.OpenForms;
2424
foreach (Form form in openForms)
2525
{
2626
if (form.TopLevel && form.Name.Equals("LogTabWindow", StringComparison.OrdinalIgnoreCase) && form.Text.Contains(callback.GetFileName(), StringComparison.Ordinal))
2727
{
28-
form.BeginInvoke(FlashWindow, [form]);
28+
_ = form.BeginInvoke(FlashWindow, [form]);
2929
}
3030
}
3131
}
3232

33+
/// <summary>
34+
/// Flash Window http://blogs.x2line.com/al/archive/2008/04/19/3392.aspx
35+
/// </summary>
36+
/// <param name="form"></param>
3337
private void FlashWindow (Form form)
3438
{
3539
FLASHWINFO fw = new()
3640
{
37-
cbSize = Convert.ToUInt32(Marshal.SizeOf(typeof(FLASHWINFO))),
41+
cbSize = Convert.ToUInt32(Marshal.SizeOf<FLASHWINFO>()),
3842
hwnd = form.Handle,
39-
dwFlags = 14,
43+
dwFlags = FLASHW.FLASHW_TRAY | FLASHW.FLASHW_CAPTION | FLASHW.FLASHW_TIMER,
4044
uCount = 0
4145
};
4246

43-
Win32Stuff.FlashWindowEx(ref fw);
47+
_ = FlashWindowEx(fw);
4448
}
4549

4650
public string GetDescription ()

src/FlashIconHighlighter/Win32Stuff.cs

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/LogExpert.Core/Classes/Filter/FilterPipe.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using ColumnizerLib;
55

66
using LogExpert.Core.Interface;
7+
78
using NLog;
89

910
namespace LogExpert.Core.Classes.Filter;
@@ -23,7 +24,7 @@ public class FilterPipe : IDisposable
2324

2425
#region cTor
2526

26-
public FilterPipe(FilterParams filterParams, ILogWindow logWindow)
27+
public FilterPipe (FilterParams filterParams, ILogWindow logWindow)
2728
{
2829
FilterParams = filterParams;
2930
LogWindow = logWindow;
@@ -68,15 +69,12 @@ public void OpenFile ()
6869

6970
public void CloseFile ()
7071
{
71-
if (_writer != null)
72-
{
73-
_writer.Close();
74-
_writer = null;
75-
}
72+
_writer?.Close();
73+
_writer = null;
7674
}
7775

7876
//TOOD: check if the callers are checking for null before calling
79-
public bool WriteToPipe (ILogLine textLine, int orgLineNum)
77+
public bool WriteToPipe (ILogLineMemory textLine, int orgLineNum)
8078
{
8179
ArgumentNullException.ThrowIfNull(textLine, nameof(textLine));
8280

@@ -88,7 +86,7 @@ public bool WriteToPipe (ILogLine textLine, int orgLineNum)
8886
{
8987
try
9088
{
91-
_writer.WriteLine(textLine.FullLine);
89+
_writer.WriteLine(textLine.FullLine.ToString());
9290
_lineMappingList.Add(orgLineNum);
9391
return true;
9492
}

src/LogExpert.Core/Classes/Log/LogfileReader.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,15 +1277,15 @@ private void ReadToBufferList (ILogFileInfo logFileInfo, long filePos, int start
12771277
}
12781278
}
12791279

1280-
AcquireDisposeReaderLock();
1280+
AcquireDisposeLockUpgradableReadLock();
12811281
if (logBuffer.IsDisposed)
12821282
{
12831283
UpgradeDisposeLockToWriterLock();
12841284
ReReadBuffer(logBuffer);
12851285
DowngradeDisposeLockFromWriterLock();
12861286
}
12871287

1288-
ReleaseDisposeReaderLock();
1288+
ReleaseDisposeUpgradeableReadLock();
12891289
}
12901290
}
12911291
finally

src/LogExpert.Core/EventArguments/ContextMenuPluginEventArgs.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace LogExpert.Core.EventArguments;
44

5-
public class ContextMenuPluginEventArgs(IContextMenuEntry entry, IList<int> logLines, ILogLineMemoryColumnizer columnizer,
6-
ILogExpertCallback callback) : System.EventArgs
5+
public class ContextMenuPluginEventArgs (IContextMenuEntry entry, IList<int> logLines, ILogLineMemoryColumnizer columnizer,
6+
ILogExpertCallbackMemory callback) : EventArgs
77
{
88

99
#region Properties
@@ -14,7 +14,7 @@ public class ContextMenuPluginEventArgs(IContextMenuEntry entry, IList<int> logL
1414

1515
public ILogLineMemoryColumnizer Columnizer { get; } = columnizer;
1616

17-
public ILogExpertCallback Callback { get; } = callback;
17+
public ILogExpertCallbackMemory Callback { get; } = callback;
1818

1919
#endregion
2020
}

src/LogExpert.Core/Interface/ILogWindow.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,21 @@ public interface ILogWindow
199199
/// </remarks>
200200
void WritePipeTab (IList<LineEntry> lineEntryList, string title);
201201

202+
/// <summary>
203+
/// Creates a new tab containing the specified list of log line entries.
204+
/// </summary>
205+
/// <param name="lineEntryList">
206+
/// A list of <see cref="LineEntryMemory"/> objects containing the lines and their
207+
/// original line numbers to display in the new tab.
208+
/// </param>
209+
/// <param name="title">The title to display on the tab.</param>
210+
/// <remarks>
211+
/// This method is used to pipe filtered or selected content into a new tab
212+
/// without creating a physical file. The new tab maintains references to the
213+
/// original line numbers for context.
214+
/// </remarks>
215+
void WritePipeTab (IList<LineEntryMemory> lineEntryList, string title);
216+
202217
/// <summary>
203218
/// Activates this log window and brings it to the foreground.
204219
/// </summary>

0 commit comments

Comments
 (0)