Skip to content

Commit

Permalink
presetting log filter condition by commandline(#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
itn3000 committed Sep 2, 2024
1 parent 83975c9 commit 3d1880f
Show file tree
Hide file tree
Showing 7 changed files with 2,145 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<WEventViewerVersion>0.3.0</WEventViewerVersion>
<WEventViewerVersion>0.4.0</WEventViewerVersion>
</PropertyGroup>
</Project>
33 changes: 33 additions & 0 deletions LICENSE-package.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,36 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

-----------------

Options.cs

Authors:
Jonathan Pryor <[email protected]>, <[email protected]>
Federico Di Gregorio <[email protected]>
Rolf Bjarne Kvinge <[email protected]>

Copyright (C) 2008 Novell (http://www.novell.com)
Copyright (C) 2009 Federico Di Gregorio.
Copyright (C) 2012 Xamarin Inc (http://www.xamarin.com)
Copyright (C) 2017 Microsoft Corporation (http://www.microsoft.com)

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ OpenLogWindow:

# ChangeLog

## 0.4.0

* open OpenLogWindow at first for convenience
* log filter can be preset by commandline now

## 0.3.0

* add MSI installer to release
Expand Down
80 changes: 79 additions & 1 deletion src/WEventViewer/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
using Microsoft.Extensions.DependencyInjection;
using Mono.Options;
using System;
using System.Collections.Generic;
using System.Diagnostics.Eventing.Reader;
using System.Reflection.Metadata.Ecma335;
using WEventViewer.Model;
using WEventViewer.ViewModel;
Expand All @@ -10,6 +14,70 @@ namespace WEventViewer;

public partial class App : Application
{
class WEventViewOptions
{
public string LogName = "";
public string LogType = "";
public List<int> LogLevels = new List<int>();
}
static OptionSet CreateOptionSet(OpenLogWindowViewModel vm)
{
var set = new OptionSet()
.Add("n=|logname=", x => vm.LogName = x)
.Add("t=|logtype=", x =>
{
vm.CurrentSelected = x.ToLower() switch
{
"logname" => vm.PathTypes[0],
"filepath" => vm.PathTypes[1],
_ => throw new ArgumentException("invalid logtype")
};
})
.Add("l=|loglevel=", x =>
{
switch(x.ToLower())
{
case "critical":
vm.IsCriticalChecked = true;
break;
case "error":
vm.IsErrorChecked = true;
break;
case "warning":
vm.IsWarningChecked = true;
break;
case "information":
vm.IsInformationChecked = true;
break;
case "verbose":
vm.IsVerboseChecked = true;
break;
}
vm.UseFilterByLevel = true;
})
.Add("p=|provider=", x => vm.ProviderNames = x)
.Add("b=|begin=", x =>
{
DateTime dt = DateTime.Parse(x);
vm.BeginDate = dt.ToString("yyyy-MM-dd");
vm.BeginTime = dt.ToString("HH:mm:ss");
vm.UseTimeCreated = true;
})
.Add("e=|end=", x =>
{
DateTime dt = DateTime.Parse(x);
vm.EndDate = dt.ToString("yyyy-MM-dd");
vm.EndTime = dt.ToString("HH:mm:ss");
vm.UseTimeCreated = true;
})
.Add("r=|raw=", x =>
{
vm.RawQuery = x;
vm.UseRawQuery = true;
})
;
return set;
}
public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
Expand All @@ -23,7 +91,16 @@ public override void OnFrameworkInitializationCompleted()
collection.AddSingleton<MainWindowViewModel>();
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime classic)
{
collection.AddSingleton<OpenLogWindowViewModel>(provider => new OpenLogWindowViewModel() { });
collection.AddSingleton<OpenLogWindowViewModel>(provider =>
{
var vm = new OpenLogWindowViewModel();
if (classic.Args != null)
{
var optset = CreateOptionSet(vm);
optset.Parse(classic.Args);
}
return vm;
});
}
collection.AddSingleton<MainWindow>(provider =>
{
Expand All @@ -38,6 +115,7 @@ public override void OnFrameworkInitializationCompleted()
collection.AddTransient<ProviderNameWindowViewModel>();
collection.AddTransient<LogNameViewModel>();
collection.AddTransient<AboutViewModel>();
collection.AddTransient<DetailedLogViewModel>();
var serviceProvider = collection.BuildServiceProvider();
var vm = serviceProvider.GetRequiredService<MainWindowViewModel>();
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
Expand Down
3 changes: 2 additions & 1 deletion src/WEventViewer/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
MinHeight="300"
MinWidth="400"
Height="{Binding Mode=OneWayToSource,Path=CurrentWindowHeight}"
Title="WEventViewer">
Title="WEventViewer"
Loaded="Window_Loaded_1">
<Design.DataContext>
<vm:MainWindowViewModel></vm:MainWindowViewModel>
</Design.DataContext>
Expand Down
8 changes: 8 additions & 0 deletions src/WEventViewer/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,12 @@ private async void CopyAsXmlClicked(object? sender, Avalonia.Interactivity.Route
await Clipboard.SetTextAsync(xmlstr);
}
}

private void Window_Loaded_1(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
{
if (DataContext is MainWindowViewModel vm)
{
vm.OpenCommand.Execute(null);
}
}
}
Loading

0 comments on commit 3d1880f

Please sign in to comment.