PageRenderTime 41ms CodeModel.GetById 17ms RepoModel.GetById 0ms 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. using Microsoft.Practices.Composite.Events;
  18. using Microsoft.Practices.Composite.Regions;
  19. using Microsoft.Practices.Composite.Wpf.Events;
  20. using StockTraderRI.Infrastructure;
  21. using StockTraderRI.Infrastructure.Models;
  22. using StockTraderRI.Modules.News.Article;
  23. namespace StockTraderRI.Modules.News.Controllers
  24. {
  25. public class NewsController : INewsController
  26. {
  27. private readonly IRegionManager regionManager;
  28. private readonly IArticlePresentationModel articlePresentationModel;
  29. private readonly IEventAggregator eventAggregator;
  30. private readonly INewsReaderPresenter readerPresenter;
  31. public NewsController(IRegionManager regionManager, IArticlePresentationModel articlePresentationModel, IEventAggregator eventAggregator)
  32. {
  33. this.regionManager = regionManager;
  34. this.articlePresentationModel = articlePresentationModel;
  35. this.eventAggregator = eventAggregator;
  36. this.articlePresentationModel.Controller = this;
  37. }
  38. public void Run()
  39. {
  40. this.regionManager.Regions[RegionNames.NewsRegion].Add(articlePresentationModel.View);
  41. eventAggregator.GetEvent<TickerSymbolSelectedEvent>().Subscribe(ShowNews, ThreadOption.UIThread);
  42. }
  43. public NewsController(IRegionManager regionManager,
  44. IArticlePresentationModel articlePresentationModel,
  45. IEventAggregator eventAggregator,
  46. INewsReaderPresenter readerPresenter) :
  47. this(regionManager, articlePresentationModel, eventAggregator)
  48. {
  49. this.readerPresenter = readerPresenter;
  50. }
  51. public void ShowNews(string companySymbol)
  52. {
  53. articlePresentationModel.SetTickerSymbol(companySymbol);
  54. }
  55. public void CurrentNewsArticleChanged(NewsArticle article)
  56. {
  57. this.readerPresenter.SetNewsArticle(article);
  58. }
  59. public void ShowNewsReader()
  60. {
  61. readerPresenter.Show();
  62. }
  63. }
  64. }