PageRenderTime 16ms CodeModel.GetById 12ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/V1/trunk/Source/StockTraderRI/StockTraderRI.Modules.News/Controllers/NewsController.cs

#
C# | 72 lines | 48 code | 8 blank | 16 comment | 0 complexity | edff1128d843e5f2afcf033b8b2c2c7e MD5 | raw file
 1//===============================================================================
 2// Microsoft patterns & practices
 3// Composite Application Guidance for Windows Presentation Foundation
 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
18using Microsoft.Practices.Composite.Events;
19using Microsoft.Practices.Composite.Regions;
20using Microsoft.Practices.Composite.Wpf.Events;
21using StockTraderRI.Infrastructure;
22using StockTraderRI.Infrastructure.Models;
23using StockTraderRI.Modules.News.Article;
24
25namespace StockTraderRI.Modules.News.Controllers
26{
27    public class NewsController : INewsController
28    {
29        private readonly IRegionManager regionManager;
30        private readonly IArticlePresentationModel articlePresentationModel;
31        private readonly IEventAggregator eventAggregator;
32        private readonly INewsReaderPresenter readerPresenter;
33
34        public NewsController(IRegionManager regionManager, IArticlePresentationModel articlePresentationModel, IEventAggregator eventAggregator)
35        {
36            this.regionManager = regionManager;
37            this.articlePresentationModel = articlePresentationModel;
38            this.eventAggregator = eventAggregator;
39            this.articlePresentationModel.Controller = this;
40        }
41
42        public void Run()
43        {
44            this.regionManager.Regions[RegionNames.NewsRegion].Add(articlePresentationModel.View);
45            eventAggregator.GetEvent<TickerSymbolSelectedEvent>().Subscribe(ShowNews, ThreadOption.UIThread);
46        }
47
48        public NewsController(IRegionManager regionManager,
49                                IArticlePresentationModel articlePresentationModel,
50                                IEventAggregator eventAggregator,
51                                INewsReaderPresenter readerPresenter) :
52            this(regionManager, articlePresentationModel, eventAggregator)
53        {
54            this.readerPresenter = readerPresenter;
55        }
56
57        public void ShowNews(string companySymbol)
58        {
59            articlePresentationModel.SetTickerSymbol(companySymbol);
60        }
61
62        public void CurrentNewsArticleChanged(NewsArticle article)
63        {
64            this.readerPresenter.SetNewsArticle(article);
65        }
66
67        public void ShowNewsReader()
68        {
69            readerPresenter.Show();
70        }
71    }
72}