PageRenderTime 65ms CodeModel.GetById 59ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/V1/trunk/Source/QuickStarts/EventAggregation/ModuleB/ActivityPresenter.cs

#
C# | 67 lines | 41 code | 10 blank | 16 comment | 4 complexity | b34b2b882e1c4c05b9079ebc58388f88 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 System.Diagnostics;
19using System.Globalization;
20using EventAggregation.Infrastructure;
21using Microsoft.Practices.Composite.Events;
22using Microsoft.Practices.Composite.Wpf.Events;
23using ModuleB.Properties;
24
25namespace ModuleB
26{
27    public class ActivityPresenter
28    {
29        private string _customerId;
30        private IEventAggregator eventAggregator;
31        private SubscriptionToken subscriptionToken;
32
33        public ActivityPresenter(IEventAggregator eventAggregator)
34        {
35            this.eventAggregator = eventAggregator;
36        }
37
38        void FundAddedEventHandler(FundOrder fundOrder)
39        {
40            Debug.Assert(View != null);
41            View.AddContent(fundOrder.TickerSymbol);
42        }
43
44        public IActivityView View { get; set; }
45
46        public string CustomerId
47        {
48            get { return _customerId; }
49            set
50            {
51                _customerId = value;
52
53                FundAddedEvent fundAddedEvent = eventAggregator.GetEvent<FundAddedEvent>();
54
55                if (subscriptionToken != null)
56                {
57                    fundAddedEvent.Unsubscribe(subscriptionToken);
58                }
59
60                subscriptionToken = fundAddedEvent.Subscribe(FundAddedEventHandler, ThreadOption.UIThread, false,
61                                                             fundOrder => fundOrder.CustomerId == _customerId);
62
63                View.Title = string.Format(CultureInfo.CurrentCulture, Resources.ActivityTitle, CustomerId);
64            }
65        }
66    }
67}