Exemplo n.º 1
0
        private void RetrieveFormatsFromPrinter(object sender, DoWorkEventArgs e)
        {
            List <SavedFormat> savedFormats = GetSavedFormats();

            foreach (SavedFormat format in savedFormats)
            {
                Dictionary <string, string> formatAttributes = new Dictionary <string, string> {
                    { attributeKeys[0], format.formatDrive },
                    { attributeKeys[1], format.formatName },
                    { attributeKeys[2], format.formatExtension },
                    { attributeKeys[3], "/Resources/btn_star_big_on.png" },
                    { FORMAT_SOURCE_KEY, format.sourcePrinterName },
                    { SavedFormat._ID, format.id.ToString() }
                };

                AddFormatToList(formatAttributes);
            }

            try {
                OpenConnection();
                ZebraPrinterLinkOs printer        = ZebraPrinterFactory.GetLinkOsPrinter(printerConnection);
                string[]           printerFormats = printer.RetrieveFileNames(new string[] { "ZPL" });
                foreach (string format in printerFormats)
                {
                    int colonPosition = format.IndexOf(":");
                    int dotPosition   = format.LastIndexOf(".");

                    if (dotPosition < 0)
                    {
                        dotPosition = format.Length;
                    }

                    string drive     = format.Substring(0, colonPosition + 1);
                    string extension = format.Substring(dotPosition);
                    string name      = format.Substring(colonPosition + 1, dotPosition - 2);

                    Dictionary <string, string> formatAttributes = new Dictionary <string, string> {
                        { attributeKeys[0], drive },
                        { attributeKeys[1], name },
                        { attributeKeys[2], extension },
                        { attributeKeys[3], "/Resources/btn_star_big_off.png" },
                        { FORMAT_SOURCE_KEY, FORMAT_SOURCE_PRINTER },
                        { SavedFormat._ID, "-1" }
                    };

                    AddFormatToList(formatAttributes);
                }
            } catch (ConnectionException error) {
                errorMessage = "Connection Error: " + error.Message;
            } finally {
                CloseConnection();
            }
        }