PageRenderTime 47ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/V4/StockTrader RI/Desktop/StockTraderRI.Modules.Position/PositionSummary/PositionSummaryViewModel.cs

#
C# | 81 lines | 54 code | 11 blank | 16 comment | 6 complexity | 834271dfd2c11aeff3973a45d6c703d9 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.Composition;
  18. using System.Windows.Input;
  19. using Microsoft.Practices.Prism.Events;
  20. using Microsoft.Practices.Prism.ViewModel;
  21. using StockTraderRI.Infrastructure;
  22. using StockTraderRI.Modules.Position.Controllers;
  23. using System;
  24. namespace StockTraderRI.Modules.Position.PositionSummary
  25. {
  26. [Export(typeof(IPositionSummaryViewModel))]
  27. [PartCreationPolicy(CreationPolicy.NonShared)]
  28. public class PositionSummaryViewModel : NotificationObject, IPositionSummaryViewModel
  29. {
  30. private PositionSummaryItem currentPositionSummaryItem;
  31. private readonly IEventAggregator eventAggregator;
  32. public IObservablePosition Position { get; private set; }
  33. [ImportingConstructor]
  34. public PositionSummaryViewModel(IOrdersController ordersController, IEventAggregator eventAggregator, IObservablePosition observablePosition)
  35. {
  36. if (ordersController == null)
  37. {
  38. throw new ArgumentNullException("ordersController");
  39. }
  40. this.eventAggregator = eventAggregator;
  41. this.Position = observablePosition;
  42. BuyCommand = ordersController.BuyCommand;
  43. SellCommand = ordersController.SellCommand;
  44. this.CurrentPositionSummaryItem = new PositionSummaryItem("FAKEINDEX", 0, 0, 0);
  45. }
  46. public ICommand BuyCommand { get; private set; }
  47. public ICommand SellCommand { get; private set; }
  48. public string HeaderInfo
  49. {
  50. get { return "POSITION"; }
  51. }
  52. public PositionSummaryItem CurrentPositionSummaryItem
  53. {
  54. get { return currentPositionSummaryItem; }
  55. set
  56. {
  57. if (currentPositionSummaryItem != value)
  58. {
  59. currentPositionSummaryItem = value;
  60. this.RaisePropertyChanged(() => this.CurrentPositionSummaryItem);
  61. if (currentPositionSummaryItem != null)
  62. {
  63. eventAggregator.GetEvent<TickerSymbolSelectedEvent>().Publish(
  64. CurrentPositionSummaryItem.TickerSymbol);
  65. }
  66. }
  67. }
  68. }
  69. }
  70. }