annotate Stocks/Stocks.Common/ConfigurationService.cs @ 111:6cb8cd05ad6b

Remove automated tests
author stevenhollidge <stevenhollidge@hotmail.com>
date Sun, 06 May 2012 21:51:38 +0100
parents e5d46bb6cdb0
children
rev   line source
0
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
1 using System;
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
2 using System.Collections.Generic;
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
3 using Stocks.Common;
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
4 using Stocks.Common.Core;
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
5 using Stocks.Common.Models;
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
6 using Newtonsoft.Json;
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
7
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
8 namespace Stocks.Common
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
9 {
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
10 public class ConfigurationService : IConfigurationService
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
11 {
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
12 private string jsonFilename;
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
13 private string serviceUrlPrefix = "http://finance.yahoo.com/d/quotes.csv?s=";
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
14 private string serviceUrlSuffix = "&f=snl1";
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
15
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
16 public ConfigurationService(string filename)
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
17 {
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
18 jsonFilename = filename;
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
19 }
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
20 public List<Company> GetCompanies()
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
21 {
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
22 return new FileSerializer().DeserializeJson<Company>(jsonFilename);
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
23 }
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
24
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
25 public string GetServiceUrl(string symbolCsv)
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
26 {
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
27 if (string.IsNullOrEmpty(symbolCsv))
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
28 throw new ArgumentException();
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
29
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
30 return string.Concat(serviceUrlPrefix, symbolCsv, serviceUrlSuffix);
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
31 }
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
32
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
33 public string GetServiceUrl(string[] symbols)
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
34 {
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
35 if (symbols == null || symbols.Length == 0)
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
36 throw new ArgumentException();
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
37
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
38 var symbolCsv = string.Join(",", symbols);
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
39 return GetServiceUrl(symbolCsv);
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
40 }
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
41 }
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
42 }