Guest User

Untitled

a guest
Dec 7th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. public class OrderViewModel : Notifier
  2. {
  3. DispatcherTimer dispatcherTimer = new DispatcherTimer();
  4. private SoftproofTransporterClientApi api = new SoftproofTransporterClientApi();
  5. private ObservableCollection<Order> _orders = new ObservableCollection<Order>();
  6. public ObservableCollection<Order> Orders
  7. {
  8. get { return _orders; }
  9. set { PropertySetter(ref _orders, "Orders", value); }
  10. }
  11.  
  12. public OrderViewModel()
  13. {
  14. dispatcherTimer.Tick += new EventHandler(UpdateOrders);
  15. dispatcherTimer.Interval = new TimeSpan(0, 0, 2);
  16. dispatcherTimer.Start();
  17. }
  18.  
  19. private void UpdateOrders(object sender, EventArgs e)
  20. {
  21. GetOrders();
  22. }
  23.  
  24. private void GetOrders()
  25. {
  26. api.GetOrders((orderResult) =>
  27. Deployment.Current.Dispatcher.BeginInvoke( ()=>
  28. {
  29. DateTime dt = DateTime.Now;
  30. string time = String.Format("{0:d/M/yyyy HH:mm:ss}", dt);
  31. try
  32. {
  33. Orders = orderResult.Orders;
  34. Debug.WriteLine("Updated Orders at " + time);
  35. }
  36. catch { Debug.WriteLine("Could not get Orders at " + time); }
  37. })
  38. );
  39. }
  40.  
  41. }
Add Comment
Please, Sign In to add comment