// ***************************************************************** // **** Constructors **** // ***************************************************************** // // // /// <summary> /// Set values to members of writer manager by ticker list, economic data manager, listener manager and connect to the database. /// </summary> /// <param name="tickers"></param> /// <param name="economicDataManager"></param> /// <param name="listenerManager"></param> public Writer(EconomicDataManager economicDataManager, ListenerManager listenerManager, DataBaseReader dataBaseReader) { // Set values to members. m_EconomicDataManager = economicDataManager; listenerManager.ListenComplete += new EventHandler(Writer_ListenComplete); m_DataBaseReader = dataBaseReader; // Instantiate other members. m_EconomicDataPointQueue = new Queue <EconomicDataPoint>(); m_WaitHandle = new EventWaitHandle(false, EventResetMode.ManualReset); // Get the current row count in the database. m_Row = m_DataBaseReader.DataBaseRowCount; try { // Writing SQL connection. StringBuilder dataBaseString = new StringBuilder(); dataBaseString.AppendFormat("Server={0};User Id={1};Password={2};Database={3};Connection Timeout ={4};" , m_DataBaseReader.m_Host, m_DataBaseReader.m_Login, m_DataBaseReader.m_Password, m_DataBaseReader.m_DataBase, m_DataBaseReader.m_TimeOutMinutes * 60); m_MySqlEconomicDataTableConnection = new MySqlConnection(dataBaseString.ToString()); m_MySqlEconomicDataTableConnection.Open(); } catch (MySqlException ex) { Console.WriteLine(ex.ToString()); Logging.WriteErrorLog(ex.ToString()); } }
// ***************************************************************** // **** Properties **** // ***************************************************************** // // #endregion//Properties #region Public Methods // ***************************************************************** // **** Public Methods **** // ***************************************************************** // // // // // // /// <summary> /// Operate in order and the last step contains creation of another thread. /// </summary> public void Run() { // Initiatelize the logging instrument. Logging.InitiateLogging(m_CountryCode); // Read configuration parameters that include start date, end date and future date from the txt file. ReadConfigFile(); // Create data base reader connection and read all ticker info and economic data from the database. DataBaseReader m_DataBaseReader = new DataBaseReader(); // Create the tickerlist from what we got from the data base reader and also get tickers by country. TickerList m_TickerList = new TickerList(m_DataBaseReader, m_CountryCode); // Get all tickers from one specified country and prepare chunks of tickers. m_TickerList.SetTickersToChunks(m_CountryCode); //// Connect to the Bloomberg to get economic data. ConnectToBloomberg(); ////// Test only one ticker!!! //m_TickerList.TryOneTicker("UGRSSOTO Index", true); //m_StartDate = "20110101"; //m_FutureDate = "20140201"; //m_EconomicDataManager = new EconomicDataManager(m_StartDate, m_EndDate, m_FutureDate); //m_ListenerManager = new ListenerManager(m_Session, m_TickerList, m_EconomicDataManager); //m_Writer = new Writer(m_EconomicDataManager, m_ListenerManager, m_DataBaseReader); //m_EconomicDataManager.SetWriter(m_Writer); //m_Writer.StringGeneratingComplete += new EventHandler(WriterManager_StringGeneratingComplete); //m_ListenerManager.StartEconomicDataListening(); //// Assign date range for economic data manager. m_EconomicDataManager = new EconomicDataManager(m_StartDate, m_EndDate, m_FutureDate); // Create listener manager to do chunk by chunk listening. m_ListenerManager = new ListenerManager(m_Session, m_TickerList, m_EconomicDataManager); // Create writer and currently there is other thread created. m_Writer = new Writer(m_EconomicDataManager, m_ListenerManager, m_DataBaseReader); // Economic data series need writer. m_EconomicDataManager.SetWriter(m_Writer); // Subscribe to the event when string generates complete. m_Writer.StringGeneratingComplete += new EventHandler(WriterManager_StringGeneratingComplete); // Launch listener manager. m_ListenerManager.StartEconomicDataListening(); }
// ***************************************************************** // **** Constructors **** // ***************************************************************** // // // /// <summary> /// Set values to members of writer manager by ticker list, economic data manager, listener manager and connect to the database. /// </summary> /// <param name="tickers"></param> /// <param name="economicDataManager"></param> /// <param name="listenerManager"></param> public WriterManager(List <string> tickers, EconomicDataManager economicDataManager, ListenerManager listenerManager, DataBaseReader dataBaseReader) { // Set values to members. m_Tickers = tickers; m_EconomicDataManager = economicDataManager; listenerManager.ListenComplete += new EventHandler(WriterManager_ListenComplete); m_DataBaseReader = dataBaseReader; // Instantiate other members. m_EconomicDataPointQueue = new Queue <EconomicDataPoint>(); m_WaitHandle = new EventWaitHandle(false, EventResetMode.ManualReset); // Get the current row count in the database. m_Row = m_DataBaseReader.DataBaseRowCount; // Connect to the data base. StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendFormat("Server={0};User Id={1};Password={2};Database={3};Connection Timeout ={4};" , m_DataBaseReader.m_Host, m_DataBaseReader.m_Login, m_DataBaseReader.m_Password, m_DataBaseReader.m_DataBase, m_DataBaseReader.m_TimeOutMinutes * 60); m_MySqlEconomicDataTableConnection = new MySqlConnection(stringBuilder.ToString()); }