private void doDirectBroadcast(String directBroadcastRange)
 {
     try {
         DiscoveredPrinter[] printers = NetworkDiscoverer.DirectedBroadcast(directBroadcastRange);
         displayPrinters(printers);
     } catch (DiscoveryException ex) {
         handleException(ex.Message);
     }
 }
Example #2
0
        /// <exception cref="ConnectionException"></exception>
        /// <exception cref="DiscoveryException"></exception>
        private void PerformDiscovery()
        {
            DiscoveryHandlerImpl discoveryHandler = new DiscoveryHandlerImpl(this);

            switch (discoveryMethodsDropdown.SelectedItem)
            {
            case DiscoveryMethod.DirectedBroadcast:
                NetworkDiscoverer.DirectedBroadcast(discoveryHandler, viewModel.IpAddress);
                break;

            case DiscoveryMethod.FindPrintersNearMe:
                NetworkDiscoverer.FindPrinters(discoveryHandler);
                break;

            case DiscoveryMethod.LocalBroadcast:
                NetworkDiscoverer.LocalBroadcast(discoveryHandler);
                break;

            case DiscoveryMethod.MulticastBroadcast:
                NetworkDiscoverer.Multicast(discoveryHandler, int.Parse(viewModel.NumberOfHops));
                break;

            case DiscoveryMethod.SubnetSearch:
                NetworkDiscoverer.SubnetSearch(discoveryHandler, viewModel.SubnetRange);
                break;

            case DiscoveryMethod.ZebraUsbDrivers:
                try {
                    discoveryHandler = null;
                    discoverPrintersButton.IsEnabled = false;
                    viewModel.DiscoveredPrinters.Clear();

                    foreach (DiscoveredPrinterDriver printer in UsbDiscoverer.GetZebraDriverPrinters())
                    {
                        viewModel.DiscoveredPrinters.Add(printer);
                    }
                } finally {
                    SetDiscoverButtonState(true);
                }
                break;

            case DiscoveryMethod.UsbDirect:
                try {
                    discoveryHandler = null;
                    discoverPrintersButton.IsEnabled = false;
                    viewModel.DiscoveredPrinters.Clear();

                    foreach (DiscoveredUsbPrinter printer in UsbDiscoverer.GetZebraUsbPrinters())
                    {
                        viewModel.DiscoveredPrinters.Add(printer);
                    }
                } finally {
                    SetDiscoverButtonState(true);
                }
                break;

            case DiscoveryMethod.Bluetooth:
                BluetoothDiscoverer.FindPrinters(discoveryHandler);
                break;
            }
        }
Example #3
0
        private async void DiscoverPrintersButton_Clicked(object sender, EventArgs eventArgs)
        {
            SetInputEnabled(false);

            try {
                ClearDiscoveredPrinters();

                DiscoveryHandlerImplementation discoveryHandler = new DiscoveryHandlerImplementation(this);

                await Task.Factory.StartNew(() => {
                    switch (GetSelectedDiscoveryMethod())
                    {
                    case DiscoveryMethod.LocalBroadcast:
                        NetworkDiscoverer.LocalBroadcast(discoveryHandler);
                        break;

                    case DiscoveryMethod.DirectedBroadcast:
                        NetworkDiscoverer.DirectedBroadcast(discoveryHandler, IpAddressEntry.Text);
                        break;

                    case DiscoveryMethod.MulticastBroadcast:
                        if (string.IsNullOrWhiteSpace(NumberOfHopsEntry.Text))
                        {
                            throw new ArgumentException("Number of hops must not be empty");
                        }

                        try {
                            NetworkDiscoverer.Multicast(discoveryHandler, int.Parse(NumberOfHopsEntry.Text));
                        } catch (FormatException) {
                            Device.BeginInvokeOnMainThread(async() => {
                                await DisplayAlert("Format Error", "Number of hops must be an integer", "OK");
                            });
                        } finally {
                            SetInputEnabled(true);
                        }
                        break;

                    case DiscoveryMethod.SubnetSearch:
                        if (string.IsNullOrWhiteSpace(SubnetRangeEntry.Text))
                        {
                            throw new ArgumentException("Subnet range must not be empty");
                        }

                        NetworkDiscoverer.SubnetSearch(discoveryHandler, SubnetRangeEntry.Text);
                        break;

                    case DiscoveryMethod.ZebraUsbDrivers:
                        try {
                            foreach (DiscoveredPrinter printer in DependencyService.Get <IConnectionManager>().GetZebraUsbDriverPrinters())
                            {
                                Device.BeginInvokeOnMainThread(() => {
                                    discoveredPrinters.Add(printer);
                                });
                            }
                        } catch (NotImplementedException) {
                            Device.BeginInvokeOnMainThread(async() => {
                                await DisplayAlert("Error", "USB driver discovery not supported on this platform", "OK");
                            });
                        } finally {
                            SetInputEnabled(true);
                        }
                        break;

                    case DiscoveryMethod.UsbDirect:
                        try {
                            DependencyService.Get <IConnectionManager>().GetZebraUsbDirectPrinters(discoveryHandler);
                        } catch (NotImplementedException) {
                            Device.BeginInvokeOnMainThread(async() => {
                                await DisplayAlert("Error", "USB direct discovery not supported on this platform", "OK");
                            });
                        } finally {
                            SetInputEnabled(true);
                        }
                        break;

                    case DiscoveryMethod.FindPrintersNearMe:
                        NetworkDiscoverer.FindPrinters(discoveryHandler);
                        break;

                    case DiscoveryMethod.FindAllBluetoothDevices:
                        try {
                            DependencyService.Get <IConnectionManager>().FindBluetoothPrinters(discoveryHandler);
                        } catch (NotImplementedException) {
                            Device.BeginInvokeOnMainThread(async() => {
                                await DisplayAlert("Error", "Bluetooth discovery not supported on this platform", "OK");
                            });
                        } finally {
                            SetInputEnabled(true);
                        }
                        break;
                    }
                });
            } catch (Exception e) {
                await DisplayAlert("Error", e.Message, "OK");

                SetInputEnabled(true);
            }
        }