Exemplo n.º 1
0
        /// <summary>
        /// Extract all stock objects
        /// </summary>
        /// <param name="sourceContent"></param>
        /// <returns></returns>
        public static List<StockObject> ProcessStockObjectList(string sourceContent)
        {
            List<StockObject> listStockObjects = new List<StockObject>();

            string[] parts = sourceContent.Split(new string[] { "/tr>" }, StringSplitOptions.RemoveEmptyEntries);
            //Console.WriteLine("parts.Length = {0}", parts.Length);
            for (int i = 0; i < parts.Length; i++)
            {
                try
                {
                    int length = 0;
                    string content = parts[i];
                    int trStart = content.IndexOf("<tr>");
                    int trEnd = content.IndexOf("</tr>");
                    if (trStart < 0 && trEnd < 0)
                    {
                        continue;
                    }
                    if (trEnd < 0)
                    {
                        trEnd = content.Length - 1;
                        length = trEnd - trStart;
                    }
                    else
                    {
                        length = trEnd + "</tr>".Length - trStart;
                    }
                    string trContent = content.Substring(trStart, length);

                    StockObject so = new StockObject();
                    if (so.Parse(trContent))
                        listStockObjects.Add(so);
                    //Console.WriteLine("[{0}]:{1},{2},{3},{4},{5},{6},{7}", i, so.symbol, so.name, so.lastTrade, so.lastTreadTime, so.change, so.changePercent, so.volume);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("index={0},{1}", i, ex.Message);
                    //throw ex;
                }
            }

            return listStockObjects;
        }
Exemplo n.º 2
0
 public static string InsertStockObject(Stock stock, StockObject so)
 {
     string queryTemp = "INSERT INTO {0} (smarket,stype,symbol,name,last_trade,last_trade_time,change,change_percent,volume) VALUES('{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}')";
     return string.Format(queryTemp, stock.table, stock.market, stock.type, so.symbol, so.name, so.lastTrade, so.lastTreadTime, so.change, so.changePercent, so.volume);
 }