Ejemplo n.º 1
0
        /// <summary>
        /// Constructor. Sets up the stock simulation. Note that all
        /// Quote and Stock view model objects are hooked up to the
        /// Quotes event from the Stock model quote generator.
        /// </summary>
        public StockSimulationViewModel()
        {
            // Create model and collections for data binding
            _stockModel   = new StockSimulationModel();
            _stockQuotes  = new ObservableCollection <QuoteViewModel>();
            _stockDetails = new ObservableCollection <StockViewModel>();

            foreach (Stock sd in _stockModel.Stocks)
            {
                // Create Quote view model objects, and hook their ConsumeQuote
                // method up to the Quotes event from the quote generator.
                QuoteViewModel qvm = new QuoteViewModel(new Quote(sd.FiID, sd.InitialPrice));
                _stockModel.QuoteGenerator.Quotes += qvm.ConsumeQuote;
                _stockQuotes.Add(qvm);

                // Create Stock view model objects, and hook their ConsumeQuote
                // method up to the Quotes event from the quote generator.
                StockViewModel sdvm = new StockViewModel(sd, sd.InitialPrice);
                _stockModel.QuoteGenerator.Quotes += sdvm.ConsumeQuote;
                _stockDetails.Add(sdvm);
            }

            // Start the simulation!
            _stockModel.Start();
        }
Ejemplo n.º 2
0
        public MainPage()
        {
            this.InitializeComponent();

            StockSimulationModel ssm = new StockSimulationModel();

            ssm.QuoteGenerator.Quotes += q =>
            {
                Debug.WriteLine($"Got quote: {q.FiID}@{q.Price:F2}");
            };

            ssm.Start();
        }