Skip to content

Commit 6a16062

Browse files
committed
add help window and commandline options(#9)
1 parent 3d1880f commit 6a16062

File tree

6 files changed

+135
-22
lines changed

6 files changed

+135
-22
lines changed

README.md

+11
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@ This program is viewer for Windows EventLog
1515
* double click on log, then open detailed log information
1616
* select log and right-click and select "Copy as XML" in context menu, then EventLog XML will be copied to clipboard
1717

18+
## Commandline Options
19+
20+
* `-n/--logname LOGNAME`: target LogName or exported windows eventlog file path
21+
* `-t/--logtype LOGTYPE`: LogName kind, 'logname': from Windows EventLog store, 'filepath': exported Windows Event Log file(*.evtx)
22+
* `-l/--loglevel LOGLEVEL`: LogLevel filter: available values: critical,error,warning,information,verbose
23+
* `-p/--provider PROVIDER`: LogProvider filter
24+
* `-b/--begin BEGINDATE`: createAt filter begin time
25+
* `-e/--end ENDDATE`: createAt filter end time
26+
* `-r/--raw RAW_QUERY`: raw filtering query
27+
* `-h/--help`: display help window
28+
1829
# Screen Shots
1930

2031
MainWindow:

src/WEventViewer/App.axaml.cs

+56-22
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System;
77
using System.Collections.Generic;
88
using System.Diagnostics.Eventing.Reader;
9+
using System.IO;
910
using System.Reflection.Metadata.Ecma335;
1011
using WEventViewer.Model;
1112
using WEventViewer.ViewModel;
@@ -20,11 +21,12 @@ class WEventViewOptions
2021
public string LogType = "";
2122
public List<int> LogLevels = new List<int>();
2223
}
24+
static bool ShowHelp = false;
2325
static OptionSet CreateOptionSet(OpenLogWindowViewModel vm)
2426
{
2527
var set = new OptionSet()
26-
.Add("n=|logname=", x => vm.LogName = x)
27-
.Add("t=|logtype=", x =>
28+
.Add("n=|logname=", "LogName or Exported EventLog file path(*.evtx)", x => vm.LogName = x)
29+
.Add("t=|logtype=", "LogName kind, 'logname': from Windows EventLog store, 'filepath': exported Windows Event Log file(*.evtx) ", x =>
2830
{
2931
vm.CurrentSelected = x.ToLower() switch
3032
{
@@ -33,7 +35,7 @@ static OptionSet CreateOptionSet(OpenLogWindowViewModel vm)
3335
_ => throw new ArgumentException("invalid logtype")
3436
};
3537
})
36-
.Add("l=|loglevel=", x =>
38+
.Add("l=|loglevel=", "log severity: availables = critical,error,warning,information,verbose", x =>
3739
{
3840
switch(x.ToLower())
3941
{
@@ -55,26 +57,27 @@ static OptionSet CreateOptionSet(OpenLogWindowViewModel vm)
5557
}
5658
vm.UseFilterByLevel = true;
5759
})
58-
.Add("p=|provider=", x => vm.ProviderNames = x)
59-
.Add("b=|begin=", x =>
60+
.Add("p=|provider=", "log provider name", x => vm.ProviderNames = x)
61+
.Add("b=|begin=", "log begin datetime", x =>
6062
{
6163
DateTime dt = DateTime.Parse(x);
6264
vm.BeginDate = dt.ToString("yyyy-MM-dd");
6365
vm.BeginTime = dt.ToString("HH:mm:ss");
6466
vm.UseTimeCreated = true;
6567
})
66-
.Add("e=|end=", x =>
68+
.Add("e=|end=", "log end datetime", x =>
6769
{
6870
DateTime dt = DateTime.Parse(x);
6971
vm.EndDate = dt.ToString("yyyy-MM-dd");
7072
vm.EndTime = dt.ToString("HH:mm:ss");
7173
vm.UseTimeCreated = true;
7274
})
73-
.Add("r=|raw=", x =>
75+
.Add("r=|raw=", "log filtering query by raw filter string", x =>
7476
{
7577
vm.RawQuery = x;
7678
vm.UseRawQuery = true;
7779
})
80+
.Add("h|help", x => ShowHelp = true)
7881
;
7982
return set;
8083
}
@@ -89,19 +92,24 @@ public override void OnFrameworkInitializationCompleted()
8992
collection.AddSingleton<EventLogRepository>();
9093
collection.AddSingleton<IViewModelFactory, ViewModelFactoryServiceProvider>(provider => new ViewModelFactoryServiceProvider(provider));
9194
collection.AddSingleton<MainWindowViewModel>();
92-
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime classic)
93-
{
94-
collection.AddSingleton<OpenLogWindowViewModel>(provider =>
95-
{
96-
var vm = new OpenLogWindowViewModel();
97-
if (classic.Args != null)
98-
{
99-
var optset = CreateOptionSet(vm);
100-
optset.Parse(classic.Args);
101-
}
102-
return vm;
103-
});
104-
}
95+
collection.AddSingleton<OpenLogWindowViewModel>();
96+
//if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime classic)
97+
//{
98+
// collection.AddSingleton<OpenLogWindowViewModel>(provider =>
99+
// {
100+
// var vm = new OpenLogWindowViewModel();
101+
// if (classic.Args != null)
102+
// {
103+
// var optset = CreateOptionSet(vm);
104+
// var remaining = optset.Parse(classic.Args);
105+
// if(remaining.Count > 0)
106+
// {
107+
// vm.LogName = remaining[0];
108+
// }
109+
// }
110+
// return vm;
111+
// });
112+
//}
105113
collection.AddSingleton<MainWindow>(provider =>
106114
{
107115
return new MainWindow(provider.GetRequiredService<IViewModelFactory>())
@@ -116,11 +124,37 @@ public override void OnFrameworkInitializationCompleted()
116124
collection.AddTransient<LogNameViewModel>();
117125
collection.AddTransient<AboutViewModel>();
118126
collection.AddTransient<DetailedLogViewModel>();
127+
collection.AddTransient<HelpWindowViewModel>(provider =>
128+
{
129+
var optset = CreateOptionSet(provider.GetRequiredService<OpenLogWindowViewModel>());
130+
using var sw = new StringWriter();
131+
optset.WriteOptionDescriptions(sw);
132+
return new HelpWindowViewModel() { HelpMessage = sw.ToString() };
133+
});
134+
collection.AddTransient<HelpWindow>(provider => new HelpWindow() { DataContext = provider.GetRequiredService<HelpWindowViewModel>() });
119135
var serviceProvider = collection.BuildServiceProvider();
120-
var vm = serviceProvider.GetRequiredService<MainWindowViewModel>();
136+
//var vm = serviceProvider.GetRequiredService<MainWindowViewModel>();
137+
var w = serviceProvider.GetRequiredService<MainWindow>();
121138
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
122139
{
123-
desktop.MainWindow = serviceProvider.GetRequiredService<MainWindow>();
140+
var openLogVM = serviceProvider.GetRequiredService<OpenLogWindowViewModel>();
141+
var optset = CreateOptionSet(openLogVM);
142+
if (desktop.Args != null)
143+
{
144+
var remaining = optset.Parse(desktop.Args);
145+
if(remaining.Count > 0)
146+
{
147+
openLogVM.LogName = remaining[0];
148+
}
149+
}
150+
if (ShowHelp)
151+
{
152+
desktop.MainWindow = serviceProvider.GetRequiredService<HelpWindow>();
153+
}
154+
else
155+
{
156+
desktop.MainWindow = w;
157+
}
124158
}
125159
else if (ApplicationLifetime is ISingleViewApplicationLifetime singleViewPlatform)
126160
{

src/WEventViewer/HelpWindow.axaml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<Window xmlns="https://github.com/avaloniaui"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:vm="using:WEventViewer.ViewModel"
6+
mc:Ignorable="d" d:DesignWidth="400" d:DesignHeight="450"
7+
x:Class="WEventViewer.HelpWindow"
8+
x:DataType="vm:HelpWindowViewModel"
9+
Title="HelpWindow">
10+
<Design.DataContext>
11+
<vm:HelpWindowViewModel/>
12+
</Design.DataContext>
13+
<Grid HorizontalAlignment="Stretch">
14+
<Grid.RowDefinitions>
15+
<RowDefinition Height="*"/>
16+
<RowDefinition Height="Auto"/>
17+
</Grid.RowDefinitions>
18+
<Grid.ColumnDefinitions>
19+
<ColumnDefinition Width="*"/>
20+
</Grid.ColumnDefinitions>
21+
<ScrollViewer Grid.Row="0" Grid.Column="0" HorizontalAlignment="Stretch" MaxWidth="600" HorizontalScrollBarVisibility="Auto">
22+
<TextBlock Text="{Binding HelpMessage}" HorizontalAlignment="Left" MaxWidth="{Binding $parent.Bounds.Width}"/>
23+
</ScrollViewer>
24+
<Button Name="CloseButton" Content="Close" HorizontalAlignment="Right" Grid.Row="1" Click="Button_Click"/>
25+
</Grid>
26+
</Window>

src/WEventViewer/HelpWindow.axaml.cs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Avalonia;
2+
using Avalonia.Controls;
3+
using Avalonia.Markup.Xaml;
4+
5+
namespace WEventViewer;
6+
7+
public partial class HelpWindow : Window
8+
{
9+
public HelpWindow()
10+
{
11+
InitializeComponent();
12+
}
13+
14+
private void Button_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
15+
{
16+
Close();
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"profiles": {
3+
"WEventViewer": {
4+
"commandName": "Project"
5+
},
6+
"WEventViewer-Help": {
7+
"commandName": "Project",
8+
"commandLineArgs": "--help"
9+
}
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace WEventViewer.ViewModel
8+
{
9+
public class HelpWindowViewModel
10+
{
11+
public string HelpMessage { get; set; } = "";
12+
}
13+
}

0 commit comments

Comments
 (0)