public async Task <WiFiConnectionStatus> ConnectToNetwork(WiFiListViewItemPresenter network, bool autoConnect)
        {
            await Window.Current.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                _availableNetworksLock.WaitAsync();
            });

            if (network == null)
            {
                return(WiFiConnectionStatus.UnspecifiedFailure);
            }

            try
            {
                var result = await network.Adapter.ConnectAsync(network.AvailableNetwork, autoConnect?WiFiReconnectionKind.Automatic : WiFiReconnectionKind.Manual);

                // Call redirect only for Open WiFi
                if (NetworkPresenter.IsNetworkOpen(network))
                {
                    // Navigate to http://www.msftconnecttest.com/redirect
                    await Window.Current.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                    {
                        await DoRedirectDialogAsync();
                    });
                }

                App.LogService.Write($"LEAVE {result.ConnectionStatus}");
                return(result.ConnectionStatus);
            }
            catch (Exception)
            {
                return(WiFiConnectionStatus.UnspecifiedFailure);
            }
        }
        private async void ConnectButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                EnableView(false, true);

                var button  = sender as Button;
                var network = button.DataContext as WiFiListViewItemPresenter;
                if (NetworkPresenter.IsNetworkOpen(network))
                {
                    await ConnectToWiFiAsync(network, null, Window.Current.Dispatcher);
                }
                else if (network.IsEapAvailable)
                {
                    SwitchToItemState(network, WiFiEapPasswordState, false);
                }
                else
                {
                    SwitchToItemState(network, WiFiPasswordState, false);
                }
            }
            catch (Exception ex)
            {
                App.LogService.Write(ex.ToString());
                throw;
            }
            finally
            {
                EnableView(true, true);
            }
        }
 /// <summary>
 /// 簡易サーバーを開始
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void clickStartServer(object sender, RoutedEventArgs e)
 {
     this.textIP.Text    = NetworkPresenter.GetCurrentIpv4Address();
     _server             = new SimpleWebServer();
     _server.OnReceived += _server_OnReceived;
     _server.Start();
 }
Exemple #4
0
        private void OnSetupTextboxGotFocus(object sender, RoutedEventArgs e)
        {
            TextBox tbx = sender as TextBox;

            if (tbx.Text.Trim() == "")
            {
                tbx.Text = "http://" + NetworkPresenter.GetCurrentIpv4Address() + "/" + tbx.Tag + "/public";
            }
        }
        public async Task UpdateNetworkInfo()
        {
            this.DeviceName   = DeviceInfoPresenter.GetDeviceName();
            this.IpAddress1   = NetworkPresenter.GetCurrentIpv4Address();
            this.NetworkName1 = NetworkPresenter.GetCurrentNetworkName();

            var networkInfos = await NetworkPresenter.GetNetworkInformation();

            this.NetworkInfos = new ObservableCollection <NetworkPresenter.NetworkInfo>(networkInfos);
        }
Exemple #6
0
 private void ConnectButtonClicked(WiFiAvailableNetwork network)
 {
     if (NetworkPresenter.IsNetworkOpen(network))
     {
         ConnectToWifi(network, null, Window.Current.Dispatcher);
     }
     else
     {
         WifiPassword = "";
         SwitchToItemState(network, "WifiPasswordState", false);
     }
 }
Exemple #7
0
        private void SetupEthernet()
        {
            var ethernetProfile = NetworkPresenter.GetDirectConnectionName();

            if (ethernetProfile == null)
            {
                NoneFoundVisibility        = Visibility.Visible;
                DirectConnectionVisibility = Visibility.Collapsed;
            }
            else
            {
                NoneFoundVisibility        = Visibility.Collapsed;
                DirectConnectionVisibility = Visibility.Visible;
            }
        }
        public void SetUpDirectConnection()
        {
            var ethernetProfile = NetworkPresenter.GetDirectConnectionName();

            if (ethernetProfile == null)
            {
                NoneFoundText.Visibility = Visibility.Visible;
                DirectConnectionStackPanel.Visibility = Visibility.Collapsed;
            }
            else
            {
                NoneFoundText.Visibility = Visibility.Collapsed;
                DirectConnectionStackPanel.Visibility = Visibility.Visible;
            }
        }
        private async Task OnConnected(WiFiListViewItemPresenter network, WiFiConnectionStatus status, CoreDispatcher dispatcher)
        {
            if (status == WiFiConnectionStatus.Success)
            {
                await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    var itemLocation = WiFiListViewItems.IndexOf(network);

                    // Don't move if index is -1 or 0
                    if (itemLocation > 0)
                    {
                        // Make sure first network doesn't also show connected
                        SwitchToItemState(WiFiListViewItems[0], WiFiInitialState, true);

                        // Show current connected network at top of list in connected state
                        WiFiListViewItems.Move(itemLocation, 0);
                    }

                    network.Message          = string.Empty;
                    network.IsMessageVisible = false;

                    var item = SwitchToItemState(network, WiFiConnectedState, true);
                    if (item != null)
                    {
                        item.IsSelected = true;
                    }
                });

                if (!NetworkPresenter.IsNetworkOpen(network))
                {
                    NetworkConnected?.Invoke(this, new EventArgs());
                }
            }
            else
            {
                // Entering the wrong password may cause connection attempts to timeout
                // Disconnecting the adapter will return it to a non-busy state
                if (status == WiFiConnectionStatus.Timeout)
                {
                    network.Adapter.Disconnect();
                }
                var resourceLoader = ResourceLoader.GetForCurrentView();
                network.Message          = Common.GetLocalizedText(status.ToString() + "Text");
                network.IsMessageVisible = true;
                SwitchToItemState(network, WiFiConnectState, true);
            }
        }
Exemple #10
0
        public static string SerializeMessage(string apiSettings, string action, string param)
        {
            var dataObj = new BridgeMessage()
            {
                Timestamp   = DateTime.Now,
                IpFrom      = NetworkPresenter.GetCurrentIpv4Address(),
                ApiSettings = apiSettings,
                Action      = action,
                Parameter   = param
            };

            string body = JsonConvert.SerializeObject(dataObj, Formatting.None, new JsonSerializerSettings()
            {
                NullValueHandling = NullValueHandling.Ignore
            });

            return(body);
        }
Exemple #11
0
        // Displays basic device info
        private void DisplayDeviceInfoDialog(object sender, RoutedEventArgs e)
        {
            string msg = string.Format(Common.GetLocalizedText("DeviceInfoDialogMessage"),
                                       NetworkPresenter.GetCurrentIpv4Address(),
                                       Common.GetOSVersionString(),
                                       Common.GetAppVersion());

            foreach (var feature in AppComposer.Imports.Features)
            {
                if (!string.IsNullOrEmpty(feature.DeviceInfo))
                {
                    msg += "\n" + feature.DeviceInfo;
                }
            }

            DialogButton primaryButton = new DialogButton(Common.GetLocalizedText("DeviceInfoDialogButton"), (Sender, ClickEventsArgs) =>
            {
                NavigateTo(typeof(DeviceInfoPage));
            });

            AppService.DisplayDialog(Common.GetLocalizedText("DeviceInfoDialogTitle"), msg, primaryButton);
        }
        private async Task <bool> UpdateNetworkInfo()
        {
            DeviceName  = DeviceInfoPresenter.GetDeviceName();
            IPAddress   = NetworkPresenter.GetCurrentIpv4Address();
            NetworkName = NetworkPresenter.GetCurrentNetworkName();
            AppBuild    = Common.GetAppVersion();

            AzureHub      = IoTHubService?.HostName ?? Common.GetLocalizedText("NotAvailable");
            AzureDeviceId = IoTHubService?.DeviceId ?? Common.GetLocalizedText("NotAvailable");

            var networkInfoList = await NetworkPresenter.GetNetworkInformation();

            if (networkInfoList != null)
            {
                NetworkCollection.Clear();
                foreach (var network in networkInfoList)
                {
                    NetworkCollection.Add(new NetworkInfoDataTemplate(network));
                }
                return(true);
            }
            return(false);
        }
Exemple #13
0
 private void SetupDeviceNames()
 {
     DeviceName      = DeviceInfoPresenter.GetDeviceName();
     DeviceIpAddress = NetworkPresenter.GetCurrentIpv4Address();
 }
Exemple #14
0
        /// <summary>
        /// Invoked when the application is launched normally by the end user. Other entry points
        /// will be used such as when the application is launched to open a specific file.
        /// </summary>
        /// <param name="e">Details about the launch request and process.</param>
        protected override async void OnLaunched(LaunchActivatedEventArgs e)
        {
            LogService.Write();

            // Check if this is the first time the app is being launched
            // If OnLaunched is called again when the app is still running (e.g. selecting "Switch to" in WDP
            // while the app is running), the initialization code should not run again
            if (!(Window.Current.Content is Frame rootFrame))
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();
                rootFrame.NavigationFailed += OnNavigationFailed;

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;

                // Try to set the map token from file located in LocalState folder
                await WeatherHelper.SetMapTokenFromFileAsync("MapToken.config");

                // Enable kiosk mode if file is detected
                Settings.KioskMode = await FileUtil.ReadFileAsync("kiosk_mode") != null;

                // Use MEF to import features and components from other assemblies in the appx package.
                foreach (var feature in AppComposer.Imports.Features)
                {
                    try
                    {
                        LogService.Write($"Loading Feature: {feature.FeatureName}");
                        feature.OnLoaded(this);
                    }
                    catch (Exception ex)
                    {
                        LogService.Write(ex.ToString());
                    }
                }

                // Enable multi-view
                MultiViewManager            = new MultiViewManager(Window.Current.Dispatcher, ApplicationView.GetForCurrentView().Id);
                MultiViewManager.ViewAdded += MultiViewManager_ViewAdded;

                // Subscribe for IoT Hub property updates if available
                var iotHubService = GetForCurrentContext().GetRegisteredService <IIoTHubService>();
                if (iotHubService != null)
                {
                    iotHubService.DesiredPropertyUpdated += App_DesiredPropertyUpdated;
                }

                // Make sure we weren't launched in the background
                if (e != null && e.PrelaunchActivated == false)
                {
                    // When the navigation stack isn't restored navigate to the first page,
                    // configuring the new page by passing required information as a navigation
                    // parameter

#if !FORCE_OOBE_WELCOME_SCREEN
                    if (ApplicationData.Current.LocalSettings.Values.ContainsKey(Constants.HasDoneOOBEKey))
                    {
                        rootFrame.Navigate(typeof(MainPage), e.Arguments);
                    }
                    else
#endif
                    {
                        rootFrame.Navigate(typeof(OOBEWelcomePage), e.Arguments);
                    }
                }
            }

            // Ensure the current window is active
            Window.Current.Activate();

            // Update asynchronously
            var updateAsyncTask = NetworkPresenter.UpdateAvailableNetworksAsync(false);
        }
Exemple #15
0
 private void UpdateNetworkInfo()
 {
     DeviceName  = DeviceInfoPresenter.GetDeviceName();
     IPv4Address = NetworkPresenter.GetCurrentIpv4Address();
 }