PageRenderTime 52ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/V4/StockTrader RI/Desktop/StockTraderRI.Modules.Market/TrendLine/TrendLineViewModel.cs

#
C# | 91 lines | 66 code | 9 blank | 16 comment | 6 complexity | c3fb875d91177daea72c7bece437076d 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.Linq;
  20. using System.Text;
  21. using System.ComponentModel.Composition;
  22. using Microsoft.Practices.Prism.ViewModel;
  23. using StockTraderRI.Infrastructure.Interfaces;
  24. using Microsoft.Practices.Prism.Events;
  25. using StockTraderRI.Infrastructure.Models;
  26. using StockTraderRI.Infrastructure;
  27. namespace StockTraderRI.Modules.Market.TrendLine
  28. {
  29. [Export(typeof(TrendLineViewModel))]
  30. public class TrendLineViewModel : NotificationObject
  31. {
  32. private readonly IMarketHistoryService marketHistoryService;
  33. private string tickerSymbol;
  34. private MarketHistoryCollection historyCollection;
  35. [ImportingConstructor]
  36. public TrendLineViewModel(IMarketHistoryService marketHistoryService, IEventAggregator eventAggregator)
  37. {
  38. if (eventAggregator == null)
  39. {
  40. throw new ArgumentNullException("eventAggregator");
  41. }
  42. this.marketHistoryService = marketHistoryService;
  43. eventAggregator.GetEvent<TickerSymbolSelectedEvent>().Subscribe(this.TickerSymbolChanged);
  44. }
  45. public void TickerSymbolChanged(string newTickerSymbol)
  46. {
  47. MarketHistoryCollection newHistoryCollection = this.marketHistoryService.GetPriceHistory(newTickerSymbol);
  48. this.TickerSymbol = newTickerSymbol;
  49. this.HistoryCollection = newHistoryCollection;
  50. }
  51. public string TickerSymbol
  52. {
  53. get
  54. {
  55. return this.tickerSymbol;
  56. }
  57. set
  58. {
  59. if (this.tickerSymbol != value)
  60. {
  61. this.tickerSymbol = value;
  62. this.RaisePropertyChanged(() => this.TickerSymbol);
  63. }
  64. }
  65. }
  66. public MarketHistoryCollection HistoryCollection
  67. {
  68. get
  69. {
  70. return historyCollection;
  71. }
  72. private set
  73. {
  74. if (this.historyCollection != value)
  75. {
  76. this.historyCollection = value;
  77. this.RaisePropertyChanged(() => this.HistoryCollection);
  78. }
  79. }
  80. }
  81. }
  82. }