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

Latest
author adminsh@apollo
date Tue, 20 Mar 2012 13:37:46 +0000
parents
children dfc81f8bb838
comparison
equal deleted inserted replaced
19:09d18d6e5f40 20:6109bc268b90
1 using System;
2 using System.Collections.Generic;
3 using Stocks.Common;
4 using Stocks.Common.Core;
5 using Stocks.Common.Models;
6 using Newtonsoft.Json;
7
8 namespace Stocks.Common
9 {
10 public class ConfigurationService : IConfigurationService
11 {
12 private string jsonFilename;
13 private string serviceUrlPrefix = "http://finance.yahoo.com/d/quotes.csv?s=";
14 private string serviceUrlSuffix = "&f=snl1";
15
16 public ConfigurationService(string filename)
17 {
18 jsonFilename = filename;
19 }
20 public List<Company> GetCompanies()
21 {
22 return new FileSerializer().DeserializeJson<Company>(jsonFilename);
23 }
24
25 public string GetServiceUrl(string symbolCsv)
26 {
27 if (string.IsNullOrEmpty(symbolCsv))
28 throw new ArgumentException();
29
30 return string.Concat(serviceUrlPrefix, symbolCsv, serviceUrlSuffix);
31 }
32
33 public string GetServiceUrl(string[] symbols)
34 {
35 if (symbols == null || symbols.Length == 0)
36 throw new ArgumentException();
37
38 var symbolCsv = string.Join(",", symbols);
39 return GetServiceUrl(symbolCsv);
40 }
41 }
42 }