mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/RRJServer.git
synced 2026-03-28 19:55:48 +03:00
refract Server 0
This commit is contained in:
@@ -4,37 +4,45 @@
|
||||
#include <QFile>
|
||||
#include <QThread>
|
||||
#include <QErrorMessage>
|
||||
|
||||
#include "serverlmswidget.h"
|
||||
#include "dialogsettingstray.h"
|
||||
#include "specialmessagebox.h"
|
||||
#include "ui_serverlmswidget.h"
|
||||
#include "metatypes.h"
|
||||
#include "ui_serverlmswidget.h"
|
||||
|
||||
|
||||
const QString ServerLMSWidget::languageENG = "en_EN";
|
||||
const QString ServerLMSWidget::languageRUS = "ru_RU";
|
||||
|
||||
|
||||
ServerLMSWidget::ServerLMSWidget(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::ServerLMSWidget),
|
||||
waitAnimationWidget(nullptr),
|
||||
updateThread(nullptr),
|
||||
loggerThread(nullptr),
|
||||
mutex(nullptr),
|
||||
serverThread(nullptr),
|
||||
server(nullptr),
|
||||
dataParser(nullptr),
|
||||
processingSystem(nullptr),
|
||||
updateController(nullptr),
|
||||
assetsManager(nullptr),
|
||||
commonClientHandler(nullptr),
|
||||
chatSystem(nullptr),
|
||||
providerDBLMS(nullptr),
|
||||
updateController(nullptr),
|
||||
assetsManager(nullptr),
|
||||
docsUpdater(nullptr),
|
||||
cfiController(nullptr),
|
||||
providerDBLMS(nullptr),
|
||||
first (true),
|
||||
cfiController(nullptr),
|
||||
first(true),
|
||||
language(languageENG),
|
||||
errorCode(0),
|
||||
versionStr("..."),
|
||||
flStartInitialization(false)
|
||||
stateVersionMaterials("..."),
|
||||
dbIsConnected(false),
|
||||
stateServer(EStateServer::stoped),
|
||||
stateBlockAutorization(EStateBlockAutorization::unblocked),
|
||||
flStartInitialization(false),
|
||||
flTryConnectionToDB(false),
|
||||
flNeedReconnectDB(false)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
@@ -49,26 +57,31 @@ ServerLMSWidget::ServerLMSWidget(QWidget *parent) :
|
||||
|
||||
updateMyStyleSheet();
|
||||
|
||||
setLanguageInterfase();
|
||||
initLanguageInterfase();
|
||||
|
||||
waitAnimationWidget = new WaitAnimationWidget;
|
||||
QMovie *movie = new QMovie(":/resources/icons/762.gif");
|
||||
waitAnimationWidget->setParent(this);
|
||||
waitAnimationWidget->initialize(movie,this);
|
||||
|
||||
updateStateOnlyVersion();
|
||||
updateStateOnlyVersionMaterials();
|
||||
}
|
||||
|
||||
ServerLMSWidget::~ServerLMSWidget()
|
||||
{
|
||||
if(flStartInitialization)
|
||||
{
|
||||
server->stopServer();
|
||||
emit signal_StopServer();
|
||||
//server->stopServer();
|
||||
|
||||
updateThread->quit();
|
||||
updateThread->wait();
|
||||
delete updateThread;
|
||||
|
||||
serverThread->quit();
|
||||
serverThread->wait();
|
||||
delete serverThread;
|
||||
|
||||
delete server;
|
||||
delete commonClientHandler;
|
||||
delete dataParser;
|
||||
@@ -79,8 +92,6 @@ ServerLMSWidget::~ServerLMSWidget()
|
||||
delete assetsManager;
|
||||
delete chatSystem;
|
||||
|
||||
delete mutex;
|
||||
|
||||
loggerThread->quit();
|
||||
loggerThread->wait();
|
||||
delete loggerThread;
|
||||
@@ -94,6 +105,16 @@ ServerLMSWidget::~ServerLMSWidget()
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
||||
//INTERFACE
|
||||
void ServerLMSWidget::start()
|
||||
{
|
||||
startInitialization_step0();
|
||||
}
|
||||
|
||||
|
||||
//EVENT
|
||||
|
||||
void ServerLMSWidget::changeEvent(QEvent *event)
|
||||
{
|
||||
// В случае получения события изменения языка приложения
|
||||
@@ -103,7 +124,7 @@ void ServerLMSWidget::changeEvent(QEvent *event)
|
||||
|
||||
updateStateOnlyServer();
|
||||
updateStateOnlyDB();
|
||||
updateStateOnlyVersion();
|
||||
updateStateOnlyVersionMaterials();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,27 +134,137 @@ void ServerLMSWidget::resizeEvent(QResizeEvent *event)
|
||||
waitAnimationWidget->resize(size);
|
||||
}
|
||||
|
||||
void ServerLMSWidget::slot_UpdateListClients()
|
||||
|
||||
//STYLESHEET
|
||||
|
||||
void ServerLMSWidget::updateMyStyleSheet()
|
||||
{
|
||||
QString styleSheet = loadStyleSheet();
|
||||
styleSheet = styleSheet.replace("\n", "");
|
||||
|
||||
this->setStyleSheet(styleSheet);
|
||||
}
|
||||
|
||||
QString ServerLMSWidget::loadStyleSheet()
|
||||
{
|
||||
QString fileName = "./resources/css/styleSheetMain.css";
|
||||
QFile styleSheetFile(fileName);
|
||||
if (!styleSheetFile.open(QFile::ReadOnly | QFile::Text))
|
||||
{
|
||||
SpecMsgBox::WarningClose(this, tr("The file could not be opened ") + fileName);
|
||||
return QStringLiteral("");
|
||||
}
|
||||
else
|
||||
{
|
||||
QByteArray byteArray = styleSheetFile.readAll();
|
||||
styleSheetFile.close();
|
||||
|
||||
QString style = byteArray;
|
||||
return style;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//LANGUAGE
|
||||
|
||||
void ServerLMSWidget::initLanguageInterfase()
|
||||
{
|
||||
ServerDBSettings settings;
|
||||
DialogSettingsTray::loadSettings(&settings);
|
||||
|
||||
if(settings.Language == "ENG")
|
||||
{
|
||||
qtLanguageTranslator.load(QString("translations/RRJServer_") + languageENG, ".");
|
||||
language = languageENG;
|
||||
}
|
||||
else
|
||||
{
|
||||
qtLanguageTranslator.load(QString("translations/RRJServer_") + languageRUS, ".");
|
||||
language = languageRUS;
|
||||
}
|
||||
|
||||
qApp->installTranslator(&qtLanguageTranslator);
|
||||
|
||||
emit signal_LanguageChanged(language);
|
||||
}
|
||||
|
||||
|
||||
//UPDATE STATES
|
||||
|
||||
void ServerLMSWidget::updateStateOnlyServer()
|
||||
{
|
||||
if(stateServer == EStateServer::started)
|
||||
{
|
||||
if(stateBlockAutorization == EStateBlockAutorization::unblocked)
|
||||
{
|
||||
ui->lblOnOffText->setText(tr("started"));
|
||||
ui->lblOnOff->setPixmap(QPixmap(QStringLiteral(":/resources/icons/circleGreen.png")));
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->lblOnOffText->setText(tr("started") + ", " + tr("locked"));
|
||||
ui->lblOnOff->setPixmap(QPixmap(QStringLiteral(":/resources/icons/lock.png")));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->lblOnOffText->setText(tr("stoped"));
|
||||
ui->lblOnOff->setPixmap(QPixmap(QStringLiteral(":/resources/icons/stoped.png")));
|
||||
}
|
||||
|
||||
emit signal_updateStateServer(stateServer, stateBlockAutorization);
|
||||
}
|
||||
|
||||
void ServerLMSWidget::updateStateOnlyDB()
|
||||
{
|
||||
if(dbIsConnected)
|
||||
{
|
||||
//Настройки БД
|
||||
QString strDBsettings = tr("connected") + QString(" [%1 (%2) %3 : %4]").arg(dbSettings.dbName,
|
||||
dbSettings.dbType,
|
||||
dbSettings.dbHostName,
|
||||
QString::number(dbSettings.dbPort));
|
||||
ui->lblDBsettings->setText(strDBsettings);
|
||||
ui->lblDBisConnected->setPixmap(QPixmap(QStringLiteral(":/resources/icons/circleGreen.png")));
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->lblDBsettings->setText(tr("not connected"));
|
||||
ui->lblDBisConnected->setPixmap(QPixmap(QStringLiteral(":/resources/icons/circleGray.png")));
|
||||
|
||||
ui->btnStopServer->setEnabled(false);
|
||||
ui->btnStartServer->setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
void ServerLMSWidget::updateStateOnlyVersionMaterials()
|
||||
{
|
||||
ui->lblVersionText->setText(stateVersionMaterials);
|
||||
}
|
||||
|
||||
|
||||
//SLOTS
|
||||
|
||||
void ServerLMSWidget::slot_UpdateListClients(QStringList listFullName)
|
||||
{
|
||||
//Очищаем список
|
||||
ui->listWidget_Clients->clear();
|
||||
|
||||
for (const ClientHandler *handler : server->getClientsMap()->values())
|
||||
for (const QString clientFullName : listFullName)
|
||||
{
|
||||
QString strClient = handler->getClient()->getFullName();
|
||||
//QString clientFullName = handler->getClient()->getFullName();
|
||||
|
||||
ui->listWidget_Clients->addItem(strClient);
|
||||
ui->listWidget_Clients->addItem(clientFullName);
|
||||
ui->listWidget_Clients->scrollToBottom();
|
||||
ui->listWidget_Clients->setCurrentRow(ui->listWidget_Clients->count() - 1);
|
||||
}
|
||||
|
||||
int countClients = (*server->getClientsMap()).count();
|
||||
int countClients = listFullName.count();
|
||||
Logger::instance().log("SERVER: countClients = " + QString::number(countClients));
|
||||
}
|
||||
|
||||
void ServerLMSWidget::slot_AddMessageToLog(QString message)
|
||||
{
|
||||
//ui->loggerTextField->appendPlainText(message);
|
||||
ui->loggerTextField->appendHtml(message);
|
||||
}
|
||||
|
||||
@@ -143,60 +274,100 @@ void ServerLMSWidget::slot_ErrorPostgreSQL(QString text)
|
||||
SpecMsgBox::CriticalClose(this, tr("Error PostgreSQL!") + "\n" + text);
|
||||
}
|
||||
|
||||
void ServerLMSWidget::slot_StateConnectionToDB(bool dbIsConnected, DataBaseSettings dbSettings)
|
||||
{
|
||||
this->dbIsConnected = dbIsConnected;
|
||||
this->dbSettings = dbSettings;
|
||||
updateStateOnlyDB();
|
||||
}
|
||||
|
||||
void ServerLMSWidget::slot_StateServer(EStateServer stateServer, EStateBlockAutorization stateBlockAutorization)
|
||||
{
|
||||
if(this->stateServer != stateServer)
|
||||
{
|
||||
if(stateServer == EStateServer::started)
|
||||
{
|
||||
ui->btnStartServer->setEnabled(false);
|
||||
ui->btnStopServer->setEnabled(true);
|
||||
emit signal_Tray_ShowMessage(tr("Server is started!"));
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->btnStopServer->setEnabled(false);
|
||||
ui->btnStartServer->setEnabled(true);
|
||||
emit signal_Tray_ShowMessage(tr("Server is stoped!"));
|
||||
}
|
||||
}
|
||||
this->stateServer = stateServer;
|
||||
this->stateBlockAutorization = stateBlockAutorization;
|
||||
updateStateOnlyServer();
|
||||
}
|
||||
|
||||
void ServerLMSWidget::slot_StateVersionMaterials(QString versionStr)
|
||||
{
|
||||
this->stateVersionMaterials = versionStr;
|
||||
updateStateOnlyVersionMaterials();
|
||||
}
|
||||
|
||||
void ServerLMSWidget::slot_ResultTryConnectDb(bool result)
|
||||
{
|
||||
if(flTryConnectionToDB)
|
||||
{
|
||||
flTryConnectionToDB = false;
|
||||
|
||||
if(result)
|
||||
{
|
||||
//Настройки БД
|
||||
DataBaseSettings dbSettings = providerDBLMS->getDBSettings();
|
||||
QString strDBsettings = QString("%1 (%2) %3 : %4").arg(dbSettings.dbName,
|
||||
dbSettings.dbType,
|
||||
dbSettings.dbHostName,
|
||||
QString::number(dbSettings.dbPort));
|
||||
|
||||
Logger::instance().log("Connection to DB completed!");
|
||||
|
||||
emit signal_Tray_ShowMessage(tr("Database connection OK!") + "\n" + strDBsettings);
|
||||
|
||||
on_btnStartServer_clicked();
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger::instance().log("Database connection error!");
|
||||
|
||||
emit signal_Tray_ShowMessage(tr("Database connection error!"), QSystemTrayIcon::Critical);
|
||||
|
||||
emit signal_Menu_ShowWindow();
|
||||
|
||||
SpecMsgBox::CriticalClose(this, tr("Database connection error!"));
|
||||
|
||||
on_btnSettings_clicked();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ServerLMSWidget::slot_ResultTryDisConnectDb(bool result)
|
||||
{
|
||||
if(flNeedReconnectDB)
|
||||
{
|
||||
flNeedReconnectDB = false;
|
||||
|
||||
SpecMsgBox::WarningClose(this, tr("Database settings have been changed.\nThe server will be restarted."));
|
||||
|
||||
tryConnectionToDB();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ServerLMSWidget::slot_UpdateDocs()
|
||||
{
|
||||
//QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
|
||||
emit signal_updateDocsXML();
|
||||
|
||||
//if(docsUpdater->slot_updateDocsXML())
|
||||
//emit signal_DocsChanged();
|
||||
|
||||
//QApplication::restoreOverrideCursor();
|
||||
|
||||
//TODO для теста
|
||||
//cfiController->test();
|
||||
}
|
||||
|
||||
void ServerLMSWidget::slot_startInitialization_step1()
|
||||
void ServerLMSWidget::slot_UpdateControllerInitializeFinished()
|
||||
{
|
||||
Logger::instance().log("Update docs.xml...");
|
||||
slot_UpdateDocs();
|
||||
Logger::instance().log("Update docs.xml completed!");
|
||||
|
||||
ui->btnStopServer->setEnabled(false);
|
||||
ui->btnStartServer->setEnabled(true);
|
||||
|
||||
flStartInitialization = true;
|
||||
|
||||
updateStateOnlyServer();
|
||||
updateStateOnlyDB();
|
||||
updateStateOnlyVersion();
|
||||
|
||||
//QApplication::restoreOverrideCursor();
|
||||
|
||||
if(hasError() == 100)
|
||||
return;
|
||||
|
||||
Logger::instance().log("Try connection to DB...");
|
||||
tryConnectionToDB();
|
||||
|
||||
waitAnimationWidget->hideWithStop();
|
||||
|
||||
emit signal_InitializeFinished();
|
||||
startInitialization_step1();
|
||||
}
|
||||
|
||||
void ServerLMSWidget::slot_setVersion(QString versionStr)
|
||||
{
|
||||
this->versionStr = versionStr;
|
||||
Logger::instance().log("Set Version: " + versionStr);
|
||||
updateStateOnlyVersion();
|
||||
}
|
||||
|
||||
void ServerLMSWidget::start()
|
||||
{
|
||||
startInitialization_step0();
|
||||
}
|
||||
|
||||
void ServerLMSWidget::slot_BlockAutorizationIndicate(bool block, QString blocker, QString types)
|
||||
{
|
||||
@@ -225,9 +396,13 @@ void ServerLMSWidget::slot_LanguageChanged(QString language)
|
||||
emit signal_LanguageChanged(language);
|
||||
}
|
||||
|
||||
|
||||
//ON_BTN
|
||||
|
||||
void ServerLMSWidget::on_btnStartServer_clicked()
|
||||
{
|
||||
if(server->startServer())
|
||||
emit signal_StartServer();
|
||||
//if(server->startServer())
|
||||
{
|
||||
//QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
|
||||
@@ -237,7 +412,7 @@ void ServerLMSWidget::on_btnStartServer_clicked()
|
||||
|
||||
//updateStateOnlyServer();
|
||||
|
||||
emit signal_Tray_ShowMessage(tr("Server is started!"));
|
||||
//emit signal_Tray_ShowMessage(tr("Server is started!"));
|
||||
|
||||
//QApplication::restoreOverrideCursor();
|
||||
}
|
||||
@@ -245,7 +420,8 @@ void ServerLMSWidget::on_btnStartServer_clicked()
|
||||
|
||||
void ServerLMSWidget::on_btnStopServer_clicked()
|
||||
{
|
||||
if(server->stopServer())
|
||||
emit signal_StopServer();
|
||||
//if(server->stopServer())
|
||||
{
|
||||
//QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
|
||||
@@ -255,7 +431,7 @@ void ServerLMSWidget::on_btnStopServer_clicked()
|
||||
|
||||
//updateStateOnlyServer();
|
||||
|
||||
emit signal_Tray_ShowMessage(tr("Server is stoped!"));
|
||||
//emit signal_Tray_ShowMessage(tr("Server is stoped!"));
|
||||
|
||||
//QApplication::restoreOverrideCursor();
|
||||
}
|
||||
@@ -289,15 +465,18 @@ void ServerLMSWidget::on_btnSettings_clicked()
|
||||
{
|
||||
on_btnStopServer_clicked();
|
||||
|
||||
providerDBLMS->deAuthorizationAll();
|
||||
//providerDBLMS->deAuthorizationAll();
|
||||
|
||||
providerDBLMS->DisConnectionFromDB();
|
||||
//providerDBLMS->DisConnectionFromDB();
|
||||
|
||||
updateStateOnlyDB();
|
||||
flNeedReconnectDB = true;
|
||||
flTryConnectionToDB = false;
|
||||
|
||||
SpecMsgBox::WarningClose(this, tr("Database settings have been changed.\nThe server will be restarted."));
|
||||
emit signal_TryDisConnectionFromDB();
|
||||
|
||||
tryConnectionToDB();
|
||||
//updateStateOnlyDB();
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -309,72 +488,31 @@ void ServerLMSWidget::on_btnSettings_clicked()
|
||||
}
|
||||
}
|
||||
|
||||
void ServerLMSWidget::setLanguageInterfase()
|
||||
{
|
||||
ServerDBSettings settings;
|
||||
DialogSettingsTray::loadSettings(&settings);
|
||||
|
||||
if(settings.Language == "ENG")
|
||||
{
|
||||
qtLanguageTranslator.load(QString("translations/RRJServer_") + languageENG, ".");
|
||||
language = languageENG;
|
||||
}
|
||||
else
|
||||
{
|
||||
qtLanguageTranslator.load(QString("translations/RRJServer_") + languageRUS, ".");
|
||||
language = languageRUS;
|
||||
}
|
||||
|
||||
qApp->installTranslator(&qtLanguageTranslator);
|
||||
|
||||
emit signal_LanguageChanged(language);
|
||||
}
|
||||
|
||||
void ServerLMSWidget::updateMyStyleSheet()
|
||||
{
|
||||
QString styleSheet = loadStyleSheet();
|
||||
styleSheet = styleSheet.replace("\n", "");
|
||||
|
||||
this->setStyleSheet(styleSheet);
|
||||
}
|
||||
|
||||
QString ServerLMSWidget::loadStyleSheet()
|
||||
{
|
||||
QString fileName = "./resources/css/styleSheetMain.css";
|
||||
QFile styleSheetFile(fileName);
|
||||
if (!styleSheetFile.open(QFile::ReadOnly | QFile::Text))
|
||||
{
|
||||
SpecMsgBox::WarningClose(this, tr("The file could not be opened ") + fileName);
|
||||
return QStringLiteral("");
|
||||
}
|
||||
else
|
||||
{
|
||||
QByteArray byteArray = styleSheetFile.readAll();
|
||||
styleSheetFile.close();
|
||||
|
||||
QString style = byteArray;
|
||||
return style;
|
||||
}
|
||||
}
|
||||
//INIT
|
||||
|
||||
void ServerLMSWidget::startInitialization_step0()
|
||||
{
|
||||
emit signal_Tray_ShowMessage(tr("Starting the server..."));
|
||||
|
||||
waitAnimationWidget->showWithPlay();
|
||||
|
||||
//QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
|
||||
providerDBLMS = new ProviderDBLMS(this);
|
||||
connect(providerDBLMS, &ProviderDBLMS::signal_ErrorPostgreSQL, this, &ServerLMSWidget::slot_ErrorPostgreSQL);
|
||||
//connect(providerDBLMS, &ProviderDBLMS::signal_BlockAutorization, this, &ServerLMSWidget::slot_BlockAutorizationIndicate);
|
||||
|
||||
mutex = new QMutex;
|
||||
waitAnimationWidget->showWithPlay();
|
||||
|
||||
updateThread = new QThread;
|
||||
loggerThread = new QThread;
|
||||
serverThread = new QThread;
|
||||
|
||||
providerDBLMS = new ProviderDBLMS();
|
||||
providerDBLMS->moveToThread(serverThread);
|
||||
|
||||
connect(providerDBLMS, &ProviderDBLMS::signal_ErrorPostgreSQL, this, &ServerLMSWidget::slot_ErrorPostgreSQL);
|
||||
connect(providerDBLMS, &ProviderDBLMS::signal_StateConnectionToDB, this, &ServerLMSWidget::slot_StateConnectionToDB);
|
||||
connect(this, &ServerLMSWidget::signal_TryConnectionToDB, providerDBLMS, &ProviderDBLMS::slot_TryConnectionToDB);
|
||||
connect(this, &ServerLMSWidget::signal_TryDisConnectionFromDB, providerDBLMS, &ProviderDBLMS::slot_TryDisConnectionFromDB);
|
||||
connect(providerDBLMS, &ProviderDBLMS::signal_ResultTryConnectDb, this, &ServerLMSWidget::slot_ResultTryConnectDb);
|
||||
connect(providerDBLMS, &ProviderDBLMS::signal_ResultTryDisConnectDb, this, &ServerLMSWidget::slot_ResultTryDisConnectDb);
|
||||
|
||||
chatSystem = new ChatSystem();
|
||||
chatSystem->moveToThread(serverThread);
|
||||
|
||||
assetsManager = new AssetsManager;
|
||||
assetsManager->moveToThread(updateThread);
|
||||
@@ -389,22 +527,33 @@ void ServerLMSWidget::startInitialization_step0()
|
||||
cfiController->moveToThread(updateThread);
|
||||
|
||||
processingSystem = new ProcessingSystem(providerDBLMS, updateController, docsUpdater, cfiController);
|
||||
processingSystem->moveToThread(serverThread);
|
||||
|
||||
dataParser = new DataParser(assetsManager, processingSystem);
|
||||
dataParser->moveToThread(serverThread);
|
||||
|
||||
commonClientHandler = new CommonClientHandler;
|
||||
//connect(this, &ServerLMSWidget::signal_DocsChanged, commonClientHandler, &CommonClientHandler::slot_DocsChanged);
|
||||
connect(docsUpdater, &DocsUpdater::signal_DocsChanged, commonClientHandler, &CommonClientHandler::slot_DocsChanged);
|
||||
//connect(commonClientHandler, &CommonClientHandler::sigSetServerState, this, &ServerLMSWidget::slot_trySetServerState);
|
||||
commonClientHandler->moveToThread(serverThread);
|
||||
|
||||
connect(docsUpdater, &DocsUpdater::signal_DocsChanged, commonClientHandler, &CommonClientHandler::slot_DocsChanged);
|
||||
|
||||
server = new MultiThreadServer(updateController, docsUpdater, processingSystem, dataParser, 6000);
|
||||
server->moveToThread(serverThread);
|
||||
|
||||
connect(server, &MultiThreadServer::signal_StateServer, this, &ServerLMSWidget::slot_StateServer);
|
||||
connect(server, &MultiThreadServer::signal_UpdateListClients, this, &ServerLMSWidget::slot_UpdateListClients);
|
||||
|
||||
connect(this, &ServerLMSWidget::signal_StartServer, server, &MultiThreadServer::slot_StartServer);
|
||||
connect(this, &ServerLMSWidget::signal_StopServer, server, &MultiThreadServer::slot_StopServer);
|
||||
|
||||
server = new MultiThreadServer(this, updateController, processingSystem, dataParser, 6000);
|
||||
connect(server, &MultiThreadServer::signal_BlockAutorizationIndicate, this, &ServerLMSWidget::slot_BlockAutorizationIndicate);
|
||||
connect(providerDBLMS, &ProviderDBLMS::signal_BlockAutorization, server, &MultiThreadServer::slot_BlockAutorization/*, Qt::DirectConnection*/);
|
||||
connect(providerDBLMS, &ProviderDBLMS::signal_BlockAutorization, server, &MultiThreadServer::slot_BlockAutorization, Qt::DirectConnection /*Тут именно DirectConnection!*/);
|
||||
connect(updateController, &UpdateController::signal_BlockAutorization, server, &MultiThreadServer::slot_BlockAutorization/*, Qt::DirectConnection*/);
|
||||
connect(server, &MultiThreadServer::signal_sendPacketToAllClients, commonClientHandler, &CommonClientHandler::slot_sendPacketToAllClients);
|
||||
|
||||
loggerThread->start();
|
||||
updateThread->start();
|
||||
serverThread->start();
|
||||
|
||||
commonClientHandler->initialize(server->getClientsMap(), processingSystem, dataParser);
|
||||
processingSystem->initialize(server, dataParser, commonClientHandler, updateController, chatSystem);
|
||||
@@ -415,108 +564,54 @@ void ServerLMSWidget::startInitialization_step0()
|
||||
Logger::instance().setLogToFile(true);
|
||||
|
||||
connect(this, &ServerLMSWidget::sigUpdateControllerInitialize, updateController, &UpdateController::initialize);
|
||||
connect(updateController, &UpdateController::sigInitializeFinished, this, &ServerLMSWidget::slot_startInitialization_step1);
|
||||
connect(updateController, &UpdateController::sigInitializeFinished, this, &ServerLMSWidget::slot_UpdateControllerInitializeFinished);
|
||||
connect(this, &ServerLMSWidget::sigCalculateFullHash, updateController, &UpdateController::calculateFullHash, Qt::AutoConnection);
|
||||
connect(updateController, &UpdateController::sigErrorRequired, this, &ServerLMSWidget::setError);
|
||||
connect(updateController, &UpdateController::sigUpdateDocs, this, &ServerLMSWidget::slot_UpdateDocs, Qt::AutoConnection);
|
||||
connect(&Logger::instance(), &Logger::sigLogToWidget, this, &ServerLMSWidget::slot_AddMessageToLog, Qt::QueuedConnection);
|
||||
|
||||
connect(assetsManager, &AssetsManager::signal_setVersion, this, &ServerLMSWidget::slot_setVersion);
|
||||
connect(assetsManager, &AssetsManager::signal_setVersion, this, &ServerLMSWidget::slot_StateVersionMaterials);
|
||||
|
||||
connect(this, &ServerLMSWidget::signal_updateDocsXML, docsUpdater, &DocsUpdater::slot_updateDocsXML);
|
||||
|
||||
emit sigUpdateControllerInitialize(commonClientHandler, dataParser, assetsManager);
|
||||
}
|
||||
|
||||
void ServerLMSWidget::startInitialization_step1()
|
||||
{
|
||||
Logger::instance().log("Update docs.xml...");
|
||||
slot_UpdateDocs();
|
||||
Logger::instance().log("Update docs.xml completed!");
|
||||
|
||||
ui->btnStopServer->setEnabled(false);
|
||||
ui->btnStartServer->setEnabled(true);
|
||||
|
||||
flStartInitialization = true;
|
||||
|
||||
updateStateOnlyServer();
|
||||
updateStateOnlyDB();
|
||||
updateStateOnlyVersionMaterials();
|
||||
|
||||
//QApplication::restoreOverrideCursor();
|
||||
|
||||
if(hasError() == 100)
|
||||
return;
|
||||
|
||||
Logger::instance().log("Try connection to DB...");
|
||||
tryConnectionToDB();
|
||||
|
||||
waitAnimationWidget->hideWithStop();
|
||||
|
||||
emit signal_InitializeFinished();
|
||||
}
|
||||
|
||||
|
||||
//CONNECT DB
|
||||
|
||||
void ServerLMSWidget::tryConnectionToDB()
|
||||
{
|
||||
if(! providerDBLMS->ConnectionToDB())
|
||||
{
|
||||
Logger::instance().log("Database connection error!");
|
||||
|
||||
emit signal_Tray_ShowMessage(tr("Database connection error!"), QSystemTrayIcon::Critical);
|
||||
|
||||
emit signal_Menu_ShowWindow();
|
||||
|
||||
SpecMsgBox::CriticalClose(this, tr("Database connection error!"));
|
||||
|
||||
on_btnSettings_clicked();
|
||||
}
|
||||
else
|
||||
{
|
||||
providerDBLMS->deAuthorizationAll();
|
||||
|
||||
//Настройки БД
|
||||
DataBaseSettings dbSettings = providerDBLMS->getDBSettings();
|
||||
QString strDBsettings = QString("%1 (%2) %3 : %4").arg(dbSettings.dbName,
|
||||
dbSettings.dbType,
|
||||
dbSettings.dbHostName,
|
||||
QString::number(dbSettings.dbPort));
|
||||
|
||||
Logger::instance().log("Connection to DB completed!");
|
||||
|
||||
emit signal_Tray_ShowMessage(tr("Database connection OK!") + "\n" + strDBsettings);
|
||||
|
||||
on_btnStartServer_clicked();
|
||||
}
|
||||
|
||||
updateStateOnlyDB();
|
||||
}
|
||||
|
||||
void ServerLMSWidget::updateStateOnlyServer()
|
||||
{
|
||||
if(server)
|
||||
{
|
||||
if(server->getStateServer() == EStateServer::started)
|
||||
{
|
||||
if(server->getStateBlockAutorization() == EStateBlockAutorization::unblocked)
|
||||
{
|
||||
ui->lblOnOffText->setText(tr("started"));
|
||||
ui->lblOnOff->setPixmap(QPixmap(QStringLiteral(":/resources/icons/circleGreen.png")));
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->lblOnOffText->setText(tr("started") + ", " + tr("locked"));
|
||||
ui->lblOnOff->setPixmap(QPixmap(QStringLiteral(":/resources/icons/lock.png")));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->lblOnOffText->setText(tr("stoped"));
|
||||
ui->lblOnOff->setPixmap(QPixmap(QStringLiteral(":/resources/icons/stoped.png")));
|
||||
}
|
||||
|
||||
emit signal_updateStateServer(server->getStateServer(), server->getStateBlockAutorization());
|
||||
}
|
||||
}
|
||||
|
||||
void ServerLMSWidget::updateStateOnlyDB()
|
||||
{
|
||||
if(providerDBLMS)
|
||||
{
|
||||
if(providerDBLMS->DBisConnected())
|
||||
{
|
||||
//Настройки БД
|
||||
DataBaseSettings dbSettings = providerDBLMS->getDBSettings();
|
||||
QString strDBsettings = tr("connected") + QString(" [%1 (%2) %3 : %4]").arg(dbSettings.dbName,
|
||||
dbSettings.dbType,
|
||||
dbSettings.dbHostName,
|
||||
QString::number(dbSettings.dbPort));
|
||||
ui->lblDBsettings->setText(strDBsettings);
|
||||
ui->lblDBisConnected->setPixmap(QPixmap(QStringLiteral(":/resources/icons/circleGreen.png")));
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->lblDBsettings->setText(tr("not connected"));
|
||||
ui->lblDBisConnected->setPixmap(QPixmap(QStringLiteral(":/resources/icons/circleGray.png")));
|
||||
|
||||
ui->btnStopServer->setEnabled(false);
|
||||
ui->btnStartServer->setEnabled(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ServerLMSWidget::updateStateOnlyVersion()
|
||||
{
|
||||
ui->lblVersionText->setText(versionStr);
|
||||
flTryConnectionToDB = true;
|
||||
flNeedReconnectDB = false;
|
||||
emit signal_TryConnectionToDB();
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user