public class DataService
{
List<Company> _companies = new List<Company>();
Dictionary<string, List<Quote>> _cache = new Dictionary<string, List<Quote>>();
private DataService()
{
_companies.Add(new Company() { Symbol = "box", Name = "Box Inc" });
_companies.Add(new Company() { Symbol = "fb", Name = "Facebook" });
}
public List<Company> GetCompanies()
{
return _companies;
}
public List<Quote> GetSymbolData(string symbol)
{
if (!_cache.Keys.Contains(symbol))
{
string path = string.Format("FinancialChartExplorer.Resources.{0}.json", symbol);
var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(path);
var ser = new DataContractJsonSerializer(typeof(Quote[]));
var data = (Quote[])ser.ReadObject(stream);
_cache.Add(symbol, data.ToList());
}
return _cache[symbol];
}
static DataService _ds;
public static DataService GetService()
{
if (_ds == null)
_ds = new DataService();
return _ds;
}
}