예제 #1
0
        public PrinterDiscoveryWindow()
        {
            InitializeComponent();

            selectedPrinterInfo = new PrinterInfo();

            DoubleAnimation da = new DoubleAnimation()
            {
                From           = 0,
                To             = 360,
                Duration       = new Duration(TimeSpan.FromSeconds(1.5)),
                RepeatBehavior = RepeatBehavior.Forever
            };

            rt = new RotateTransform();
            animatedDiscoveryArrow_image.RenderTransform       = rt;
            animatedDiscoveryArrow_image.RenderTransformOrigin = new Point(0.5, 0.5);
            rt.BeginAnimation(RotateTransform.AngleProperty, da);

            List <DiscoveredUsbPrinter> connectedUsbPrinters = UsbDiscoverer.GetZebraUsbPrinters(new ZebraPrinterFilter());

            foreach (DiscoveredUsbPrinter usbPrinter in connectedUsbPrinters)
            {
                string imageSource = "/Resources/usb.png";
                Application.Current.Dispatcher.Invoke(() => {
                    PrinterDiscoverListView.Items.Add(new { ConnectionImageSource = imageSource, FriendlyName = "USB Printer (" + usbPrinter.DiscoveryDataMap["SERIAL_NUMBER"] + ")", IpAddress = usbPrinter.Address });
                });
            }

            DiscoveryHandlerImpl networkDiscoHandler = new DiscoveryHandlerImpl(this);

            NetworkDiscoverer.FindPrinters(networkDiscoHandler);

            DiscoveryHandlerImpl bluetoothDiscoHandler = null;

            if (IsBluetoothSupported())
            {
                bluetoothDiscoHandler = new DiscoveryHandlerImpl(this);
                BluetoothDiscoverer.FindPrinters(bluetoothDiscoHandler);
            }

            if (bluetoothDiscoHandler != null)
            {
                Task.Run(() => {
                    while (!bluetoothDiscoHandler.DiscoveryComplete || !networkDiscoHandler.DiscoveryComplete)
                    {
                        Thread.Sleep(50);
                    }
                    Application.Current.Dispatcher.Invoke(() => {
                        animatedDiscoveryArrow_image.Visibility = Visibility.Hidden;
                    });
                });
            }
            else
            {
                Task.Run(() => {
                    while (!networkDiscoHandler.DiscoveryComplete)
                    {
                        Thread.Sleep(50);
                    }
                    Application.Current.Dispatcher.Invoke(() => {
                        animatedDiscoveryArrow_image.Visibility = Visibility.Hidden;
                    });
                });
            }
        }
예제 #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;
            }
        }