# HG changeset patch # User stevenh7776 stevenhollidge@hotmail.com # Date 1329753898 -25200 # Node ID 57f20ba55884c91eced65cd8204ae915edb18445 # Parent ef54074d528548fef7beb048743ca08f07260683 Fix for webClientShim to use downloadString instead of downloadData Refactoring and introduction of static TimedDelegates.Execute() helper method diff -r ef54074d5285 -r 57f20ba55884 Stocks/Stocks.Common/Core/TimedDelegates.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Stocks/Stocks.Common/Core/TimedDelegates.cs Mon Feb 20 23:04:58 2012 +0700 @@ -0,0 +1,20 @@ +using System; +using System.Diagnostics; + +namespace Stocks.Common.Core +{ + public class TimedDelegates + { + public static T Execute( + Func func, + T paramIn, + out Stopwatch stopwatch) + { + stopwatch = new Stopwatch(); + stopwatch.Start(); + T result = func(paramIn); + stopwatch.Stop(); + return result; + } + } +} \ No newline at end of file diff -r ef54074d5285 -r 57f20ba55884 Stocks/Stocks.Common/Stocks.Common.csproj --- a/Stocks/Stocks.Common/Stocks.Common.csproj Mon Feb 20 22:29:44 2012 +0700 +++ b/Stocks/Stocks.Common/Stocks.Common.csproj Mon Feb 20 23:04:58 2012 +0700 @@ -48,6 +48,7 @@ + diff -r ef54074d5285 -r 57f20ba55884 Stocks/Stocks.Common/WebClientShim.cs --- a/Stocks/Stocks.Common/WebClientShim.cs Mon Feb 20 22:29:44 2012 +0700 +++ b/Stocks/Stocks.Common/WebClientShim.cs Mon Feb 20 23:04:58 2012 +0700 @@ -17,7 +17,7 @@ public string DownloadString(string address) { - return _webClient.DownloadData(address).ToString(); + return _webClient.DownloadString(address).ToString(); } } } diff -r ef54074d5285 -r 57f20ba55884 Stocks/Stocks.Service.Tests.Unit/StockServiceTests.cs --- a/Stocks/Stocks.Service.Tests.Unit/StockServiceTests.cs Mon Feb 20 22:29:44 2012 +0700 +++ b/Stocks/Stocks.Service.Tests.Unit/StockServiceTests.cs Mon Feb 20 23:04:58 2012 +0700 @@ -30,7 +30,7 @@ service.Start(); Assert.Equal(true, service.IsActive); - using (var task2 = Task.Factory.StartNew(() => Thread.Sleep(500))) + using (var task2 = Task.Factory.StartNew(() => Thread.Sleep(50))) { task2.Wait(); } service.Stop(); Assert.Equal(false, service.IsActive); diff -r ef54074d5285 -r 57f20ba55884 Stocks/Stocks.Service/AssemblyInit.cs --- a/Stocks/Stocks.Service/AssemblyInit.cs Mon Feb 20 22:29:44 2012 +0700 +++ b/Stocks/Stocks.Service/AssemblyInit.cs Mon Feb 20 23:04:58 2012 +0700 @@ -17,8 +17,6 @@ logger.Info("Init: {0} {1} ", Assembly.GetExecutingAssembly().GetName(), fvi.ProductVersion); - - var kernel = new StandardKernel(new IoCModule()); } } } diff -r ef54074d5285 -r 57f20ba55884 Stocks/Stocks.Service/StocksService.cs --- a/Stocks/Stocks.Service/StocksService.cs Mon Feb 20 22:29:44 2012 +0700 +++ b/Stocks/Stocks.Service/StocksService.cs Mon Feb 20 23:04:58 2012 +0700 @@ -7,6 +7,7 @@ using Stocks.Common; using Stocks.Common.Events; using Stocks.Common.Models; +using Stocks.Common.Core; namespace Stocks.Service { @@ -79,13 +80,14 @@ { try { - Stopwatch timeToDownload = new Stopwatch(); + Stopwatch timeToDownload; while (IsActive) { - timeToDownload.Restart(); - string webResponse = _webClient.DownloadString(_serviceUrl); - timeToDownload.Stop(); + string webResponse = TimedDelegates.Execute( + _webClient.DownloadString, + _serviceUrl, + out timeToDownload); PopulatePricesFromWebResponse(webResponse); UpdateStats(timeToDownload, webResponse);