Exemplo n.º 1
0
        static void FindPreviousInterfaceIfAnyAndAddIfNeeded(List <NetworkInterfaceDevice> existingDevices, InterfaceType interfaceType)
        {
            LogThisStatic(LogLevel.Debug, $"-> Find previous {interfaceType.GetDescriptionString()} device selection ...");

            if (Global.AppSettings != null &&
                ((interfaceType == InterfaceType.Ethernet && Global.AppSettings.EthernetInterface != null) ||
                 (interfaceType == InterfaceType.WiFi && Global.AppSettings.WifiInterface != null)))
            {
                NetworkInterfaceDevice deviceToConsider;

                if (interfaceType == InterfaceType.Ethernet)
                {
                    deviceToConsider = Global.AppSettings.EthernetInterface;
                }
                else if (interfaceType == InterfaceType.WiFi)
                {
                    deviceToConsider = Global.AppSettings.WifiInterface;
                }
                else
                {
                    throw new Exception("ERROR as2xj5 :: Invalid network interface type specfied.");
                }

                if (deviceToConsider != null)
                {
                    int index;
                    if ((index = existingDevices.IndexOf(deviceToConsider)) != -1)
                    {
                        LogThisStatic(LogLevel.Trace, $"Previous {interfaceType.GetDescriptionString()} device is WAS NOT found ...");

                        existingDevices.ElementAt(index).DoNotAutoDiscard = deviceToConsider.DoNotAutoDiscard;
                        if (interfaceType == InterfaceType.Ethernet)
                        {
                            Global.AppSettings.EthernetInterface = existingDevices.ElementAt(index);
                        }
                        else
                        {
                            Global.AppSettings.WifiInterface = existingDevices.ElementAt(index);
                        }
                    }
                    else
                    {
                        LogThisStatic(LogLevel.Trace, $"Previous {interfaceType.GetDescriptionString()} device is WAS found ...");

                        if (deviceToConsider.DoNotAutoDiscard == true)
                        {
                            deviceToConsider.CurrentState = InterfaceState.DevicePhysicallyDisconnected;
                            existingDevices.Add(deviceToConsider);
                        }
                        else
                        {
                            if (interfaceType == InterfaceType.Ethernet)
                            {
                                Global.AppSettings.EthernetInterface = null;
                            }
                            else
                            {
                                Global.AppSettings.WifiInterface = null;
                            }
                        }
                    }
                }
                else
                {
                    LogThisStatic(LogLevel.Warn, $"Previous {interfaceType.GetDescriptionString()} device is null...");
                }
            }
        }