public MainWindow() { InitializeComponent(); // Kill ourself if we already have a wired network connection... if (NetworkConfig.IsWiredNetworkAvailable()) { #if !DEBUG Application.Current.Shutdown(); #endif } var parameters = Helper.GetRawArguments(); var parameter = string.Empty; var customUrl = string.Empty; var debug = false; if (parameters.Length >= 2) { for (int i = 0; i < 2; i++) { parameter = parameters[i]; if (parameter.ToLower().StartsWith("http")) { customUrl = parameter; } if (parameter.ToLower().StartsWith("debug")) { debug = true; } } } // prevent clipping... if (SystemParameters.PrimaryScreenWidth <= 1024) { Width = 1024; } string tooltip; winPEVersion = (string)Microsoft.Win32.Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\WinPE", "Version", ""); if (!string.IsNullOrWhiteSpace(winPEVersion)) { tooltip = "WirelessConnect Version: " + Assembly.GetExecutingAssembly().GetName().Version.ToString() + ", WinPE Version: " + winPEVersion; } else { tooltip = "WirelessConnect Version: " + Assembly.GetExecutingAssembly().GetName().Version.ToString(); } label_Header.ToolTip = tooltip; Helper.PreventTouchToMousePromotion.Register(label_ManualConfiguration); var loaderImageName = string.Empty; foreach (var resource in Assembly.GetExecutingAssembly().GetManifestResourceNames()) { if (resource.EndsWith(".gif")) { // "WirelessConnect.ajax-loader.gif" loaderImageName = resource; } } var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(loaderImageName); var image = System.Drawing.Image.FromStream(stream); Loaded += (s, e) => { pictureBox_Initializing.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; pictureBox_Initializing.BackColor = Color.Transparent; pictureBox_Initializing.Image = image; }; // make sure WLAN AutoConfig Service is started (especially needed when running in WinPE) NetworkConfig.StartWirelessAutoConfigService(); networkConfig = new NetworkConfig(customUrl); DataContext = connectionState; connectionState.InternetAccessable += ConnectionState_InternetAccessable; connectionState.CheckForInternetReady += ConnectionState_CheckForInternetReady; // construction of an individual delay timer for WinPE timing issues on first connect // now reduced to 100ms... in the next section we wait for wlan subsysten during a WinPE session firstConnect = new Timer((o) => { firstConnectLock = false; }); // disable all UI elements unitl network is specific delay listBox_Networks.IsEnabled = false; button_Refresh.IsEnabled = false; textBox_SecurityKey.IsEnabled = false; textBox_NetworkName.IsEnabled = false; comboBox_Authentication.IsEnabled = false; button_Continue.IsEnabled = false; button_ConnectDisconnect.IsEnabled = false; expander_ManualConfiguration.IsEnabled = false; label_ManualConfiguration.IsEnabled = false; label_SecurityKey_Clear.Visibility = Visibility.Collapsed; // trigger enable of UI elements after delay // different for WinPE session than Windows session // in WinPE measurements on a Surface 4 Pro showed a 60 seconds delay before the wlan subsystem was ready! var task = Task.Factory.StartNew(() => { Application.Current.Dispatcher.Invoke(new Action(() => { Cursor = Cursors.Wait; })); // wait time for Windows Session var waitSeconds = 0.5F; if (!string.IsNullOrWhiteSpace(winPEVersion)) { // wait time for WinPE Session if (!debug) { waitSeconds = 55; } else // prevent wait if debug command line argument is specified... { waitSeconds = 1; } } Thread.Sleep((int)waitSeconds * 1000); Application.Current.Dispatcher.Invoke(new Action(() => { winFormHost.Visibility = Visibility.Collapsed; button_Refresh_Click(null, null); listBox_Networks.IsEnabled = true; button_Refresh.IsEnabled = true; button_Refresh.Content = "Refresh"; textBox_SecurityKey.IsEnabled = true; textBox_NetworkName.IsEnabled = true; comboBox_Authentication.IsEnabled = true; button_Continue.IsEnabled = false; button_ConnectDisconnect.IsEnabled = true; expander_ManualConfiguration.IsEnabled = true; label_ManualConfiguration.IsEnabled = true; Cursor = Cursors.Arrow; })); StartNetworkAvailabilityBackgroundCheck(); }); }
private void NetworkConnectivityBackgroundCheck() { try { if (NetworkConfig.IsWiredNetworkAvailable()) { if (connectionState.Wired != "Green") { connectionState.Wired = "Green"; button_Continue.IsEnabled = true; } if (connectionState.Wired == "Green") { ConnectionState_CheckForInternetReady(null, null); } if (useWiredConnectionQuestion) { var result = MessageBox.Show("Wired network connection available\nDo you want to use the wired connection?", "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { Application.Current.Shutdown(); } else { useWiredConnectionQuestion = false; } } } else { if (connectionState.Wired != "Red") { connectionState.Wired = "Red"; connectionState.InternetAccess = "Red"; button_Continue.IsEnabled = false; } // would you like to see the choice everytime a network cable is plugged in, uncomment next line... // otherwise it's displayed only at the first time //useWiredConnection = true; } if (NetworkConfig.GetWirelessNetworkConnectionState()) { if (connectionState.Wireless != "Green") { connectionState.Wireless = "Green"; listBox_Networks.IsEnabled = false; button_Refresh.IsEnabled = false; if (!string.IsNullOrWhiteSpace(textBox_SecurityKey.Text)) { currentSecurityKey = textBox_SecurityKey.Text; textBox_SecurityKey.Text = "*********************"; } textBox_SecurityKey.IsEnabled = false; textBox_NetworkName.IsEnabled = false; comboBox_Authentication.IsEnabled = false; //button_Continue.IsEnabled = true; button_ConnectDisconnect.Content = "Disconnect"; expander_ManualConfiguration.IsEnabled = false; label_ManualConfiguration.IsEnabled = false; button_Continue.Focus(); button_Continue.IsEnabled = true; label_NetworkName_Clear.IsEnabled = false; label_SecurityKey_Clear.IsEnabled = false; } if (connectionState.Wireless == "Green") { ConnectionState_CheckForInternetReady(null, null); } } else { if (connectionState.Wireless != "Red") { connectionState.Wireless = "Red"; button_ConnectDisconnect.Content = "Connect"; listBox_Networks.IsEnabled = true; button_Refresh.IsEnabled = true; if (!string.IsNullOrWhiteSpace(textBox_SecurityKey.Text)) { textBox_SecurityKey.Text = currentSecurityKey; } textBox_SecurityKey.IsEnabled = true; textBox_NetworkName.IsEnabled = true; comboBox_Authentication.IsEnabled = true; button_Continue.IsEnabled = false; textBox_NetworkName.Text = string.Empty; expander_ManualConfiguration.IsEnabled = true; label_ManualConfiguration.IsEnabled = true; label_NetworkName_Clear.IsEnabled = true; label_SecurityKey_Clear.IsEnabled = true; } } } catch (Exception) { } }