Esempio n. 1
0
        private void GetFormatVariables(object sender, DoWorkEventArgs e)
        {
            object[] parameters               = e.Argument as object[];
            dynamic  selectedFormat           = parameters[0] as dynamic;
            string   lastFormatOpened         = (string)parameters[1];
            string   lastFormatOpenedSource   = (string)parameters[2];
            string   lastFormatOpenedContents = (string)parameters[3];

            object[] results = new object[4];

            long formatId = long.Parse(selectedFormat.FormatId);

            lastFormatOpened       = selectedFormat.FormatDrive + selectedFormat.FormatName + selectedFormat.FormatExtension;
            lastFormatOpenedSource = selectedFormat.FormatSource;

            try {
                OpenConnection();
                ZebraPrinterLinkOs printer = ZebraPrinterFactory.GetLinkOsPrinter(printerConnection);

                if (lastFormatOpenedSource.Equals("Sample") && formatId > 0)
                {
                    using (SavedFormatProvider provider = new SavedFormatProvider()) {
                        lastFormatOpenedContents = provider.GetFormatContents(formatId);
                    }
                }
                else
                {
                    byte[] formatInBytes = printer.RetrieveFormatFromPrinter(lastFormatOpened);
                    lastFormatOpenedContents = Encoding.UTF8.GetString(formatInBytes);
                }

                fieldDescDataVars = printer.GetVariableFields(lastFormatOpenedContents).ToList();
                fieldDescDataVars = FormatFieldDescriptionDataVars(fieldDescDataVars);

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

                results[0] = lastFormatOpened;
                results[1] = lastFormatOpenedSource;
                results[2] = lastFormatOpenedContents;
                results[3] = formatVariableCollection;
                e.Result   = results;
            } catch (ConnectionException error) {
                errorMessage = "Connection Error: " + error.Message;
            } finally {
                CloseConnection();
            }
        }