mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/RRJServer.git
synced 2026-03-27 19:45:43 +03:00
refract Server 0
This commit is contained in:
@@ -9,12 +9,11 @@
|
||||
const QString DataBaseLMS::TypeUserDBInstructor = "instructor";
|
||||
const QString DataBaseLMS::TypeUserDBTrainee = "trainee";
|
||||
|
||||
DataBaseLMS::DataBaseLMS(QWidget *ownerWidget, QObject *parent):
|
||||
DataBaseLMS::DataBaseLMS(QObject *parent):
|
||||
QObject(parent),
|
||||
db(nullptr),
|
||||
UserNamePostgres(""),
|
||||
PasswordPostgres(""),
|
||||
ownerWidget(ownerWidget)
|
||||
PasswordPostgres("")
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ class DATABASELMS_EXPORT DataBaseLMS : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
DataBaseLMS(QWidget *ownerWidget, QObject *parent = nullptr);
|
||||
DataBaseLMS(QObject *parent = nullptr);
|
||||
~DataBaseLMS();
|
||||
|
||||
signals:
|
||||
@@ -132,9 +132,6 @@ protected:
|
||||
|
||||
QString UserNamePostgres;
|
||||
QString PasswordPostgres;
|
||||
|
||||
private:
|
||||
QWidget* ownerWidget;
|
||||
};
|
||||
|
||||
#endif // DATABASELMS_H
|
||||
|
||||
@@ -4,9 +4,8 @@
|
||||
#include <QTime>
|
||||
#include "interfacedatabaselms.h"
|
||||
|
||||
InterfaceDataBaseLMS::InterfaceDataBaseLMS(QWidget *ownerWidget, QObject *parent):
|
||||
DataBaseLMS(ownerWidget, parent),
|
||||
ownerWidget(ownerWidget)
|
||||
InterfaceDataBaseLMS::InterfaceDataBaseLMS(QObject *parent):
|
||||
DataBaseLMS(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ public:
|
||||
errAlreadyLogIn
|
||||
};
|
||||
public:
|
||||
InterfaceDataBaseLMS(QWidget *ownerWidget, QObject *parent = nullptr);
|
||||
InterfaceDataBaseLMS(QObject *parent = nullptr);
|
||||
|
||||
public:
|
||||
//Соединение
|
||||
@@ -105,9 +105,6 @@ public:
|
||||
int replaceReportFIM(TaskAmmFim task);
|
||||
int changeStatusTaskFIM(int id_task, QString status);
|
||||
int changeStatusTaskAMM(int id_task, QString status);
|
||||
|
||||
private:
|
||||
QWidget* ownerWidget;
|
||||
};
|
||||
|
||||
#endif // INTERFACEDATABASELMS_H
|
||||
|
||||
@@ -110,6 +110,8 @@ QString AssetsManager::setVersion(QString versionName)
|
||||
currentVersionData = version;
|
||||
saveVersionToFile(currentVersionData);
|
||||
|
||||
Logger::instance().log("Set Version of materials: " + versionName);
|
||||
|
||||
emit signal_setVersion(versionName);
|
||||
|
||||
return version->getAbsolutPath();
|
||||
|
||||
@@ -13,12 +13,10 @@ QObject(parent)
|
||||
|
||||
}
|
||||
|
||||
void RecognizeSystem::initialize(UpdateController *updateController,DataParser* dataParser,
|
||||
ServerLMSWidget *server,SendSystem *sendSystem, ClientHandler *handler)
|
||||
void RecognizeSystem::initialize(UpdateController *updateController,DataParser* dataParser,SendSystem *sendSystem, ClientHandler *handler)
|
||||
{
|
||||
this->updateController = updateController;
|
||||
this->dataParser = dataParser;
|
||||
this->server = server;
|
||||
this->clientHandler = handler;
|
||||
this->sendSystem = sendSystem;
|
||||
socket = handler->getSocket();
|
||||
@@ -28,7 +26,7 @@ void RecognizeSystem::initialize(UpdateController *updateController,DataParser*
|
||||
connect(this,&RecognizeSystem::sigDeleteVersion,updateController,&UpdateController::deleteAssetVersion,Qt::AutoConnection);
|
||||
connect(this,&RecognizeSystem::sigCopyVersion,updateController,&UpdateController::createCopyVersion,Qt::AutoConnection);
|
||||
connect(this,&RecognizeSystem::sigXmlParser,dataParser->getProcessParser(),&ProcessParser::slot_read,Qt::AutoConnection);
|
||||
connect(this,&RecognizeSystem::sigRecalculateDocs,server,&ServerLMSWidget::slot_UpdateDocs,Qt::AutoConnection);
|
||||
//connect(this,&RecognizeSystem::sigRecalculateDocs,server,&ServerLMSWidget::slot_UpdateDocs,Qt::AutoConnection);
|
||||
connect(this,&RecognizeSystem::sigSendDocs,sendSystem,&SendSystem::sendDocs,Qt::AutoConnection);
|
||||
|
||||
qDebug() << "Recognize init thread ID " << QThread::currentThreadId();
|
||||
@@ -448,7 +446,8 @@ void RecognizeSystem::recognize()
|
||||
if(packetType == PacketType::RECALCULATE_DOCS)
|
||||
{
|
||||
emit sigCalculateHash();
|
||||
emit sigRecalculateDocs();
|
||||
//emit sigRecalculateDocs();
|
||||
emit signal_updateDocsXML();
|
||||
}
|
||||
|
||||
if(packetType == PacketType::GET_DOCS)
|
||||
|
||||
@@ -25,8 +25,7 @@ class RecognizeSystem : public QObject
|
||||
|
||||
public:
|
||||
RecognizeSystem(QObject *parent = nullptr);
|
||||
void initialize(UpdateController *updateController,DataParser *dataParser,
|
||||
ServerLMSWidget *server,SendSystem *sendSystem, ClientHandler *handler);
|
||||
void initialize(UpdateController *updateController,DataParser *dataParser, SendSystem *sendSystem, ClientHandler *handler);
|
||||
void recognize();
|
||||
~RecognizeSystem();
|
||||
|
||||
@@ -37,14 +36,15 @@ signals:
|
||||
void sigChangeVersion(QString versionName);
|
||||
void sigDeleteVersion(QString versionName);
|
||||
void sigCopyVersion(QString versionName,QString newVersionName,QString author);
|
||||
void sigRecalculateDocs();
|
||||
//void sigRecalculateDocs();
|
||||
void sigSendDocs(QString docsPath);
|
||||
|
||||
void signal_updateDocsXML();
|
||||
|
||||
private:
|
||||
UpdateController *updateController;
|
||||
SendSystem *sendSystem;
|
||||
DataParser *dataParser;
|
||||
ServerLMSWidget *server;
|
||||
QString command;
|
||||
PacketType packetType;
|
||||
QString filePath;
|
||||
|
||||
@@ -9,8 +9,8 @@ ClientHandler::ClientHandler( QObject *parent):
|
||||
{
|
||||
}
|
||||
|
||||
void ClientHandler::initialize(int descriptor,ServerLMSWidget *serverWidget,
|
||||
UpdateController *updateController,DataParser *dataParser)
|
||||
void ClientHandler::initialize(int descriptor,
|
||||
UpdateController *updateController,DataParser *dataParser, QMutex *mutex)
|
||||
{
|
||||
this->socket = new QTcpSocket;
|
||||
this->thread = new QThread;
|
||||
@@ -30,7 +30,6 @@ void ClientHandler::initialize(int descriptor,ServerLMSWidget *serverWidget,
|
||||
recognizeSystem->moveToThread(thread);
|
||||
|
||||
this->updateController = updateController;
|
||||
this->server = serverWidget;
|
||||
|
||||
QString peerName = socket->peerName();
|
||||
QString peerAddress = socket->peerAddress().toString();
|
||||
@@ -38,6 +37,8 @@ void ClientHandler::initialize(int descriptor,ServerLMSWidget *serverWidget,
|
||||
|
||||
client = new Client(peerName,peerAddress,peerPort,socket);
|
||||
|
||||
connect(recognizeSystem,&RecognizeSystem::signal_updateDocsXML,this,&ClientHandler::signal_updateDocsXML);
|
||||
|
||||
connect(this,&ClientHandler::sigSendXmlAnswer,sendSystem,&SendSystem::sendXmlAnswer,Qt::AutoConnection);
|
||||
connect(this,&ClientHandler::sigInitSender,sendSystem,&SendSystem::initialize,Qt::AutoConnection/*Qt::DirectConnection*/);
|
||||
connect(this,&ClientHandler::sigFileBlock,sendSystem,&SendSystem::sendFileBlock,Qt::AutoConnection);
|
||||
@@ -57,9 +58,9 @@ void ClientHandler::initialize(int descriptor,ServerLMSWidget *serverWidget,
|
||||
connect(socket,&QTcpSocket::readyRead,this,&ClientHandler::initClientType,Qt::AutoConnection);
|
||||
initClientType();
|
||||
|
||||
recognizeSystem->initialize(updateController,dataParser,serverWidget,sendSystem, this);
|
||||
recognizeSystem->initialize(updateController,dataParser,sendSystem, this);
|
||||
sendSystem->setClient(client,socket);
|
||||
emit sigInitSender(dataParser,serverWidget->getMutex());
|
||||
emit sigInitSender(dataParser, mutex);
|
||||
|
||||
Logger::instance().log("SERVER: Client connected");
|
||||
}
|
||||
|
||||
@@ -69,12 +69,14 @@ signals:
|
||||
void sigSendPacketType(PacketType packetType);
|
||||
void sigSendStop();
|
||||
|
||||
void signal_updateDocsXML();
|
||||
|
||||
public :
|
||||
QThread *thread;
|
||||
QTcpSocket *socket;
|
||||
|
||||
void initialize(int descriptor, ServerLMSWidget *serverWidget,
|
||||
UpdateController *updateController, DataParser *dataParser);
|
||||
void initialize(int descriptor,
|
||||
UpdateController *updateController, DataParser *dataParser, QMutex *mutex);
|
||||
void setClient(Client *value);
|
||||
private:
|
||||
UpdateController *updateController;
|
||||
@@ -82,7 +84,6 @@ private:
|
||||
Client *client;
|
||||
|
||||
SendSystem *sendSystem;
|
||||
ServerLMSWidget *server;
|
||||
|
||||
void initClientType();
|
||||
void packetTypeInit(PacketType packet, Client *client);
|
||||
|
||||
@@ -6,4 +6,9 @@ void registerMetaType()
|
||||
qRegisterMetaType<PacketType>("PacketType");
|
||||
qRegisterMetaType<UserType>("UserType");
|
||||
qRegisterMetaType<LogLevel>("LogLevel");
|
||||
qRegisterMetaType<QStringList>("QStringList");
|
||||
qRegisterMetaType<DataBaseSettings>("DataBaseSettings");
|
||||
|
||||
qRegisterMetaType<EStateServer>("EStateServer");
|
||||
qRegisterMetaType<EStateBlockAutorization>("EStateBlockAutorization");
|
||||
}
|
||||
|
||||
@@ -4,11 +4,17 @@
|
||||
#include "Data/PacketType.h"
|
||||
#include "Data/typesDataServerClient.h"
|
||||
#include "Systems/logger.h"
|
||||
#include "databaselms.h"
|
||||
|
||||
void registerMetaType();
|
||||
|
||||
Q_DECLARE_METATYPE(PacketType)
|
||||
Q_DECLARE_METATYPE(UserType)
|
||||
Q_DECLARE_METATYPE(LogLevel)
|
||||
Q_DECLARE_METATYPE(QStringList)
|
||||
Q_DECLARE_METATYPE(DataBaseSettings)
|
||||
|
||||
Q_DECLARE_METATYPE(EStateServer)
|
||||
Q_DECLARE_METATYPE(EStateBlockAutorization)
|
||||
|
||||
#endif // METATYPES_H
|
||||
|
||||
@@ -1,27 +1,39 @@
|
||||
#include "multithreadserver.h"
|
||||
|
||||
MultiThreadServer::MultiThreadServer(ServerLMSWidget *widget,UpdateController *updateController,ProcessingSystem *processingSystem,
|
||||
MultiThreadServer::MultiThreadServer(UpdateController *updateController, DocsUpdater *docsUpdater,ProcessingSystem *processingSystem,
|
||||
DataParser *dataParser,qint16 hostPort, QObject *parent ):
|
||||
QTcpServer(parent),
|
||||
serverLmsWidget(widget),
|
||||
mutex(nullptr),
|
||||
hostPort(hostPort),
|
||||
processingSystem(processingSystem),
|
||||
updateController(updateController),
|
||||
docsUpdater(docsUpdater),
|
||||
dataParser(dataParser),
|
||||
stateServer(stoped),
|
||||
stateBlockAutorization(blocked)
|
||||
{
|
||||
clientsMap = new QMap<int,ClientHandler*>;
|
||||
mutex = new QMutex;
|
||||
|
||||
connect(this, &MultiThreadServer::signal_updateDocsXML, docsUpdater, &DocsUpdater::slot_updateDocsXML);
|
||||
}
|
||||
|
||||
MultiThreadServer::~MultiThreadServer()
|
||||
{
|
||||
delete mutex;
|
||||
}
|
||||
|
||||
void MultiThreadServer::incomingConnection(qintptr socketDesriptor)
|
||||
{
|
||||
ClientHandler* newClient = new ClientHandler;
|
||||
|
||||
connect(this,&MultiThreadServer::sigInitClient,newClient,&ClientHandler::initialize, Qt::AutoConnection/*Qt::DirectConnection*/);
|
||||
connect(newClient,&ClientHandler::signal_updateDocsXML,this,&MultiThreadServer::slot_UpdateDocs);
|
||||
|
||||
//connect(this,&MultiThreadServer::sigInitClient,newClient,&ClientHandler::initialize, Qt::AutoConnection/*Qt::DirectConnection*/);
|
||||
connect(newClient,&ClientHandler::sigClientDisconnected,this,&MultiThreadServer::slotDisconnectClient,Qt::AutoConnection);
|
||||
emit sigInitClient(socketDesriptor,serverLmsWidget,updateController,dataParser);
|
||||
disconnect(this,&MultiThreadServer::sigInitClient,newClient,&ClientHandler::initialize);
|
||||
//emit sigInitClient(socketDesriptor,serverLmsWidget,updateController,dataParser, getMutex());
|
||||
newClient->initialize(socketDesriptor,updateController,dataParser, getMutex());
|
||||
//disconnect(this,&MultiThreadServer::sigInitClient,newClient,&ClientHandler::initialize);
|
||||
|
||||
addClient(socketDesriptor,newClient);
|
||||
|
||||
@@ -40,19 +52,18 @@ bool MultiThreadServer::startServer()
|
||||
{
|
||||
if(stateServer == stoped)
|
||||
{
|
||||
//connect(tcpServer, &QTcpServer::newConnection, this, &ServerLMSWidget::slotNewConnection,Qt::AutoConnection);
|
||||
|
||||
if(!listen(QHostAddress::Any, hostPort))
|
||||
{
|
||||
stateServer = stoped;
|
||||
emit signal_StateServer(stateServer, stateBlockAutorization);
|
||||
Logger::instance().log("SERVER: start ERROR");
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
stateServer = started;
|
||||
slot_BlockAutorization(false, "SERVER", "StopServer");
|
||||
emit signal_StateServer(stateServer, stateBlockAutorization);
|
||||
Logger::instance().log("SERVER: start OK");
|
||||
return true;
|
||||
}
|
||||
@@ -71,6 +82,7 @@ bool MultiThreadServer::stopServer()
|
||||
close();
|
||||
stateServer = stoped;
|
||||
slot_BlockAutorization(true, "SERVER", "StopServer");
|
||||
emit signal_StateServer(stateServer, stateBlockAutorization);
|
||||
Logger::instance().log("SERVER: stop OK");
|
||||
return true;
|
||||
}
|
||||
@@ -83,9 +95,20 @@ QMap<int, ClientHandler *> *MultiThreadServer::getClientsMap() const
|
||||
return clientsMap;
|
||||
}
|
||||
|
||||
QStringList MultiThreadServer::getClientFullNameList()
|
||||
{
|
||||
QStringList list;
|
||||
for(ClientHandler* handler : *getClientsMap())
|
||||
{
|
||||
QString clientFullName = handler->getClient()->getFullName();
|
||||
list.append(clientFullName);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
void MultiThreadServer::updateClientList()
|
||||
{
|
||||
serverLmsWidget->slot_UpdateListClients();
|
||||
emit signal_UpdateListClients(getClientFullNameList());
|
||||
}
|
||||
|
||||
void MultiThreadServer::disableClients()
|
||||
@@ -151,8 +174,8 @@ void MultiThreadServer::slotDisconnectClient(QString peerAddress, QString peerPo
|
||||
emit signalStopSendFile();
|
||||
Logger::instance().log("SERVER: Client " + login + " disconnected");
|
||||
|
||||
serverLmsWidget->slot_UpdateListClients();
|
||||
serverLmsWidget->getProcessingSystem()->processingClientDeAutorization(login);
|
||||
emit signal_UpdateListClients(getClientFullNameList());
|
||||
processingSystem->processingClientDeAutorization(login);
|
||||
}
|
||||
|
||||
bool MultiThreadServer::slot_BlockAutorization(bool block, QString whoFullName, QString type)
|
||||
@@ -259,15 +282,30 @@ bool MultiThreadServer::slot_BlockAutorization(bool block, QString whoFullName,
|
||||
return res;
|
||||
}
|
||||
|
||||
void MultiThreadServer::slot_StartServer()
|
||||
{
|
||||
startServer();
|
||||
}
|
||||
|
||||
void MultiThreadServer::slot_StopServer()
|
||||
{
|
||||
stopServer();
|
||||
}
|
||||
|
||||
void MultiThreadServer::slot_UpdateDocs()
|
||||
{
|
||||
emit signal_updateDocsXML();
|
||||
}
|
||||
|
||||
void MultiThreadServer::removeClient(int idSocket)
|
||||
{
|
||||
clientsMap->remove(idSocket);
|
||||
serverLmsWidget->slot_UpdateListClients();
|
||||
emit signal_UpdateListClients(getClientFullNameList());
|
||||
}
|
||||
|
||||
void MultiThreadServer::addClient(qintptr descriptor, ClientHandler *client)
|
||||
{
|
||||
(*clientsMap)[descriptor] = client;
|
||||
serverLmsWidget->slot_UpdateListClients();
|
||||
emit signal_UpdateListClients(getClientFullNameList());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,27 +1,26 @@
|
||||
#ifndef MULTITHREADSERVER_H
|
||||
#define MULTITHREADSERVER_H
|
||||
|
||||
#include "serverlmswidget.h"
|
||||
#include "Systems/processingsystem.h"
|
||||
#include <QObject>
|
||||
|
||||
class ProcessingSystem;
|
||||
class DocsUpdater;
|
||||
class MultiThreadServer : public QTcpServer
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MultiThreadServer(ServerLMSWidget *widget,UpdateController *updateController,ProcessingSystem *processingSystem,
|
||||
MultiThreadServer(UpdateController *updateController, DocsUpdater *docsUpdater,ProcessingSystem *processingSystem,
|
||||
DataParser *dataParser, qint16 hostPort, QObject *parent = nullptr);
|
||||
~MultiThreadServer();
|
||||
|
||||
|
||||
QMap<int, ClientHandler *> *getClientsMap() const;
|
||||
QStringList getClientFullNameList();
|
||||
void updateClientList();
|
||||
void disableClients();
|
||||
|
||||
bool startServer();
|
||||
bool stopServer();
|
||||
|
||||
EStateBlockAutorization getStateBlockAutorization() const
|
||||
{
|
||||
return stateBlockAutorization;
|
||||
@@ -30,38 +29,60 @@ public:
|
||||
{
|
||||
return stateServer;
|
||||
}
|
||||
QMutex *getMutex() const
|
||||
{
|
||||
return mutex;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
bool startServer();
|
||||
bool stopServer();
|
||||
|
||||
void blockAutorization()
|
||||
{
|
||||
stateBlockAutorization = blocked;
|
||||
emit signal_StateServer(stateServer, stateBlockAutorization);
|
||||
}
|
||||
void unBlockAutorization()
|
||||
{
|
||||
stateBlockAutorization = unblocked;
|
||||
emit signal_StateServer(stateServer, stateBlockAutorization);
|
||||
}
|
||||
|
||||
signals:
|
||||
void sigInitClient(int descriptor, ServerLMSWidget *serverWidget,
|
||||
UpdateController *updateController, DataParser *dataParser);
|
||||
//void sigInitClient(int descriptor, ServerLMSWidget *serverWidget,
|
||||
// UpdateController *updateController, DataParser *dataParser, QMutex *mutex);
|
||||
void signalStopSendFile();
|
||||
|
||||
void signal_BlockAutorizationIndicate(bool block, QString blocker, QString types);
|
||||
void signal_sendPacketToAllClients(PacketType packetType, bool flOnlyGUI);
|
||||
|
||||
void signal_StateServer(EStateServer stateServer, EStateBlockAutorization stateBlockAutorization);
|
||||
|
||||
void signal_UpdateListClients(QStringList listFullName);
|
||||
|
||||
void signal_updateDocsXML();
|
||||
|
||||
public slots:
|
||||
void slotDisconnectClient(QString peerAddress, QString peerPort);
|
||||
|
||||
bool slot_BlockAutorization(bool block, QString whoFullName, QString type);
|
||||
|
||||
void slot_StartServer();
|
||||
void slot_StopServer();
|
||||
|
||||
void slot_UpdateDocs();
|
||||
protected:
|
||||
void incomingConnection(qintptr handle) override;
|
||||
|
||||
private:
|
||||
ServerLMSWidget *serverLmsWidget;
|
||||
QMutex *mutex;
|
||||
QMap<int, ClientHandler*> *clientsMap;
|
||||
qint16 hostPort;
|
||||
ProcessingSystem *processingSystem;
|
||||
UpdateController *updateController;
|
||||
DocsUpdater *docsUpdater;
|
||||
DataParser *dataParser;
|
||||
|
||||
EStateServer stateServer;
|
||||
|
||||
@@ -3,12 +3,11 @@
|
||||
#include <QThread>
|
||||
#include <QMessageBox>
|
||||
|
||||
ProviderDBLMS::ProviderDBLMS(QWidget *parentWidget, QObject *parent) :
|
||||
ProviderDBLMS::ProviderDBLMS(QObject *parent) :
|
||||
QObject(parent),
|
||||
dbLMS(nullptr),
|
||||
parentWidget(parentWidget)
|
||||
dbLMS(nullptr)
|
||||
{
|
||||
dbLMS = new InterfaceDataBaseLMS(parentWidget);
|
||||
dbLMS = new InterfaceDataBaseLMS();
|
||||
connect(dbLMS, &InterfaceDataBaseLMS::signal_ErrorPostgreSQL, this, &ProviderDBLMS::signal_ErrorPostgreSQL);
|
||||
}
|
||||
|
||||
@@ -17,6 +16,15 @@ ProviderDBLMS::~ProviderDBLMS()
|
||||
DisConnectionFromDB();
|
||||
}
|
||||
|
||||
void ProviderDBLMS::slot_TryConnectionToDB()
|
||||
{
|
||||
ConnectionToDB();
|
||||
}
|
||||
void ProviderDBLMS::slot_TryDisConnectionFromDB()
|
||||
{
|
||||
DisConnectionFromDB();
|
||||
}
|
||||
|
||||
bool ProviderDBLMS::ConnectionToDB()
|
||||
{
|
||||
mtxAccess.lock();
|
||||
@@ -26,15 +34,31 @@ bool ProviderDBLMS::ConnectionToDB()
|
||||
{
|
||||
bool res = Q_EMIT signal_BlockAutorization(false, "SERVER", "DisConnectionDB");
|
||||
|
||||
bool res1 = dbLMS->deAuthorizationAllTrainees();
|
||||
bool res2 = dbLMS->deAuthorizationAllInstructors();
|
||||
|
||||
emit signal_StateConnectionToDB(true, getDBSettings());
|
||||
emit signal_ResultTryConnectDb(true);
|
||||
|
||||
mtxAccess.unlock();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
emit signal_StateConnectionToDB(false, getDBSettings());
|
||||
emit signal_ResultTryConnectDb(false);
|
||||
|
||||
mtxAccess.unlock();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool res1 = dbLMS->deAuthorizationAllTrainees();
|
||||
bool res2 = dbLMS->deAuthorizationAllInstructors();
|
||||
|
||||
emit signal_StateConnectionToDB(true, getDBSettings());
|
||||
emit signal_ResultTryConnectDb(true);
|
||||
|
||||
mtxAccess.unlock();
|
||||
return true;
|
||||
}
|
||||
@@ -46,7 +70,19 @@ void ProviderDBLMS::DisConnectionFromDB()
|
||||
{
|
||||
bool res = Q_EMIT signal_BlockAutorization(true, "SERVER", "DisConnectionDB");
|
||||
|
||||
dbLMS->disConnectionFromDB();
|
||||
bool res1 = dbLMS->deAuthorizationAllTrainees();
|
||||
bool res2 = dbLMS->deAuthorizationAllInstructors();
|
||||
|
||||
if(dbLMS->disConnectionFromDB())
|
||||
{
|
||||
emit signal_ResultTryDisConnectDb(true);
|
||||
emit signal_StateConnectionToDB(false, getDBSettings());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
emit signal_ResultTryDisConnectDb(true);
|
||||
emit signal_StateConnectionToDB(false, getDBSettings());
|
||||
}
|
||||
mtxAccess.unlock();
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ class ProviderDBLMS : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ProviderDBLMS(QWidget *parentWidget, QObject *parent = nullptr);
|
||||
explicit ProviderDBLMS(QObject *parent = nullptr);
|
||||
~ProviderDBLMS();
|
||||
public:
|
||||
QString getMainInstructorName();
|
||||
@@ -75,10 +75,20 @@ Q_SIGNALS:
|
||||
bool signal_BlockAutorization(bool block, QString whoFullName, QString type);
|
||||
signals:
|
||||
void signal_ErrorPostgreSQL(QString text);
|
||||
void signal_StateConnectionToDB(bool dbIsConnected, DataBaseSettings dbSettings);
|
||||
|
||||
public:
|
||||
void signal_ResultTryConnectDb(bool result);
|
||||
void signal_ResultTryDisConnectDb(bool result);
|
||||
|
||||
public slots:
|
||||
void slot_TryConnectionToDB();
|
||||
void slot_TryDisConnectionFromDB();
|
||||
|
||||
private:
|
||||
bool ConnectionToDB();
|
||||
void DisConnectionFromDB();
|
||||
|
||||
public:
|
||||
bool DBisConnected();
|
||||
DataBaseSettings getDBSettings();
|
||||
|
||||
@@ -94,7 +104,6 @@ public:
|
||||
private:
|
||||
InterfaceDataBaseLMS* dbLMS;
|
||||
QMutex mtxAccess;
|
||||
QWidget *parentWidget;
|
||||
};
|
||||
|
||||
#endif // PROVIDERDBLMS_H
|
||||
|
||||
@@ -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),
|
||||
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,61 +274,101 @@ void ServerLMSWidget::slot_ErrorPostgreSQL(QString text)
|
||||
SpecMsgBox::CriticalClose(this, tr("Error PostgreSQL!") + "\n" + text);
|
||||
}
|
||||
|
||||
void ServerLMSWidget::slot_UpdateDocs()
|
||||
void ServerLMSWidget::slot_StateConnectionToDB(bool dbIsConnected, DataBaseSettings dbSettings)
|
||||
{
|
||||
//QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
|
||||
emit signal_updateDocsXML();
|
||||
|
||||
//if(docsUpdater->slot_updateDocsXML())
|
||||
//emit signal_DocsChanged();
|
||||
|
||||
//QApplication::restoreOverrideCursor();
|
||||
|
||||
//TODO для теста
|
||||
//cfiController->test();
|
||||
this->dbIsConnected = dbIsConnected;
|
||||
this->dbSettings = dbSettings;
|
||||
updateStateOnlyDB();
|
||||
}
|
||||
|
||||
void ServerLMSWidget::slot_startInitialization_step1()
|
||||
void ServerLMSWidget::slot_StateServer(EStateServer stateServer, EStateBlockAutorization stateBlockAutorization)
|
||||
{
|
||||
Logger::instance().log("Update docs.xml...");
|
||||
slot_UpdateDocs();
|
||||
Logger::instance().log("Update docs.xml completed!");
|
||||
|
||||
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);
|
||||
|
||||
flStartInitialization = true;
|
||||
|
||||
emit signal_Tray_ShowMessage(tr("Server is stoped!"));
|
||||
}
|
||||
}
|
||||
this->stateServer = stateServer;
|
||||
this->stateBlockAutorization = stateBlockAutorization;
|
||||
updateStateOnlyServer();
|
||||
updateStateOnlyDB();
|
||||
updateStateOnlyVersion();
|
||||
}
|
||||
|
||||
//QApplication::restoreOverrideCursor();
|
||||
void ServerLMSWidget::slot_StateVersionMaterials(QString versionStr)
|
||||
{
|
||||
this->stateVersionMaterials = versionStr;
|
||||
updateStateOnlyVersionMaterials();
|
||||
}
|
||||
|
||||
if(hasError() == 100)
|
||||
return;
|
||||
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."));
|
||||
|
||||
Logger::instance().log("Try connection to DB...");
|
||||
tryConnectionToDB();
|
||||
|
||||
waitAnimationWidget->hideWithStop();
|
||||
|
||||
emit signal_InitializeFinished();
|
||||
}
|
||||
}
|
||||
|
||||
void ServerLMSWidget::slot_setVersion(QString versionStr)
|
||||
|
||||
void ServerLMSWidget::slot_UpdateDocs()
|
||||
{
|
||||
this->versionStr = versionStr;
|
||||
Logger::instance().log("Set Version: " + versionStr);
|
||||
updateStateOnlyVersion();
|
||||
emit signal_updateDocsXML();
|
||||
}
|
||||
|
||||
void ServerLMSWidget::start()
|
||||
void ServerLMSWidget::slot_UpdateControllerInitializeFinished()
|
||||
{
|
||||
startInitialization_step0();
|
||||
startInitialization_step1();
|
||||
}
|
||||
|
||||
|
||||
void ServerLMSWidget::slot_BlockAutorizationIndicate(bool block, QString blocker, QString types)
|
||||
{
|
||||
if(block)
|
||||
@@ -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,53 +488,8 @@ 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()
|
||||
{
|
||||
@@ -363,18 +497,22 @@ void ServerLMSWidget::startInitialization_step0()
|
||||
|
||||
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;
|
||||
|
||||
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::tryConnectionToDB()
|
||||
void ServerLMSWidget::startInitialization_step1()
|
||||
{
|
||||
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")));
|
||||
Logger::instance().log("Update docs.xml...");
|
||||
slot_UpdateDocs();
|
||||
Logger::instance().log("Update docs.xml completed!");
|
||||
|
||||
ui->btnStopServer->setEnabled(false);
|
||||
ui->btnStartServer->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();
|
||||
}
|
||||
|
||||
void ServerLMSWidget::updateStateOnlyVersion()
|
||||
|
||||
//CONNECT DB
|
||||
|
||||
void ServerLMSWidget::tryConnectionToDB()
|
||||
{
|
||||
ui->lblVersionText->setText(versionStr);
|
||||
flTryConnectionToDB = true;
|
||||
flNeedReconnectDB = false;
|
||||
emit signal_TryConnectionToDB();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -24,13 +24,12 @@
|
||||
|
||||
#include <Data/typesDataServerClient.h>
|
||||
#include <Data/Client.h>
|
||||
|
||||
#include "multithreadserver.h"
|
||||
#include "providerdblms.h"
|
||||
#include "docsupdater.h"
|
||||
|
||||
#include "waitanimationwidget.h"
|
||||
#include "specialmessagebox.h"
|
||||
|
||||
#include "cficontroller.h"
|
||||
|
||||
|
||||
@@ -51,25 +50,24 @@ class ChatSystem;
|
||||
class DocsUpdater;
|
||||
class CfiController;
|
||||
|
||||
|
||||
class SERVERLMS_EXPORT ServerLMSWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ServerLMSWidget(QWidget *parent = nullptr);
|
||||
~ServerLMSWidget();
|
||||
|
||||
void start();
|
||||
|
||||
public:
|
||||
static const QString languageENG;
|
||||
static const QString languageRUS;
|
||||
|
||||
protected:
|
||||
// Метод получения событий
|
||||
// В нём будет производиться проверка события смены перевода приложения
|
||||
void changeEvent(QEvent * event) override;
|
||||
public:
|
||||
explicit ServerLMSWidget(QWidget *parent = nullptr);
|
||||
~ServerLMSWidget();
|
||||
|
||||
public:
|
||||
void start();
|
||||
|
||||
protected:
|
||||
void changeEvent(QEvent * event) override;
|
||||
void resizeEvent(QResizeEvent *event) override;
|
||||
|
||||
signals:
|
||||
@@ -95,19 +93,30 @@ signals:
|
||||
|
||||
void signal_InitializeFinished();
|
||||
|
||||
void signal_TryConnectionToDB();
|
||||
void signal_TryDisConnectionFromDB();
|
||||
|
||||
void signal_StartServer();
|
||||
void signal_StopServer();
|
||||
|
||||
public slots:
|
||||
void slot_LanguageChanged(QString language);
|
||||
void slot_UpdateListClients();
|
||||
void slot_UpdateListClients(QStringList listFullName);
|
||||
void slot_BlockAutorizationIndicate(bool block, QString blocker, QString types);
|
||||
void slot_AddMessageToLog(QString message);
|
||||
|
||||
void slot_ErrorPostgreSQL(QString text);
|
||||
void slot_StateConnectionToDB(bool dbIsConnected, DataBaseSettings dbSettings);
|
||||
void slot_StateServer(EStateServer stateServer, EStateBlockAutorization stateBlockAutorization);
|
||||
|
||||
void slot_UpdateDocs();
|
||||
|
||||
void slot_startInitialization_step1();
|
||||
void slot_UpdateControllerInitializeFinished();
|
||||
|
||||
void slot_setVersion(QString versionStr);
|
||||
void slot_StateVersionMaterials(QString stateVersionMaterials);
|
||||
|
||||
void slot_ResultTryConnectDb(bool result);
|
||||
void slot_ResultTryDisConnectDb(bool result);
|
||||
|
||||
public:
|
||||
QString getLanguage()
|
||||
@@ -139,11 +148,6 @@ public:
|
||||
return processingSystem;
|
||||
}
|
||||
|
||||
QMutex *getMutex() const
|
||||
{
|
||||
return mutex;
|
||||
}
|
||||
|
||||
void removeClient(int socketId);
|
||||
|
||||
private slots:
|
||||
@@ -152,17 +156,19 @@ private slots:
|
||||
void on_btnSettings_clicked();
|
||||
|
||||
private:
|
||||
void setLanguageInterfase();
|
||||
void updateMyStyleSheet();
|
||||
QString loadStyleSheet();
|
||||
void initLanguageInterfase();
|
||||
|
||||
void startInitialization_step0();
|
||||
|
||||
void tryConnectionToDB();
|
||||
|
||||
private:
|
||||
void updateStateOnlyServer();
|
||||
void updateStateOnlyDB();
|
||||
void updateStateOnlyVersion();
|
||||
void updateStateOnlyVersionMaterials();
|
||||
|
||||
private:
|
||||
void startInitialization_step0();
|
||||
void startInitialization_step1();
|
||||
void tryConnectionToDB();
|
||||
|
||||
private:
|
||||
Ui::ServerLMSWidget *ui;
|
||||
@@ -172,31 +178,36 @@ private:
|
||||
|
||||
QThread *updateThread;
|
||||
QThread *loggerThread;
|
||||
QThread *serverThread;
|
||||
|
||||
QMutex *mutex;
|
||||
MultiThreadServer *server; //serverThread
|
||||
DataParser *dataParser; //serverThread
|
||||
ProcessingSystem *processingSystem; //serverThread
|
||||
CommonClientHandler *commonClientHandler; //serverThread
|
||||
ChatSystem *chatSystem; //serverThread
|
||||
ProviderDBLMS* providerDBLMS; //serverThread
|
||||
|
||||
MultiThreadServer *server;
|
||||
|
||||
DataParser *dataParser;
|
||||
ProcessingSystem *processingSystem;
|
||||
UpdateController *updateController; //updateThread
|
||||
AssetsManager *assetsManager; //updateThread
|
||||
CommonClientHandler *commonClientHandler;
|
||||
ChatSystem *chatSystem;
|
||||
|
||||
DocsUpdater* docsUpdater; //updateThread
|
||||
CfiController* cfiController; //updateThread
|
||||
|
||||
ProviderDBLMS* providerDBLMS;
|
||||
|
||||
bool first = true; // для тестов Unity
|
||||
bool first; // для тестов Unity
|
||||
|
||||
QTranslator qtLanguageTranslator;
|
||||
QString language;
|
||||
|
||||
int errorCode;
|
||||
QString versionStr;
|
||||
|
||||
QString stateVersionMaterials;
|
||||
bool dbIsConnected;
|
||||
DataBaseSettings dbSettings;
|
||||
EStateServer stateServer;
|
||||
EStateBlockAutorization stateBlockAutorization;
|
||||
|
||||
bool flStartInitialization;
|
||||
bool flTryConnectionToDB;
|
||||
bool flNeedReconnectDB;
|
||||
};
|
||||
|
||||
#endif // SERVERLMSWIDGET_H
|
||||
|
||||
Reference in New Issue
Block a user