annotate MetroWpf/Stocks.Common/ConfigurationService.cs @ 22:a7a4cde39999

ninject aand company data updates
author adminsh@apollo
date Tue, 20 Mar 2012 15:07:49 +0000
parents dfc81f8bb838
children
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 }
21
dfc81f8bb838 working version for sttocks except ui within metrowpf
adminsh@apollo
parents: 20
diff changeset
20
20
adminsh@apollo
parents:
diff changeset
21 public List<Company> GetCompanies()
adminsh@apollo
parents:
diff changeset
22 {
adminsh@apollo
parents:
diff changeset
23 return new FileSerializer().DeserializeJson<Company>(jsonFilename);
adminsh@apollo
parents:
diff changeset
24 }
adminsh@apollo
parents:
diff changeset
25
adminsh@apollo
parents:
diff changeset
26 public string GetServiceUrl(string symbolCsv)
adminsh@apollo
parents:
diff changeset
27 {
adminsh@apollo
parents:
diff changeset
28 if (string.IsNullOrEmpty(symbolCsv))
adminsh@apollo
parents:
diff changeset
29 throw new ArgumentException();
adminsh@apollo
parents:
diff changeset
30
adminsh@apollo
parents:
diff changeset
31 return string.Concat(serviceUrlPrefix, symbolCsv, serviceUrlSuffix);
adminsh@apollo
parents:
diff changeset
32 }
adminsh@apollo
parents:
diff changeset
33
adminsh@apollo
parents:
diff changeset
34 public string GetServiceUrl(string[] symbols)
adminsh@apollo
parents:
diff changeset
35 {
adminsh@apollo
parents:
diff changeset
36 if (symbols == null || symbols.Length == 0)
adminsh@apollo
parents:
diff changeset
37 throw new ArgumentException();
adminsh@apollo
parents:
diff changeset
38
adminsh@apollo
parents:
diff changeset
39 var symbolCsv = string.Join(",", symbols);
adminsh@apollo
parents:
diff changeset
40 return GetServiceUrl(symbolCsv);
adminsh@apollo
parents:
diff changeset
41 }
adminsh@apollo
parents:
diff changeset
42 }
adminsh@apollo
parents:
diff changeset
43 }