Example #1
0
        // ReSharper disable once UnusedMethodReturnValue.Local
        public bool ExecuteTest(bool configure)
        {
            if (_testThread != null)
            {
                return(false);
            }
            CultureInfo cultureInfo = Thread.CurrentThread.CurrentCulture;

            TestOk         = false;
            ConfigPossible = false;
            AdapterType    = -1;
            AccessPoint ap = _form.GetSelectedAp();

            if (ap != null)
            {
                AuthRequest authRequest = new AuthRequest(ap);
                if (authRequest.IsPasswordRequired)
                {
                    authRequest.Password = _form.WifiPassword;
                }
                ap.ConnectAsync(authRequest, true, success =>
                {
                    _form.BeginInvoke((Action)(() =>
                    {
                        if (!success)
                        {
                            _form.UpdateStatusText(Resources.Strings.ConnectionFailed);
                        }
                        else
                        {
                            _form.PerformSearch();
                        }
                    }));
                });
                return(true);
            }

            WlanInterface wlanIface = _form.GetSelectedWifiDevice();

            if (wlanIface != null)
            {
                try
                {
                    WlanConnectionAttributes conn = wlanIface.CurrentConnection;
                    string ssidString             = Encoding.ASCII.GetString(conn.wlanAssociationAttributes.dot11Ssid.SSID).TrimEnd('\0');
                    string ipAddr = string.Empty;
                    bool   isEnet = string.Compare(ssidString, Patch.AdapterSsidEnet, StringComparison.OrdinalIgnoreCase) == 0;

                    IPInterfaceProperties ipProp = wlanIface.NetworkInterface.GetIPProperties();
                    if (ipProp == null)
                    {
                        _form.UpdateStatusText(Resources.Strings.ConnectionFailed);
                        return(false);
                    }
                    ipAddr = (from addr in ipProp.DhcpServerAddresses where addr.AddressFamily == AddressFamily.InterNetwork select addr.ToString()).FirstOrDefault();
                    if (string.IsNullOrEmpty(ipAddr))
                    {
                        _form.UpdateStatusText(Resources.Strings.ConnectionFailed);
                        return(false);
                    }

                    if (isEnet)
                    {
                        if (configure)
                        {
                            Process.Start(string.Format("http://{0}", ipAddr));
                            _form.UpdateStatusText(Resources.Strings.WifiUrlOk);
                            TestOk         = true;
                            ConfigPossible = true;
                            return(true);
                        }
                    }
                    _testThread = new Thread(() =>
                    {
                        try
                        {
                            Thread.CurrentThread.CurrentCulture   = cultureInfo;
                            Thread.CurrentThread.CurrentUICulture = cultureInfo;
                            if (isEnet)
                            {
                                TestOk = RunWifiTestEnetRetry(ipAddr);
                                if (TestOk)
                                {
                                    ConfigPossible = true;
                                }
                            }
                            else
                            {
                                TestOk = RunWifiTestElm(ipAddr, configure, out bool configRequired);
                                if (TestOk && configRequired)
                                {
                                    ConfigPossible = true;
                                }
                            }
                        }
                        finally
                        {
                            _testThread = null;
                            _form.UpdateButtonStatus();
                        }
                    });
                    _testThread.Start();
                }
                catch (Exception)
                {
                    _form.UpdateStatusText(Resources.Strings.ConnectionFailed);
                    return(false);
                }
                return(true);
            }

            BluetoothDeviceInfo devInfo = _form.GetSelectedBtDevice();

            if (devInfo == null)
            {
                return(false);
            }
            string pin = _form.BluetoothPin;

            _testThread = new Thread(() =>
            {
                try
                {
                    Thread.CurrentThread.CurrentCulture   = cultureInfo;
                    Thread.CurrentThread.CurrentUICulture = cultureInfo;
                    _form.UpdateStatusText(Resources.Strings.Connecting);
                    if (!ConnectBtDevice(devInfo, pin))
                    {
                        _form.UpdateStatusText(Resources.Strings.ConnectionFailed);
                        return;
                    }
                    TestOk = RunBtTest(configure, out bool configRequired);
                    if (TestOk && configRequired)
                    {
                        ConfigPossible = true;
                    }
                }
                finally
                {
                    DisconnectStream();
                    _testThread = null;
                    _form.UpdateButtonStatus();
                }
            });
            _testThread.Start();
            return(true);
        }
Example #2
0
        // ReSharper disable once UnusedMethodReturnValue.Local
        public bool ExecuteTest(bool configure)
        {
            if (_testThread != null)
            {
                return(false);
            }
            CultureInfo cultureInfo = Thread.CurrentThread.CurrentCulture;

            TestOk         = false;
            ConfigPossible = false;
            AccessPoint ap = _form.GetSelectedAp();

            if (ap != null)
            {
                AuthRequest authRequest = new AuthRequest(ap);
                if (authRequest.IsPasswordRequired)
                {
                    authRequest.Password = _form.WifiPassword;
                }
                ap.ConnectAsync(authRequest, true, success =>
                {
                    _form.BeginInvoke((Action)(() =>
                    {
                        if (!success)
                        {
                            _form.UpdateStatusText(Resources.Strings.ConnectionFailed);
                        }
                        else
                        {
                            _form.PerformSearch();
                        }
                    }));
                });
                return(true);
            }

            WlanInterface wlanIface = _form.GetSelectedWifiDevice();

            if (wlanIface != null)
            {
                try
                {
                    IPInterfaceProperties ipProp = wlanIface.NetworkInterface.GetIPProperties();
                    if (ipProp == null)
                    {
                        _form.UpdateStatusText(Resources.Strings.ConnectionFailed);
                        return(false);
                    }
                    string ipAddr = (from addr in ipProp.DhcpServerAddresses where addr.AddressFamily == AddressFamily.InterNetwork select addr.ToString()).FirstOrDefault();
                    if (string.IsNullOrEmpty(ipAddr))
                    {
                        _form.UpdateStatusText(Resources.Strings.ConnectionFailed);
                        return(false);
                    }
                    if (configure)
                    {
                        Process.Start(string.Format("http://{0}", ipAddr));
                        _form.UpdateStatusText(Resources.Strings.WifiUrlOk);
                        TestOk         = true;
                        ConfigPossible = true;
                        return(true);
                    }
                    _testThread = new Thread(() =>
                    {
                        try
                        {
                            Thread.CurrentThread.CurrentCulture   = cultureInfo;
                            Thread.CurrentThread.CurrentUICulture = cultureInfo;
                            TestOk = RunWifiTestRetry(ipAddr);
                            if (TestOk)
                            {
                                ConfigPossible = true;
                            }
                        }
                        finally
                        {
                            _testThread = null;
                            _form.UpdateButtonStatus();
                        }
                    });
                    _testThread.Start();
                }
                catch (Exception)
                {
                    _form.UpdateStatusText(Resources.Strings.ConnectionFailed);
                    return(false);
                }
                return(true);
            }

            BluetoothDeviceInfo devInfo = _form.GetSelectedBtDevice();

            if (devInfo == null)
            {
                return(false);
            }
            string pin = _form.BluetoothPin;

            _testThread = new Thread(() =>
            {
                try
                {
                    Thread.CurrentThread.CurrentCulture   = cultureInfo;
                    Thread.CurrentThread.CurrentUICulture = cultureInfo;
                    _form.UpdateStatusText(Resources.Strings.Connecting);
                    if (!ConnectBtDevice(devInfo, pin))
                    {
                        _form.UpdateStatusText(Resources.Strings.ConnectionFailed);
                        return;
                    }
                    bool configRequired;
                    TestOk = RunBtTest(configure, out configRequired);
                    if (TestOk && configRequired)
                    {
                        ConfigPossible = true;
                    }
                }
                finally
                {
                    DisconnectBtDevice();
                    _testThread = null;
                    _form.UpdateButtonStatus();
                }
            });
            _testThread.Start();
            return(true);
        }