Initial commit

This commit is contained in:
2020-05-01 11:27:56 +02:00
commit 2c6c03869c
38 changed files with 1576 additions and 0 deletions
+63
View File
@@ -0,0 +1,63 @@
#include "DataInterface/DataCondenser.h"
#include <INIReader.h>
#include <Logging.h>
#include <MySQLClient.h>
#include <iostream>
#include <sstream>
#include <string>
int main(int argc, char** argv)
{
try
{
Logging::OpenLog();
Logging::SetLogMask(Logging::Severity::Info);
INIReader iniReader("DataCondenser.ini");
if (iniReader.ParseError() != 0)
throw std::runtime_error("Can't read DataCondenser.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);
}
DataStorageInterface::DataInterface::DataCondenser condenser(&mySQLClient);
condenser.CondenseData();
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;
}
+89
View File
@@ -0,0 +1,89 @@
#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;
}
+77
View File
@@ -0,0 +1,77 @@
#include "API/WebAPI.h"
#include "DataInterface/GraphClient.h"
#include <DataStorageClient.h>
#include <HttpServer.h>
#include <INIReader.h>
#include <Logging.h>
#include <MySQLClient.h>
#include <sstream>
int main(int argc, char** argv)
{
try
{
Logging::OpenLog();
Logging::SetLogMask(Logging::Severity::Info);
INIReader iniReader("DataStorageAPI.ini");
if (iniReader.ParseError() != 0)
throw std::runtime_error("Can't read DataLogger.ini.");
Logging::Log(Logging::Severity::Info, "Starting DataStorageAPI");
int port = iniReader.GetInteger("DataStorageAPI", "Port", 0);
if (port == 0)
throw std::runtime_error("Port directive missing in ini file.");
std::string table = iniReader.Get("DataStorageAPI", "Table", "");
if (table.empty())
throw std::runtime_error("Table directive missing in ini file.");
std::shared_ptr<MySQL::MySQLClient> pMySQLClient = std::make_shared<MySQL::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.");
pMySQLClient->Connect(hostname, username, password, database);
}
DataStorage::DataStorageClient dataStorageClient(pMySQLClient, table);
DataStorageInterface::DataInterface::GraphClient graphClient(pMySQLClient.get());
auto callback = std::bind(&DataStorageInterface::API::WebAPI::ProcessQuery, &dataStorageClient, &graphClient, std::placeholders::_1, std::placeholders::_2);
Http::HttpServer server(port, callback);
Logging::Log(Logging::Severity::Info, "Startup Complete");
server.Wait();
Logging::Log(Logging::Severity::Info, "Stopping DataStorageAPI...");
Logging::CloseLog();
}
catch (const std::exception& e)
{
std::stringstream ss;
ss << "ERROR: " << e.what() << std::endl;
Logging::Log(Logging::Severity::Error, ss.str());
Logging::CloseLog();
return -1;
}
return 0;
}
+1
View File
@@ -0,0 +1 @@
../Makefile