Ejemplo n.º 1
0
        /// <summary>
        /// Used to centralize GUI updates instead of relying on external triggers.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <remarks>
        /// </remarks>
        void myTimer_Tick(object sender, EventArgs e)
        {
            var timeOfUpdate = DateTime.Now;

            // dequeue all product updates
            MessageFeed.Message message = null;
            while (this.myPendingMessages.TryDequeue(out message))
            {
                if (this.cachedPriceData.ContainsKey(message.GetIDKey()) == false)
                {
                    InsertNewPriceSorted(message);
                }
                this.cachedPriceData[message.GetIDKey()].UpdateWith(message, timeOfUpdate);

                List <Double> additionalPricesToAdd = this.priceWindowTracker.CheckMessage(message);
                if (additionalPricesToAdd.Count > 0)
                {
                    foreach (double newPrice in additionalPricesToAdd)
                    {
                        var newMessage = new MessageFeed.Message(
                            MessageFeed.Message.MessageTypeEnum.PRICE,
                            message.Symbol,
                            MessageFeed.Message.ActionEnum.ADD,
                            MessageFeed.Message.BidAskEnum.BID,
                            newPrice,
                            0
                            );
                        InsertNewPriceSorted(newMessage);
                    }
                }
            }

            // Loop over all products to reset any data-changed times
            // **NOTE** This has O(n) complexity, which if that was undesirable... it could be restructured
            //          to store all change times, objects, and properties in a queue where it would merely
            //          process any that have expired and whose color must be changed back. But that is a
            //          moderately complex solution for an evaluation project...
            foreach (var displayedProduct in this.displayedProducts)
            {
                displayedProduct.ClearChangedTimes(timeOfUpdate);
            }
        }
Ejemplo n.º 2
0
        private void InsertNewPriceSorted(MessageFeed.Message message)
        {
            var newDisplayedPrice = new DisplayedProduct(message.Symbol, message.Price);

            this.cachedPriceData[message.GetIDKey()] = newDisplayedPrice;

            // Sequential search to find correct location to add
            for (int index = 0; index < displayedProducts.Count; index++)
            {
                if ((newDisplayedPrice.Symbol.CompareTo(this.displayedProducts[index].Symbol) < 0) ||
                    (newDisplayedPrice.Symbol == this.displayedProducts[index].Symbol && this.displayedProducts[index].Price < newDisplayedPrice.Price))
                {
                    this.displayedProducts.Insert(index, newDisplayedPrice);
                    return;
                }
            }
            // To get here, it must be sorted after all products
            this.displayedProducts.Add(newDisplayedPrice);
        }