Skip to content

Commit 73bc9db

Browse files
committed
wip commit
1 parent b91aaee commit 73bc9db

File tree

4 files changed

+58
-6
lines changed

4 files changed

+58
-6
lines changed

src/WEventViewer/MainWindow.axaml.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
using Avalonia.Controls;
2+
using CommunityToolkit.Mvvm.Input;
3+
using CommunityToolkit.Mvvm.Messaging;
4+
using WEventViewer.ViewModel;
25

36
namespace WEventViewer;
47

@@ -7,5 +10,15 @@ public partial class MainWindow : Window
710
public MainWindow()
811
{
912
InitializeComponent();
13+
WeakReferenceMessenger.Default.Register<MainWindow, OpenLogRequest>(this, async (recpient, req) =>
14+
{
15+
var vm = new OpenLogWindowViewModel();
16+
var dlg = new OpenLogWindow()
17+
{
18+
DataContext = vm
19+
};
20+
await dlg.ShowDialog(this);
21+
22+
});
1023
}
1124
}

src/WEventViewer/Model/EventLogRepository.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,11 @@ internal class EventLogRepository
4747
{
4848
List<LogRecord> records = [];
4949
public IEnumerable<LogRecord> Records => records;
50-
public async Task Load(string logName, PathType pathType, string query, CancellationToken token)
50+
public async Task Load(string logName, PathType pathType, string? query, CancellationToken token, IProgress<long> progress)
5151
{
5252
var lst = new List<LogRecord>();
5353
using var evreader = new EventLogReader(new EventLogQuery(logName, pathType, query));
54+
long count = 0;
5455
while(!token.IsCancellationRequested)
5556
{
5657
await Task.Yield();
@@ -60,7 +61,13 @@ public async Task Load(string logName, PathType pathType, string query, Cancella
6061
break;
6162
}
6263
lst.Add(record.ToLogRecord());
64+
count++;
65+
if((count & 0xff) == 0)
66+
{
67+
progress?.Report(count);
68+
}
6369
}
70+
progress?.Report(count);
6471
while(!token.IsCancellationRequested)
6572
{
6673
var old = records;

src/WEventViewer/ViewModel/MainWindowViewModel.cs

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,51 @@
44
using System.Text;
55
using System.Threading.Tasks;
66
using Avalonia.Controls;
7+
using CommunityToolkit.Mvvm.DependencyInjection;
78
using CommunityToolkit.Mvvm.Input;
89
using CommunityToolkit.Mvvm.Messaging;
10+
using CommunityToolkit.Mvvm.Collections;
911
using System.Windows.Input;
1012
using WEventViewer.Model;
13+
using System.Diagnostics.Eventing.Reader;
14+
using System.Diagnostics.Eventing;
15+
using System.Collections.ObjectModel;
1116

1217
namespace WEventViewer.ViewModel
1318
{
19+
class OpenLogRequest(MainWindowViewModel vm, string logName, PathType pathType)
20+
{
21+
public string LogName => logName;
22+
public PathType PathType => pathType;
23+
}
1424
internal class MainWindowViewModel
1525
{
16-
record class OpenLogMessage(MainWindowViewModel vm);
1726
EventLogRepository? _EventLogRepository;
1827
public MainWindowViewModel(): this(null)
1928
{
2029
}
2130
public MainWindowViewModel(EventLogRepository repository)
2231
{
23-
OpenCommand = new RelayCommand(() =>
32+
_Progress = new Progress<long>(l => LogCount = l);
33+
_EventLogRepository = repository;
34+
OpenCommand = new RelayCommand(async () =>
2435
{
25-
var ret = WeakReferenceMessenger.Default.Send<OpenLogMessage>(new(this));
36+
var ret = WeakReferenceMessenger.Default.Send<OpenLogRequest>(new OpenLogRequest(this, "", PathType.LogName));
37+
await _EventLogRepository.Load(ret.LogName, ret.PathType, null, default, _Progress);
2638
});
27-
_EventLogRepository = repository;
2839
}
40+
Progress<long> _Progress;
2941
public ICommand OpenCommand;
42+
long _LogCount;
43+
public long LogCount
44+
{
45+
get => _LogCount;
46+
set
47+
{
48+
_LogCount = value;
49+
50+
}
51+
}
52+
public ObservableCollection<LogRecord> LogRecords;
3053
}
3154
}

src/WEventViewer/ViewModel/OpenLogWindowViewModel.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Avalonia.Data.Converters;
2+
using CommunityToolkit.Mvvm.Input;
23
using System;
34
using System.Collections.Generic;
45
using System.ComponentModel;
@@ -7,6 +8,7 @@
78
using System.Linq;
89
using System.Text;
910
using System.Threading.Tasks;
11+
using System.Windows.Input;
1012

1113
namespace WEventViewer.ViewModel
1214
{
@@ -67,7 +69,14 @@ public PathType PathType
6769
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(PathType)));
6870
}
6971
}
70-
72+
public OpenLogWindowViewModel()
73+
{
74+
IsOk = false;
75+
OkCommand = new RelayCommand(() => IsOk = true);
76+
}
77+
public bool IsOk;
78+
public ICommand OkCommand;
7179
public event PropertyChangedEventHandler? PropertyChanged;
80+
7281
}
7382
}

0 commit comments

Comments
 (0)