private void UploadProfile(string profilePath, Connection connection)
        {
            if (connection != null)
            {
                try {
                    connection.Open();
                    ZebraPrinter       genericPrinter = ZebraPrinterFactory.GetInstance(connection);
                    ZebraPrinterLinkOs printer        = ZebraPrinterFactory.CreateLinkOsPrinter(genericPrinter);

                    if (printer != null)
                    {
                        printer.LoadProfile(profilePath, FileDeletionOption.NONE, false);
                        string printerAddress = connectionSelector.getConnectionAddress();
                        MessageBoxCreator.ShowInformation($"Profile loaded successfully to printer {printerAddress}", "Profile Uploaded Successfully");
                    }
                    else
                    {
                        MessageBoxCreator.ShowError("Profile loading is only available on Link-OS(TM) printers", "Error");
                    }
                } catch (ConnectionException e) {
                    MessageBoxCreator.ShowError(e.Message, "Connection Error");
                } catch (ZebraPrinterLanguageUnknownException e) {
                    MessageBoxCreator.ShowError(e.Message, "Connection Error");
                } catch (IOException e) {
                    MessageBoxCreator.ShowError(e.Message, "Connection Error");
                } catch (Exception e) {
                    MessageBoxCreator.ShowError(e.Message, "Upload Profile Error");
                } finally {
                    SetButtonStates(true);
                    try {
                        connection.Close();
                    } catch (ConnectionException) { }
                }
            }
        }
        private void PrintFormat(string formatName)
        {
            Connection printerConnection = null;

            try {
                printerConnection = connectionSelector.GetConnection();
                printerConnection.Open();

                Dictionary <int, string> formatVars = GetFormatVariables();
                ZebraPrinterFactory.GetInstance(printerConnection).PrintStoredFormat(formatName, formatVars, "UTF-8");
            } catch (ArgumentException e) {
                MessageBoxCreator.ShowError(e.Message, "Communication Error");
            } catch (ConnectionException e) {
                MessageBoxCreator.ShowError(e.Message, "Communication Error");
            } catch (ZebraPrinterLanguageUnknownException e) {
                MessageBoxCreator.ShowError(e.Message, "Communication Error");
            } finally {
                if (printerConnection != null)
                {
                    try {
                        printerConnection.Close();
                    } catch (ConnectionException) { }
                }
            }
        }
Ejemplo n.º 3
0
 void Start()
 {
     //This creates the message box with the given style.
     // MessageBoxCreator.CreateMessageBox(myStyle);
     Detector.pause = true;
     //This would create a message box and override the text whilst keeping to the style.
     MessageBoxCreator.CreateMessageBox(myStyle, "Bienvenido(a): " + Menu.nombre, "La compañia Xim-Miners puso unas vigas para delimitar la zona en la que tienes que minar. ¡No dejes de minar!.", "Aceptar");
 }
 private void RetrieveFormatsButton_Click(object sender, RoutedEventArgs e)
 {
     try {
         SetButtonState(retrieveFormatsButton, false);
         PopulateListWithFormats();
     } catch (Exception ex) {
         MessageBoxCreator.ShowError(ex.Message, "Stored Format Error");
     }
 }
Ejemplo n.º 5
0
 private void GetPrinterStatusButton_Click(object sender, RoutedEventArgs e)
 {
     try {
         SetTestButtonState(false);
         GetPrinterStatus();
     } catch (Exception ex) {
         MessageBoxCreator.ShowError(ex.Message, "Printer Status Error");
     }
 }
Ejemplo n.º 6
0
 private void SendFileButton_Click(object sender, RoutedEventArgs e)
 {
     try {
         SetSendFileButtonState(false);
         SendFileToPrinter();
     } catch (Exception ex) {
         MessageBoxCreator.ShowError(ex.Message, "Send File Error");
     }
 }
Ejemplo n.º 7
0
 private void RunSmartCardDemo(bool sendData)
 {
     try {
         SetButtonStates(false);
         ReadSmartCard(sendData);
     } catch (Exception e) {
         MessageBoxCreator.ShowError(e.Message, "Smart Card Error");
     }
 }
Ejemplo n.º 8
0
 private void ReadMagCardButton_Click(object sender, RoutedEventArgs e)
 {
     try {
         SetButtonState(false);
         UpdateMagCardOutput("");
         ReadMagCard();
     } catch (Exception ex) {
         MessageBoxCreator.ShowError(ex.Message, "Mag Card Data Error");
     }
 }
        private void UpdateSettingsTable()
        {
            Connection connection = null;

            try {
                connection = connectionSelector.GetConnection();
                connection.Open();

                ZebraPrinter       genericPrinter = ZebraPrinterFactory.GetInstance(connection);
                ZebraPrinterLinkOs printer        = ZebraPrinterFactory.CreateLinkOsPrinter(genericPrinter);

                if (printer != null)
                {
                    Dictionary <string, Sdk.Settings.Setting> settings = printer.GetAllSettings();

                    Application.Current.Dispatcher.Invoke(() => {
                        if (settings != null)
                        {
                            foreach (string key in settings.Keys)
                            {
                                viewModel.Settings.Add(new Setting {
                                    Key = key, Value = settings[key].Value, Range = printer.GetSettingRange(key)
                                });
                            }
                        }
                        else
                        {
                            MessageBoxCreator.ShowError("Error reading settings", "Settings Error");
                        }

                        printerSettingsGrid.UnselectAll();
                    });
                }
                else
                {
                    MessageBoxCreator.ShowError("Connected printer does not support settings", "Connection Error");
                }
            } catch (ConnectionException e) {
                MessageBoxCreator.ShowError(e.Message, "Connection Error");
            } catch (ZebraPrinterLanguageUnknownException e) {
                MessageBoxCreator.ShowError(e.Message, "Connection Error");
            } catch (SettingsException e) {
                MessageBoxCreator.ShowError(e.Message, "Settings Error");
            } catch (Exception e) {
                MessageBoxCreator.ShowError(e.Message, "Save Settings Error");
            } finally {
                SetButtonStates(true);
                try {
                    if (connection != null)
                    {
                        connection.Close();
                    }
                } catch (ConnectionException) { }
            }
        }
        private void TestConnectionStringButton_Click(object sender, RoutedEventArgs e)
        {
            try {
                viewModel.LogData = "Log:\n\n";
                SetTestButtonState(false);

                TestConnectionString();
            } catch (Exception ex) {
                MessageBoxCreator.ShowError(ex.Message, "Connection Builder Error");
            }
        }
 private async void GetSettingsButton_Click(object sender, RoutedEventArgs e)
 {
     try {
         SetButtonStates(false);
         ClearSettings();
         await Task.Run(() => UpdateSettingsTable());
     } catch (Exception ex) {
         MessageBoxCreator.ShowError(ex.Message, "Get Settings Error");
         SetButtonStates(true);
     }
 }
Ejemplo n.º 12
0
        private void GetPrinterStatus()
        {
            Connection printerConnection = null;

            Task.Run(() => {
                try {
                    printerConnection = connectionSelector.GetConnection();
                    printerConnection.Open();

                    ZebraPrinter printer             = ZebraPrinterFactory.GetInstance(printerConnection);
                    ZebraPrinterLinkOs linkOsPrinter = ZebraPrinterFactory.CreateLinkOsPrinter(printer);

                    ZebraPrinterStatus status = (linkOsPrinter != null) ? linkOsPrinter.GetCurrentStatus() : printer.GetCurrentStatus();

                    string[] printerStatusString      = new PrinterStatusMessages(status).GetStatusMessage();
                    List <string> printerStatusPrefix = GetPrinterStatusPrefix(status);

                    StringBuilder sb = new StringBuilder();
                    foreach (string s in printerStatusPrefix)
                    {
                        sb.AppendLine(s);
                    }

                    foreach (string s in printerStatusString)
                    {
                        sb.AppendLine(s);
                    }

                    Application.Current.Dispatcher.Invoke(() => {
                        printerStatus.Text = sb.ToString();
                    });
                } catch (ConnectionException e) {
                    MessageBoxCreator.ShowError(e.Message, "Connection Error");
                } catch (ZebraPrinterLanguageUnknownException e) {
                    MessageBoxCreator.ShowError(e.Message, "Connection Error");
                } finally {
                    if (printerConnection != null)
                    {
                        try {
                            printerConnection.Close();
                        } catch (ConnectionException) {
                        } finally {
                            SetTestButtonState(true);
                        }
                    }
                    else
                    {
                        SetTestButtonState(true);
                    }
                }
            });
        }
        private void CreateFormatTableDialog()
        {
            SetButtonState(retrieveFormatsButton, false);
            SetFormatListState(false);

            string     formatName        = (string)storedFilesList.SelectedValue;
            Connection printerConnection = null;

            Task.Run(() => {
                try {
                    printerConnection = connectionSelector.GetConnection();
                    printerConnection.Open();

                    ZebraPrinter printer = ZebraPrinterFactory.GetInstance(printerConnection);
                    byte[] formatData    = printer.RetrieveFormatFromPrinter(formatName);

                    fieldDescDataVars = printer.GetVariableFields(Encoding.UTF8.GetString(formatData)).ToList();
                    fieldDescDataVars = FormatFieldDescriptionDataVars(fieldDescDataVars);

                    formatVariables = new ObservableCollection <FormatVariable>();
                    for (int i = 0; i < fieldDescDataVars.Count; ++i)
                    {
                        formatVariables.Add(new FormatVariable {
                            FieldName = fieldDescDataVars[i].FieldName, FieldValue = ""
                        });
                    }

                    try {
                        if (printerConnection != null)
                        {
                            printerConnection.Close();
                        }
                    } catch (ConnectionException) { }

                    ShowStoredFormatDialog(formatName);
                } catch (Exception e) {
                    MessageBoxCreator.ShowError(e.Message, "Communication Error");
                    SetButtonState(retrieveFormatsButton, true);
                    SetFormatListState(true);
                } finally {
                    try {
                        if (printerConnection != null && printerConnection.Connected)
                        {
                            printerConnection.Close();
                        }
                    } catch (ConnectionException) { }
                }
            });
        }
        private void TestConnectionString()
        {
            Task.Run(() => {
                try {
                    ClearProgress();
                    connection = ZebraConnectionBuilder.Build(GetConnectionStringForSdk());
                    PublishProgress("Connection string evaluated as class type " + connection.GetType().Name);
                    connection.Open();

                    PublishProgress("Connection opened successfully");

                    if (IsAttemptingStatusConnection())
                    {
                        ZebraPrinterLinkOs printer = ZebraPrinterFactory.GetLinkOsPrinter(connection);
                        PublishProgress("Created a printer, attempting to retrieve status");

                        ZebraPrinterStatus status = printer.GetCurrentStatus();
                        PublishProgress("Is printer ready to print? " + status.isReadyToPrint);
                    }
                    else
                    {
                        ZebraPrinter printer = ZebraPrinterFactory.GetInstance(connection);
                        PublishProgress("Created a printer, attempting to print a config label");
                        printer.PrintConfigurationLabel();
                    }

                    PublishProgress("Closing connection");
                } catch (ConnectionException) {
                    MessageBoxCreator.ShowError("Connection could not be opened", "Error");
                } catch (ZebraPrinterLanguageUnknownException) {
                    MessageBoxCreator.ShowError("Could not create printer", "Error");
                } finally {
                    if (connection != null)
                    {
                        try {
                            connection.Close();
                        } catch (ConnectionException) { } finally {
                            connection = null;
                            SetTestButtonState(true);
                        }
                    }
                    else
                    {
                        SetTestButtonState(true);
                    }
                }
            });
        }
        private bool SaveModifiedSettingsToPrinter()
        {
            bool       result     = false;
            Connection connection = null;

            try {
                connection = connectionSelector.GetConnection();
                connection.Open();

                ZebraPrinter       genericPrinter = ZebraPrinterFactory.GetInstance(connection);
                ZebraPrinterLinkOs printer        = ZebraPrinterFactory.CreateLinkOsPrinter(genericPrinter);

                if (printer != null)
                {
                    foreach (string key in viewModel.ModifiedSettings.Keys)
                    {
                        if (printer.IsSettingReadOnly(key) == false)
                        {
                            printer.SetSetting(key, viewModel.ModifiedSettings[key]);
                        }
                    }

                    viewModel.ModifiedSettings.Clear();
                    result = true;
                }
                else
                {
                    MessageBoxCreator.ShowError("Connected printer does not support settings", "Connection Error");
                }
            } catch (ConnectionException e) {
                MessageBoxCreator.ShowError(e.Message, "Connection Error");
            } catch (ZebraPrinterLanguageUnknownException e) {
                MessageBoxCreator.ShowError(e.Message, "Connection Error");
            } catch (SettingsException e) {
                MessageBoxCreator.ShowError(e.Message, "Settings Error");
            } catch (Exception e) {
                MessageBoxCreator.ShowError(e.Message, "Save Settings Error");
            } finally {
                try {
                    if (connection != null)
                    {
                        connection.Close();
                    }
                } catch (ConnectionException) { }
            }
            return(result);
        }
Ejemplo n.º 16
0
        private void ReadMagCard()
        {
            Connection connection = null;
            Task       t          = Task.Run(() => {
                try {
                    connection = connectionSelector.GetConnection();
                    connection.Open();

                    ZebraPrinter printer        = ZebraPrinterFactory.GetInstance(connection);
                    MagCardReader magCardReader = MagCardReaderFactory.Create(printer);

                    if (magCardReader != null)
                    {
                        UpdateMagCardOutput("");
                        SetButtonText("Swipe Card Now");
                        string[] trackData = magCardReader.Read(30000);

                        if (trackData[0].Equals("") && trackData[1].Equals("") && trackData[2].Equals(""))
                        {
                            MessageBoxCreator.ShowError("Connection timed out", "Mag Card Error");
                        }
                        else
                        {
                            UpdateMagCardOutput(trackData[0] + "\r\n" + trackData[1] + "\r\n" + trackData[2]);
                        }
                    }
                    else
                    {
                        MessageBoxCreator.ShowError("Printer does not have a mag card reader", "Mag Card Error");
                    }
                } catch (ConnectionException e) {
                    MessageBoxCreator.ShowError(e.Message, "Connection Error");
                } catch (ZebraPrinterLanguageUnknownException e) {
                    MessageBoxCreator.ShowError(e.Message, "Connection Error");
                } finally {
                    if (connection != null)
                    {
                        try {
                            connection.Close();
                        } catch (ConnectionException) { }
                    }
                    SetButtonText("Read Mag Card");
                    SetButtonState(true);
                }
            });
        }
 private async void SaveSettingsButton_Click(object sender, RoutedEventArgs e)
 {
     try {
         SetButtonStates(false);
         if (await Task.Run(() => SaveModifiedSettingsToPrinter()))
         {
             ClearSettings();
             await Task.Run(() => UpdateSettingsTable());
         }
         else
         {
             SetButtonStates(true);
         }
     } catch (Exception ex) {
         MessageBoxCreator.ShowError(ex.Message, "Save Settings Error");
         SetButtonStates(true);
     }
 }
        private void PerformListFiles(bool isFormat)
        {
            Connection printerConnection = null;

            try {
                Application.Current.Dispatcher.Invoke(() => {
                    printerConnection = connectionSelector.GetConnection();
                });

                printerConnection.Open();
                ZebraPrinter printer = ZebraPrinterFactory.GetInstance(printerConnection);

                string[] formatExtensions;
                if (printer.PrinterControlLanguage == PrinterLanguage.ZPL)
                {
                    formatExtensions = new string[] { "ZPL" };
                }
                else
                {
                    formatExtensions = new string[] { "FMT", "LBL" };
                }

                string[] formats = isFormat ? printer.RetrieveFileNames(formatExtensions) : printer.RetrieveFileNames();

                Application.Current.Dispatcher.Invoke(() => {
                    foreach (string format in formats)
                    {
                        viewModel.FormatsList.Add(format);
                    }
                });
            } catch (ConnectionException e) {
                MessageBoxCreator.ShowError(e.Message, "Connection Error");
            } catch (ZebraIllegalArgumentException e) {
                MessageBoxCreator.ShowError(e.Message, "Connection Error");
            } catch (ZebraPrinterLanguageUnknownException e) {
                MessageBoxCreator.ShowError(e.Message, "Connection Error");
            } finally {
                if (printerConnection != null)
                {
                    printerConnection.Close();
                }
            }
        }
Ejemplo n.º 19
0
        private void ReadSmartCard(bool sendData)
        {
            Connection connection = null;

            Task.Run(() => {
                try {
                    UpdateSmartCardOutput("");

                    Application.Current.Dispatcher.Invoke(() => {
                        connection = connectionSelector.GetConnection();
                    });

                    connection.Open();

                    ZebraPrinter printer            = ZebraPrinterFactory.GetInstance(connection);
                    SmartcardReader smartcardReader = SmartcardReaderFactory.Create(printer);
                    if (smartcardReader != null)
                    {
                        byte[] response = sendData ? smartcardReader.DoCommand("8010000008") : smartcardReader.GetATR();

                        UpdateSmartCardOutput(string.Concat(response.Select(x => x.ToString("x2"))));
                        smartcardReader.Close();
                    }
                    else
                    {
                        MessageBoxCreator.ShowError("Printer does not have a smart card reader", "Smart Card Error");
                    }
                } catch (ConnectionException e) {
                    MessageBoxCreator.ShowError(e.Message, "Connection Error");
                } catch (ZebraPrinterLanguageUnknownException e) {
                    MessageBoxCreator.ShowError(e.Message, "Connection Error");
                } finally {
                    if (connection != null)
                    {
                        try {
                            connection.Close();
                        } catch (ConnectionException) { }
                    }
                    SetButtonStates(true);
                }
            });
        }
 private async void UploadProfileButton_Click(object sender, RoutedEventArgs e)
 {
     try {
         SetButtonStates(false);
         OpenFileDialog openFileDialog = new OpenFileDialog();
         if (openFileDialog.ShowDialog() == true)
         {
             string     profilePath = openFileDialog.FileName;
             Connection connection  = connectionSelector.GetConnection();
             await Task.Run(() => UploadProfile(profilePath, connection));
         }
         else
         {
             SetButtonStates(true);
         }
     } catch (Exception ex) {
         MessageBoxCreator.ShowError(ex.Message, "Upload Profile Error");
         SetButtonStates(true);
     }
 }
        private void CreateProfile(string profilePath, Connection connection)
        {
            if (connection != null)
            {
                try {
                    connection.Open();
                    ZebraPrinter       genericPrinter = ZebraPrinterFactory.GetInstance(connection);
                    ZebraPrinterLinkOs printer        = ZebraPrinterFactory.CreateLinkOsPrinter(genericPrinter);

                    if (printer != null)
                    {
                        if (!profilePath.EndsWith(".zprofile"))
                        {
                            profilePath += ".zprofile";
                        }
                        printer.CreateProfile(profilePath);
                        MessageBoxCreator.ShowInformation($"Profile created successfully at location '{profilePath}'", "Profile Created Successfully");
                    }
                    else
                    {
                        MessageBoxCreator.ShowError("Profile creation is only available on Link-OS(TM) printers", "Error");
                    }
                } catch (ConnectionException e) {
                    MessageBoxCreator.ShowError(e.Message, "Connection Error");
                } catch (ZebraPrinterLanguageUnknownException e) {
                    MessageBoxCreator.ShowError(e.Message, "Connection Error");
                } catch (IOException e) {
                    MessageBoxCreator.ShowError(e.Message, "Connection Error");
                } catch (ZebraIllegalArgumentException e) {
                    MessageBoxCreator.ShowError(e.Message, "Connection Error");
                } catch (Exception e) {
                    MessageBoxCreator.ShowError(e.Message, "Create Profile Error");
                } finally {
                    SetButtonStates(true);
                    try {
                        connection.Close();
                    } catch (ConnectionException) { }
                }
            }
        }
Ejemplo n.º 22
0
        private void SendFileToPrinter()
        {
            string     filePath          = null;
            Connection printerConnection = null;

            Task.Run(() => {
                try {
                    printerConnection = connectionSelector.GetConnection();
                    printerConnection.Open();
                    ZebraPrinter printer = ZebraPrinterFactory.GetInstance(printerConnection);

                    filePath = CreateDemoFile(printer.PrinterControlLanguage);
                    printer.SendFileContents(filePath);
                } catch (ConnectionException e) {
                    MessageBoxCreator.ShowError(e.Message, "Connection Error");
                } catch (IOException e) {
                    MessageBoxCreator.ShowError(e.Message, "IO Error");
                } catch (ZebraPrinterLanguageUnknownException e) {
                    MessageBoxCreator.ShowError(e.Message, "Connection Error");
                } catch (Exception e) {
                    MessageBoxCreator.ShowError(e.Message, "Send File Error");
                } finally {
                    try {
                        if (printerConnection != null)
                        {
                            printerConnection.Close();
                        }
                    } catch (ConnectionException) { }

                    if (filePath != null)
                    {
                        try {
                            new FileInfo(filePath).Delete();
                        } catch { }
                    }

                    SetSendFileButtonState(true);
                }
            });
        }
        private void ShowStoredFormatDialog(string formatName)
        {
            Application.Current.Dispatcher.Invoke(() => {
                StoredFormatDialog storedFormatDialog = new StoredFormatDialog(new StoredFormatDialogViewModel(formatVariables));

                Button printFormatButton = storedFormatDialog.PrintFormatButton;
                printFormatButton.Click += async(s, e) => {
                    try {
                        SetButtonState(printFormatButton, false);
                        await Task.Run(() => PrintFormat(formatName));
                    } catch (Exception ex) {
                        MessageBoxCreator.ShowError(ex.Message, "Print Format Error");
                    } finally {
                        SetButtonState(printFormatButton, true);
                    }
                };

                storedFormatDialog.ShowDialog();
                SetButtonState(retrieveFormatsButton, true);
                SetFormatListState(true);
            });
        }
Ejemplo n.º 24
0
        private void PrintButton_Click(object sender, RoutedEventArgs evt)
        {
            SetPrintButtonState(false);
            Connection printerConnection = null;

            Task.Run(() => {
                try {
                    printerConnection = connectionSelector.GetConnection();
                    printerConnection.Open();
                    ZebraImageI image = ZebraImageFactory.GetImage(fileSelector.FileName);
                    if (viewModel.ShouldStoreImage)
                    {
                        ZebraPrinterFactory.GetInstance(printerConnection).StoreImage(viewModel.StoredFileName, image, 540, 412);
                    }
                    ZebraPrinterFactory.GetInstance(printerConnection).PrintImage(image, 0, 0, 550, 412, false);
                } catch (ConnectionException e) {
                    MessageBoxCreator.ShowError(e.Message, "Connection Error");
                } catch (ZebraPrinterLanguageUnknownException e) {
                    MessageBoxCreator.ShowError(e.Message, "Connection Error");
                } catch (IOException e) {
                    MessageBoxCreator.ShowError(e.Message, "Image Error");
                }  catch (ZebraIllegalArgumentException e) {
                    MessageBoxCreator.ShowError(e.Message, "Illegal Arguments");
                } catch (ArgumentException e) {
                    MessageBoxCreator.ShowError(e.Message, "Invalid File Path");
                } finally {
                    try {
                        if (printerConnection != null)
                        {
                            printerConnection.Close();
                        }
                    } catch (ConnectionException) {
                    } finally {
                        SetPrintButtonState(true);
                    }
                }
            });
        }
        private void PopulateListWithFormats()
        {
            Connection printerConnection = null;

            Task.Run(() => {
                try {
                    ClearFormatList();
                    printerConnection = connectionSelector.GetConnection();

                    printerConnection.Open();
                    ZebraPrinter printer = ZebraPrinterFactory.GetInstance(printerConnection);

                    string[] formatExtensions = printer.PrinterControlLanguage == PrinterLanguage.ZPL ? new String[] { "ZPL" } : new String[] { "FMT", "LBL" };
                    string[] formats          = printer.RetrieveFileNames(formatExtensions);

                    AddFormatsToList(formats);
                } catch (ConnectionException e) {
                    MessageBoxCreator.ShowError(e.Message, "Communication Error");
                } catch (ZebraPrinterLanguageUnknownException e) {
                    MessageBoxCreator.ShowError(e.Message, "Communication Error");
                } catch (ZebraIllegalArgumentException e) {
                    MessageBoxCreator.ShowError(e.Message, "Communication Error");
                } finally {
                    try {
                        if (printerConnection != null)
                        {
                            printerConnection.Close();
                        }
                    } catch (ConnectionException) {
                    } finally {
                        SetButtonState(retrieveFormatsButton, true);
                        SetFormatListState(true);
                    }
                }
            });
        }
Ejemplo n.º 26
0
 private void ShowErrorMessage(string message)
 {
     MessageBoxCreator.ShowError(message, "Discovery Error");
 }