Skip to content

Commit 3d1880f

Browse files
committed
presetting log filter condition by commandline(#9)
1 parent 83975c9 commit 3d1880f

7 files changed

+2145
-3
lines changed

Directory.Build.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project>
33
<PropertyGroup>
4-
<WEventViewerVersion>0.3.0</WEventViewerVersion>
4+
<WEventViewerVersion>0.4.0</WEventViewerVersion>
55
</PropertyGroup>
66
</Project>

LICENSE-package.txt

+33
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,36 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
4444
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
4545
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
4646
SOFTWARE.
47+
48+
-----------------
49+
50+
Options.cs
51+
52+
Authors:
53+
54+
Federico Di Gregorio <[email protected]>
55+
Rolf Bjarne Kvinge <[email protected]>
56+
57+
Copyright (C) 2008 Novell (http://www.novell.com)
58+
Copyright (C) 2009 Federico Di Gregorio.
59+
Copyright (C) 2012 Xamarin Inc (http://www.xamarin.com)
60+
Copyright (C) 2017 Microsoft Corporation (http://www.microsoft.com)
61+
62+
Permission is hereby granted, free of charge, to any person obtaining
63+
a copy of this software and associated documentation files (the
64+
"Software"), to deal in the Software without restriction, including
65+
without limitation the rights to use, copy, modify, merge, publish,
66+
distribute, sublicense, and/or sell copies of the Software, and to
67+
permit persons to whom the Software is furnished to do so, subject to
68+
the following conditions:
69+
70+
The above copyright notice and this permission notice shall be
71+
included in all copies or substantial portions of the Software.
72+
73+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
74+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
75+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
76+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
77+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
78+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
79+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ OpenLogWindow:
2626

2727
# ChangeLog
2828

29+
## 0.4.0
30+
31+
* open OpenLogWindow at first for convenience
32+
* log filter can be preset by commandline now
33+
2934
## 0.3.0
3035

3136
* add MSI installer to release

src/WEventViewer/App.axaml.cs

+79-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
using Avalonia.Controls.ApplicationLifetimes;
33
using Avalonia.Markup.Xaml;
44
using Microsoft.Extensions.DependencyInjection;
5+
using Mono.Options;
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Diagnostics.Eventing.Reader;
59
using System.Reflection.Metadata.Ecma335;
610
using WEventViewer.Model;
711
using WEventViewer.ViewModel;
@@ -10,6 +14,70 @@ namespace WEventViewer;
1014

1115
public partial class App : Application
1216
{
17+
class WEventViewOptions
18+
{
19+
public string LogName = "";
20+
public string LogType = "";
21+
public List<int> LogLevels = new List<int>();
22+
}
23+
static OptionSet CreateOptionSet(OpenLogWindowViewModel vm)
24+
{
25+
var set = new OptionSet()
26+
.Add("n=|logname=", x => vm.LogName = x)
27+
.Add("t=|logtype=", x =>
28+
{
29+
vm.CurrentSelected = x.ToLower() switch
30+
{
31+
"logname" => vm.PathTypes[0],
32+
"filepath" => vm.PathTypes[1],
33+
_ => throw new ArgumentException("invalid logtype")
34+
};
35+
})
36+
.Add("l=|loglevel=", x =>
37+
{
38+
switch(x.ToLower())
39+
{
40+
case "critical":
41+
vm.IsCriticalChecked = true;
42+
break;
43+
case "error":
44+
vm.IsErrorChecked = true;
45+
break;
46+
case "warning":
47+
vm.IsWarningChecked = true;
48+
break;
49+
case "information":
50+
vm.IsInformationChecked = true;
51+
break;
52+
case "verbose":
53+
vm.IsVerboseChecked = true;
54+
break;
55+
}
56+
vm.UseFilterByLevel = true;
57+
})
58+
.Add("p=|provider=", x => vm.ProviderNames = x)
59+
.Add("b=|begin=", x =>
60+
{
61+
DateTime dt = DateTime.Parse(x);
62+
vm.BeginDate = dt.ToString("yyyy-MM-dd");
63+
vm.BeginTime = dt.ToString("HH:mm:ss");
64+
vm.UseTimeCreated = true;
65+
})
66+
.Add("e=|end=", x =>
67+
{
68+
DateTime dt = DateTime.Parse(x);
69+
vm.EndDate = dt.ToString("yyyy-MM-dd");
70+
vm.EndTime = dt.ToString("HH:mm:ss");
71+
vm.UseTimeCreated = true;
72+
})
73+
.Add("r=|raw=", x =>
74+
{
75+
vm.RawQuery = x;
76+
vm.UseRawQuery = true;
77+
})
78+
;
79+
return set;
80+
}
1381
public override void Initialize()
1482
{
1583
AvaloniaXamlLoader.Load(this);
@@ -23,7 +91,16 @@ public override void OnFrameworkInitializationCompleted()
2391
collection.AddSingleton<MainWindowViewModel>();
2492
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime classic)
2593
{
26-
collection.AddSingleton<OpenLogWindowViewModel>(provider => new OpenLogWindowViewModel() { });
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+
});
27104
}
28105
collection.AddSingleton<MainWindow>(provider =>
29106
{
@@ -38,6 +115,7 @@ public override void OnFrameworkInitializationCompleted()
38115
collection.AddTransient<ProviderNameWindowViewModel>();
39116
collection.AddTransient<LogNameViewModel>();
40117
collection.AddTransient<AboutViewModel>();
118+
collection.AddTransient<DetailedLogViewModel>();
41119
var serviceProvider = collection.BuildServiceProvider();
42120
var vm = serviceProvider.GetRequiredService<MainWindowViewModel>();
43121
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)

src/WEventViewer/MainWindow.axaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
MinHeight="300"
1010
MinWidth="400"
1111
Height="{Binding Mode=OneWayToSource,Path=CurrentWindowHeight}"
12-
Title="WEventViewer">
12+
Title="WEventViewer"
13+
Loaded="Window_Loaded_1">
1314
<Design.DataContext>
1415
<vm:MainWindowViewModel></vm:MainWindowViewModel>
1516
</Design.DataContext>

src/WEventViewer/MainWindow.axaml.cs

+8
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,12 @@ private async void CopyAsXmlClicked(object? sender, Avalonia.Interactivity.Route
123123
await Clipboard.SetTextAsync(xmlstr);
124124
}
125125
}
126+
127+
private void Window_Loaded_1(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
128+
{
129+
if (DataContext is MainWindowViewModel vm)
130+
{
131+
vm.OpenCommand.Execute(null);
132+
}
133+
}
126134
}

0 commit comments

Comments
 (0)