Exemple #1
0
        public async void UpdateRangeAndType()
        {
            await printerManager.PerformAction($"Getting range and type for setting {viewModel.SettingName}...", (zebraCardPrinter, connection) => {
                // Settings can only be set on device settings within the settings demo, so no need to call GetJobSettingRange() and GetJobSettingType() for print settings
                string range = zebraCardPrinter.GetSettingRange(viewModel.SettingName);
                string type  = zebraCardPrinter.GetSettingType(viewModel.SettingName);

                Application.Current.Dispatcher.Invoke(() => {
                    viewModel.Range = range;
                    viewModel.Type  = type;
                });
            }, (exception) => {
                MessageBoxHelper.ShowError($"Error getting range and type for setting {exception.Message}");
            });
        }
Exemple #2
0
        public async void RetrieveSettings()
        {
            viewModel.DeviceSettings.Clear();
            viewModel.PrintSettings.Clear();

            await printerManager.PerformAction("Retrieving settings...", (zebraCardPrinter, connection) => {
                Dictionary <string, string> deviceSettings = zebraCardPrinter.GetAllSettingValues();
                Dictionary <string, string> printSettings  = zebraCardPrinter.GetAllJobSettingValues();

                Application.Current.Dispatcher.Invoke(() => {
                    foreach (var entry in deviceSettings)
                    {
                        viewModel.DeviceSettings.Add(new PrinterSetting(entry.Key, entry.Value));
                    }
                    foreach (var entry in printSettings)
                    {
                        viewModel.PrintSettings.Add(new PrinterSetting(entry.Key, entry.Value));
                    }
                });
            }, (exception) => {
                MessageBoxHelper.ShowError($"Error retrieving settings: {exception.Message}");

                Application.Current.Dispatcher.Invoke(() => {
                    viewModel.DeviceSettings.Clear();
                    viewModel.PrintSettings.Clear();
                });
            }, null);
        }
        private async void PrintButton_Click(object sender, RoutedEventArgs e)
        {
            int?       jobId      = null;
            CardSource?cardSource = null;

            JobStatusControl.ClearLog();

            await printerManager.PerformAction("Sending print job to printer...", (zebraCardPrinter, connection) => {
                if (printerManager.IsPrinterReady(zebraCardPrinter, JobStatusControl))
                {
                    TemplateJob templateJob = CreateTemplateJob();
                    if (templateJob.JobInfo.CardDestination.HasValue)
                    {
                        if (templateJob.JobInfo.CardDestination.Value == CardDestination.Eject && zebraCardPrinter.HasLaminator())
                        {
                            templateJob.JobInfo.CardDestination = CardDestination.LaminatorAny;
                        }
                    }

                    cardSource = templateJob.JobInfo.CardSource;
                    jobId      = zebraCardPrinter.PrintTemplate(1, templateJob);
                }
            }, (exception) => {
                string errorMessage = $"Error printing card: {exception.Message}";
                MessageBoxHelper.ShowError(errorMessage);
                JobStatusControl.UpdateLog(errorMessage);
            });

            if (jobId.HasValue && cardSource.HasValue)
            {
                await JobStatusControl.StartPolling(printerManager.Printer, new JobInfo(jobId.Value, cardSource.Value));
            }
        }
        private async void RetrieveSettings()
        {
            viewModel.PrinterSettings.Clear();
            viewModel.GeneralSettings.Clear();
            viewModel.MediaSettings.Clear();
            viewModel.SensorSettings.Clear();

            await printerManager.PerformAction("Retrieving settings...", (zebraCardPrinter, connection) => {
                List <PrinterSetting> printerSettingList = BuildPrinterSettingList(zebraCardPrinter.GetPrinterInformation());
                List <PrinterSetting> generalSettingList = BuildGeneralSettingList(zebraCardPrinter.GetPrinterStatus());
                List <MediaInfo> mediaInfoList           = zebraCardPrinter.GetMediaInformation();

                Dictionary <string, string> sensorStateList = zebraCardPrinter.GetSensorStates();
                Dictionary <string, string> sensorValueList = zebraCardPrinter.GetSensorValues();

                Application.Current.Dispatcher.Invoke(() => {
                    foreach (PrinterSetting printerSetting in printerSettingList)
                    {
                        viewModel.PrinterSettings.Add(printerSetting);
                    }
                    foreach (PrinterSetting printerSetting in generalSettingList)
                    {
                        viewModel.GeneralSettings.Add(printerSetting);
                    }
                    foreach (MediaInfo mediaInfo in mediaInfoList)
                    {
                        viewModel.MediaSettings.Add(mediaInfo);
                    }
                    foreach (var entry in sensorStateList)
                    {
                        viewModel.SensorSettings.Add(new PrinterSetting(entry.Key, entry.Value));
                    }
                    foreach (var entry in sensorValueList)
                    {
                        viewModel.SensorSettings.Add(new PrinterSetting(entry.Key, entry.Value));
                    }
                });
            }, (exception) => {
                MessageBoxHelper.ShowError($"Error retrieving settings: {exception.Message}");

                Application.Current.Dispatcher.Invoke(() => {
                    viewModel.PrinterSettings.Clear();
                    viewModel.GeneralSettings.Clear();
                    viewModel.MediaSettings.Clear();
                    viewModel.SensorSettings.Clear();
                });
            }, null);
        }
Exemple #5
0
        private async void PrintButton_Click(object sender, RoutedEventArgs e)
        {
            ZebraCardGraphics graphics = null;
            int?       jobId           = null;
            CardSource?cardSource      = null;

            JobStatusControl.ClearLog();
            await printerManager.PerformAction("Sending print job to printer...", (zebraCardPrinter, connection) => {
                if (printerManager.IsPrinterReady(zebraCardPrinter, JobStatusControl))
                {
                    graphics = new ZebraCardGraphics(zebraCardPrinter);

                    List <GraphicsInfo> graphicsData = new List <GraphicsInfo>();

                    if (viewModel.PrintFrontSide)
                    {
                        byte[] frontSideGraphicData = ImageHelper.ConvertImage(ImageHelper.CreateImageFromFile(viewModel.FrontSideGraphicFilename));
                        graphics.Initialize(0, 0, OrientationType.Landscape, viewModel.FrontSidePrintType, System.Drawing.Color.White);
                        graphics.DrawImage(frontSideGraphicData, 0, 0, 0, 0, RotationType.RotateNoneFlipNone);
                        graphicsData.Add(BuildGraphicsInfo(graphics.CreateImage(), CardSide.Front, viewModel.FrontSidePrintType));
                        graphics.Clear();
                    }

                    if (viewModel.PrintFrontSideOverlay)
                    {
                        if (viewModel.FrontSideOverlayGraphicFilename != null)
                        {
                            byte[] frontSideOverlayGraphicData = ImageHelper.ConvertImage(ImageHelper.CreateImageFromFile(viewModel.FrontSideOverlayGraphicFilename));
                            graphics.Initialize(0, 0, OrientationType.Landscape, PrintType.Overlay, System.Drawing.Color.White);
                            graphics.DrawImage(frontSideOverlayGraphicData, 0, 0, 0, 0, RotationType.RotateNoneFlipNone);
                            graphicsData.Add(BuildGraphicsInfo(graphics.CreateImage(), CardSide.Front, PrintType.Overlay));
                            graphics.Clear();
                        }
                        else
                        {
                            graphicsData.Add(BuildGraphicsInfo(null, CardSide.Front, PrintType.Overlay));
                            graphics.Clear();
                        }
                    }

                    if (viewModel.PrintBackSide)
                    {
                        byte[] backSideGraphicData = ImageHelper.ConvertImage(ImageHelper.CreateImageFromFile(viewModel.BackSideGraphicFilename));
                        graphics.Initialize(0, 0, OrientationType.Landscape, PrintType.MonoK, System.Drawing.Color.White);
                        graphics.DrawImage(backSideGraphicData, 0, 0, 0, 0, RotationType.RotateNoneFlipNone);
                        graphicsData.Add(BuildGraphicsInfo(graphics.CreateImage(), CardSide.Back, PrintType.MonoK));
                        graphics.Clear();
                    }

                    cardSource = (CardSource)Enum.Parse(typeof(CardSource), zebraCardPrinter.GetJobSettingValue(ZebraCardJobSettingNames.CARD_SOURCE));

                    jobId = zebraCardPrinter.Print(viewModel.Quantity, graphicsData);
                }
            }, (exception) => {
                string errorMessage = $"Error printing card: {exception.Message}";
                MessageBoxHelper.ShowError(errorMessage);
                JobStatusControl.UpdateLog(errorMessage);
            }, () => {
                if (graphics != null)
                {
                    graphics.Close();
                }
            });

            if (jobId.HasValue && cardSource.HasValue)
            {
                await JobStatusControl.StartPolling(printerManager.Printer, new JobInfo(jobId.Value, cardSource.Value));
            }
        }
Exemple #6
0
        private async void RetrieveSettingsRanges()
        {
            viewModel.Sources.Clear();
            viewModel.Destinations.Clear();
            viewModel.EncoderTypes.Clear();

            await printerManager.PerformAction("Retrieving settings ranges...", (zebraCardPrinter, connection) => {
                bool hasLaminator = zebraCardPrinter.HasLaminator();

                if (zebraCardPrinter.HasSmartCardEncoder())
                {
                    string cardSourceRange = zebraCardPrinter.GetJobSettingRange(ZebraCardJobSettingNames.CARD_SOURCE);
                    if (cardSourceRange != null)
                    {
                        foreach (CardSource source in Enum.GetValues(typeof(CardSource)))
                        {
                            if (cardSourceRange.Contains(source.ToString()))
                            {
                                Application.Current.Dispatcher.Invoke(() => {
                                    viewModel.Sources.Add(source.ToString());
                                });
                            }
                        }
                    }

                    string cardDestinationRange = zebraCardPrinter.GetJobSettingRange(ZebraCardJobSettingNames.CARD_DESTINATION);
                    if (cardDestinationRange != null)
                    {
                        foreach (CardDestination destination in Enum.GetValues(typeof(CardDestination)))
                        {
                            if (cardDestinationRange.Contains(destination.ToString()))
                            {
                                if (!destination.ToString().Contains("Laminator") || hasLaminator)
                                {
                                    Application.Current.Dispatcher.Invoke(() => {
                                        viewModel.Destinations.Add(destination.ToString());
                                    });
                                }
                            }
                        }
                    }

                    Dictionary <string, string> smartCardConfigurations = zebraCardPrinter.GetSmartCardConfigurations();
                    foreach (string encoderType in smartCardConfigurations.Keys)
                    {
                        Application.Current.Dispatcher.Invoke(() => {
                            viewModel.EncoderTypes.Add(encoderType);
                        });
                    }
                }
                else
                {
                    MessageBoxHelper.ShowError("Unable to proceed with demo because no smart card encoder was found.");
                }
            }, (exception) => {
                string errorMessage = $"Error retrieving settings ranges: {exception.Message}";
                MessageBoxHelper.ShowError(errorMessage);
                JobStatusControl.UpdateLog(errorMessage);

                Application.Current.Dispatcher.Invoke(() => {
                    viewModel.Sources.Clear();
                    viewModel.Destinations.Clear();
                    viewModel.EncoderTypes.Clear();
                });
            }, null);
        }
Exemple #7
0
        private async void RetrieveSettingsRanges()
        {
            viewModel.Sources.Clear();
            viewModel.Destinations.Clear();
            viewModel.PrintOptimizations.Clear();
            viewModel.PrintTypes.Clear();
            viewModel.CoercivityTypes.Clear();

            await printerManager.PerformAction("Retrieving settings ranges...", (zebraCardPrinter, connection) => {
                string installedRibbon = zebraCardPrinter.GetSettingValue(ZebraCardSettingNames.RIBBON_DESCRIPTION);
                if (!string.IsNullOrEmpty(installedRibbon))
                {
                    installedRibbon = installedRibbon.ToLower();

                    if (installedRibbon.Contains(ColorOption))
                    {
                        Application.Current.Dispatcher.Invoke(() => {
                            viewModel.PrintTypes.Add(PrintType.Color);
                        });
                    }

                    if (IsPrintTypeSupported(installedRibbon, MonoRibbonOptions))
                    {
                        Application.Current.Dispatcher.Invoke(() => {
                            viewModel.PrintTypes.Add(PrintType.MonoK);
                        });
                    }

                    if (IsPrintTypeSupported(installedRibbon, OverlayRibbonOptions))
                    {
                        Application.Current.Dispatcher.Invoke(() => {
                            viewModel.PrintTypes.Add(PrintType.Overlay);
                        });
                    }

                    string cardSourceRange = zebraCardPrinter.GetJobSettingRange(ZebraCardJobSettingNames.CARD_SOURCE);
                    if (cardSourceRange != null)
                    {
                        foreach (CardSource source in Enum.GetValues(typeof(CardSource)))
                        {
                            if (cardSourceRange.Contains(source.ToString()))
                            {
                                Application.Current.Dispatcher.Invoke(() => {
                                    viewModel.Sources.Add(source.ToString());
                                });
                            }
                        }
                    }

                    string cardDestinationRange = zebraCardPrinter.GetJobSettingRange(ZebraCardJobSettingNames.CARD_DESTINATION);
                    if (cardDestinationRange != null)
                    {
                        foreach (CardDestination destination in Enum.GetValues(typeof(CardDestination)))
                        {
                            if (cardDestinationRange.Contains(destination.ToString()))
                            {
                                if (!destination.ToString().Contains("Laminator") || zebraCardPrinter.HasLaminator())
                                {
                                    Application.Current.Dispatcher.Invoke(() => {
                                        viewModel.Destinations.Add(destination.ToString());
                                    });
                                }
                            }
                        }
                    }

                    bool hasMagneticEncoder = zebraCardPrinter.HasMagneticEncoder();
                    if (hasMagneticEncoder)
                    {
                        string coercivityTypeRange = zebraCardPrinter.GetJobSettingRange(ZebraCardJobSettingNames.MAG_COERCIVITY);
                        if (coercivityTypeRange != null)
                        {
                            foreach (CoercivityType coercivityType in Enum.GetValues(typeof(CoercivityType)))
                            {
                                if (coercivityTypeRange.Contains(coercivityType.ToString()))
                                {
                                    Application.Current.Dispatcher.Invoke(() => {
                                        viewModel.CoercivityTypes.Add(coercivityType.ToString());
                                    });
                                }
                            }
                        }
                    }

                    Application.Current.Dispatcher.Invoke(() => {
                        viewModel.IsPrintOptimizationAvailable = zebraCardPrinter.GetJobSettings().Contains(ZebraCardJobSettingNames.PRINT_OPTIMIZATION);
                        viewModel.HasDualSidedPrintCapability  = zebraCardPrinter.GetPrintCapability() == TransferType.DualSided;
                        viewModel.HasMagneticEncoder           = hasMagneticEncoder;
                    });
                }
                else
                {
                    throw new ZebraCardException("No ribbon installed. Please install a ribbon and try again.");
                }
            }, (exception) => {
                string errorMessage = $"Error retrieving settings ranges: {exception.Message}";
                MessageBoxHelper.ShowError(errorMessage);
                JobStatusControl.UpdateLog(errorMessage);

                Application.Current.Dispatcher.Invoke(() => {
                    viewModel.Sources.Clear();
                    viewModel.Destinations.Clear();
                    viewModel.PrintOptimizations.Clear();
                    viewModel.PrintTypes.Clear();
                    viewModel.CoercivityTypes.Clear();
                });
            }, null);
        }