changeset 4:57f20ba55884

Fix for webClientShim to use downloadString instead of downloadData Refactoring and introduction of static TimedDelegates.Execute() helper method
author stevenh7776 stevenhollidge@hotmail.com
date Mon, 20 Feb 2012 23:04:58 +0700
parents ef54074d5285
children 877d70fb8176
files Stocks/Stocks.Common/Core/TimedDelegates.cs Stocks/Stocks.Common/Stocks.Common.csproj Stocks/Stocks.Common/WebClientShim.cs Stocks/Stocks.Service.Tests.Unit/StockServiceTests.cs Stocks/Stocks.Service/AssemblyInit.cs Stocks/Stocks.Service/StocksService.cs
diffstat 6 files changed, 29 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- /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<T>(
+      Func<T, T> 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
--- 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 @@
   <ItemGroup>
     <Compile Include="ConfigurationService.cs" />
     <Compile Include="Core\ExtensionMethods.cs" />
+    <Compile Include="Core\TimedDelegates.cs" />
     <Compile Include="Events\PriceChanged.cs" />
     <Compile Include="Factory.cs" />
     <Compile Include="IConfigurationService.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();
     }
   }
 }
--- 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);
--- 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());
 		}
 	}
 }
--- 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<string>(
+            _webClient.DownloadString,
+            _serviceUrl,
+            out timeToDownload);
 
           PopulatePricesFromWebResponse(webResponse);
           UpdateStats(timeToDownload, webResponse);