Skip to content

Commit 4810e53

Browse files
committed
implement load cancel(#3),add license file
1 parent 788aff1 commit 4810e53

File tree

8 files changed

+124
-19
lines changed

8 files changed

+124
-19
lines changed

LICENSE-package.txt

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) AvaloniaUI OÜ
4+
All Rights Reserved
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
24+
-----------------
25+
26+
MIT License
27+
28+
Copyright (c) 2024 Cysharp, Inc.
29+
30+
Permission is hereby granted, free of charge, to any person obtaining a copy
31+
of this software and associated documentation files (the "Software"), to deal
32+
in the Software without restriction, including without limitation the rights
33+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
34+
copies of the Software, and to permit persons to whom the Software is
35+
furnished to do so, subject to the following conditions:
36+
37+
The above copyright notice and this permission notice shall be included in all
38+
copies or substantial portions of the Software.
39+
40+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
41+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
42+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
43+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
44+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
45+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
46+
SOFTWARE.

LICENSE.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 itn3000
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

WEventViewer.sln

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,32 @@ VisualStudioVersion = 17.0.31903.59
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{DBEA2004-5AF0-43F4-9B6A-F299056D87B7}"
77
EndProject
8-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WEventViewer", "src\WEventViewer\WEventViewer.csproj", "{8341A7C3-A124-45AC-88F3-943943A81854}"
8+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WEventViewer", "src\WEventViewer\WEventViewer.csproj", "{8341A7C3-A124-45AC-88F3-943943A81854}"
9+
EndProject
10+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "package-licenses", "package-licenses", "{F4A0E95C-19FB-4832-93B1-95C97940C368}"
11+
ProjectSection(SolutionItems) = preProject
12+
LICENSE-package.txt = LICENSE-package.txt
13+
LICENSE.txt = LICENSE.txt
14+
EndProjectSection
915
EndProject
1016
Global
1117
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1218
Debug|Any CPU = Debug|Any CPU
1319
Release|Any CPU = Release|Any CPU
1420
EndGlobalSection
15-
GlobalSection(SolutionProperties) = preSolution
16-
HideSolutionNode = FALSE
17-
EndGlobalSection
1821
GlobalSection(ProjectConfigurationPlatforms) = postSolution
1922
{8341A7C3-A124-45AC-88F3-943943A81854}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
2023
{8341A7C3-A124-45AC-88F3-943943A81854}.Debug|Any CPU.Build.0 = Debug|Any CPU
2124
{8341A7C3-A124-45AC-88F3-943943A81854}.Release|Any CPU.ActiveCfg = Release|Any CPU
2225
{8341A7C3-A124-45AC-88F3-943943A81854}.Release|Any CPU.Build.0 = Release|Any CPU
2326
EndGlobalSection
27+
GlobalSection(SolutionProperties) = preSolution
28+
HideSolutionNode = FALSE
29+
EndGlobalSection
2430
GlobalSection(NestedProjects) = preSolution
2531
{8341A7C3-A124-45AC-88F3-943943A81854} = {DBEA2004-5AF0-43F4-9B6A-F299056D87B7}
2632
EndGlobalSection
33+
GlobalSection(ExtensibilityGlobals) = postSolution
34+
SolutionGuid = {89C2DE27-9B07-431C-B61D-5E6A13475203}
35+
EndGlobalSection
2736
EndGlobal

src/WEventViewer/MainWindow.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="20" VerticalAlignment="Bottom">
5050
<Label Content="{Binding LogCount,Mode=OneWay}"/>
5151
<Label Content="{Binding LoadStatus,Mode=OneWay}"/>
52+
<Button Content="Cancel" Command="{Binding LoadCancelCommand}" IsVisible="{Binding IsLoading}"/>
5253
</StackPanel>
5354
</StackPanel>
5455
</Window>

src/WEventViewer/Model/EventLogRepository.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ public static LogRecord ToLogRecord(this EventRecord record)
4646
var keywordDisplayNames = GetKeywordsDisplayNames(record);
4747
var levelName = GetLevelDisplayName(record);
4848
var taskDisplayName = GetTaskDisplayName(record);
49-
var x = "hogehoge";
5049
var opcodeDisplayName = GetOpCodeDisplayName(record);
5150
return new LogRecord(record.ActivityId, record.Id, keywords, keywordDisplayNames, record.Level,
5251
levelName, record.LogName, record.MachineName, record.Opcode, opcodeDisplayName, record.ProcessId,

src/WEventViewer/ViewModel/DetailedLogViewModel.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,13 @@
1111

1212
namespace WEventViewer.ViewModel
1313
{
14-
internal class DetailedLogViewModel : INotifyPropertyChanged
14+
internal class DetailedLogViewModel
1515
{
1616
public DetailedLogViewModel() : this(null)
1717
{
1818
}
1919
LogRecord? logRecord;
2020

21-
public event PropertyChangedEventHandler? PropertyChanged;
22-
2321
public DetailedLogViewModel(LogRecord? logRecord)
2422
{
2523
this.logRecord = logRecord;

src/WEventViewer/ViewModel/MainWindowViewModel.cs

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
using Avalonia.Threading;
2121
using Avalonia.Input;
2222
using Microsoft.Extensions.DependencyInjection;
23+
using System.Threading;
24+
using R3;
2325

2426

2527
namespace WEventViewer.ViewModel
@@ -36,7 +38,9 @@ internal class MainWindowViewModel : ObservableRecipient
3638
{
3739
EventLogRepository _EventLogRepository;
3840
Task LoadTask;
39-
public MainWindowViewModel(): this(new EventLogRepository()) { }
41+
public MainWindowViewModel() : this(new EventLogRepository()) { }
42+
CancellationTokenSource LoadCancellationToken = new CancellationTokenSource();
43+
IDisposable IsLoadingSubscription;
4044
public MainWindowViewModel(EventLogRepository eventLogRepository)
4145
{
4246
LoadTask = Task.CompletedTask;
@@ -57,36 +61,55 @@ public MainWindowViewModel(EventLogRepository eventLogRepository)
5761
}, () => LoadTask == null || LoadTask.IsCompleted);
5862
WeakReferenceMessenger.Default.Register<MainWindowViewModel, LoadLogMessage>(this, (vm, msg) =>
5963
{
60-
LoadTask = _EventLogRepository.Load(msg.logName, msg.pathType, msg.query, default, (lst) =>
61-
{
62-
Dispatcher.UIThread.Invoke(() =>
64+
LoadCancellationToken.TryReset();
65+
LoadTask = _EventLogRepository.Load(msg.logName, msg.pathType, msg.query, LoadCancellationToken.Token, (lst) =>
6366
{
64-
_EventLogRepository.Records.AddRange(lst);
65-
OnPropertyChanged(nameof(LogCount));
66-
OnPropertyChanged(nameof(LogRecords));
67-
});
68-
})
67+
Dispatcher.UIThread.Invoke(() =>
68+
{
69+
_EventLogRepository.Records.AddRange(lst);
70+
OnPropertyChanged(nameof(LogCount));
71+
OnPropertyChanged(nameof(LogRecords));
72+
});
73+
})
6974
.ContinueWith(t =>
7075
{
7176
if (t.IsFaulted)
7277
{
7378
Dispatcher.UIThread.Invoke(() => WeakReferenceMessenger.Default.Send(new OpenErrorLogWindow(t.Exception.ToString())));
7479
}
80+
var oldcts = LoadCancellationToken;
81+
LoadCancellationToken = new CancellationTokenSource();
82+
oldcts?.Dispose();
83+
7584
Dispatcher.UIThread.Invoke(() =>
7685
{
7786
LoadStatus = "Complete";
7887
OnPropertyChanged(nameof(LoadStatus));
88+
_IsLoading.Value = false;
7989
});
8090
});
91+
_IsLoading.Value = true;
8192
});
8293
CloseCommand = new RelayCommand(() => WeakReferenceMessenger.Default.Send(new MainWindowCloseMessage()));
94+
LoadCancelCommand = new RelayCommand(() =>
95+
{
96+
if(!LoadCancellationToken.IsCancellationRequested)
97+
{
98+
LoadCancellationToken.Cancel();
99+
}
100+
});
83101
LoadStatus = string.Empty;
102+
IsLoadingSubscription = _IsLoading.Subscribe(_ =>
103+
{
104+
OnPropertyChanged(nameof(IsLoading));
105+
});
84106
}
85-
107+
ReactiveProperty<bool> _IsLoading = new ReactiveProperty<bool>(false);
108+
public bool IsLoading => _IsLoading.Value;
86109
Progress<long> _Progress;
87110
public ICommand OpenCommand { get; private set; }
88111
public ICommand CloseCommand { get; private set; }
89-
long _LogCount;
112+
public ICommand LoadCancelCommand { get; private set; }
90113
public long LogCount
91114
{
92115
get

src/WEventViewer/WEventViewer.csproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,12 @@
2727
<ItemGroup>
2828
<UpToDateCheckInput Remove="DetailedLogMessageWIndow.axaml" />
2929
</ItemGroup>
30+
<ItemGroup>
31+
<None Include="$(MSBuildThisFileDirectory)\..\..\LICENSE-package.txt">
32+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
33+
</None>
34+
<None Include="$(MSBuildThisFileDirectory)\..\..\LICENSE.txt">
35+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
36+
</None>
37+
</ItemGroup>
3038
</Project>

0 commit comments

Comments
 (0)