void RefreshNetworkInterfaceDeviceChoices(bool doNetworkDeviceReload) { LogThis(LogLevel.Debug, $"Network device re-detection request received ..."); LogThis(LogLevel.Trace, $"Re-detecting network devices ..."); if (doNetworkDeviceReload) { NetworkInterfaceDevice.LoadAllNetworkInterfaces(); } LogThis(LogLevel.Trace, $"Network device re-detection complete"); LogThis(LogLevel.Trace, $"Resetting UI controls ..."); EthernetComboBox.Items.Clear(); WifiComboBox.Items.Clear(); EthernetComboBox.Items.AddRange(NetworkInterfaceDevice.AllEthernetNetworkInterfaces.ToArray()); WifiComboBox.Items.AddRange(NetworkInterfaceDevice.AllWifiNetworkInterfaces.ToArray()); LogThis(LogLevel.Trace, $"Populating control values from current settings ..."); ReloadOldSettings(); if (EthernetComboBox.SelectedIndex == -1) { EthernetDoNotAutoDiscardCheckBox.Checked = false; EthernetDoNotAutoDiscardCheckBox.Enabled = false; } else if (((NetworkInterfaceDevice)EthernetComboBox.SelectedItem).CurrentState == InterfaceState.DevicePhysicallyDisconnected) { EthernetDoNotAutoDiscardCheckBox.Enabled = false; } if (WifiComboBox.SelectedIndex == -1) { WifiDoNotAutoDiscardCheckBox.Checked = false; WifiDoNotAutoDiscardCheckBox.Enabled = false; } else if (((NetworkInterfaceDevice)WifiComboBox.SelectedItem).CurrentState == InterfaceState.DevicePhysicallyDisconnected) { WifiDoNotAutoDiscardCheckBox.Enabled = false; } if (EthernetComboBox.SelectedIndex == -1 || WifiComboBox.SelectedIndex == -1) { this.needToInitializeSettings = true; } LogThis(LogLevel.Debug, $"Network device re-detection request complete"); }
void ValidateNetworkDeviceChoicesAndSettings(bool doingInitialSettingsLoad = false) { LogThis(LogLevel.Debug, "-> Valid device choices and settings ..."); NetworkInterfaceDevice.LoadAllNetworkInterfaces(); if (doingInitialSettingsLoad && (NetworkInterfaceDevice.AllEthernetNetworkInterfaces.Count == 0 || NetworkInterfaceDevice.AllWifiNetworkInterfaces.Count == 0)) { MessageBox.Show("Your system doesn't have Wifi and/or Ethernet adapters. Please connect them before launching this app. Exiting.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); ExitImmediately(); } if (!Global.AppSettings.AreAllSettingsValidAndPresent()) { if (doingInitialSettingsLoad == false) { MessageBox.Show("You need to re-choose one or both network interfaces"); } Global.AppSettings.ShowSettingsForm(true); } LogThis(LogLevel.Debug, "Device choices and settings validation done"); }
public override bool Equals(object obj) { LogThis(LogLevel.Debug, "-> Equals ..."); bool isEquals = true; //assumptions if (obj == null) { isEquals = false; } else if (obj.GetType() != typeof(NetworkInterfaceDevice)) { isEquals = false; } else { NetworkInterfaceDevice otherDevice = (NetworkInterfaceDevice)obj; if (this.windowsDeviceId != otherDevice.windowsDeviceId) { isEquals = false; } else if (this.deviceName != otherDevice.deviceName) { isEquals = false; } else if (this.physicalAddress != otherDevice.physicalAddress) { isEquals = false; } } LogThis(LogLevel.Debug, $"Equals comparison done - Returning: {isEquals}"); return(isEquals); }
private static void LogThisStatic(LogLevel level, string message, string callerMethodName = null, int?callDepth = null, NetworkInterfaceDevice device = null, params KeyValuePair <string, string>[] properties) { int callDepthToUse = callDepth.HasValue ? callDepth.Value : (new StackTrace()).FrameCount; int additionalPropertiesSize = 1; if (device != null) { additionalPropertiesSize += 1; } KeyValuePair <string, string>[] additionalProperties = new KeyValuePair <string, string> [additionalPropertiesSize]; additionalProperties[0] = new KeyValuePair <string, string>(Global.LoggingVarNames.CallerMethodName, callerMethodName ?? new StackFrame(1).GetMethod().Name); if (device != null) { additionalProperties[1] = new KeyValuePair <string, string>(Global.LoggingVarNames.InterfaceType, device.interfaceType != null ? device.interfaceType.GetDescriptionString() : "NULL"); } Global.Log(Logger, level, message, callDepthToUse, properties, additionalProperties); }