| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- #include "DataInterface/DataImporter.h"
- #include <clipp.h>
- #include <INIReader.h>
- #include <Logging.h>
- #include <MySQLClient.h>
- #include <SQLiteClient.h>
- #include <fstream>
- #include <iostream>
- #include <sstream>
- int main(int argc, char** argv)
- {
- try
- {
- Logging::OpenLog();
- Logging::SetLogMask(Logging::Severity::Debug);
- std::string databaseFile = "";
- clipp::group cli {
- clipp::value("SQLite Database file", databaseFile)
- };
- if (!clipp::parse(argc, argv, cli))
- {
- std::stringstream ss;
- ss << clipp::make_man_page(cli, argv[0]);
- Logging::Log(Logging::Severity::Info, ss.str());
- Logging::CloseLog();
- return 1;
- }
- {
- std::ifstream f(databaseFile);
- if (!f.good())
- throw std::runtime_error("Can't read SQLite Database file.");
- }
- INIReader iniReader("DataImporter.ini");
- if (iniReader.ParseError() != 0)
- throw std::runtime_error("Can't read DataImporter.ini.");
- MySQL::MySQLClient mySQLClient;
- {
- std::string hostname = iniReader.Get("MySQL", "Hostname", "");
- if (hostname.empty())
- throw std::runtime_error("MySQL Hostname directive missing in ini file.");
- std::string username = iniReader.Get("MySQL", "Username", "");
- if (username.empty())
- throw std::runtime_error("MySQL Username directive missing in ini file.");
- std::string password = iniReader.Get("MySQL", "Password", "");
- if (password.empty())
- throw std::runtime_error("MySQL Password directive missing in ini file.");
- std::string database = iniReader.Get("MySQL", "Database", "");
- if (database.empty())
- throw std::runtime_error("MySQL Database directive missing in ini file.");
- mySQLClient.Connect(hostname, username, password, database);
- }
- SQLite::SQLiteClient sqliteClient("./datalog.db");
- DataStorageInterface::DataInterface::DataImporter importer(&mySQLClient, &sqliteClient);
- importer.ImportData();
- Logging::CloseLog();
- }
- catch (const std::exception& e)
- {
- std::cerr << "Exception caught" << std::endl;
- std::stringstream ss;
- ss << "Type : " << typeid(e).name() << std::endl;
- ss << "ERROR: " << e.what() << std::endl;
- Logging::Log(Logging::Severity::Error, ss.str());
- Logging::CloseLog();
- return -1;
- }
- return 0;
- }
|