/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
- //===================================================================================
- // Microsoft patterns & practices
- // Composite Application Guidance for Windows Presentation Foundation and Silverlight
- //===================================================================================
- // Copyright (c) Microsoft Corporation. All rights reserved.
- // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
- // OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
- // LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
- // FITNESS FOR A PARTICULAR PURPOSE.
- //===================================================================================
- // The example companies, organizations, products, domain names,
- // e-mail addresses, logos, people, places, and events depicted
- // herein are fictitious. No association with any real company,
- // organization, product, domain name, email address, logo, person,
- // places, or events is intended or should be inferred.
- //===================================================================================
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using System.Linq;
- using System.Xml.Linq;
- using StockTraderRI.Infrastructure.Interfaces;
- using StockTraderRI.Infrastructure.Models;
- using StockTraderRI.Modules.Market.Properties;
- using System.ComponentModel.Composition;
-
- namespace StockTraderRI.Modules.Market.Services
- {
- [Export(typeof(IMarketHistoryService))]
- [PartCreationPolicy(CreationPolicy.Shared)]
- public class MarketHistoryService : IMarketHistoryService
- {
- private Dictionary<string, MarketHistoryCollection> _marketHistory;
-
- public MarketHistoryService()
- {
- InitializeMarketHistory();
- }
-
- private void InitializeMarketHistory()
- {
- XDocument document = XDocument.Parse(Resources.MarketHistory);
-
- _marketHistory = document.Descendants("MarketHistoryItem")
- .GroupBy(x => x.Attribute("TickerSymbol").Value,
- x => new MarketHistoryItem
- {
- DateTimeMarker = DateTime.Parse(x.Attribute("Date").Value, CultureInfo.InvariantCulture),
- Value = Decimal.Parse(x.Value, NumberStyles.Float, CultureInfo.InvariantCulture)
- })
- .ToDictionary(group => group.Key, group => new MarketHistoryCollection(group));
- }
-
- public MarketHistoryCollection GetPriceHistory(string tickerSymbol)
- {
- MarketHistoryCollection items = _marketHistory[tickerSymbol];
- return items;
- }
- }
- }