コード例 #1
0
        public MainViewModel()
        {
            Instruments = new ObservableCollection <Instrument>
            {
                new Instrument("AAPL", 175),
                new Instrument("MSFT", 115),
                new Instrument("GOOG", 1200),
                new Instrument("FB", 160)
            };

            _subscriptions = new Dictionary <string, Subscription>();
            _instrumentMap = new Dictionary <string, Instrument>();

            foreach (var instrument in Instruments)
            {
                _instrumentMap.Add(instrument.Ticker, instrument);
            }

            IInstrumentFactory     instrumentFactory      = new InstrumentsProvider();
            IProvidePriceGenerator priceGeneratorProvider = new PriceGeneratorProvider(instrumentFactory);

            _priceSource = new CompositePriceSource(instrumentFactory, priceGeneratorProvider);

            // commands
            StartPriceSourceCommand = new RelayCommand(StartPriceSource, CanStartPriceSource);
            StopPriceSourceCommand  = new RelayCommand(StopPriceSource, CanStopPriceSource);
            SubscribeCommand        = new RelayCommand <Instrument>(SubscribePrice, CanSubscribePrice);
            UnsubscribeCommand      = new RelayCommand <Instrument>(UnsubscribePrice, CanUnubscribePrice);
            SubscribeAllCommand     = new RelayCommand(SubscribeAll, CanSubscribeAll);
            UnsubscribeAllCommand   = new RelayCommand(UnsubscribeAll, CanUnsubscribeAll);
        }