private static void OnResponse(IAsyncResult ar) { RequestState state = ar.AsyncState as RequestState; try { HttpWebRequest request = state.Request; HttpWebResponse response = request.EndGetResponse(ar) as HttpWebResponse; using (StreamReader read = new StreamReader(response.GetResponseStream(), Encoding.UTF8)) { string html = read.ReadToEnd(); state.Host.Html = html; GetPrinterType(state); GetPrinterStatus(state); Regex replaceSpace = new Regex(@"[\s]+", RegexOptions.IgnoreCase); // 去掉连续空格 string pstatus, tstatus; pstatus = state.Printer.PrinterStatus.Replace("<br>", "").Replace("\n", "").Replace("</pre>", "").Trim(); tstatus = state.Printer.TonerStatus.Replace("<br>", "").Replace("\n", "").Replace("*", "").Trim(); pstatus = replaceSpace.Replace(pstatus, " "); tstatus = replaceSpace.Replace(tstatus, " "); state.Printer.PrinterStatus = pstatus; state.Printer.TonerStatus = tstatus; if (pstatus.IndexOf("StartIndex") == -1) { if (state.IsIndexQuery) { indexCount++; } else { count++; PrinterList.Add(state.Printer); Console.WriteLine(count.ToString() + "/" + storeCount.ToString() + " " + state.Printer.StoreNo + ": " + state.Printer.PrinterStatus + " " + state.Printer.TonerStatus); } } } response.Close(); } catch (System.Exception ex) { state.Printer.PrinterStatus = ex.Message; state.Printer.TonerStatus = ex.Message; state.Printer.PrinterNetwork = "Down"; state.Printer.Date = DateTime.Now.ToString(); if (state.IsIndexQuery) { indexCount++; } else { count++; PrinterList.Add(state.Printer); Console.WriteLine(count.ToString() + "/" + storeCount.ToString() + " " + state.Printer.StoreNo + ": " + ex.Message.ToString()); } } }
private void DiscoveryHandler_OnFoundPrinter(object sender, IDiscoveredPrinter discoveredPrinter) { System.Diagnostics.Debug.WriteLine("Found Printer:" + discoveredPrinter.ToString()); Device.BeginInvokeOnMainThread(() => { if (!PrinterList.Contains(discoveredPrinter)) { PrinterList.Add(discoveredPrinter); } }); }
public SettingToPrintViewModel(IPrintPDF pDFPrinter, IPrintExcel excelPrinter) { PDFPrinter = pDFPrinter; ExcelPrinter = excelPrinter; //PDFFilesToPrint = pDFFilesToPrint; foreach (var item in PrinterSettings.InstalledPrinters) { PrinterList.Add(item.ToString()); } PropertyCommand = new RelayCommand(PropertySet); OKCommand = new RelayCommand(OK); CancelCommand = new RelayCommand(Cancel); OptionCommand = new RelayCommand(Option); }
private void PopulatePrinterList() { try { PrinterSettings ps = new PrinterSettings(); foreach (string item in PrinterSettings.InstalledPrinters) { PrinterList.Add(item); } } catch (Exception ex) { this.messageBoxService.ShowError(this.GetType().FullName + System.Reflection.MethodBase.GetCurrentMethod().Name + ": " + ex.Message); } }