DataCondenser.cc 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include "DataInterface/DataCondenser.h"
  2. #include <INIReader.h>
  3. #include <Logging.h>
  4. #include <MySQLClient.h>
  5. #include <iostream>
  6. #include <sstream>
  7. #include <string>
  8. int main(int argc, char** argv)
  9. {
  10. try
  11. {
  12. Logging::OpenLog();
  13. Logging::SetLogMask(Logging::Severity::Info);
  14. INIReader iniReader("DataCondenser.ini");
  15. if (iniReader.ParseError() != 0)
  16. throw std::runtime_error("Can't read DataCondenser.ini.");
  17. MySQL::MySQLClient mySQLClient;
  18. {
  19. std::string hostname = iniReader.Get("MySQL", "Hostname", "");
  20. if (hostname.empty())
  21. throw std::runtime_error("MySQL Hostname directive missing in ini file.");
  22. std::string username = iniReader.Get("MySQL", "Username", "");
  23. if (username.empty())
  24. throw std::runtime_error("MySQL Username directive missing in ini file.");
  25. std::string password = iniReader.Get("MySQL", "Password", "");
  26. if (password.empty())
  27. throw std::runtime_error("MySQL Password directive missing in ini file.");
  28. std::string database = iniReader.Get("MySQL", "Database", "");
  29. if (database.empty())
  30. throw std::runtime_error("MySQL Database directive missing in ini file.");
  31. mySQLClient.Connect(hostname, username, password, database);
  32. }
  33. DataStorageInterface::DataInterface::DataCondenser condenser(&mySQLClient);
  34. condenser.CondenseData();
  35. Logging::CloseLog();
  36. }
  37. catch (const std::exception& e)
  38. {
  39. std::cerr << "Exception caught" << std::endl;
  40. std::stringstream ss;
  41. ss << "Type : " << typeid(e).name() << std::endl;
  42. ss << "ERROR: " << e.what() << std::endl;
  43. Logging::Log(Logging::Severity::Error, ss.str());
  44. Logging::CloseLog();
  45. return -1;
  46. }
  47. return 0;
  48. }