PageRenderTime 14ms CodeModel.GetById 9ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 1ms

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