예제 #1
0
        /*****************************************************************************
        *  FUNCTION:  UpdateLiveData
        *  Description:
        *  Parameters:
        *          pDataLabels -
        *          pDataValues -
        *****************************************************************************/
        public Boolean UpdateLiveData(List <String> pDataLabels, List <String> pDataValues, String pLiveUrl = "")
        {
            Boolean  success    = false;
            int      item_index = 0;
            string   item_value = "";
            DateTime last_time;

            //Ensure lists are initialized
            if (live_price == null)
            {
                live_price = new List <double>();
            }
            if (live_timestamps == null)
            {
                live_timestamps = new List <DateTime>();
            }

            //Set the live data source address
            if (pLiveUrl != "")
            {
                LiveDataAddress = pLiveUrl;
            }

            foreach (String label in pDataLabels)
            {
                item_value = pDataValues[item_index];

                //ToDo: optimize
                switch (label)
                {
                case "Last":
                    if (Helpers.ValidateNumeric(pDataValues[item_index]))
                    {
                        this.live_price.Add(Double.Parse(pDataValues[item_index]));
                        if (this.live_price.Count > LIVE_DATA_BUFFER_SIZE)
                        {
                            this.live_price.RemoveAt(0);
                        }
                    }
                    break;

                case "High":
                    if (Helpers.ValidateNumeric(pDataValues[item_index]))
                    {
                        this.live_high = Double.Parse(pDataValues[item_index]);
                    }
                    break;

                case "Low":
                    if (Helpers.ValidateNumeric(pDataValues[item_index]))
                    {
                        this.live_low = Double.Parse(pDataValues[item_index]);
                    }
                    break;

                case "Chg.":
                    if (Helpers.ValidateNumeric(pDataValues[item_index]))
                    {
                        this.live_chg = Double.Parse(pDataValues[item_index]);
                    }
                    break;

                case "Chg. %":
                    if (pDataValues[item_index].Contains("%"))
                    {
                        this.live_chg_pct = Double.Parse(pDataValues[item_index].Replace("%", ""));
                    }
                    break;

                case "Vol.":
                    this.live_volume = Helpers.ConvertVolumeString(pDataValues[item_index]);
                    break;

                case "Time":
                    last_time = DateTime.Parse(pDataValues[item_index]);

                    if (this.live_timestamps.Count > 0 &&
                        this.live_timestamps[this.live_timestamps.Count - 1] == last_time)
                    {
                        if (this.live_price.Count > this.live_timestamps.Count)
                        {
                            this.live_price.RemoveAt(this.live_price.Count - 1);
                        }
                        item_index = pDataLabels.Count;
                    }
                    else
                    {
                        this.live_timestamps.Add(last_time);
                        if (this.live_timestamps.Count > LIVE_DATA_BUFFER_SIZE)
                        {
                            this.live_timestamps.RemoveAt(0);
                        }
                    }
                    break;

                default:
                    break;
                }

                item_index++;

                if (item_index > pDataLabels.Count)
                {
                    break;
                }
            }

            if (ValidateLiveData())
            {
                this.ContainsLiveData = true;
            }
            return(success);
        }