PageRenderTime 38ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/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. //===================================================================================
  17. using System;
  18. using System.Collections.Generic;
  19. using System.Globalization;
  20. using System.Linq;
  21. using System.Xml.Linq;
  22. using StockTraderRI.Infrastructure.Interfaces;
  23. using StockTraderRI.Infrastructure.Models;
  24. using StockTraderRI.Modules.Market.Properties;
  25. using System.ComponentModel.Composition;
  26. namespace StockTraderRI.Modules.Market.Services
  27. {
  28. [Export(typeof(IMarketHistoryService))]
  29. [PartCreationPolicy(CreationPolicy.Shared)]
  30. public class MarketHistoryService : IMarketHistoryService
  31. {
  32. private Dictionary<string, MarketHistoryCollection> _marketHistory;
  33. public MarketHistoryService()
  34. {
  35. InitializeMarketHistory();
  36. }
  37. private void InitializeMarketHistory()
  38. {
  39. XDocument document = XDocument.Parse(Resources.MarketHistory);
  40. _marketHistory = document.Descendants("MarketHistoryItem")
  41. .GroupBy(x => x.Attribute("TickerSymbol").Value,
  42. x => new MarketHistoryItem
  43. {
  44. DateTimeMarker = DateTime.Parse(x.Attribute("Date").Value, CultureInfo.InvariantCulture),
  45. Value = Decimal.Parse(x.Value, NumberStyles.Float, CultureInfo.InvariantCulture)
  46. })
  47. .ToDictionary(group => group.Key, group => new MarketHistoryCollection(group));
  48. }
  49. public MarketHistoryCollection GetPriceHistory(string tickerSymbol)
  50. {
  51. MarketHistoryCollection items = _marketHistory[tickerSymbol];
  52. return items;
  53. }
  54. }
  55. }