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