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

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