22using Avalonia . Controls . ApplicationLifetimes ;
33using Avalonia . Markup . Xaml ;
44using Microsoft . Extensions . DependencyInjection ;
5+ using Mono . Options ;
6+ using System ;
7+ using System . Collections . Generic ;
8+ using System . Diagnostics . Eventing . Reader ;
59using System . Reflection . Metadata . Ecma335 ;
610using WEventViewer . Model ;
711using WEventViewer . ViewModel ;
@@ -10,6 +14,70 @@ namespace WEventViewer;
1014
1115public 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 )
0 commit comments