PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/V2/trunk/RI/Desktop/StockTraderRI.Modules.WatchList/Services/WatchListService.cs

#
C# | 62 lines | 39 code | 7 blank | 16 comment | 3 complexity | 84919694682b6ef6ed34e4efe1c5a372 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;
  18. using System.Collections.ObjectModel;
  19. using System.Globalization;
  20. using System.Windows.Input;
  21. using Microsoft.Practices.Composite.Presentation.Commands;
  22. using StockTraderRI.Infrastructure.Interfaces;
  23. namespace StockTraderRI.Modules.Watch.Services
  24. {
  25. public class WatchListService : IWatchListService
  26. {
  27. private readonly IMarketFeedService marketFeedService;
  28. private ObservableCollection<string> WatchItems { get; set; }
  29. public WatchListService(IMarketFeedService marketFeedService)
  30. {
  31. this.marketFeedService = marketFeedService;
  32. WatchItems = new ObservableCollection<string>();
  33. AddWatchCommand = new DelegateCommand<string>(AddWatch);
  34. }
  35. public ObservableCollection<string> RetrieveWatchList()
  36. {
  37. return WatchItems;
  38. }
  39. private void AddWatch(string tickerSymbol)
  40. {
  41. if (!String.IsNullOrEmpty(tickerSymbol))
  42. {
  43. string upperCasedTrimmedSymbol = tickerSymbol.ToUpper(CultureInfo.InvariantCulture).Trim();
  44. if (!WatchItems.Contains(upperCasedTrimmedSymbol))
  45. {
  46. if (marketFeedService.SymbolExists(upperCasedTrimmedSymbol))
  47. {
  48. WatchItems.Add(upperCasedTrimmedSymbol);
  49. }
  50. }
  51. }
  52. }
  53. public ICommand AddWatchCommand { get; set; }
  54. }
  55. }