Mercurial > silverbladetech
diff Stocks/Stocks.Service/StocksService.cs @ 2:29ed98d659e9
Adding WebClientShim files
author | stevenh7776 stevenhollidge@hotmail.com |
---|---|
date | Mon, 20 Feb 2012 22:04:50 +0700 |
parents | e5d46bb6cdb0 |
children | 57f20ba55884 |
line wrap: on
line diff
--- a/Stocks/Stocks.Service/StocksService.cs Mon Feb 20 21:53:40 2012 +0700 +++ b/Stocks/Stocks.Service/StocksService.cs Mon Feb 20 22:04:50 2012 +0700 @@ -1,14 +1,12 @@ using System; -using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; using System.Linq; -using System.Net; using System.Threading.Tasks; using NLog; using Stocks.Common; +using Stocks.Common.Events; using Stocks.Common.Models; -using Stocks.Common.Events; namespace Stocks.Service { @@ -20,24 +18,31 @@ private IConfigurationService _configurationService; private List<Price> _currentPrices; private string _serviceUrl; - private WebClient _webClient; + private IWebClientShim _webClient; public bool IsActive { get; private set; } public SummaryStats Stats { get; private set; } - public StocksService(IConfigurationService configurationService) + public StocksService( + IConfigurationService configurationService, + IWebClientShim webClientShim) { new AssemblyInit(); - _webClient = new WebClient(); + _webClient = webClientShim; _configurationService = configurationService; - _companies = configurationService.GetCompanies(); + Stats = new SummaryStats(); + + GetCompanyList(); + } + + private void GetCompanyList() + { + _companies = _configurationService.GetCompanies(); string symbolsCsv = _companies.Select( c => c.Symbol).Aggregate((c, d) => c + "," + d); _serviceUrl = _configurationService.GetServiceUrl(symbolsCsv); - - Stats = new SummaryStats(); } public delegate void PriceChangedEventHandler(object sender, PriceChangedEventArgs e); @@ -110,17 +115,20 @@ continue; } - if (localPrice.Equals(webPrice)) { + if (localPrice.Equals(webPrice)) continue; - } - else { - localPrice.PreviousPrice = localPrice.CurrentPrice; - localPrice.CurrentPrice = webPrice.CurrentPrice; - RaisePriceChanged(localPrice); - } + else + UpdateLocalPrice(webPrice, localPrice); } } + private void UpdateLocalPrice(Price webPrice, Price localPrice) + { + localPrice.PreviousPrice = localPrice.CurrentPrice; + localPrice.CurrentPrice = webPrice.CurrentPrice; + RaisePriceChanged(localPrice); + } + private void UpdateStats(Stopwatch timeToDownload, string webResponse) { Stats.LastWebRequest.Duration = (int)timeToDownload.ElapsedMilliseconds;