/// <summary> /// Enable the selected network adapter. /// </summary> /// <param name="o">The object to disable.</param> /// <returns>True if the invocation succeeds.</returns> public bool EnableNetworkAdapter(NetworkAdapterCustom o) { NetworkAdapter adapter; if (TryGetNetworkAdapterFromCustom(o, out adapter)) { return(adapter.Enable() != 0); } return(false); }
/// <summary> /// Return the adapter and true if it exists. False otherwise. /// </summary> /// <param name="o">The object to search for.</param> /// <param name="networkAdapter">The output if found.</param> /// <returns>True if successful.</returns> private bool TryGetNetworkAdapterFromCustom(NetworkAdapterCustom o, out NetworkAdapter networkAdapter) { networkAdapter = null; if (_allAdapters.ContainsKey(o.ConnectionName) == false) { return(false); } networkAdapter = _allAdapters[o.ConnectionName]; return(true); }
/// <summary> /// Attempts to match the adapter name to existing adapters to find the category. /// </summary> private NetworkAdapterCategory TryMatchAdapterCategory(NetworkAdapterCustom adapter) { if (_allLocalAdaptersToWatch.Contains(adapter.ConnectionName)) { return(NetworkAdapterCategory.Local); } if (_allVpnAdaptersToWatch.Contains(adapter.ConnectionName)) { return(NetworkAdapterCategory.Vpn); } return(NetworkAdapterCategory.None); }