Skip to content

Commit 531fd57

Browse files
committed
* Adde ability to view application logs
* Automatic scrolling in application log widow * Minor code fixes
1 parent b2ce3f7 commit 531fd57

File tree

7 files changed

+146
-17
lines changed

7 files changed

+146
-17
lines changed

MemPlus/Classes/LOG/Log.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ public abstract class Log : ILogMethods
99
/// </summary>
1010
internal LogType LogType { get; set; }
1111

12-
protected DateTime Time;
13-
protected string Data;
12+
public DateTime Time { get; set; }
13+
public string Data { get; set; }
1414

1515
public DateTime GetDate()
1616
{

MemPlus/Classes/LOG/LogController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace MemPlus.Classes.LOG
55
{
6-
internal class LogController
6+
public class LogController
77
{
88
private readonly List<Log> _logList;
99
internal delegate void LogAdded(Log l);

MemPlus/MemPlus.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@
6161
<Generator>MSBuild:Compile</Generator>
6262
<SubType>Designer</SubType>
6363
</ApplicationDefinition>
64+
<Page Include="Windows\ApplicationLogWindow.xaml">
65+
<SubType>Designer</SubType>
66+
<Generator>MSBuild:Compile</Generator>
67+
</Page>
6468
<Page Include="Windows\MainWindow.xaml">
6569
<Generator>MSBuild:Compile</Generator>
6670
<SubType>Designer</SubType>
@@ -76,6 +80,9 @@
7680
<Compile Include="Classes\RAM\RamController.cs" />
7781
<Compile Include="Classes\RAM\MemPlus.cs" />
7882
<Compile Include="Classes\GUI\StyleManager.cs" />
83+
<Compile Include="Windows\ApplicationLogWindow.xaml.cs">
84+
<DependentUpon>ApplicationLogWindow.xaml</DependentUpon>
85+
</Compile>
7986
<Compile Include="Windows\MainWindow.xaml.cs">
8087
<DependentUpon>MainWindow.xaml</DependentUpon>
8188
<SubType>Code</SubType>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<syncfusion:ChromelessWindow
2+
x:Class="MemPlus.Windows.ApplicationLogWindow"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
7+
xmlns:local="clr-namespace:MemPlus.Windows"
8+
xmlns:syncfusion="http://schemas.syncfusion.com/wpf"
9+
mc:Ignorable="d"
10+
UseLayoutRounding="True"
11+
WindowStartupLocation="CenterScreen"
12+
TitleTextAlignment="Center"
13+
Title="MemPlus - Application Logs" Height="300" Width="300">
14+
<Grid>
15+
<Grid.RowDefinitions>
16+
<RowDefinition></RowDefinition>
17+
<RowDefinition Height="Auto"></RowDefinition>
18+
</Grid.RowDefinitions>
19+
<ListView x:Name="LsvLogs" ScrollBar.Scroll="LsvLogs_OnScroll">
20+
<ListView.View>
21+
<GridView x:Name="DynGrid">
22+
<GridViewColumn Header="Date" DisplayMemberBinding="{Binding Time}" />
23+
<GridViewColumn Header="Content" DisplayMemberBinding="{Binding Data}" />
24+
</GridView>
25+
</ListView.View>
26+
</ListView>
27+
</Grid>
28+
</syncfusion:ChromelessWindow>
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
using System;
2+
using System.Diagnostics;
3+
using System.Linq;
4+
using System.Windows;
5+
using System.Windows.Controls;
6+
using System.Windows.Controls.Primitives;
7+
using MemPlus.Classes;
8+
using MemPlus.Classes.LOG;
9+
10+
namespace MemPlus.Windows
11+
{
12+
/// <inheritdoc cref="Syncfusion.Windows.Shared.ChromelessWindow" />
13+
/// <summary>
14+
/// Interaction logic for ApplicationLogWindow.xaml
15+
/// </summary>
16+
public partial class ApplicationLogWindow
17+
{
18+
19+
private readonly LogController _logController;
20+
private bool _autoScroll;
21+
22+
public ApplicationLogWindow(LogController logController)
23+
{
24+
_logController = logController;
25+
26+
_logController.AddLog(new ApplicationLog("Initializing Application Log Window"));
27+
28+
InitializeComponent();
29+
ChangeVisualStyle();
30+
31+
_logController.AddLog(new ApplicationLog("Done initializing Application Log Window"));
32+
33+
FillLogView();
34+
35+
_logController.LogAddedEvent += LogAddedEvent;
36+
_logController.LogClearedEvent += LogClearedEvent;
37+
_logController.LogDeletedEvent += LogDeletedEvent;
38+
39+
_autoScroll = true;
40+
}
41+
42+
private void FillLogView()
43+
{
44+
foreach (Log l in _logController.GetLogs().Where(l => l.LogType == LogType.Application))
45+
{
46+
LsvLogs.Items.Add(l);
47+
}
48+
}
49+
50+
private void LogDeletedEvent(Log log)
51+
{
52+
if (log.LogType != LogType.Application) return;
53+
LsvLogs.Items.Remove(log);
54+
}
55+
56+
private void LogClearedEvent()
57+
{
58+
LsvLogs.Items.Clear();
59+
}
60+
61+
private void LogAddedEvent(Log log)
62+
{
63+
Dispatcher.Invoke(() =>
64+
{
65+
LsvLogs.Items.Add(log);
66+
67+
if (_autoScroll)
68+
{
69+
LsvLogs.SelectedIndex = LsvLogs.Items.Count - 1;
70+
LsvLogs.ScrollIntoView(LsvLogs.SelectedItem);
71+
}
72+
});
73+
}
74+
75+
private void ChangeVisualStyle()
76+
{
77+
_logController.AddLog(new ApplicationLog("Changing MainWindow theme style"));
78+
StyleManager.ChangeStyle(this);
79+
_logController.AddLog(new ApplicationLog("Done changing MainWindow theme style"));
80+
}
81+
82+
private void LsvLogs_OnScroll(object sender, ScrollEventArgs e)
83+
{
84+
ScrollBar sb = e.OriginalSource as ScrollBar;
85+
86+
if (sb != null && sb.Orientation == Orientation.Horizontal)
87+
return;
88+
_autoScroll = Math.Abs(sb.Value - sb.Maximum) < 1;
89+
}
90+
}
91+
}

MemPlus/Windows/MainWindow.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@
2323
<MenuItem Header="Application logs" />
2424
</MenuItem>
2525
<Separator />
26-
<MenuItem Header="Exit" />
26+
<MenuItem Header="Exit" Click="ExitMenuItem_OnClick" />
2727
</MenuItem>
2828

2929
<MenuItem Header="_Tools">
3030
<MenuItem Header="RAM Analyzer"></MenuItem>
3131
<Separator />
3232
<MenuItem Header="Logs">
3333
<MenuItem Header="RAM Optimizer log" />
34-
<MenuItem Header="Application logs" />
34+
<MenuItem Header="Application logs" Click="ApplicationLogsMenuItem_OnClick" />
3535
<Separator />
3636
<MenuItem Header="Clear" Click="ClearLogsMenuItem_OnClick" />
3737
</MenuItem>

MemPlus/Windows/MainWindow.xaml.cs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ public partial class MainWindow
2020
public MainWindow()
2121
{
2222
_logController = new LogController();
23-
_logController.AddLog(new ApplicationLog("Initializing MemPlus"));
24-
25-
_logController.LogAddedEvent += LogAddedEvent;
23+
_logController.AddLog(new ApplicationLog("Initializing MainWindow"));
2624

2725
InitializeComponent();
2826
ChangeVisualStyle();
@@ -34,7 +32,7 @@ public MainWindow()
3432
app.Activated += Active;
3533
app.Deactivated += Passive;
3634

37-
_logController.AddLog(new ApplicationLog("Done initializing MemPlus"));
35+
_logController.AddLog(new ApplicationLog("Done initializing MainWindow"));
3836
}
3937

4038
private void Active(object sender, EventArgs args)
@@ -48,21 +46,16 @@ private void Passive(object sender, EventArgs args)
4846
_ramController.DisableMonitor();
4947
Overlay.Visibility = Visibility.Visible;
5048
}
51-
52-
private static void LogAddedEvent(Log log)
53-
{
54-
if (log.LogType != LogType.Application) return;
55-
Console.WriteLine("[" + log.GetDate() + "] " + log.GetData());
56-
}
49+
5750

5851
internal void ChangeVisualStyle()
5952
{
60-
_logController.AddLog(new ApplicationLog("Changing MemPlus theme style"));
53+
_logController.AddLog(new ApplicationLog("Changing MainWindow theme style"));
6154

6255
StyleManager.ChangeStyle(this);
6356
CgRamUsage.Scales[0].Ranges[0].Stroke = new SolidColorBrush(Properties.Settings.Default.MetroColor);
6457

65-
_logController.AddLog(new ApplicationLog("Done changing MemPlus theme style"));
58+
_logController.AddLog(new ApplicationLog("Done changing MainWindow theme style"));
6659
}
6760

6861
private async void BtnClearMemory_OnClick(object sender, RoutedEventArgs e)
@@ -98,5 +91,15 @@ private void ClearLogsMenuItem_OnClick(object sender, RoutedEventArgs e)
9891
{
9992
_logController.ClearLogs();
10093
}
94+
95+
private void ExitMenuItem_OnClick(object sender, RoutedEventArgs e)
96+
{
97+
Application.Current.Shutdown();
98+
}
99+
100+
private void ApplicationLogsMenuItem_OnClick(object sender, RoutedEventArgs e)
101+
{
102+
new ApplicationLogWindow(_logController).ShowDialog();
103+
}
101104
}
102105
}

0 commit comments

Comments
 (0)