7 Poco::AutoPtr<Poco::Util::AbstractConfiguration>
_config = NULL;
11 Poco::SharedPtr<HCE::database::DBSession>
Session = NULL;
26 if (Poco::Util::Application::initialized() ==
true || this->_initializedHCEServerApplication ==
true) {
31 Poco::Util::ServerApplication::initialize(
self);
33 this->initializeConfigurationFile();
34 this->initializeLoggers();
35 this->initializeDataBaseSession ();
37 this->_initializedHCEServerApplication =
true;
39 catch (
const Poco::NotFoundException& exception) {
40 Poco::Message msg (
"Application",exception.displayText() + this->ADDITION_INFORM_STRING_NOT_FOUND, Poco::Message::PRIO_CRITICAL,__FILE__,__LINE__);
43 catch (
const Poco::Exception& exception) {
44 Poco::Message msg (
"Application",exception.displayText(),Poco::Message::PRIO_CRITICAL,__FILE__,__LINE__);
47 catch (
const std::exception& exception) {
48 Poco::Message msg (
"Application",exception.what(),Poco::Message::PRIO_CRITICAL,__FILE__,__LINE__);
52 if (this->_initializedHCEServerApplication ==
false) {
55 throw Poco::ApplicationException(APPLICATION_NOT_INITIALIZED_EXCEPTION);
61 Poco::Util::ServerApplication::reinitialize(
self);
66 this->uninitializeDataBaseSession();
68 Poco::Util::ServerApplication::uninitialize();
72 if (this->_configFileRequest ==
false) {
74 #ifdef PATH_TO_CONFIG_FILE
76 Poco::Util::ServerApplication::loadConfiguration(PATH_TO_CONFIG_FILE);
78 catch(Poco::FileNotFoundException &exception){
79 Poco::Util::ServerApplication::loadConfiguration();
82 Poco::Util::ServerApplication::loadConfiguration();
87 Poco::Util::ServerApplication::loadConfiguration(this->_configFile);
90 HCE::_config = Poco::AutoPtr<Poco::Util::AbstractConfiguration>(&config(),
true);
95 if (this->isDataBaseSectionExists()) {
96 this->dataBaseType = this->getDBType();
97 std::string initializeString;
98 if (this->dataBaseType ==
SQLITE) {
99 initializeString = this->initializeSQLiteConnectionString();
100 Poco::Data::SQLite::Connector::registerConnector();
105 initializeString = this->initializeMySQLConnectionString();
106 Poco::Data::MySQL::Connector::registerConnector();
114 if (this->isDataBaseSectionExists()) {
115 if (this->dataBaseType ==
SQLITE) {
116 Poco::Data::SQLite::Connector::unregisterConnector();
119 Poco::Data::MySQL::Connector::unregisterConnector();
125 bool returnValue =
false;
126 Poco::Util::AbstractConfiguration::Keys keysInConfigurationFile;
128 auto it = find(keysInConfigurationFile.begin(),keysInConfigurationFile.end(),
DataBase_KEY);
129 if (it != keysInConfigurationFile.end()) {
143 std::string initializeString(
"host=" + host +
";user=" + user +
";password=" + password +
";db=" + db +
";compress=" + compress +
";auto-reconnect=" + auto_reconnect);
145 Poco::Message msg (
"PocoWrapperSession",initializeString,Poco::Message::PRIO_INFORMATION,__FILE__,__LINE__);
148 return initializeString;
153 std::string initializeString(
"db=" + db);
155 Poco::Message msg (
"PocoWrapperSession",initializeString,Poco::Message::PRIO_INFORMATION,__FILE__,__LINE__);
158 return initializeString;
173 Poco::Util::ServerApplication::defineOptions(options);
176 Poco::Util::Option(
"config-file",
"f")
177 .description (
"Load configuration data from a file.")
184 Poco::Util::Option(
"help",
"h")
185 .description (
"Show help information.")
191 Poco::Util::Option(
"version",
"v")
192 .description (
"Show version information.")
200 this->_configFileRequest =
true;
201 this->_configFile = value;
205 this->_showHelpInfo =
true;
206 Poco::Util::HelpFormatter helpFormatter(options());
207 helpFormatter.setCommand(commandName());
208 helpFormatter.setUsage(
"OPTIONS");
209 helpFormatter.setHeader(
"Some options that demonstrates some of the features of the HCE::Application");
210 helpFormatter.format(std::cout);