Exemplo n.º 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);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            IInstrumentFactory     instrumentFactory      = new InstrumentsProvider();
            IProvidePriceGenerator priceGeneratorProvider = new PriceGeneratorProvider(instrumentFactory);
            ISourcePrice           priceSource            = new CompositePriceSource(instrumentFactory, priceGeneratorProvider);

            // start source
            priceSource.Start();

            var priceObserver = new InstrumentPriceObserver();

            priceObserver.OnPriceReceived += OnPriceReceived;

            var subscription1 = priceSource.Subscribe("AAPL", priceObserver);
            var subscription2 = priceSource.Subscribe("MSFT", priceObserver);
            var subscription3 = priceSource.Subscribe("GOOG", priceObserver);

            Console.ReadKey();
            subscription1.Dispose();
            subscription2.Dispose();
            subscription3.Dispose();
            priceSource.Stop();
        }