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