private async void SendFileButton_Clicked(object sender, EventArgs eventArgs)
        {
            SetInputEnabled(false);

            string     filePath   = null;
            Connection connection = null;

            try {
                await Task.Factory.StartNew(() => {
                    connection = CreateConnection();
                    connection.Open();

                    ZebraPrinter printer = ZebraPrinterFactory.GetInstance(connection);

                    filePath = CreateDemoFile(printer.PrinterControlLanguage);
                    printer.SendFileContents(filePath);
                });
            } catch (Exception e) {
                await DisplayAlert("Error", e.Message, "OK");
            } finally {
                try {
                    connection?.Close();
                } catch (ConnectionException) { }

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

                SetInputEnabled(true);
            }
        }
コード例 #2
0
 //发送文件
 public static bool SendFile(string filePath)
 {
     if (printer != null && filePath != "")
     {
         printer.SendFileContents(filePath);
         return(true);
     }
     return(false);
 }
コード例 #3
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);
                }
            });
        }