PageRenderTime 21ms CodeModel.GetById 14ms app.highlight 5ms RepoModel.GetById 1ms 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//===================================================================================
17using System;
18using System.Collections.ObjectModel;
19using System.Globalization;
20using System.Windows.Input;
21using Microsoft.Practices.Composite.Presentation.Commands;
22using StockTraderRI.Infrastructure.Interfaces;
23
24namespace StockTraderRI.Modules.Watch.Services
25{
26    public class WatchListService : IWatchListService
27    {
28        private readonly IMarketFeedService marketFeedService;
29
30        private ObservableCollection<string> WatchItems { get; set; }
31
32        public WatchListService(IMarketFeedService marketFeedService)
33        {
34            this.marketFeedService = marketFeedService;
35            WatchItems = new ObservableCollection<string>();
36
37            AddWatchCommand = new DelegateCommand<string>(AddWatch);
38        }
39
40        public ObservableCollection<string> RetrieveWatchList()
41        {
42            return WatchItems;
43        }
44
45        private void AddWatch(string tickerSymbol)
46        {
47            if (!String.IsNullOrEmpty(tickerSymbol))
48            {
49                string upperCasedTrimmedSymbol = tickerSymbol.ToUpper(CultureInfo.InvariantCulture).Trim();
50                if (!WatchItems.Contains(upperCasedTrimmedSymbol))
51                {
52                    if (marketFeedService.SymbolExists(upperCasedTrimmedSymbol))
53                    {
54                        WatchItems.Add(upperCasedTrimmedSymbol);
55                    }
56                }
57            }
58        }
59
60        public ICommand AddWatchCommand { get; set; }
61    }
62}