public void PrinterOnline(ZebraCardPrinter zebraCardPrinter, string firmwareVersion)
        {
            Connection newConnection = null;

            try {
                DiscoveredPrinter newPrinter = null;
                newConnection = zebraCardPrinter.Connection;
                newConnection.Open();

                Dictionary <string, string> discoveryData = DiscoveryUtilCard.GetDiscoveryDataMap(newConnection);

                if (oldPrinter is DiscoveredUsbPrinter)
                {
                    newPrinter = new DiscoveredUsbPrinter((newConnection as UsbConnection).SimpleConnectionName, discoveryData);
                }
                else if (oldPrinter is DiscoveredCardPrinterNetwork)
                {
                    newPrinter = new DiscoveredCardPrinterNetwork(discoveryData);
                }
                else
                {
                    throw new ArgumentException("Not a reconnectable printer type");
                }

                ReconnectionFinished(newPrinter);
            } catch (Exception e) {
                MessageBoxHelper.ShowError("Could not reconnect to printer: " + e.Message);
            } finally {
                ConnectionHelper.CleanUpQuietly(zebraCardPrinter, newConnection);
            }
        }
Exemple #2
0
        private void ConnectButton_Click(object sender, RoutedEventArgs e)
        {
            string ipAddressText = IpAddressInput.Text;

            IndeterminateProgressDialog indeterminateProgressDialog = new IndeterminateProgressDialog($"Connecting to {ipAddressText}...");

            Task.Run(() => {
                Application.Current.Dispatcher.Invoke(() => {
                    indeterminateProgressDialog.ShowDialog();
                });
            });

            Task.Run(() => {
                TcpConnection connection          = null;
                ZebraCardPrinter zebraCardPrinter = null;

                try {
                    connection = GetTcpConnection(ipAddressText);
                    connection.Open();

                    zebraCardPrinter = ZebraCardPrinterFactory.GetInstance(connection);

                    string model = zebraCardPrinter.GetPrinterInformation().Model;
                    if (model != null)
                    {
                        if (!model.ToLower().Contains("zxp1") && !model.ToLower().Contains("zxp3"))
                        {
                            printerManager.Printer = new DiscoveredCardPrinterNetwork(DiscoveryUtilCard.GetDiscoveryDataMap(connection));

                            Application.Current.Dispatcher.Invoke(() => {
                                Close();
                            });
                        }
                        else
                        {
                            throw new ConnectionException("Printer model not supported");
                        }
                    }
                    else
                    {
                        throw new SettingsException("No printer model found");
                    }
                } catch (Exception exception) {
                    MessageBoxHelper.ShowError($"Error connecting to printer {ipAddressText}: {exception.Message}");
                } finally {
                    ConnectionHelper.CleanUpQuietly(zebraCardPrinter, connection);

                    Application.Current.Dispatcher.Invoke(() => {
                        indeterminateProgressDialog.Close();
                    });
                }
            });
        }