diff MetroWpf/Stocks.Common/ConfigurationService.cs @ 20:6109bc268b90

Latest
author adminsh@apollo
date Tue, 20 Mar 2012 13:37:46 +0000
parents
children dfc81f8bb838
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MetroWpf/Stocks.Common/ConfigurationService.cs	Tue Mar 20 13:37:46 2012 +0000
@@ -0,0 +1,42 @@
+using System;
+using System.Collections.Generic;
+using Stocks.Common;
+using Stocks.Common.Core;
+using Stocks.Common.Models;
+using Newtonsoft.Json;
+
+namespace Stocks.Common
+{
+  public class ConfigurationService : IConfigurationService
+  {
+    private string jsonFilename;
+    private string serviceUrlPrefix = "http://finance.yahoo.com/d/quotes.csv?s=";
+    private string serviceUrlSuffix = "&f=snl1";
+
+    public ConfigurationService(string filename)
+    {
+      jsonFilename = filename;
+    }
+    public List<Company> GetCompanies()
+    {
+      return new FileSerializer().DeserializeJson<Company>(jsonFilename);
+    }
+
+    public string GetServiceUrl(string symbolCsv)
+    {
+      if (string.IsNullOrEmpty(symbolCsv))
+        throw new ArgumentException();
+
+      return string.Concat(serviceUrlPrefix, symbolCsv, serviceUrlSuffix);
+    }
+
+    public string GetServiceUrl(string[] symbols)
+    {
+      if (symbols == null || symbols.Length == 0)
+        throw new ArgumentException();
+      
+      var symbolCsv = string.Join(",", symbols);
+      return GetServiceUrl(symbolCsv);
+    }
+  }
+}
\ No newline at end of file