diff --git a/Source/NETworkManager.Models/Generated Files/CsWinRT/WinRTEventHelpers.cs b/Source/NETworkManager.Models/Generated Files/CsWinRT/WinRTEventHelpers.cs index 723dfc26f4..41efc07a13 100644 --- a/Source/NETworkManager.Models/Generated Files/CsWinRT/WinRTEventHelpers.cs +++ b/Source/NETworkManager.Models/Generated Files/CsWinRT/WinRTEventHelpers.cs @@ -1,6 +1,6 @@ //------------------------------------------------------------------------------ // -// This file was generated by cswinrt.exe version 2.0.8.240703.1 +// This file was generated by cswinrt.exe version 2.1.3.240909.1 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. diff --git a/Source/NETworkManager.Settings/GlobalStaticConfiguration.cs b/Source/NETworkManager.Settings/GlobalStaticConfiguration.cs index 3f5fc1fd14..e6e408d2ee 100644 --- a/Source/NETworkManager.Settings/GlobalStaticConfiguration.cs +++ b/Source/NETworkManager.Settings/GlobalStaticConfiguration.cs @@ -1,7 +1,4 @@ -using System; -using System.IO; -using System.Linq; -using DnsClient; +using DnsClient; using Lextm.SharpSnmpLib.Messaging; using NETworkManager.Models; using NETworkManager.Models.Export; @@ -10,6 +7,9 @@ using NETworkManager.Models.PuTTY; using NETworkManager.Models.RemoteDesktop; using NETworkManager.Utilities; +using System; +using System.IO; +using System.Linq; // ReSharper disable InconsistentNaming @@ -22,8 +22,8 @@ public static class GlobalStaticConfiguration // Type to search (average type speed --> 187 chars/min) public static TimeSpan SearchDispatcherTimerTimeSpan => new(0, 0, 0, 0, 750); - // Status window delay in ms - public static int StatusWindowDelayBeforeOpen => 5000; + // Network config + public static int NetworkChangeDetectionDelay => 5000; // Profile config public static bool Profile_ExpandProfileView => true; diff --git a/Source/NETworkManager.Utilities/DNSClient.cs b/Source/NETworkManager.Utilities/DNSClient.cs index cd9b7d0af1..62de1e4fbc 100644 --- a/Source/NETworkManager.Utilities/DNSClient.cs +++ b/Source/NETworkManager.Utilities/DNSClient.cs @@ -40,31 +40,31 @@ public void Configure(DNSClientSettings settings) { _settings = settings; - Log.Debug("Configuring DNS client..."); + Log.Debug("Configure - Configuring DNS client..."); if (_settings.UseCustomDNSServers) { - Log.Debug("Using custom DNS servers..."); + Log.Debug("Configure - Using custom DNS servers..."); // Setup custom DNS servers List servers = []; foreach (var (server, port) in _settings.DNSServers) { - Log.Debug($"Adding custom DNS server: {server}:{port}"); + Log.Debug($"Configure - Adding custom DNS server: {server}:{port}"); servers.Add(new IPEndPoint(IPAddress.Parse(server), port)); } - Log.Debug("Creating LookupClient with custom DNS servers..."); + Log.Debug("Configure - Creating LookupClient with custom DNS servers..."); _client = new LookupClient(new LookupClientOptions(servers.ToArray())); } else { - Log.Debug("Creating LookupClient with Windows default DNS servers..."); + Log.Debug("Configure - Creating LookupClient with Windows default DNS servers..."); _client = new LookupClient(); } - Log.Debug("DNS client configured."); + Log.Debug("Configure - DNS client configured."); _isConfigured = true; } @@ -74,7 +74,7 @@ public void Configure(DNSClientSettings settings) /// public void UpdateWindowsDNSSever() { - Log.Debug("Recreating LookupClient with with Windows default DNS servers..."); + Log.Debug("UpdateWindowsDNSSever - Recreating LookupClient with with Windows default DNS servers..."); _client = new LookupClient(); } diff --git a/Source/NETworkManager/App.xaml.cs b/Source/NETworkManager/App.xaml.cs index f73c852cd5..1b95b2c5e4 100644 --- a/Source/NETworkManager/App.xaml.cs +++ b/Source/NETworkManager/App.xaml.cs @@ -244,7 +244,8 @@ private void Application_Exit(object sender, ExitEventArgs e) if (_singleInstanceClose || CommandLineManager.Current.Help) return; - Log.Info("Stop background job (if it exists)..."); + Log.Info("Stop background job, if it exists..."); + _dispatcherTimer?.Stop(); Save(); diff --git a/Source/NETworkManager/Generated Files/CsWinRT/WinRTEventHelpers.cs b/Source/NETworkManager/Generated Files/CsWinRT/WinRTEventHelpers.cs index 723dfc26f4..41efc07a13 100644 --- a/Source/NETworkManager/Generated Files/CsWinRT/WinRTEventHelpers.cs +++ b/Source/NETworkManager/Generated Files/CsWinRT/WinRTEventHelpers.cs @@ -1,6 +1,6 @@ //------------------------------------------------------------------------------ // -// This file was generated by cswinrt.exe version 2.0.8.240703.1 +// This file was generated by cswinrt.exe version 2.1.3.240909.1 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. diff --git a/Source/NETworkManager/MainWindow.xaml b/Source/NETworkManager/MainWindow.xaml index d3fb4a0ea5..76c5e17fb9 100644 --- a/Source/NETworkManager/MainWindow.xaml +++ b/Source/NETworkManager/MainWindow.xaml @@ -237,7 +237,7 @@ _flyoutRunCommandAreAnimationsEnabled; - set - { - if (value == _flyoutRunCommandAreAnimationsEnabled) - return; - - _flyoutRunCommandAreAnimationsEnabled = value; - OnPropertyChanged(); - } - } - private bool _isRestartRequired; public bool IsRestartRequired @@ -701,7 +686,7 @@ private void LoadApplicationList() // Select the application // Set application via command line, or select the default one, fallback to the first visible one var applicationList = Applications.Cast().ToArray(); - + if (CommandLineManager.Current.Application != ApplicationName.None) SelectedApplication = applicationList.FirstOrDefault(x => x.Name == CommandLineManager.Current.Application); else @@ -1244,7 +1229,6 @@ private void OpenRunAction() { ConfigurationManager.OnDialogOpen(); - FlyoutRunCommandAreAnimationsEnabled = true; FlyoutRunCommandIsOpen = true; } @@ -1259,7 +1243,7 @@ private void RunCommandDoAction() private void RunCommandCloseAction() { - RunCommandFlyoutClose().ConfigureAwait(false); + RunCommandFlyoutClose(); } #endregion @@ -1321,28 +1305,24 @@ private void RunCommandDo() } // Close the flyout - RunCommandFlyoutClose(true).ConfigureAwait(false); + RunCommandFlyoutClose(true); } /// /// Close the run command flyout and clear the search. /// - private async Task RunCommandFlyoutClose(bool clearSearch = false) + private void RunCommandFlyoutClose(bool clearSearch = false) { if (!FlyoutRunCommandIsOpen) return; - - FlyoutRunCommandAreAnimationsEnabled = false; + FlyoutRunCommandIsOpen = false; ConfigurationManager.OnDialogClose(); // Clear the search if (clearSearch) - { - await Task.Delay(500); // Wait for the animation to finish RunCommandSearch = string.Empty; - } } #endregion @@ -1360,7 +1340,7 @@ private void FlyoutRunCommand_IsKeyboardFocusWithinChanged(object sender, Depend if (e.NewValue is not false) return; - RunCommandFlyoutClose().ConfigureAwait(false); + RunCommandFlyoutClose(); } #endregion @@ -1946,7 +1926,7 @@ private async void OnNetworkHasChanged() _isNetworkChanging = true; // Wait, because the event may be triggered several times. - await Task.Delay(GlobalStaticConfiguration.StatusWindowDelayBeforeOpen); + await Task.Delay(GlobalStaticConfiguration.NetworkChangeDetectionDelay); Log.Info("Network availability or address has changed!"); diff --git a/Source/NETworkManager/StatusWindow.xaml.cs b/Source/NETworkManager/StatusWindow.xaml.cs index ffdbc2e1ca..a4184ca53b 100644 --- a/Source/NETworkManager/StatusWindow.xaml.cs +++ b/Source/NETworkManager/StatusWindow.xaml.cs @@ -4,6 +4,7 @@ using System.Windows.Forms; using System.Windows.Input; using System.Windows.Threading; +using log4net; using NETworkManager.Settings; using NETworkManager.Utilities; using NETworkManager.Views; @@ -42,7 +43,7 @@ private void OnPropertyChanged([CallerMemberName] string propertyName = null) #endregion #region Variables - + // Set priority to make the ui smoother private readonly DispatcherTimer _dispatcherTimerClose = new(DispatcherPriority.Normal); @@ -102,7 +103,7 @@ public int Time private void ReloadAction() { - Reload(); + Check(); } public ICommand ShowMainWindowCommand => new RelayCommand(_ => ShowMainWindowAction()); @@ -126,9 +127,9 @@ private void CloseAction() #region Methods - private void Reload() + private void Check() { - _networkConnectionView.Reload(); + _networkConnectionView.Check(); } /// @@ -137,19 +138,28 @@ private void Reload() /// Automatically close the window after a certain time. public void ShowWindow(bool enableCloseTimer = false) { - // Show on primary screen in left/bottom corner + // Set window position on primary screen // ToDo: User setting... - Left = Screen.PrimaryScreen.WorkingArea.Right - Width - 10; - Top = Screen.PrimaryScreen.WorkingArea.Bottom - Height - 10; + if (Screen.PrimaryScreen != null) + { + Left = Screen.PrimaryScreen.WorkingArea.Right - Width - 10; + Top = Screen.PrimaryScreen.WorkingArea.Bottom - Height - 10; + } + // Show the window Show(); - + + // Check the network connection + Check(); + + // Close the window after a certain time if (enableCloseTimer) { SetupCloseTimer(); return; } + // Focus the window Activate(); } diff --git a/Source/NETworkManager/ViewModels/DashboardViewModel.cs b/Source/NETworkManager/ViewModels/DashboardViewModel.cs index 4f56fd0f00..8bccf3a447 100644 --- a/Source/NETworkManager/ViewModels/DashboardViewModel.cs +++ b/Source/NETworkManager/ViewModels/DashboardViewModel.cs @@ -9,13 +9,16 @@ public DashboardViewModel() private void LoadSettings() { + } public void OnViewVisible() { + } public void OnViewHide() { + } } \ No newline at end of file diff --git a/Source/NETworkManager/ViewModels/IPApiDNSResolverWidgetViewModel.cs b/Source/NETworkManager/ViewModels/IPApiDNSResolverWidgetViewModel.cs index 016a95c6fa..027847f1d6 100644 --- a/Source/NETworkManager/ViewModels/IPApiDNSResolverWidgetViewModel.cs +++ b/Source/NETworkManager/ViewModels/IPApiDNSResolverWidgetViewModel.cs @@ -1,6 +1,4 @@ -using System.ComponentModel; -using System.Net.NetworkInformation; -using System.Threading.Tasks; +using System.Threading.Tasks; using System.Windows.Input; using NETworkManager.Models.IPApi; using NETworkManager.Settings; @@ -10,23 +8,6 @@ namespace NETworkManager.ViewModels; public class IPApiDNSResolverWidgetViewModel : ViewModelBase { - #region Events - - private void SettingsManager_PropertyChanged(object sender, PropertyChangedEventArgs e) - { - switch (e.PropertyName) - { - case nameof(SettingsInfo.Dashboard_CheckIPApiDNSResolver): - // Check if enabled via settings - if (SettingsManager.Current.Dashboard_CheckIPApiDNSResolver) - Check(); - - break; - } - } - - #endregion - #region Variables private bool _isRunning; @@ -65,18 +46,12 @@ private set public IPApiDNSResolverWidgetViewModel() { - // Detect if network address or status changed... - NetworkChange.NetworkAvailabilityChanged += (_, _) => Check(); - NetworkChange.NetworkAddressChanged += (_, _) => Check(); - LoadSettings(); - - // Detect if settings have changed... - SettingsManager.Current.PropertyChanged += SettingsManager_PropertyChanged; } private void LoadSettings() { + } #endregion diff --git a/Source/NETworkManager/ViewModels/IPApiIPGeolocationWidgetViewModel.cs b/Source/NETworkManager/ViewModels/IPApiIPGeolocationWidgetViewModel.cs index a81cda84a6..5f68a2c463 100644 --- a/Source/NETworkManager/ViewModels/IPApiIPGeolocationWidgetViewModel.cs +++ b/Source/NETworkManager/ViewModels/IPApiIPGeolocationWidgetViewModel.cs @@ -1,6 +1,4 @@ -using System.ComponentModel; -using System.Net.NetworkInformation; -using System.Threading.Tasks; +using System.Threading.Tasks; using System.Windows.Input; using log4net; using NETworkManager.Models.IPApi; @@ -11,23 +9,6 @@ namespace NETworkManager.ViewModels; public class IPApiIPGeolocationWidgetViewModel : ViewModelBase { - #region Events - - private void SettingsManager_PropertyChanged(object sender, PropertyChangedEventArgs e) - { - switch (e.PropertyName) - { - case nameof(SettingsInfo.Dashboard_CheckIPApiIPGeolocation): - // Check if enabled via settings - if (SettingsManager.Current.Dashboard_CheckIPApiIPGeolocation) - Check(); - - break; - } - } - - #endregion - #region Variables private static readonly ILog Log = LogManager.GetLogger(typeof(IPApiIPGeolocationWidgetViewModel)); @@ -68,14 +49,7 @@ private set public IPApiIPGeolocationWidgetViewModel() { - // Detect if network address or status changed... - NetworkChange.NetworkAvailabilityChanged += (_, _) => Check(); - NetworkChange.NetworkAddressChanged += (_, _) => Check(); - LoadSettings(); - - // Detect if settings have changed... - SettingsManager.Current.PropertyChanged += SettingsManager_PropertyChanged; } private void LoadSettings() diff --git a/Source/NETworkManager/ViewModels/NetworkConnectionWidgetViewModel.cs b/Source/NETworkManager/ViewModels/NetworkConnectionWidgetViewModel.cs index b820026a36..e03a2535f2 100644 --- a/Source/NETworkManager/ViewModels/NetworkConnectionWidgetViewModel.cs +++ b/Source/NETworkManager/ViewModels/NetworkConnectionWidgetViewModel.cs @@ -1,44 +1,23 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; +using NETworkManager.Models.Network; +using NETworkManager.Settings; +using NETworkManager.Utilities; +using System; using System.Net; using System.Net.Http; -using System.Net.NetworkInformation; using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; using System.Windows.Input; -using NETworkManager.Models.Network; -using NETworkManager.Settings; -using NETworkManager.Utilities; +using log4net; using NetworkInterface = NETworkManager.Models.Network.NetworkInterface; namespace NETworkManager.ViewModels; public class NetworkConnectionWidgetViewModel : ViewModelBase { - #region Events - - private void SettingsManager_PropertyChanged(object sender, PropertyChangedEventArgs e) - { - switch (e.PropertyName) - { - case nameof(SettingsInfo.Dashboard_CheckPublicIPAddress): - OnPropertyChanged(nameof(CheckPublicIPAddressEnabled)); - - // Check connection if enabled via settings - if (CheckPublicIPAddressEnabled) - CheckConnection(); - - break; - } - } - - #endregion - #region Variables + private static readonly ILog Log = LogManager.GetLogger(typeof(NetworkConnectionWidgetViewModel)); - private bool _isChecking; #region Computer @@ -465,14 +444,7 @@ private set public NetworkConnectionWidgetViewModel() { - // Detect if network address or status changed... - NetworkChange.NetworkAvailabilityChanged += (_, _) => CheckConnection(); - NetworkChange.NetworkAddressChanged += (_, _) => CheckConnection(); - LoadSettings(); - - // Detect if settings have changed... - SettingsManager.Current.PropertyChanged += SettingsManager_PropertyChanged; } private void LoadSettings() @@ -483,96 +455,115 @@ private void LoadSettings() #region ICommands & Actions - public ICommand CheckConnectionViaHotkeyCommand => new RelayCommand(_ => CheckConnectionViaHotkeyAction()); + public ICommand CheckViaHotkeyCommand => new RelayCommand(_ => CheckViaHotkeyAction()); - private void CheckConnectionViaHotkeyAction() + private void CheckViaHotkeyAction() { - CheckConnection(); + Check(); } #endregion #region Methods - public void CheckConnection() + public void Check() { - CheckConnectionAsync().ConfigureAwait(false); + CheckAsync().ConfigureAwait(false); } - - private CancellationTokenSource _tokenSource; - private CancellationToken _ct; - - private async Task CheckConnectionAsync() + + private CancellationTokenSource _cancellationTokenSource; + private Task _checkTask = Task.CompletedTask; + + private async Task CheckAsync() { - // Already in queue - if (_tokenSource is { IsCancellationRequested: true }) - return; - - // Cancel if running - if (_isChecking) + Log.Info("Checking network connection..."); + + // Cancel previous checks if running + if(!_checkTask.IsCompleted) { - _tokenSource.Cancel(); - - while (_isChecking) await Task.Delay(250, _ct); + Log.Info("Cancelling previous checks..."); + await _cancellationTokenSource.CancelAsync(); + + try + { + await _checkTask; + } + catch(OperationCanceledException) + { + Log.Info("Task was cancelled from previous checks."); + } + finally + { + _cancellationTokenSource.Dispose(); + } } - - // Start check - _isChecking = true; - - _tokenSource = new CancellationTokenSource(); - _ct = _tokenSource.Token; + + _cancellationTokenSource = new CancellationTokenSource(); + var wasCanceled = false; try { - await Task.Run(async () => - { - List tasks = new() - { - CheckConnectionComputerAsync(_ct), - CheckConnectionRouterAsync(_ct), - CheckConnectionInternetAsync(_ct) - }; - - await Task.WhenAll(tasks); - }, _tokenSource.Token); + _checkTask = RunTask(_cancellationTokenSource.Token); + await _checkTask; } catch (OperationCanceledException) { + wasCanceled = true; + Log.Info("Task was cancelled from current checks."); } finally { - _tokenSource.Dispose(); - _isChecking = false; + if (!wasCanceled) + Log.Info("Network connection check completed."); } } - + + private async Task RunTask(CancellationToken ct) + { + await Task.WhenAll( + CheckConnectionComputerAsync(ct), + CheckConnectionRouterAsync(ct), + CheckConnectionInternetAsync(ct) + ); + } + private Task CheckConnectionComputerAsync(CancellationToken ct) { return Task.Run(async () => { + Log.Debug("CheckConnectionComputerAsync - Checking local connection..."); + // Init variables IsComputerIPv4Checking = true; ComputerIPv4 = ""; ComputerIPv4State = ConnectionState.None; + IsComputerIPv6Checking = true; ComputerIPv6 = ""; ComputerIPv6State = ConnectionState.None; + IsComputerDNSChecking = true; ComputerDNS = ""; ComputerDNSState = ConnectionState.None; // Detect local IPv4 address + Log.Debug("CheckConnectionComputerAsync - Detecting local IPv4 address..."); + var detectedLocalIPv4Address = await NetworkInterface.DetectLocalIPAddressBasedOnRoutingAsync( IPAddress.Parse(SettingsManager.Current.Dashboard_PublicIPv4Address)); if (detectedLocalIPv4Address != null) { + Log.Debug("CheckConnectionComputerAsync - Local IPv4 address detected: " + detectedLocalIPv4Address); + ComputerIPv4 = detectedLocalIPv4Address.ToString(); ComputerIPv4State = string.IsNullOrEmpty(ComputerIPv4) ? ConnectionState.Critical : ConnectionState.OK; } else { + Log.Debug("CheckConnectionComputerAsync - Local IPv4 address not detected."); + ComputerIPv4 = "-/-"; ComputerIPv4State = ConnectionState.Critical; } @@ -583,17 +574,23 @@ await NetworkInterface.DetectLocalIPAddressBasedOnRoutingAsync( ct.ThrowIfCancellationRequested(); // Detect local IPv6 address + Log.Debug("CheckConnectionComputerAsync - Detecting local IPv6 address..."); + var detectedLocalIPv6Address = await NetworkInterface.DetectLocalIPAddressBasedOnRoutingAsync( IPAddress.Parse(SettingsManager.Current.Dashboard_PublicIPv6Address)); if (detectedLocalIPv6Address != null) { + Log.Debug("CheckConnectionComputerAsync - Local IPv6 address detected: " + detectedLocalIPv6Address); + ComputerIPv6 = detectedLocalIPv6Address.ToString(); ComputerIPv6State = string.IsNullOrEmpty(ComputerIPv6) ? ConnectionState.Critical : ConnectionState.OK; } else { + Log.Debug("CheckConnectionComputerAsync - Local IPv6 address not detected."); + ComputerIPv6 = "-/-"; ComputerIPv6State = ConnectionState.Critical; } @@ -606,25 +603,49 @@ await NetworkInterface.DetectLocalIPAddressBasedOnRoutingAsync( // Try to resolve local DNS based on IPv4 if (ComputerIPv4State == ConnectionState.OK) { + Log.Debug("CheckConnectionComputerAsync - Resolving local DNS based on IPv4..."); + var dnsResult = await DNSClient.GetInstance().ResolvePtrAsync(IPAddress.Parse(ComputerIPv4)); if (!dnsResult.HasError) { + Log.Debug("CheckConnectionComputerAsync - Local DNS based on IPv4 resolved: " + dnsResult.Value); + ComputerDNS = dnsResult.Value; ComputerDNSState = ConnectionState.OK; } + else + { + Log.Debug("CheckConnectionComputerAsync - Local DNS based on IPv4 not resolved."); + } + } + else + { + Log.Debug("CheckConnectionComputerAsync - Local DNS based on IPv4 not resolved due to invalid IPv4 address."); } // Try to resolve local DNS based on IPv6 if IPv4 failed if (string.IsNullOrEmpty(ComputerDNS) && ComputerIPv6State == ConnectionState.OK) { + Log.Debug("CheckConnectionComputerAsync - Resolving local DNS based on IPv6..."); + var dnsResult = await DNSClient.GetInstance().ResolvePtrAsync(IPAddress.Parse(ComputerIPv6)); if (!dnsResult.HasError) { + Log.Debug("CheckConnectionComputerAsync - Local DNS based on IPv6 resolved: " + dnsResult.Value); + ComputerDNS = dnsResult.Value; ComputerDNSState = ConnectionState.OK; } + else + { + Log.Debug("CheckConnectionComputerAsync - Local DNS based on IPv6 not resolved."); + } + } + else + { + Log.Debug("CheckConnectionComputerAsync - Local DNS based on IPv6 not resolved due to IPv4 DNS resolved or invalid IPv6 address"); } if (string.IsNullOrEmpty(ComputerDNS)) @@ -634,6 +655,8 @@ await NetworkInterface.DetectLocalIPAddressBasedOnRoutingAsync( } IsComputerDNSChecking = false; + + Log.Debug("CheckConnectionComputerAsync - Local connection check completed."); }, ct); } @@ -641,6 +664,8 @@ private Task CheckConnectionRouterAsync(CancellationToken ct) { return Task.Run(async () => { + Log.Debug("CheckConnectionRouterAsync - Checking router connection..."); + // Init variables IsRouterIPv4Checking = true; RouterIPv4 = ""; @@ -653,29 +678,39 @@ private Task CheckConnectionRouterAsync(CancellationToken ct) RouterDNSState = ConnectionState.None; // Detect router IPv4 and if it is reachable + Log.Debug("CheckConnectionRouterAsync - Detecting computer and router IPv4 address..."); + var detectedLocalIPv4Address = await NetworkInterface.DetectLocalIPAddressBasedOnRoutingAsync( IPAddress.Parse(SettingsManager.Current.Dashboard_PublicIPv4Address)); if (detectedLocalIPv4Address != null) { + Log.Debug("CheckConnectionRouterAsync - Computer IPv4 address detected: " + detectedLocalIPv4Address); + var detectedRouterIPv4 = await NetworkInterface.DetectGatewayBasedOnLocalIPAddressAsync( detectedLocalIPv4Address); - + if (detectedRouterIPv4 != null) { + Log.Debug("CheckConnectionRouterAsync - Router IPv4 address detected: " + detectedRouterIPv4); + RouterIPv4 = detectedRouterIPv4.ToString(); RouterIPv4State = string.IsNullOrEmpty(RouterIPv4) ? ConnectionState.Critical : ConnectionState.OK; } else { + Log.Debug("CheckConnectionRouterAsync - Router IPv4 address not detected."); + RouterIPv4 = "-/-"; RouterIPv4State = ConnectionState.Critical; } } else { + Log.Debug("CheckConnectionRouterAsync - Computer IPv4 address not detected."); + RouterIPv4 = "-/-"; RouterIPv4State = ConnectionState.Critical; } @@ -686,28 +721,38 @@ await NetworkInterface.DetectGatewayBasedOnLocalIPAddressAsync( ct.ThrowIfCancellationRequested(); // Detect router IPv6 and if it is reachable + Log.Debug("CheckConnectionRouterAsync - Detecting computer and router IPv6 address..."); + var detectedComputerIPv6 = await NetworkInterface.DetectLocalIPAddressBasedOnRoutingAsync( IPAddress.Parse(SettingsManager.Current.Dashboard_PublicIPv6Address)); if (detectedComputerIPv6 != null) { + Log.Debug("CheckConnectionRouterAsync - Computer IPv6 address detected: " + detectedComputerIPv6); + var detectedRouterIPv6 = await NetworkInterface.DetectGatewayBasedOnLocalIPAddressAsync(detectedComputerIPv6); if (detectedRouterIPv6 != null) { + Log.Debug("CheckConnectionRouterAsync - Router IPv6 address detected: " + detectedRouterIPv6); + RouterIPv6 = detectedRouterIPv6.ToString(); RouterIPv6State = string.IsNullOrEmpty(RouterIPv6) ? ConnectionState.Critical : ConnectionState.OK; } else { + Log.Debug("CheckConnectionRouterAsync - Router IPv6 address not detected."); + RouterIPv6 = "-/-"; RouterIPv6State = ConnectionState.Critical; } } else { + Log.Debug("CheckConnectionRouterAsync - Computer IPv6 address not detected."); + RouterIPv6 = "-/-"; RouterIPv6State = ConnectionState.Critical; } @@ -720,25 +765,49 @@ await NetworkInterface.DetectLocalIPAddressBasedOnRoutingAsync( // Try to resolve router DNS based on IPv4 if (RouterIPv4State == ConnectionState.OK) { + Log.Debug("CheckConnectionRouterAsync - Resolving router DNS based on IPv4..."); + var dnsResult = await DNSClient.GetInstance().ResolvePtrAsync(IPAddress.Parse(RouterIPv4)); if (!dnsResult.HasError) { + Log.Debug("CheckConnectionRouterAsync - Router DNS based on IPv4 resolved: " + dnsResult.Value); + RouterDNS = dnsResult.Value; RouterDNSState = ConnectionState.OK; } + else + { + Log.Debug("CheckConnectionRouterAsync - Router DNS based on IPv4 not resolved."); + } + } + else + { + Log.Debug("CheckConnectionRouterAsync - Router DNS based on IPv4 not resolved due to invalid IPv4 address."); } // Try to resolve router DNS based on IPv6 if IPv4 failed if (string.IsNullOrEmpty(RouterDNS) && RouterIPv6State == ConnectionState.OK) { + Log.Debug("CheckConnectionRouterAsync - Resolving router DNS based on IPv6..."); + var dnsResult = await DNSClient.GetInstance().ResolvePtrAsync(IPAddress.Parse(RouterIPv6)); if (!dnsResult.HasError) { + Log.Debug("CheckConnectionRouterAsync - Router DNS based on IPv6 resolved: " + dnsResult.Value); + RouterDNS = dnsResult.Value; RouterDNSState = ConnectionState.OK; } + else + { + Log.Debug("CheckConnectionRouterAsync - Router DNS based on IPv6 not resolved."); + } + } + else + { + Log.Debug("CheckConnectionRouterAsync - Router DNS based on IPv6 not resolved due to IPv4 DNS resolved or invalid IPv6 address."); } if (string.IsNullOrEmpty(RouterDNS)) @@ -748,6 +817,8 @@ await NetworkInterface.DetectLocalIPAddressBasedOnRoutingAsync( } IsRouterDNSChecking = false; + + Log.Debug("CheckConnectionRouterAsync - Router connection check completed."); }, ct); } @@ -759,6 +830,8 @@ private Task CheckConnectionInternetAsync(CancellationToken ct) if (!CheckPublicIPAddressEnabled) return; + Log.Debug("CheckConnectionInternetAsync - Checking internet connection..."); + // Init variables IsInternetIPv4Checking = true; InternetIPv4 = ""; @@ -771,12 +844,16 @@ private Task CheckConnectionInternetAsync(CancellationToken ct) InternetDNSState = ConnectionState.None; // Detect public IPv4 and if it is reachable + Log.Debug("Detecting public IPv4 address..."); + var publicIPv4AddressAPI = SettingsManager.Current.Dashboard_UseCustomPublicIPv4AddressAPI ? SettingsManager.Current.Dashboard_CustomPublicIPv4AddressAPI : GlobalStaticConfiguration.Dashboard_PublicIPv4AddressAPI; try { + Log.Debug("CheckConnectionInternetAsync - Checking public IPv4 address from: " + publicIPv4AddressAPI); + HttpClient httpClient = new(); var httpResponse = await httpClient.GetAsync(publicIPv4AddressAPI, ct); @@ -786,17 +863,23 @@ private Task CheckConnectionInternetAsync(CancellationToken ct) if (match.Success) { + Log.Debug("CheckConnectionInternetAsync - Public IPv4 address detected: " + match.Value); + InternetIPv4 = match.Value; InternetIPv4State = ConnectionState.OK; } else { + Log.Debug("CheckConnectionInternetAsync - Public IPv4 address not detected due to invalid format."); + InternetIPv4 = "-/-"; InternetIPv4State = ConnectionState.Critical; } } catch { + Log.Debug("CheckConnectionInternetAsync - Public IPv4 address not detected due to exception."); + InternetIPv4 = "-/-"; InternetIPv4State = ConnectionState.Critical; } @@ -807,12 +890,16 @@ private Task CheckConnectionInternetAsync(CancellationToken ct) ct.ThrowIfCancellationRequested(); // Detect public IPv6 and if it is reachable + Log.Debug("CheckConnectionInternetAsync - Detecting public IPv6 address..."); + var publicIPv6AddressAPI = SettingsManager.Current.Dashboard_UseCustomPublicIPv6AddressAPI ? SettingsManager.Current.Dashboard_CustomPublicIPv6AddressAPI : GlobalStaticConfiguration.Dashboard_PublicIPv6AddressAPI; try { + Log.Debug("CheckConnectionInternetAsync - Checking public IPv6 address from: " + publicIPv6AddressAPI); + HttpClient httpClient = new(); var httpResponse = await httpClient.GetAsync(publicIPv6AddressAPI, ct); @@ -822,17 +909,23 @@ private Task CheckConnectionInternetAsync(CancellationToken ct) if (match.Success) { + Log.Debug("CheckConnectionInternetAsync - Public IPv6 address detected: " + match.Value); + InternetIPv6 = match.Value; InternetIPv6State = ConnectionState.OK; } else { + Log.Debug("CheckConnectionInternetAsync - Public IPv6 address not detected due to invalid format."); + InternetIPv6 = "-/-"; InternetIPv6State = ConnectionState.Critical; } } catch { + Log.Debug("CheckConnectionInternetAsync - Public IPv6 address not detected due to exception."); + InternetIPv6 = "-/-"; InternetIPv6State = ConnectionState.Critical; } @@ -845,25 +938,49 @@ private Task CheckConnectionInternetAsync(CancellationToken ct) // Try to resolve public DNS based on IPv4 if (InternetIPv4State == ConnectionState.OK) { + Log.Debug("CheckConnectionInternetAsync - Resolving public DNS based on IPv4..."); + var dnsResult = await DNSClient.GetInstance().ResolvePtrAsync(IPAddress.Parse(InternetIPv4)); if (!dnsResult.HasError) { + Log.Debug("CheckConnectionInternetAsync - Public DNS based on IPv4 resolved: " + dnsResult.Value); + InternetDNS = dnsResult.Value; InternetDNSState = ConnectionState.OK; } + else + { + Log.Debug("CheckConnectionInternetAsync - Public DNS based on IPv4 not resolved."); + } + } + else + { + Log.Debug("CheckConnectionInternetAsync - Public DNS based on IPv4 not resolved due to invalid IPv4 address."); } // Try to resolve public DNS based on IPv6 if IPv4 failed if (string.IsNullOrEmpty(InternetDNS) && InternetIPv6State == ConnectionState.OK) { + Log.Debug("CheckConnectionInternetAsync - Resolving public DNS based on IPv6..."); + var dnsResult = await DNSClient.GetInstance().ResolvePtrAsync(IPAddress.Parse(InternetIPv6)); if (!dnsResult.HasError) { + Log.Debug("CheckConnectionInternetAsync - Public DNS based on IPv6 resolved: " + dnsResult.Value); + InternetDNS = dnsResult.Value; InternetDNSState = ConnectionState.OK; } + else + { + Log.Debug("CheckConnectionInternetAsync - Public DNS based on IPv6 not resolved."); + } + } + else + { + Log.Debug("CheckConnectionInternetAsync - Public DNS based on IPv6 not resolved due to IPv4 DNS resolved or invalid IPv6 address."); } if (string.IsNullOrEmpty(InternetDNS)) @@ -873,8 +990,9 @@ private Task CheckConnectionInternetAsync(CancellationToken ct) } IsInternetDNSChecking = false; + + Log.Debug("CheckConnectionInternetAsync - Internet connection check completed."); }, ct); } - #endregion -} \ No newline at end of file +} diff --git a/Source/NETworkManager/ViewModels/WiFiViewModel.cs b/Source/NETworkManager/ViewModels/WiFiViewModel.cs index f8cfda4793..ada6b68518 100644 --- a/Source/NETworkManager/ViewModels/WiFiViewModel.cs +++ b/Source/NETworkManager/ViewModels/WiFiViewModel.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; +using System.Diagnostics; using System.Linq; using System.Threading.Tasks; using System.Windows.Data; @@ -114,7 +115,7 @@ public WiFiAdapterInfo SelectedAdapter if (!_isLoading) SettingsManager.Current.WiFi_InterfaceId = value.NetworkInterfaceInfo.Id; - Scan(value).ConfigureAwait(false); + ScanAsync(value).ConfigureAwait(false); } _selectedAdapters = value; @@ -301,18 +302,18 @@ public IList SelectedNetworks } } - public SeriesCollection Radio1Series { get; set; } = new(); + public SeriesCollection Radio1Series { get; set; } = []; public string[] Radio1Labels { get; set; } = - { " ", " ", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", " ", " " }; + [" ", " ", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", " ", " "]; - public SeriesCollection Radio2Series { get; set; } = new(); + public SeriesCollection Radio2Series { get; set; } = []; public string[] Radio2Labels { get; set; } = - { + [ " ", " ", "36", "40", "44", "48", "52", "56", "60", "64", "", "", "", "", "100", "104", "108", "112", "116", "120", "124", "128", "132", "136", "140", "144", "149", "153", "157", "161", "165", " ", " " - }; + ]; public Func FormattedDbm { get; set; } = value => $"- {100 - value} dBm"; // Reverse y-axis 0 to -100 @@ -471,7 +472,7 @@ public WiFiViewModel(IDialogCoordinator instance) }; // Load network adapters - LoadAdapters(SettingsManager.Current.WiFi_InterfaceId).ConfigureAwait(false); + LoadAdaptersAsync(SettingsManager.Current.WiFi_InterfaceId).ConfigureAwait(false); // Auto refresh _autoRefreshTimer.Tick += AutoRefreshTimer_Tick; @@ -506,7 +507,7 @@ private void LoadSettings() private void ReloadAdapterAction() { - LoadAdapters(SelectedAdapter?.NetworkInterfaceInfo.Id).ConfigureAwait(false); + LoadAdaptersAsync(SelectedAdapter?.NetworkInterfaceInfo.Id).ConfigureAwait(false); } public ICommand ScanNetworksCommand => @@ -519,7 +520,7 @@ private bool ScanNetworks_CanExecute(object obj) private async Task ScanNetworksAction() { - await Scan(SelectedAdapter, true); + await ScanAsync(SelectedAdapter, true); } public ICommand ConnectCommand => new RelayCommand(_ => ConnectAction()); @@ -555,7 +556,7 @@ private static void OpenSettingsAction() #region Methods /// - /// Request access to the WiFi adapter. + /// Request access to the Wi-Fi adapter. /// /// Fails if the access is denied. private static bool RequestAccess() @@ -565,8 +566,10 @@ private static bool RequestAccess() return accessStatus == WiFiAccessStatus.Allowed; } - private async Task LoadAdapters(string adapterId = null) + private async Task LoadAdaptersAsync(string adapterId = null) { + Log.Debug("LoadAdaptersAsync - Trying to get WiFi adapters..."); + IsAdaptersLoading = true; // Show a loading animation for the user @@ -582,23 +585,44 @@ private async Task LoadAdapters(string adapterId = null) Adapters.Clear(); } - + // Check if we found any adapters if (Adapters.Count > 0) { - // Check for existing adapter id or select the first one + Log.Debug("LoadAdaptersAsync - Found " + Adapters.Count + " WiFi adapters."); + + // Check for previous selected adapter if (string.IsNullOrEmpty(adapterId)) + { + Log.Debug("LoadAdaptersAsync - No previous adapter ID found. Selecting the first adapter."); + SelectedAdapter = Adapters.FirstOrDefault(); + } else + { + Log.Debug("LoadAdaptersAsync - Previous adapter ID found. Trying to select the adapter with the ID: " + adapterId); + SelectedAdapter = Adapters.FirstOrDefault(s => s.NetworkInterfaceInfo.Id.ToString() == adapterId) ?? Adapters.FirstOrDefault(); + } + + Log.Debug("LoadAdaptersAsync - Selected adapter: " + SelectedAdapter?.NetworkInterfaceInfo.Name + " (" + + SelectedAdapter?.NetworkInterfaceInfo.Id + ")"); + } + else + { + Log.Debug("LoadAdaptersAsync - No WiFi adapters found."); } IsAdaptersLoading = false; + + Log.Debug("LoadAdaptersAsync - Done."); } - - private async Task Scan(WiFiAdapterInfo adapterInfo, bool refreshing = false, uint delayInMs = 0) + + private async Task ScanAsync(WiFiAdapterInfo adapterInfo, bool refreshing = false, uint delayInMs = 0) { + Log.Debug($"ScanAsync - Scanning WiFi adapter \"{adapterInfo.NetworkInterfaceInfo.Name}\" with delay of {delayInMs} ms..."); + if (refreshing) { StatusMessage = Strings.SearchingForNetworksDots; @@ -619,13 +643,20 @@ private async Task Scan(WiFiAdapterInfo adapterInfo, bool refreshing = false, ui { var wiFiNetworkScanInfo = await WiFi.GetNetworksAsync(adapterInfo.WiFiAdapter); + Log.Debug("ScanAsync - Scan completed. Found " + wiFiNetworkScanInfo.WiFiNetworkInfos.Count + " networks."); + // Clear the values after the scan to make the UI smoother + Log.Debug("ScanAsync - Clearing old values..."); Networks.Clear(); Radio1Series.Clear(); Radio2Series.Clear(); + Log.Debug("ScanAsync - Adding new values..."); foreach (var network in wiFiNetworkScanInfo.WiFiNetworkInfos) { + Log.Debug("ScanAsync - Add network: " + network.AvailableNetwork.Ssid + " with channel frequency: " + + network.AvailableNetwork.ChannelCenterFrequencyInKilohertz); + Networks.Add(network); if (WiFi.ConvertChannelFrequencyToGigahertz(network.AvailableNetwork @@ -640,13 +671,15 @@ private async Task Scan(WiFiAdapterInfo adapterInfo, bool refreshing = false, ui } catch (Exception ex) { + Log.Error($"Error while scanning WiFi adapter \"{adapterInfo.NetworkInterfaceInfo.Name}\".", ex); + + statusMessage = string.Format(Strings.ErrorWhileScanningWiFiAdapterXXXWithErrorXXX, + adapterInfo.NetworkInterfaceInfo.Name, ex.Message); + // Clear the existing old values if an error occurs Networks.Clear(); Radio1Series.Clear(); Radio2Series.Clear(); - - statusMessage = string.Format(Strings.ErrorWhileScanningWiFiAdapterXXXWithErrorXXX, - adapterInfo.NetworkInterfaceInfo.Name, ex.Message); } finally { @@ -655,12 +688,14 @@ private async Task Scan(WiFiAdapterInfo adapterInfo, bool refreshing = false, ui IsBackgroundSearchRunning = false; IsNetworksLoading = false; + + Log.Debug("ScanAsync - Done."); } } private ChartValues GetDefaultChartValues(WiFiRadio radio) { - ChartValues values = new(); + ChartValues values = []; for (var i = 0; i < (radio == WiFiRadio.One ? Radio1Labels.Length : Radio2Labels.Length); i++) values.Add(-1); @@ -685,8 +720,10 @@ private ChartValues GetChartValues(WiFiNetworkInfo network, WiFiRadio ra private LineSeries GetSeriesCollection(WiFiNetworkInfo network, WiFiRadio radio) { - var index = Array.IndexOf(radio == WiFiRadio.One ? Radio1Labels : Radio2Labels, - $"{WiFi.GetChannelFromChannelFrequency(network.AvailableNetwork.ChannelCenterFrequencyInKilohertz)}"); + var radioLabels = radio == WiFiRadio.One ? Radio1Labels : Radio2Labels; + var channel = WiFi.GetChannelFromChannelFrequency(network.AvailableNetwork.ChannelCenterFrequencyInKilohertz); + + var index = Array.IndexOf(radioLabels, $"{channel}"); return new LineSeries { @@ -766,9 +803,9 @@ private async void Connect() // Hide message automatically _hideConnectionStatusMessageTimer.Start(); - // Update the wifi networks. + // Update the Wi-Fi networks. // Wait because an error may occur if a refresh is done directly after connecting. - await Scan(SelectedAdapter, true, 5000); + await ScanAsync(SelectedAdapter, true, 5000); }, async instance => { // Connect WPS @@ -802,9 +839,9 @@ private async void Connect() // Hide message automatically _hideConnectionStatusMessageTimer.Start(); - // Update the wifi networks. + // Update the Wi-Fi networks. // Wait because an error may occur if a refresh is done directly after connecting. - await Scan(SelectedAdapter, true, 5000); + await ScanAsync(SelectedAdapter, true, 5000); }, _ => { _dialogCoordinator.HideMetroDialogAsync(this, customDialog); }, (selectedAdapter, selectedNetwork), connectMode); @@ -834,7 +871,7 @@ private async void Disconnect() } // Refresh - await Scan(SelectedAdapter, true, 2500); + await ScanAsync(SelectedAdapter, true, 2500); } private async Task Export() @@ -908,7 +945,7 @@ private async void AutoRefreshTimer_Tick(object sender, EventArgs e) _autoRefreshTimer.Stop(); // Scan networks - await Scan(SelectedAdapter, true); + await ScanAsync(SelectedAdapter, true); // Restart timer... _autoRefreshTimer.Start(); diff --git a/Source/NETworkManager/Views/DashboardView.xaml.cs b/Source/NETworkManager/Views/DashboardView.xaml.cs index c3f6632f74..9512c34509 100644 --- a/Source/NETworkManager/Views/DashboardView.xaml.cs +++ b/Source/NETworkManager/Views/DashboardView.xaml.cs @@ -6,24 +6,45 @@ public partial class DashboardView { private readonly DashboardViewModel _viewModel = new(); + private readonly NetworkConnectionWidgetView _networkConnectionWidgetView = new(); + private readonly IPApiIPGeolocationWidgetView _ipApiIPGeolocationWidgetView = new(); + private readonly IPApiDNSResolverWidgetView _ipApiDNSResolverWidgetView = new(); + + public DashboardView() { InitializeComponent(); DataContext = _viewModel; // Load views - ContentControlNetworkConnection.Content = new NetworkConnectionWidgetView(); - ContentControlIPApiIPGeolocation.Content = new IPApiIPGeolocationWidgetView(); - ContentControlIPApiDNSResolver.Content = new IPApiDNSResolverWidgetView(); + ContentControlNetworkConnection.Content = _networkConnectionWidgetView; + ContentControlIPApiIPGeolocation.Content = _ipApiIPGeolocationWidgetView; + ContentControlIPApiDNSResolver.Content = _ipApiDNSResolverWidgetView; + + // Check all widgets + Check(); + } + + public void OnViewVisible() + { + _viewModel.OnViewVisible(); + + // Check all widgets + Check(); } public void OnViewHide() { _viewModel.OnViewHide(); } - - public void OnViewVisible() + + /// + /// Check all widgets + /// + private void Check() { - _viewModel.OnViewVisible(); + _networkConnectionWidgetView.Check(); + _ipApiIPGeolocationWidgetView.Check(); + _ipApiDNSResolverWidgetView.Check(); } } \ No newline at end of file diff --git a/Source/NETworkManager/Views/IPApiDNSResolverWidgetView.xaml b/Source/NETworkManager/Views/IPApiDNSResolverWidgetView.xaml index ef277499e7..61cec61b2a 100644 --- a/Source/NETworkManager/Views/IPApiDNSResolverWidgetView.xaml +++ b/Source/NETworkManager/Views/IPApiDNSResolverWidgetView.xaml @@ -11,7 +11,7 @@ xmlns:viewModels="clr-namespace:NETworkManager.ViewModels" xmlns:system="clr-namespace:System;assembly=mscorlib" mc:Ignorable="d" MinHeight="200" - d:DataContext="{d:DesignInstance viewModels:IPApiDNSResolverWidgetViewModel}" Loaded="UserControl_Loaded"> + d:DataContext="{d:DesignInstance viewModels:IPApiDNSResolverWidgetViewModel}"> diff --git a/Source/NETworkManager/Views/IPApiDNSResolverWidgetView.xaml.cs b/Source/NETworkManager/Views/IPApiDNSResolverWidgetView.xaml.cs index b36a945e9c..3f6965507d 100644 --- a/Source/NETworkManager/Views/IPApiDNSResolverWidgetView.xaml.cs +++ b/Source/NETworkManager/Views/IPApiDNSResolverWidgetView.xaml.cs @@ -1,5 +1,4 @@ -using System.Windows; -using NETworkManager.ViewModels; +using NETworkManager.ViewModels; namespace NETworkManager.Views; @@ -13,7 +12,7 @@ public IPApiDNSResolverWidgetView() DataContext = _viewModel; } - private void UserControl_Loaded(object sender, RoutedEventArgs e) + public void Check() { _viewModel.Check(); } diff --git a/Source/NETworkManager/Views/IPApiIPGeolocationWidgetView.xaml b/Source/NETworkManager/Views/IPApiIPGeolocationWidgetView.xaml index ca769b03fd..389e13d83b 100644 --- a/Source/NETworkManager/Views/IPApiIPGeolocationWidgetView.xaml +++ b/Source/NETworkManager/Views/IPApiIPGeolocationWidgetView.xaml @@ -11,8 +11,7 @@ xmlns:settings="clr-namespace:NETworkManager.Settings;assembly=NETworkManager.Settings" xmlns:system="clr-namespace:System;assembly=mscorlib" mc:Ignorable="d" MinHeight="200" - d:DataContext="{d:DesignInstance viewModels:IPApiIPGeolocationWidgetViewModel}" - Loaded="UserControl_Loaded"> + d:DataContext="{d:DesignInstance viewModels:IPApiIPGeolocationWidgetViewModel}"> diff --git a/Source/NETworkManager/Views/IPApiIPGeolocationWidgetView.xaml.cs b/Source/NETworkManager/Views/IPApiIPGeolocationWidgetView.xaml.cs index 1566ca3623..54e004404a 100644 --- a/Source/NETworkManager/Views/IPApiIPGeolocationWidgetView.xaml.cs +++ b/Source/NETworkManager/Views/IPApiIPGeolocationWidgetView.xaml.cs @@ -1,5 +1,4 @@ -using System.Windows; -using NETworkManager.ViewModels; +using NETworkManager.ViewModels; namespace NETworkManager.Views; @@ -13,7 +12,7 @@ public IPApiIPGeolocationWidgetView() DataContext = _viewModel; } - private void UserControl_Loaded(object sender, RoutedEventArgs e) + public void Check() { _viewModel.Check(); } diff --git a/Source/NETworkManager/Views/NetworkConnectionWidgetView.xaml b/Source/NETworkManager/Views/NetworkConnectionWidgetView.xaml index bd293f12ad..6414ee6ca2 100644 --- a/Source/NETworkManager/Views/NetworkConnectionWidgetView.xaml +++ b/Source/NETworkManager/Views/NetworkConnectionWidgetView.xaml @@ -9,9 +9,9 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:viewModels="clr-namespace:NETworkManager.ViewModels" mc:Ignorable="d" - d:DataContext="{d:DesignInstance viewModels:NetworkConnectionWidgetViewModel}" Loaded="UserControl_Loaded"> + d:DataContext="{d:DesignInstance viewModels:NetworkConnectionWidgetViewModel}"> - + diff --git a/Source/NETworkManager/Views/NetworkConnectionWidgetView.xaml.cs b/Source/NETworkManager/Views/NetworkConnectionWidgetView.xaml.cs index d9e826b18d..caf8c582f6 100644 --- a/Source/NETworkManager/Views/NetworkConnectionWidgetView.xaml.cs +++ b/Source/NETworkManager/Views/NetworkConnectionWidgetView.xaml.cs @@ -1,5 +1,4 @@ -using System.Windows; -using NETworkManager.ViewModels; +using NETworkManager.ViewModels; namespace NETworkManager.Views; @@ -13,13 +12,8 @@ public NetworkConnectionWidgetView() DataContext = _viewModel; } - public void Reload() + public void Check() { - _viewModel.CheckConnection(); - } - - private void UserControl_Loaded(object sender, RoutedEventArgs e) - { - _viewModel.CheckConnection(); + _viewModel.Check(); } } \ No newline at end of file