/// <summary> /// Очищает репозиторий. /// </summary> public void Clear() { Subnets.ToList().ForEach(x => x.Printers.Clear()); Subnets.Clear(); Printers.Clear(); ModelSummaries.Clear(); SubnetSummaries.Clear(); DeviceCount = 0; SubnetCount = 0; }
private async Task ListPrinters() { Printers.Clear(); var result = Service.GetAllPrinters(); foreach (var item in result) { Printers.Add(item); } await Task.CompletedTask; }
/// <summary> /// Обновляет все принтеры в словаре. /// </summary> /// <param name="allPrinters">Новый список принтеров</param> public void UpdatePrinters(IEnumerable <PrinterDTO> allPrinters) { // Если список не пустой обновить состояние каждого объекта. if (allPrinters.Any()) { foreach (var printer in allPrinters) { UpdatePrinter(printer); } } // Иначе очистить текущий список. else { Printers.Clear(); } }
public void Start() { var config = _configService.GetConfiguration(); IsActive = config.IsPrinterActivated; Printers.Clear(); foreach (var printer in PrinterSettings.InstalledPrinters) { Printers.Add(printer.ToString()); } IsActive = Printers.Contains(config.Printer); if (IsActive) { DefaultPrinter = config.Printer; } }
/// <summary> /// Changes list of printers /// </summary> public void ChangePrinters() { LogHelper.LogDebug(); // check if it's Demo mode if (IsTestMode) { ResetDemoPrinters(); bool nocolored = false; CanPrintWithColor = true; Printers printers = null; if (PrintWithColor) { printers = Printers.Colored; if (printers == null || printers.Count < 1) { nocolored = true; } } else { printers = demoPrinters; } if (nocolored) { LogHelper.LogDebug("No available color printers found. You are not allowed to print colored this time."); WPFNotifier.Warning("No available color printers found. You are not allowed to print colored this time."); CanPrintWithColor = false; return; } if (printers == null || printers.Count < 1) { LogHelper.LogDebug("No available printers found. You are not allowed to print this time."); WPFNotifier.Warning("No available printers found. You are not allowed to print this time."); return; } LogHelper.LogDebug("Add printers to combo : " + printers.Count); Printers.Clear(); foreach (var name in printers.ToArray()) { LogHelper.LogDebug("Adding : " + name); Printers.Add(name); } LogHelper.LogDebug("Added printers to combo : " + Printers.Count); Thread.Sleep(100); SetDefaultPrinter(); } else { try { bool nocolored = false; CanPrintWithColor = true; Printers printers = null; if (PrintWithColor) { printers = MainController.Singleton.AvailablePrinters.Colored; if (printers == null || printers.Count < 1) { nocolored = true; } } else { printers = MainController.Singleton.AvailablePrinters; } if (nocolored) { LogHelper.LogDebug("No available color printers found. You are not allowed to print colored this time."); WPFNotifier.Warning("No available color printers found. You are not allowed to print colored this time."); CanPrintWithColor = false; return; } if (printers == null || printers.Count < 1) { LogHelper.LogDebug("No available printers found. You are not allowed to print this time."); WPFNotifier.Warning("No available printers found. You are not allowed to print this time."); return; } LogHelper.LogDebug("Add printers to combo : " + printers.Count); MainController.Singleton.Dispatcher.Invoke(new Action(() => { try { Printers.Clear(); foreach (var name in printers.ToArray()) { LogHelper.LogDebug("Adding : " + name); Printers.Add(name); } LogHelper.LogDebug("Added printers to combo : " + Printers.Count); } catch (Exception ex) { WPFNotifier.Error("XXX.", null, ex); } }), DispatcherPriority.Background); Thread.Sleep(100); SetDefaultPrinter(); } catch (Exception ex) { WPFNotifier.Error("This printer is not available now. Try to use one of the other printers.", null, ex); Close(); } } }