示例#1
0
        private void SaveStockPrice(Stock stock)
        {
            var store = DocumentStore.Store;

            using (var session = store.OpenSession())
            {
                var dbStock = session.Load<Stock>("stocks/" + stock.Symbol);

                if (dbStock == null)
                {
                    session.Store(stock);
                }
                else
                {
                    dbStock.Price = stock.Price;
                }

                session.SaveChanges();
            }
        }
示例#2
0
        private bool TryUpdateStockPrice(Stock stock)
        {
            // Randomly choose whether to update this stock or not
            var r = _updateOrNotRandom.NextDouble();
            if (r > .1)
            {
                return false;
            }

            // Update the stock price by a random factor of the range percent
            var random = new Random((int)Math.Floor(stock.Price));
            var percentChange = random.NextDouble() * _rangePercent;
            var pos = random.NextDouble() > .51;
            var change = Math.Round(stock.Price * (decimal)percentChange, 2);
            change = pos ? change : -change;

            stock.Price += change;
            return true;
        }
示例#3
0
 private void BroadcastStockPrice(Stock stock)
 {
     Clients.All.updateStockPrice(stock);
 }