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