PageRenderTime 11ms CodeModel.GetById 1ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 1ms

/V4/StockTrader RI/Desktop/StockTraderRI.Modules.Market/Services/MarketHistoryService.cs

#
C# | 60 lines | 39 code | 5 blank | 16 comment | 0 complexity | 82a0a2e99c0190717422c85d1df29ff2 MD5 | raw file
 1//===================================================================================
 2// Microsoft patterns & practices
 3// Composite Application Guidance for Windows Presentation Foundation and Silverlight
 4//===================================================================================
 5// Copyright (c) Microsoft Corporation.  All rights reserved.
 6// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
 7// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
 8// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 9// FITNESS FOR A PARTICULAR PURPOSE.
10//===================================================================================
11// The example companies, organizations, products, domain names,
12// e-mail addresses, logos, people, places, and events depicted
13// herein are fictitious.  No association with any real company,
14// organization, product, domain name, email address, logo, person,
15// places, or events is intended or should be inferred.
16//===================================================================================
17using System;
18using System.Collections.Generic;
19using System.Globalization;
20using System.Linq;
21using System.Xml.Linq;
22using StockTraderRI.Infrastructure.Interfaces;
23using StockTraderRI.Infrastructure.Models;
24using StockTraderRI.Modules.Market.Properties;
25using System.ComponentModel.Composition;
26
27namespace StockTraderRI.Modules.Market.Services
28{
29    [Export(typeof(IMarketHistoryService))]
30    [PartCreationPolicy(CreationPolicy.Shared)]
31    public class MarketHistoryService : IMarketHistoryService
32    {
33        private Dictionary<string, MarketHistoryCollection> _marketHistory;
34
35        public MarketHistoryService()
36        {
37            InitializeMarketHistory();
38        }
39
40        private void InitializeMarketHistory()
41        {
42            XDocument document = XDocument.Parse(Resources.MarketHistory);
43
44            _marketHistory = document.Descendants("MarketHistoryItem")
45                .GroupBy(x => x.Attribute("TickerSymbol").Value,
46                         x => new MarketHistoryItem
47                                  {
48                                      DateTimeMarker = DateTime.Parse(x.Attribute("Date").Value, CultureInfo.InvariantCulture),
49                                      Value = Decimal.Parse(x.Value, NumberStyles.Float, CultureInfo.InvariantCulture)
50                                  })
51                .ToDictionary(group => group.Key, group => new MarketHistoryCollection(group));
52        }
53
54        public MarketHistoryCollection GetPriceHistory(string tickerSymbol)
55        {
56            MarketHistoryCollection items = _marketHistory[tickerSymbol];
57            return items;
58        }
59    }
60}