Ejemplo n.º 1
0
        private void AddToDb <T>(object sender, DataUpdatedArgs args, StockType st) where T : StockBase
        {
            logger.Info("Adding to DB with stocktype=" + st.ToString());
            var stocksValues = args.Values;

            foreach (var stockAnsiToValues in stocksValues)
            {
                if (st == StockType.RT)
                {
                    StockRT stock = new StockRT(stockAnsiToValues.Value);
                    logger.Debug("Adding stock with type RT with stockname=" + stockAnsiToValues.Key);
                    this.stocks[stockAnsiToValues.Key].Tables.RT.Add(stock);
                }
                else if (st == StockType.Daily)
                {
                    StockDaily stock = new StockDaily(stockAnsiToValues.Value);
                    logger.Debug("Adding stock with type Daily with stockname=" + stockAnsiToValues.Key);
                    this.stocks[stockAnsiToValues.Key].Tables.Daily.Add(stock);
                }
                else
                {
                    logger.Error("Unknown stock type while trying to enter data to DB");
                    throw new Exception("Unknown stock type");
                }
                this.stocks[stockAnsiToValues.Key].Tables.SaveChanges();
            }
        }
Ejemplo n.º 2
0
 private void UpdateStocksData(object sender, ElapsedEventArgs args)
 {
     try
     {
         // TODO: make this better
         logger.Info("Getting new data from yahoo.");
         data = GetFromYahoo();
         DataUpdated(this, data);
         logger.Info("Done updating data.");
     }
     catch (Exception e)
     {
         logger.Error(e, "Caught exception while updating data. " + e.Message);
         logger.Debug(e.StackTrace);
     }
 }
Ejemplo n.º 3
0
        private void AddToDb <T>(object sender, DataUpdatedArgs args, StockType st) where T : StockBase
        {
            var stocksValues = args.Values;

            foreach (var stockAnsiToValues in stocksValues)
            {
                if (st == StockType.RT)
                {
                    StockRT stock = new StockRT(stockAnsiToValues.Value);
                    this.stocks[stockAnsiToValues.Key].Tables.RT.Add(stock);
                }
                else if (st == StockType.Daily)
                {
                    StockDaily stock = new StockDaily(stockAnsiToValues.Value);
                    this.stocks[stockAnsiToValues.Key].Tables.Daily.Add(stock);
                }
                else
                {
                    throw new Exception("Unknown stock type");
                }
            }
        }
Ejemplo n.º 4
0
 private void AddDailyToDB(object sender, DataUpdatedArgs args)
 {
     AddToDb <StockDaily>(sender, args, StockType.Daily);
 }
Ejemplo n.º 5
0
 private void AddRTToDB(object sender, DataUpdatedArgs args)
 {
     AddToDb <StockRT>(sender, args, StockType.RT);
 }