Blackthorn

List Printers

Nov 7th, 2014
450
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.50 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using System.Threading.Tasks;
  7.  
  8. using System.Net.Http;
  9. using JSNetworkPrinters;
  10.  
  11. namespace StringMagic
  12. {
  13.     class Program
  14.     {
  15.         static void Main(string[] args)
  16.         {
  17.             var printers = GetPrinters();
  18.             foreach (Printer p in printers.Result)
  19.             {
  20.                 Console.WriteLine("Supply info:\n");
  21.                 foreach (PrinterSupply c in p.Supply)
  22.                 {
  23.                     Console.WriteLine(c.ToString());
  24.                 }
  25.                 Console.WriteLine("\nTray info:\n");
  26.                 foreach (PrinterTray t in p.Trays)
  27.                 {
  28.                     Console.WriteLine(t.ToString());
  29.                 }
  30.             }
  31.            
  32.             Console.ReadKey();
  33.         }
  34.  
  35.         static async Task<Printer[]> GetPrinters()
  36.         {
  37.             HttpClient httpClient = new HttpClient() { MaxResponseContentBufferSize = 1000000 };
  38.             List<string> requestUrls = new List<string>();
  39.             requestUrls.Add("http://pastebin.com/raw.php?i=xmRukgtL");
  40.  
  41.             IEnumerable<Task<Printer>> downloadTasksQuery =
  42.                 from url in requestUrls select Printer.GetPrinter(url, httpClient);
  43.  
  44.             Task<Printer>[] downloadTasks = downloadTasksQuery.ToArray();
  45.             Printer[] printers = await Task.WhenAll(downloadTasks);
  46.             return printers;
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment