/V1/trunk/Source/QuickStarts/EventAggregation/ModuleB/ActivityPresenter.cs
C# | 67 lines | 41 code | 10 blank | 16 comment | 4 complexity | b34b2b882e1c4c05b9079ebc58388f88 MD5 | raw file
- //===============================================================================
- // Microsoft patterns & practices
- // Composite Application Guidance for Windows Presentation Foundation
- //===============================================================================
- // Copyright (c) Microsoft Corporation. All rights reserved.
- // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
- // OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
- // LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
- // FITNESS FOR A PARTICULAR PURPOSE.
- //===============================================================================
- // The example companies, organizations, products, domain names,
- // e-mail addresses, logos, people, places, and events depicted
- // herein are fictitious. No association with any real company,
- // organization, product, domain name, email address, logo, person,
- // places, or events is intended or should be inferred.
- //===============================================================================
-
- using System.Diagnostics;
- using System.Globalization;
- using EventAggregation.Infrastructure;
- using Microsoft.Practices.Composite.Events;
- using Microsoft.Practices.Composite.Wpf.Events;
- using ModuleB.Properties;
-
- namespace ModuleB
- {
- public class ActivityPresenter
- {
- private string _customerId;
- private IEventAggregator eventAggregator;
- private SubscriptionToken subscriptionToken;
-
- public ActivityPresenter(IEventAggregator eventAggregator)
- {
- this.eventAggregator = eventAggregator;
- }
-
- void FundAddedEventHandler(FundOrder fundOrder)
- {
- Debug.Assert(View != null);
- View.AddContent(fundOrder.TickerSymbol);
- }
-
- public IActivityView View { get; set; }
-
- public string CustomerId
- {
- get { return _customerId; }
- set
- {
- _customerId = value;
-
- FundAddedEvent fundAddedEvent = eventAggregator.GetEvent<FundAddedEvent>();
-
- if (subscriptionToken != null)
- {
- fundAddedEvent.Unsubscribe(subscriptionToken);
- }
-
- subscriptionToken = fundAddedEvent.Subscribe(FundAddedEventHandler, ThreadOption.UIThread, false,
- fundOrder => fundOrder.CustomerId == _customerId);
-
- View.Title = string.Format(CultureInfo.CurrentCulture, Resources.ActivityTitle, CustomerId);
- }
- }
- }
- }