Skip to content

Commit a69b32d

Browse files
authored
Fix: Refactor network connection & other dashboards (#2846)
* Fix: Refactor network connection & other dashboards * Fix: Network connection check * Chore: Add logging * Fix: Run command animation * Fix: Start & cancel network check tasks * Chore: Enhance logging
1 parent 02acfe0 commit a69b32d

20 files changed

+364
-254
lines changed

Source/NETworkManager.Models/Generated Files/CsWinRT/WinRTEventHelpers.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//------------------------------------------------------------------------------
22
// <auto-generated>
3-
// This file was generated by cswinrt.exe version 2.0.8.240703.1
3+
// This file was generated by cswinrt.exe version 2.1.3.240909.1
44
//
55
// Changes to this file may cause incorrect behavior and will be lost if
66
// the code is regenerated.

Source/NETworkManager.Settings/GlobalStaticConfiguration.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
using System;
2-
using System.IO;
3-
using System.Linq;
4-
using DnsClient;
1+
using DnsClient;
52
using Lextm.SharpSnmpLib.Messaging;
63
using NETworkManager.Models;
74
using NETworkManager.Models.Export;
@@ -10,6 +7,9 @@
107
using NETworkManager.Models.PuTTY;
118
using NETworkManager.Models.RemoteDesktop;
129
using NETworkManager.Utilities;
10+
using System;
11+
using System.IO;
12+
using System.Linq;
1313

1414
// ReSharper disable InconsistentNaming
1515

@@ -22,8 +22,8 @@ public static class GlobalStaticConfiguration
2222
// Type to search (average type speed --> 187 chars/min)
2323
public static TimeSpan SearchDispatcherTimerTimeSpan => new(0, 0, 0, 0, 750);
2424

25-
// Status window delay in ms
26-
public static int StatusWindowDelayBeforeOpen => 5000;
25+
// Network config
26+
public static int NetworkChangeDetectionDelay => 5000;
2727

2828
// Profile config
2929
public static bool Profile_ExpandProfileView => true;

Source/NETworkManager.Utilities/DNSClient.cs

+7-7
Original file line numberDiff line numberDiff line change
@@ -40,31 +40,31 @@ public void Configure(DNSClientSettings settings)
4040
{
4141
_settings = settings;
4242

43-
Log.Debug("Configuring DNS client...");
43+
Log.Debug("Configure - Configuring DNS client...");
4444

4545
if (_settings.UseCustomDNSServers)
4646
{
47-
Log.Debug("Using custom DNS servers...");
47+
Log.Debug("Configure - Using custom DNS servers...");
4848

4949
// Setup custom DNS servers
5050
List<NameServer> servers = [];
5151

5252
foreach (var (server, port) in _settings.DNSServers)
5353
{
54-
Log.Debug($"Adding custom DNS server: {server}:{port}");
54+
Log.Debug($"Configure - Adding custom DNS server: {server}:{port}");
5555
servers.Add(new IPEndPoint(IPAddress.Parse(server), port));
5656
}
5757

58-
Log.Debug("Creating LookupClient with custom DNS servers...");
58+
Log.Debug("Configure - Creating LookupClient with custom DNS servers...");
5959
_client = new LookupClient(new LookupClientOptions(servers.ToArray()));
6060
}
6161
else
6262
{
63-
Log.Debug("Creating LookupClient with Windows default DNS servers...");
63+
Log.Debug("Configure - Creating LookupClient with Windows default DNS servers...");
6464
_client = new LookupClient();
6565
}
6666

67-
Log.Debug("DNS client configured.");
67+
Log.Debug("Configure - DNS client configured.");
6868
_isConfigured = true;
6969
}
7070

@@ -74,7 +74,7 @@ public void Configure(DNSClientSettings settings)
7474
/// </summary>
7575
public void UpdateWindowsDNSSever()
7676
{
77-
Log.Debug("Recreating LookupClient with with Windows default DNS servers...");
77+
Log.Debug("UpdateWindowsDNSSever - Recreating LookupClient with with Windows default DNS servers...");
7878
_client = new LookupClient();
7979
}
8080

Source/NETworkManager/App.xaml.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,8 @@ private void Application_Exit(object sender, ExitEventArgs e)
244244
if (_singleInstanceClose || CommandLineManager.Current.Help)
245245
return;
246246

247-
Log.Info("Stop background job (if it exists)...");
247+
Log.Info("Stop background job, if it exists...");
248+
248249
_dispatcherTimer?.Stop();
249250

250251
Save();

Source/NETworkManager/Generated Files/CsWinRT/WinRTEventHelpers.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//------------------------------------------------------------------------------
22
// <auto-generated>
3-
// This file was generated by cswinrt.exe version 2.0.8.240703.1
3+
// This file was generated by cswinrt.exe version 2.1.3.240909.1
44
//
55
// Changes to this file may cause incorrect behavior and will be lost if
66
// the code is regenerated.

Source/NETworkManager/MainWindow.xaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@
237237
<mah:FlyoutsControl>
238238
<mah:Flyout IsKeyboardFocusWithinChanged="FlyoutRunCommand_IsKeyboardFocusWithinChanged"
239239
IsOpen="{Binding FlyoutRunCommandIsOpen, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
240-
AreAnimationsEnabled="{Binding FlyoutRunCommandAreAnimationsEnabled, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
240+
AreAnimationsEnabled="False"
241241
Visibility="{Binding FlyoutRunCommandIsOpen, Converter={StaticResource BooleanToVisibilityConverter}}"
242242
Position="Top"
243243
TitleVisibility="Collapsed"

Source/NETworkManager/MainWindow.xaml.cs

+26-46
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
1-
using System;
1+
using log4net;
2+
using MahApps.Metro.Controls.Dialogs;
3+
using NETworkManager.Controls;
4+
using NETworkManager.Documentation;
5+
using NETworkManager.Localization;
6+
using NETworkManager.Localization.Resources;
7+
using NETworkManager.Models;
8+
using NETworkManager.Models.AWS;
9+
using NETworkManager.Models.EventSystem;
10+
using NETworkManager.Models.Network;
11+
using NETworkManager.Models.PowerShell;
12+
using NETworkManager.Models.PuTTY;
13+
using NETworkManager.Profiles;
14+
using NETworkManager.Settings;
15+
using NETworkManager.Update;
16+
using NETworkManager.Utilities;
17+
using NETworkManager.ViewModels;
18+
using NETworkManager.Views;
19+
using System;
220
using System.Collections.Generic;
321
using System.Collections.ObjectModel;
422
using System.ComponentModel;
@@ -19,24 +37,6 @@
1937
using System.Windows.Interop;
2038
using System.Windows.Markup;
2139
using System.Windows.Threading;
22-
using log4net;
23-
using MahApps.Metro.Controls.Dialogs;
24-
using NETworkManager.Controls;
25-
using NETworkManager.Documentation;
26-
using NETworkManager.Localization;
27-
using NETworkManager.Localization.Resources;
28-
using NETworkManager.Models;
29-
using NETworkManager.Models.AWS;
30-
using NETworkManager.Models.EventSystem;
31-
using NETworkManager.Models.Network;
32-
using NETworkManager.Models.PowerShell;
33-
using NETworkManager.Models.PuTTY;
34-
using NETworkManager.Profiles;
35-
using NETworkManager.Settings;
36-
using NETworkManager.Update;
37-
using NETworkManager.Utilities;
38-
using NETworkManager.ViewModels;
39-
using NETworkManager.Views;
4040
using Application = System.Windows.Application;
4141
using ContextMenu = System.Windows.Controls.ContextMenu;
4242
using MouseEventArgs = System.Windows.Forms.MouseEventArgs;
@@ -329,21 +329,6 @@ public bool FlyoutRunCommandIsOpen
329329
}
330330
}
331331

332-
private bool _flyoutRunCommandAreAnimationsEnabled;
333-
334-
public bool FlyoutRunCommandAreAnimationsEnabled
335-
{
336-
get => _flyoutRunCommandAreAnimationsEnabled;
337-
set
338-
{
339-
if (value == _flyoutRunCommandAreAnimationsEnabled)
340-
return;
341-
342-
_flyoutRunCommandAreAnimationsEnabled = value;
343-
OnPropertyChanged();
344-
}
345-
}
346-
347332
private bool _isRestartRequired;
348333

349334
public bool IsRestartRequired
@@ -701,7 +686,7 @@ private void LoadApplicationList()
701686
// Select the application
702687
// Set application via command line, or select the default one, fallback to the first visible one
703688
var applicationList = Applications.Cast<ApplicationInfo>().ToArray();
704-
689+
705690
if (CommandLineManager.Current.Application != ApplicationName.None)
706691
SelectedApplication = applicationList.FirstOrDefault(x => x.Name == CommandLineManager.Current.Application);
707692
else
@@ -1244,7 +1229,6 @@ private void OpenRunAction()
12441229
{
12451230
ConfigurationManager.OnDialogOpen();
12461231

1247-
FlyoutRunCommandAreAnimationsEnabled = true;
12481232
FlyoutRunCommandIsOpen = true;
12491233
}
12501234

@@ -1259,7 +1243,7 @@ private void RunCommandDoAction()
12591243

12601244
private void RunCommandCloseAction()
12611245
{
1262-
RunCommandFlyoutClose().ConfigureAwait(false);
1246+
RunCommandFlyoutClose();
12631247
}
12641248

12651249
#endregion
@@ -1321,28 +1305,24 @@ private void RunCommandDo()
13211305
}
13221306

13231307
// Close the flyout
1324-
RunCommandFlyoutClose(true).ConfigureAwait(false);
1308+
RunCommandFlyoutClose(true);
13251309
}
13261310

13271311
/// <summary>
13281312
/// Close the run command flyout and clear the search.
13291313
/// </summary>
1330-
private async Task RunCommandFlyoutClose(bool clearSearch = false)
1314+
private void RunCommandFlyoutClose(bool clearSearch = false)
13311315
{
13321316
if (!FlyoutRunCommandIsOpen)
13331317
return;
1334-
1335-
FlyoutRunCommandAreAnimationsEnabled = false;
1318+
13361319
FlyoutRunCommandIsOpen = false;
13371320

13381321
ConfigurationManager.OnDialogClose();
13391322

13401323
// Clear the search
13411324
if (clearSearch)
1342-
{
1343-
await Task.Delay(500); // Wait for the animation to finish
13441325
RunCommandSearch = string.Empty;
1345-
}
13461326
}
13471327

13481328
#endregion
@@ -1360,7 +1340,7 @@ private void FlyoutRunCommand_IsKeyboardFocusWithinChanged(object sender, Depend
13601340
if (e.NewValue is not false)
13611341
return;
13621342

1363-
RunCommandFlyoutClose().ConfigureAwait(false);
1343+
RunCommandFlyoutClose();
13641344
}
13651345

13661346
#endregion
@@ -1946,7 +1926,7 @@ private async void OnNetworkHasChanged()
19461926
_isNetworkChanging = true;
19471927

19481928
// Wait, because the event may be triggered several times.
1949-
await Task.Delay(GlobalStaticConfiguration.StatusWindowDelayBeforeOpen);
1929+
await Task.Delay(GlobalStaticConfiguration.NetworkChangeDetectionDelay);
19501930

19511931
Log.Info("Network availability or address has changed!");
19521932

Source/NETworkManager/StatusWindow.xaml.cs

+18-8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Windows.Forms;
55
using System.Windows.Input;
66
using System.Windows.Threading;
7+
using log4net;
78
using NETworkManager.Settings;
89
using NETworkManager.Utilities;
910
using NETworkManager.Views;
@@ -42,7 +43,7 @@ private void OnPropertyChanged([CallerMemberName] string propertyName = null)
4243
#endregion
4344

4445
#region Variables
45-
46+
4647
// Set priority to make the ui smoother
4748
private readonly DispatcherTimer _dispatcherTimerClose = new(DispatcherPriority.Normal);
4849

@@ -102,7 +103,7 @@ public int Time
102103

103104
private void ReloadAction()
104105
{
105-
Reload();
106+
Check();
106107
}
107108

108109
public ICommand ShowMainWindowCommand => new RelayCommand(_ => ShowMainWindowAction());
@@ -126,9 +127,9 @@ private void CloseAction()
126127

127128
#region Methods
128129

129-
private void Reload()
130+
private void Check()
130131
{
131-
_networkConnectionView.Reload();
132+
_networkConnectionView.Check();
132133
}
133134

134135
/// <summary>
@@ -137,19 +138,28 @@ private void Reload()
137138
/// <param name="enableCloseTimer">Automatically close the window after a certain time.</param>
138139
public void ShowWindow(bool enableCloseTimer = false)
139140
{
140-
// Show on primary screen in left/bottom corner
141+
// Set window position on primary screen
141142
// ToDo: User setting...
142-
Left = Screen.PrimaryScreen.WorkingArea.Right - Width - 10;
143-
Top = Screen.PrimaryScreen.WorkingArea.Bottom - Height - 10;
143+
if (Screen.PrimaryScreen != null)
144+
{
145+
Left = Screen.PrimaryScreen.WorkingArea.Right - Width - 10;
146+
Top = Screen.PrimaryScreen.WorkingArea.Bottom - Height - 10;
147+
}
144148

149+
// Show the window
145150
Show();
146-
151+
152+
// Check the network connection
153+
Check();
154+
155+
// Close the window after a certain time
147156
if (enableCloseTimer)
148157
{
149158
SetupCloseTimer();
150159
return;
151160
}
152161

162+
// Focus the window
153163
Activate();
154164
}
155165

Source/NETworkManager/ViewModels/DashboardViewModel.cs

+3
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@ public DashboardViewModel()
99

1010
private void LoadSettings()
1111
{
12+
1213
}
1314

1415
public void OnViewVisible()
1516
{
17+
1618
}
1719

1820
public void OnViewHide()
1921
{
22+
2023
}
2124
}

Source/NETworkManager/ViewModels/IPApiDNSResolverWidgetViewModel.cs

+2-27
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System.ComponentModel;
2-
using System.Net.NetworkInformation;
3-
using System.Threading.Tasks;
1+
using System.Threading.Tasks;
42
using System.Windows.Input;
53
using NETworkManager.Models.IPApi;
64
using NETworkManager.Settings;
@@ -10,23 +8,6 @@ namespace NETworkManager.ViewModels;
108

119
public class IPApiDNSResolverWidgetViewModel : ViewModelBase
1210
{
13-
#region Events
14-
15-
private void SettingsManager_PropertyChanged(object sender, PropertyChangedEventArgs e)
16-
{
17-
switch (e.PropertyName)
18-
{
19-
case nameof(SettingsInfo.Dashboard_CheckIPApiDNSResolver):
20-
// Check if enabled via settings
21-
if (SettingsManager.Current.Dashboard_CheckIPApiDNSResolver)
22-
Check();
23-
24-
break;
25-
}
26-
}
27-
28-
#endregion
29-
3011
#region Variables
3112

3213
private bool _isRunning;
@@ -65,18 +46,12 @@ private set
6546

6647
public IPApiDNSResolverWidgetViewModel()
6748
{
68-
// Detect if network address or status changed...
69-
NetworkChange.NetworkAvailabilityChanged += (_, _) => Check();
70-
NetworkChange.NetworkAddressChanged += (_, _) => Check();
71-
7249
LoadSettings();
73-
74-
// Detect if settings have changed...
75-
SettingsManager.Current.PropertyChanged += SettingsManager_PropertyChanged;
7650
}
7751

7852
private void LoadSettings()
7953
{
54+
8055
}
8156

8257
#endregion

0 commit comments

Comments
 (0)