Exemplo n.º 1
0
        /// <summary>
        /// Generate update query code for particular ticker and date.
        /// </summary>
        /// <param name="ticker"></param>
        /// <param name="date"></param>
        /// <returns></returns>
        private string GetUpdateQueryCode(string ticker, string date)
        {
            StringBuilder     stringBuilder     = new StringBuilder();
            EconomicDataPoint economicDataPoint = m_EconomicDataManager.EconomicDataSeriesByTicker[ticker].EconomicDataPointByDate[date];

            stringBuilder.AppendFormat("update {0} set {1}", m_EconomicDataTable, WriteDataToUpdateQueryString(economicDataPoint));
            stringBuilder.AppendFormat("where tickerId = '{0}' and dateStr = '{1}';", m_DataBaseReader.ReportTickerID(ticker), date);
            return(stringBuilder.ToString());
        }
Exemplo n.º 2
0
        /// <summary>
        /// Make up the unix time stamp for which tickers that have unix time stamp of 0.
        /// </summary>
        public void MakeUpUnixTimeStamp(List <string> tickers)
        {
            long   rowId = -1;
            string date;
            string time;
            string exchangeCode;
            string unixT;

            // Update the unix time stamp of
            foreach (string ticker in tickers)
            {
                int tickerId = m_DataBaseReader.ReportTickerID(ticker);
                if (tickerId != -1)
                {
                    // Find the row id for that ticker.
                    foreach (int id in m_DataBaseReader.EconomicDataCollections.Keys)
                    {
                        List <string> dataList = m_DataBaseReader.EconomicDataCollections[id];

                        // Determine whether to update by checking unix time stamp larger than 0.
                        int UNIXTime;
                        if (!int.TryParse(dataList[EconomicDataField.UnixTime], out UNIXTime))
                        {
                            continue;
                        }
                        else
                        {
                            if (UNIXTime > 0)
                            {
                                continue;
                            }
                        }

                        if (Functions.StringToDateTime(dataList[EconomicDataField.Date]) != DateTime.MinValue && dataList[EconomicDataField.Time] != Logging.m_EmptySign && dataList[EconomicDataField.EconomicTickerID] == Convert.ToString(tickerId))
                        {
                            rowId        = id;
                            date         = dataList[EconomicDataField.Date];
                            time         = dataList[EconomicDataField.Time];
                            exchangeCode = dataList[EconomicDataField.BBGTimeZone];
                            try
                            {
                                // Calculate the unix time stamp.
                                unixT = Convert.ToString(Functions.ConvertToUnixTimeStamp(date, time, Convert.ToInt32(exchangeCode)));

                                try
                                {
                                    string       query        = string.Format("Update {0} set unixT = {1} where id = {2};", m_EconomicDataTable, unixT, rowId);
                                    MySqlCommand mySqlCommand = new MySqlCommand(query, m_MySqlEconomicDataTableConnection);
                                    mySqlCommand.ExecuteNonQuery();
                                }
                                catch (MySqlException ex)
                                {
                                    string errorInfo = ex.ToString();
                                    Console.WriteLine(errorInfo);
                                    Logging.WriteErrorLog(errorInfo);
                                }
                            }
                            catch (Exception ex)
                            {
                                string errorInfo = ex.ToString();
                                Console.WriteLine(errorInfo);
                                Logging.WriteErrorLog(errorInfo);
                            }
                        }
                    }
                }
            }
        }