2
2
using Avalonia . Controls . ApplicationLifetimes ;
3
3
using Avalonia . Markup . Xaml ;
4
4
using Microsoft . Extensions . DependencyInjection ;
5
+ using Mono . Options ;
6
+ using System ;
7
+ using System . Collections . Generic ;
8
+ using System . Diagnostics . Eventing . Reader ;
5
9
using System . Reflection . Metadata . Ecma335 ;
6
10
using WEventViewer . Model ;
7
11
using WEventViewer . ViewModel ;
@@ -10,6 +14,70 @@ namespace WEventViewer;
10
14
11
15
public partial class App : Application
12
16
{
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
+ }
13
81
public override void Initialize ( )
14
82
{
15
83
AvaloniaXamlLoader . Load ( this ) ;
@@ -23,7 +91,16 @@ public override void OnFrameworkInitializationCompleted()
23
91
collection . AddSingleton < MainWindowViewModel > ( ) ;
24
92
if ( ApplicationLifetime is IClassicDesktopStyleApplicationLifetime classic )
25
93
{
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
+ } ) ;
27
104
}
28
105
collection . AddSingleton < MainWindow > ( provider =>
29
106
{
@@ -38,6 +115,7 @@ public override void OnFrameworkInitializationCompleted()
38
115
collection . AddTransient < ProviderNameWindowViewModel > ( ) ;
39
116
collection . AddTransient < LogNameViewModel > ( ) ;
40
117
collection . AddTransient < AboutViewModel > ( ) ;
118
+ collection . AddTransient < DetailedLogViewModel > ( ) ;
41
119
var serviceProvider = collection . BuildServiceProvider ( ) ;
42
120
var vm = serviceProvider . GetRequiredService < MainWindowViewModel > ( ) ;
43
121
if ( ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop )
0 commit comments