diff MetroWpf/FxRates.Service/PricingService.cs @ 24:a8b50a087544

Stocks and FxRates working, new menu introduced. Working nicely so far
author adminsh@apollo
date Tue, 20 Mar 2012 20:18:35 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MetroWpf/FxRates.Service/PricingService.cs	Tue Mar 20 20:18:35 2012 +0000
@@ -0,0 +1,47 @@
+using System;
+using System.Threading;
+using System.Threading.Tasks;
+using FxRates.Common;
+using System.Collections.Generic;
+
+namespace FxRates.Service
+{
+  public class PricingService : IPricingService
+  {
+    PriceFactory factory;
+    bool _isRunning = false;
+    public bool IsRunning { get { return _isRunning; } }
+
+    public PricingService()
+    {
+      factory = new PriceFactory();
+    }
+
+    public void Start()
+    {
+      Task.Factory.StartNew(() =>
+      {
+        _isRunning = true;
+        while (_isRunning)
+        {
+          Thread.Sleep(10);
+          if (PriceUpdate == null) continue;
+          var latestPrice = factory.GetNextPrice();
+          PriceUpdate(null, new PriceUpdateEventArgs { LatestPrice = latestPrice });
+        }
+      });
+    }
+
+    public void Stop()
+    {
+      _isRunning = false;
+    }
+
+    public List<FxRate> GetFullCurrentPrices()
+    {
+      return factory.CurrentPrices;
+    }
+
+    public event EventHandler<PriceUpdateEventArgs> PriceUpdate;
+  }
+}
\ No newline at end of file