Skip to content

Commit

Permalink
Merge pull request #11 from itn3000/add-eventlog
Browse files Browse the repository at this point in the history
add log filter options
  • Loading branch information
itn3000 authored Aug 5, 2024
2 parents ba757d2 + 888a7eb commit e8561b3
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 75 deletions.
1 change: 1 addition & 0 deletions src/WEventViewer/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

<DataGridTextColumn Header="TimeCreated" Binding="{Binding TimeCreated}"/>
<DataGridTextColumn Header="LogName" Binding="{Binding LogName}"/>
<DataGridTextColumn Header="Provider" Binding="{Binding ProviderName}"/>
<DataGridTextColumn Header="Id" Binding="{Binding Id}"/>
<DataGridTextColumn Header="Level" Binding="{Binding Level}"/>
<DataGridTextColumn Header="Description" Binding="{Binding Formatted}"/>
Expand Down
156 changes: 92 additions & 64 deletions src/WEventViewer/OpenLogWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,40 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="using:WEventViewer.ViewModel"
xmlns:local="using:WEventViewer"
mc:Ignorable="d" d:DesignWidth="400" d:DesignHeight="500"
mc:Ignorable="d" d:DesignWidth="700" d:DesignHeight="600"
x:Class="WEventViewer.OpenLogWindow"
x:DataType="vm:OpenLogWindowViewModel"
Title="OpenLogWindow">
<Design.DataContext>
<vm:OpenLogWindowViewModel/>
</Design.DataContext>
<Window.Resources>
<vm:PathTypeValueConverter x:Key="PathTypeConverter"/>
</Window.Resources>
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="20">
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<StackPanel Margin="10" Orientation="Vertical" Grid.Row="0" Name="OptionPanel">
<Grid HorizontalAlignment="Stretch" Grid.Row="0" VerticalAlignment="Center">
<Design.DataContext>
<vm:OpenLogWindowViewModel/>
</Design.DataContext>
<Window.Resources>
<vm:PathTypeValueConverter x:Key="PathTypeConverter"/>
</Window.Resources>
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="20">
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<Grid Margin="10" Grid.Row="0" Name="OptionPanel">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid HorizontalAlignment="Stretch" Grid.Row="0" VerticalAlignment="Center">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Label Content="LogName"
<Label Content="LogName"
Margin="10,10,10,10"
VerticalAlignment="Center"
HorizontalAlignment="Left"
Grid.Column="0"
HorizontalAlignment="Left"
Grid.Column="0"
/>
<TextBox HorizontalContentAlignment="Left"
<TextBox HorizontalContentAlignment="Left"
VerticalContentAlignment="Center"
HorizontalAlignment="Stretch"
TextAlignment="Left"
Expand All @@ -41,66 +46,89 @@
MinWidth="200" MaxWidth="1000"
Grid.Column="1"
/>
<Button Name="OpenLogButton"
Grid.Column="2"
Content="Open"
<Button Name="OpenLogButton"
Grid.Column="2"
Content="Open"
IsVisible="{Binding IsEnableFilePathOpenButton}"
Click="OnLogOpenButtonClicked"/>
</Grid>
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Center">
IsEnabled="{Binding IsEnableFilePathOpenButton}"
Click="OnLogOpenButtonClicked"/>
<Button Name="OpenLogNameButton"
Grid.Column="2"
Content="Show LogName"
IsVisible="{Binding IsOpenLogNameButtonEnabled}"
IsEnabled="{Binding IsOpenLogNameButtonEnabled}"
Click="OnShowLogNameClicked"
/>
</Grid>
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Center" Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Label Content="PathType"
<Label Content="PathType"
Margin="10,10,10,10"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Grid.Column="0"/>
<!--<TextBox Margin="10,10,10,10"
<!--<TextBox Margin="10,10,10,10"
HorizontalAlignment="Stretch"
TextAlignment="Left"
VerticalContentAlignment="Center"
Text="{Binding Path=PathType, Mode=TwoWay,Converter={StaticResource PathTypeConverter}}"/>-->
<ComboBox
HorizontalAlignment="Stretch"
Margin="10"
ItemsSource="{Binding PathTypes}"
SelectedValue="{Binding CurrentSelected}"
Grid.Column="1"
HorizontalAlignment="Stretch"
Margin="10"
ItemsSource="{Binding PathTypes}"
SelectedValue="{Binding CurrentSelected}"
Grid.Column="1"
>
<ComboBox.ItemTemplate>
<DataTemplate>
<Label Content="{Binding DisplayName}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</Grid>
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" VerticalAlignment="Stretch" MaxHeight="300" MaxWidth="{Binding #OptionPanel.Bounds.Width}">
<StackPanel Orientation="Vertical" Margin="10">
<CheckBox Name="UseRawQuery" Content="raw query" Margin="10" IsChecked="{Binding UseRawQuery}"/>
<TextBox Name="RawQueryInput" Margin="10" Text="{Binding RawQuery}" IsEnabled="{Binding UseRawQuery}"/>
<Border BorderThickness="1" BorderBrush="Gray"/>
<StackPanel Orientation="Horizontal">
<CheckBox Content="Since:" IsChecked="{Binding UseBeginDate}" Margin="10"/>
<DatePicker Name="BeginDate" SelectedDate="{Binding BeginDate}" IsEnabled="{Binding UseBeginDate}"/>
<TimePicker Name="BeginTime" SelectedTime="{Binding BeginTime}" IsEnabled="{Binding UseBeginDate}"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<CheckBox Content="Until:" IsChecked="{Binding UseEndDate}" Margin="10"/>
<DatePicker Name="EndDate" SelectedDate="{Binding EndDate}" IsEnabled="{Binding UseEndDate}"/>
<TimePicker Name="EndTime" SelectedTime="{Binding EndTime}" IsEnabled="{Binding UseEndDate}"/>
</StackPanel>
<CheckBox Content="filter providers(separeted by ',')" Margin="10" IsChecked="{Binding UseProviderNames}"/>
<TextBox Text="{Binding ProviderNames}" IsEnabled="{Binding UseProviderNames}"/>
</StackPanel>
</ScrollViewer>
<!--<Expander Header="Advanced" Grid.Row="2" HorizontalAlignment="Stretch" MaxHeight="300">
<ComboBox.ItemTemplate>
<DataTemplate>
<Label Content="{Binding DisplayName}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</Grid>
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" VerticalAlignment="Stretch" Grid.Row="2">
<StackPanel Orientation="Vertical" Margin="10">
<CheckBox Name="UseRawQuery" Content="raw query" Margin="10" IsChecked="{Binding UseRawQuery}"/>
<TextBox Name="RawQueryInput" Margin="10" Text="{Binding RawQuery}" IsEnabled="{Binding UseRawQuery}"/>
<Border BorderThickness="1" BorderBrush="Gray"/>
<StackPanel Orientation="Horizontal">
<CheckBox Content="Since:" IsChecked="{Binding UseBeginDate}" Margin="10"/>
<DatePicker Name="BeginDate" SelectedDate="{Binding BeginDate}" IsEnabled="{Binding UseBeginDate}"/>
<TimePicker Name="BeginTime" SelectedTime="{Binding BeginTime}" IsEnabled="{Binding UseBeginDate}"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<CheckBox Content="Until:" IsChecked="{Binding UseEndDate}" Margin="10"/>
<DatePicker Name="EndDate" SelectedDate="{Binding EndDate}" IsEnabled="{Binding UseEndDate}"/>
<TimePicker Name="EndTime" SelectedTime="{Binding EndTime}" IsEnabled="{Binding UseEndDate}"/>
</StackPanel>
<CheckBox Content="filter providers(separeted by ',')" Margin="10" IsChecked="{Binding UseProviderNames}"/>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBox Text="{Binding ProviderNames}" IsEnabled="{Binding UseProviderNames}" Grid.Column="0" Margin="10"/>
<Button Content="Show Providers" Grid.Column="1" Margin="10" Click="OnShowProviderNamesClicked"/>
</Grid>
<CheckBox Content="filter by level" Margin="10" IsChecked="{Binding UseFilterByLevel}"/>
<StackPanel Orientation="Horizontal">
<CheckBox Content="Critical" Margin="10" IsChecked="{Binding IsCriticalChecked}" IsEnabled="{Binding UseFilterByLevel}"/>
<CheckBox Content="Error" Margin="10" IsChecked="{Binding IsErrorChecked}" IsEnabled="{Binding UseFilterByLevel}"/>
<CheckBox Content="Warning" Margin="10" IsChecked="{Binding IsWarningChecked}" IsEnabled="{Binding UseFilterByLevel}"/>
<CheckBox Content="Information" Margin="10" IsChecked="{Binding IsInformationChecked}" IsEnabled="{Binding UseFilterByLevel}"/>
<CheckBox Content="Verbose" Margin="10" IsChecked="{Binding IsVerboseChecked}" IsEnabled="{Binding UseFilterByLevel}"/>
</StackPanel>
</StackPanel>
</ScrollViewer>
<!--<Expander Header="Advanced" Grid.Row="2" HorizontalAlignment="Stretch" MaxHeight="300">
</Expander>-->
</StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Grid.Row="1" VerticalAlignment="Bottom">
<Button Content="OK" Command="{ Binding OkCommand }" Margin="10" Padding="10"/>
<Button Content="Cancel" Command="{ Binding CancelCommand }" Margin="10" Padding="10"/>
</StackPanel>
</Grid>
</Grid>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Grid.Row="1" VerticalAlignment="Bottom">
<Button Content="OK" Command="{ Binding OkCommand }" Margin="10" Padding="10"/>
<Button Content="Cancel" Command="{ Binding CancelCommand }" Margin="10" Padding="10"/>
</StackPanel>
</Grid>
</Window>
16 changes: 16 additions & 0 deletions src/WEventViewer/OpenLogWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,20 @@ public async void OnLogOpenButtonClicked(object? sender, RoutedEventArgs routedE
}
}
}
public void OnShowLogNameClicked(object? sender, RoutedEventArgs routedEventArgs)
{
var logNameWindow = new LogNameWindow()
{
DataContext = new LogNameViewModel()
};
logNameWindow.Show();
}
public void OnShowProviderNamesClicked(object? sender, RoutedEventArgs routedEventArgs)
{
var w = new ProviderNamesWindow()
{
DataContext = new ProviderNameWindowViewModel()
};
w.Show();
}
}
66 changes: 55 additions & 11 deletions src/WEventViewer/ViewModel/OpenLogWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,6 @@ internal partial class OpenLogWindowViewModel : INotifyPropertyChanged
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(LogName)));
}
}
//PathType _PathType = PathType.LogName;
//public PathType PathType
//{
// get => _PathType;
// set
// {
// _PathType = value;
// PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(PathType)));
// PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsEnableFilePathOpenButton)));
// }
//}
PathTypeDefinition _CurrentSelected = _PathTypes[0];
public PathTypeDefinition CurrentSelected
{
Expand All @@ -88,9 +77,12 @@ public PathTypeDefinition CurrentSelected
_CurrentSelected = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(CurrentSelected)));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsEnableFilePathOpenButton)));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsOpenLogNameButtonEnabled)));
}
}

public bool IsOpenLogNameButtonEnabled => _CurrentSelected != null && _CurrentSelected.PathType == PathType.LogName;

[RelayCommand]
void OnPathTypeChanged(Avalonia.Controls.SelectionChangedEventArgs evargs)
{
Expand Down Expand Up @@ -147,6 +139,7 @@ public bool UseRawQuery
UseBeginDate = false;
UseEndDate = false;
UseProviderNames = false;
UseFilterByLevel = false;
}
}
}
Expand Down Expand Up @@ -184,6 +177,34 @@ string BuildQuery()
var providerConditions = string.Join(" or ", ProviderNames.Split(',').Select(x => $"@Name = '{x.Trim()}'"));
conditions.Add($"Provider[{providerConditions}]");
}
if (UseFilterByLevel)
{
var levelConditions = new List<string>();
if(IsCriticalChecked)
{
levelConditions.Add("Level=1");
}
if(IsErrorChecked)
{
levelConditions.Add("Level=2");
}
if(IsWarningChecked)
{
levelConditions.Add("Level=3");
}
if(IsInformationChecked)
{
levelConditions.Add("Level=4");
}
if(IsVerboseChecked)
{
levelConditions.Add("Level=5");
}
if (levelConditions.Count > 0)
{
conditions.Add($"({string.Join(" or ", levelConditions)})");
}
}
if (conditions.Count > 0)
{
return $"*[System[{string.Join(" and ", conditions)}]]";
Expand Down Expand Up @@ -304,5 +325,28 @@ public bool UseProviderNames
}
}
public string ProviderNames { get; set; } = string.Empty;
bool _UseFilterByLevel = false;
public bool UseFilterByLevel
{
get => _UseFilterByLevel;
set
{
var changed = _UseFilterByLevel != value;
_UseFilterByLevel = value;
if (changed)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(UseFilterByLevel)));
if(UseRawQuery && value)
{
UseRawQuery = false;
}
}
}
}
public bool IsCriticalChecked { get; set; } = false;
public bool IsErrorChecked { get; set; } = false;
public bool IsWarningChecked { get; set; } = false;
public bool IsInformationChecked { get; set; } = false;
public bool IsVerboseChecked { get; set; } = false;
}
}

0 comments on commit e8561b3

Please sign in to comment.