Exemple #1
0
        private void TryToConnect(object sender, RoutedEventArgs e)
        {
            Overlay.Show("Connecting");

            ConnControl.Visibility = Visibility.Visible;

            var conType = CreateConnection();

            Dispatcher.Invoke(new Action(async() =>
            {
                if (conType != null)
                {
                    _brick = new Brick(conType, true);
                    _brick.BrickChanged += _brick_BrickChanged;
                    try
                    {
                        await _brick.ConnectAsync();
                        ConnControl.Visibility = Visibility.Collapsed;

                        ConnTypeRun.Text = ConnControl.GetConnectionType().ToString();
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Could not connect", "Error", MessageBoxButton.OK);
                    }
                }
                else
                {
                    MessageBox.Show("Invalid connection type for this device", "Error", MessageBoxButton.OK);
                }

                Overlay.Hide();
            }));
        }
Exemple #2
0
        private ICommunication CreateConnection()
        {
            ICommunication returnType = null;

            switch (ConnControl.GetConnectionType())
            {
            case ConnectionType.Bluetooth:
                returnType = new BluetoothCommunication();
                break;

            case ConnectionType.WiFi:
                returnType = new NetworkCommunication(ConnControl.GetIpAddress());
                break;
            }

            return(returnType);
        }
Exemple #3
0
        private ICommunication CreateConnection()
        {
            ICommunication returnType = null;

            switch (ConnControl.GetConnectionType())
            {
            case ConnectionType.Bluetooth:
                //returnType = new BluetoothCommunication(ConnControl.GetComportNumber());
                //break;
                throw new NotSupportedException("Bluetooth is not supported at the moment");

            case ConnectionType.Usb:
                returnType = new UsbCommunication();
                break;

            case ConnectionType.WiFi:
                returnType = new NetworkCommunication(ConnControl.GetIpAddress());
                break;
            }

            return(returnType);
        }
Exemple #4
0
        private async void TryToConnect(object sender, RoutedEventArgs e)
        {
            Overlay.Show("Connecting");

            //ApplicationBar.IsVisible = false;
            ConnControl.Visibility = Visibility.Visible;

            var conType = CreateConnection();

            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
            {
                if (conType != null)
                {
                    _brick = new Brick(conType, true);
                    _brick.BrickChanged += _brick_BrickChanged;
                    try
                    {
                        await _brick.ConnectAsync();
                        ConnControl.Visibility = Visibility.Collapsed;

                        ConnTypeRun.Text = ConnControl.GetConnectionType().ToString();
                        //ApplicationBar.IsVisible = true;
                    }
                    catch (Exception)
                    {
                        new MessageDialog("Could not connect", "Error").ShowAsync();
                    }
                }
                else
                {
                    MessageDialog dialog = new MessageDialog("Invalid connection type for this device", "Error");

                    await dialog.ShowAsync();
                }

                Overlay.Hide();
            });
        }