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

/V2/trunk/RI/Desktop/StockTraderRI.Modules.Market/TrendLine/TrendLinePresentationModel.cs

#
C# | 95 lines | 66 code | 13 blank | 16 comment | 6 complexity | 4a8242dde6d34064e89c620ec0a635ac 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.ComponentModel;
  18. using Microsoft.Practices.Composite.Events;
  19. using StockTraderRI.Infrastructure;
  20. using StockTraderRI.Infrastructure.Interfaces;
  21. using StockTraderRI.Infrastructure.Models;
  22. namespace StockTraderRI.Modules.Market.TrendLine
  23. {
  24. public class TrendLinePresentationModel : ITrendLinePresentationModel, INotifyPropertyChanged
  25. {
  26. private readonly IMarketHistoryService _marketHistoryService;
  27. private string tickerSymbol;
  28. private MarketHistoryCollection historyCollection;
  29. public TrendLinePresentationModel(ITrendLineView view, IMarketHistoryService marketHistoryService, IEventAggregator eventAggregator)
  30. {
  31. this.View = view;
  32. this.View.Model = this;
  33. this._marketHistoryService = marketHistoryService;
  34. eventAggregator.GetEvent<TickerSymbolSelectedEvent>().Subscribe(this.TickerSymbolChanged);
  35. }
  36. public void TickerSymbolChanged(string newTickerSymbol)
  37. {
  38. MarketHistoryCollection newHistoryCollection = this._marketHistoryService.GetPriceHistory(newTickerSymbol);
  39. this.TickerSymbol = newTickerSymbol;
  40. this.HistoryCollection = newHistoryCollection;
  41. }
  42. #region ITrendLinePresentationModel Members
  43. public ITrendLineView View { get; set; }
  44. public string TickerSymbol
  45. {
  46. get
  47. {
  48. return this.tickerSymbol;
  49. }
  50. set
  51. {
  52. if (this.tickerSymbol != value)
  53. {
  54. this.tickerSymbol = value;
  55. this.InvokePropertyChanged("TickerSymbol");
  56. }
  57. }
  58. }
  59. public MarketHistoryCollection HistoryCollection
  60. {
  61. get
  62. {
  63. return historyCollection;
  64. }
  65. private set
  66. {
  67. if (this.historyCollection != value)
  68. {
  69. this.historyCollection = value;
  70. this.InvokePropertyChanged("HistoryCollection");
  71. }
  72. }
  73. }
  74. #endregion
  75. public event PropertyChangedEventHandler PropertyChanged;
  76. private void InvokePropertyChanged(string propertyName)
  77. {
  78. PropertyChangedEventHandler Handler = PropertyChanged;
  79. if (Handler != null) Handler(this, new PropertyChangedEventArgs(propertyName));
  80. }
  81. }
  82. }