# Conflicts:
#	DOCS/MainScheme.md
This commit is contained in:
semenov
2026-02-11 10:22:06 +03:00
66 changed files with 2311 additions and 1243 deletions

View File

@@ -37,6 +37,9 @@ enum PacketType
TYPE_XMLANSWER_QUERY_TASKS_AMM_OF_TRAINEE = 106,
TYPE_XMLANSWER_QUERY_TASKS_FIM_OF_TRAINEE = 107,
TYPE_XMLANSWER_QUERY_TASKS_AMM_OF_ALL_TRAINEES = 108,
TYPE_XMLANSWER_QUERY_TASKS_FIM_OF_ALL_TRAINEES = 109,
//xml-ответы на запросы AdditionalFiles
TYPE_XMLANSWER_QUERY_TASKS_XML_FIM = 130,
TYPE_XMLANSWER_QUERY_TASKS_XML_AMM = 131,

View File

@@ -19,5 +19,7 @@
<file>resources/icons/save.png</file>
<file>resources/icons/stoped.png</file>
<file>resources/blankXML/ListCFI.xml</file>
<file>resources/blankXML/ListsTasksAMMofAllTrainees.xml</file>
<file>resources/blankXML/ListsTasksFIMofAllTrainees.xml</file>
</qresource>
</RCC>

View File

@@ -6,6 +6,7 @@
#include <Systems/Parsers/dataparser.h>
#include <Data/typesDataServerClient.h>
class DataParser;
class ClientAnswerParser : public QObject
{

View File

@@ -3,11 +3,12 @@
#include <QFile>
#include <QDomDocument>
DataParser::DataParser(AssetsManager *assetManager,ProcessingSystem *processingSystem,QObject *parent) :
DataParser::DataParser(ProcessingSystem *processingSystem,QObject *parent) :
QObject(parent)
{
qDebug() << "DataParser init thread ID " << QThread::currentThreadId();
this->processingSystem = processingSystem;
this->assetsManager = assetManager;
clientAnswer = new ClientAnswerParser;
clientAnswer->initialize(this);
@@ -21,8 +22,6 @@ QObject(parent)
processParser->initialize(processingSystem);
mutex = new QMutex;
qDebug() << "ParserThread: " << QThread::currentThreadId();
}

View File

@@ -3,7 +3,6 @@
#include "Systems/processingsystem.h"
#include "Systems/tools.h"
#include "Systems/assetsmanager.h"
#include "Systems/logger.h"
#include "Systems/Parsers/clientanswerparser.h"
#include "dbanswerparser.h"
@@ -21,7 +20,6 @@
class ProcessingSystem;
class ClientHandler;
class AssetsManager;
class ClientAnswerParser;
class DBAnswerParser;
class DocsAnswerParser;
@@ -32,7 +30,7 @@ class DataParser : public QObject
Q_OBJECT
public:
DataParser(AssetsManager *assetManager,ProcessingSystem *processingSystem,QObject* parent = nullptr);
DataParser(ProcessingSystem *processingSystem,QObject* parent = nullptr);
void xmlParser(ClientHandler *client, QByteArray array);
void xmlFileDataParse(QByteArray array);
@@ -53,7 +51,6 @@ private:
QMutex *mutex;
ProcessingSystem *processingSystem;
AssetsManager *assetsManager;
ClientAnswerParser *clientAnswer;
DBAnswerParser *dbAnswer;
DocsAnswerParser* docsAnswer;

View File

@@ -261,3 +261,136 @@ QByteArray DBAnswerParser::listTasksFIMofTrainee(bool result, QList<TaskAmmFim>
return commonDOM.toByteArray();
}
QByteArray DBAnswerParser::listsTasksAMMofAllTrainees(QMap<int, QList<TaskAmmFim> > *mapOfLists)
{
QDomDocument commonDOM;
if(! Tools::loadFileXMLtoDOM(":/resources/blankXML/ListsTasksAMMofAllTrainees.xml", &commonDOM))
return QByteArray();
QDomNode listsAllNode = commonDOM.namedItem("ListsTasksAMMofAllTrainees");
for(int key : mapOfLists->keys())
{
QList<TaskAmmFim> listOne = mapOfLists->value(key);
QDomNode listOneNode = commonDOM.createElement("ListTasksAMM");
listsAllNode.appendChild(listOneNode);
listOneNode.toElement().setAttribute("trainee_id", QString::number(key));
for(TaskAmmFim task : listOne)
{
//Задача
QDomNode taskNode = commonDOM.createElement("taskAMM");
listOneNode.appendChild(taskNode);
taskNode.toElement().setAttribute("task_id", QString::number(task.getID()));
taskNode.toElement().setAttribute("title", task.ammProcedure.title);
taskNode.toElement().setAttribute("dmCode", task.ammProcedure.dmCode);
taskNode.toElement().setAttribute("status", task.status);
for(SubProc subProc : task.listSubProc)
{//Подпроцедура
QDomNode subProcNode = commonDOM.createElement("SubProc");
taskNode.appendChild(subProcNode);
subProcNode.toElement().setAttribute("dmCode", subProc.getDmCode());
subProcNode.toElement().setAttribute("title", subProc.getTitle());
subProcNode.toElement().setAttribute("canplay", subProc.getModeListStr());
}
}
}
Tools::saveDOMtoFileXML("ListsTasksAMMofAllTrainees.xml", &commonDOM);
return commonDOM.toByteArray();
}
QByteArray DBAnswerParser::listsTasksFIMofAllTrainees(QMap<int, QList<TaskAmmFim> > *mapOfLists)
{
QDomDocument commonDOM;
if(! Tools::loadFileXMLtoDOM(":/resources/blankXML/ListsTasksFIMofAllTrainees.xml", &commonDOM))
return QByteArray();
QDomNode listsAllNode = commonDOM.namedItem("ListsTasksFIMofAllTrainees");
for(int key : mapOfLists->keys())
{
QList<TaskAmmFim> listOne = mapOfLists->value(key);
QDomNode listOneNode = commonDOM.createElement("ListTasksFIM");
listsAllNode.appendChild(listOneNode);
listOneNode.toElement().setAttribute("trainee_id", QString::number(key));
for(TaskAmmFim task : listOne)
{
//Задача
QDomNode taskNode = commonDOM.createElement("taskFIM");
listOneNode.appendChild(taskNode);
taskNode.toElement().setAttribute("task_id", QString::number(task.getID()));
taskNode.toElement().setAttribute("title", task.title);
taskNode.toElement().setAttribute("status", task.status);
for(Malfunction malfunction : task.malfunctionList)
{//Неисправность
QDomNode malfunctionNode = commonDOM.createElement("malfunction");
taskNode.appendChild(malfunctionNode);
malfunctionNode.toElement().setAttribute("dmCode", malfunction.dmCode);
malfunctionNode.toElement().setAttribute("num", malfunction.num);
malfunctionNode.toElement().setAttribute("description", malfunction.description);
malfunctionNode.toElement().setAttribute("goName", malfunction.goName);
malfunctionNode.toElement().setAttribute("objName", malfunction.objName);
for(MalfunctionSign sign : malfunction.malfunctionSigns)
{//Сигналы
QDomNode signNode = commonDOM.createElement("malfunctionSign");
malfunctionNode.appendChild(signNode);
signNode.toElement().setAttribute("type", sign.type);
signNode.toElement().setAttribute("description", sign.description);
}
}
{//FIMReport
FIMReport report = task.report;
QDomNode reportNode = commonDOM.createElement("report");
taskNode.appendChild(reportNode);
reportNode.toElement().setAttribute("report_id", report.id);
reportNode.toElement().setAttribute("mmel", report.mmel ? "true" : "false");
for(FIMReportItem reportItem : task.report.itemList)
{//FIMReportItem
QDomNode reportItemNode = commonDOM.createElement("reportItem");
reportNode.appendChild(reportItemNode);
reportItemNode.toElement().setAttribute("item_id", reportItem.id);
reportItemNode.toElement().setAttribute("text", reportItem.text);
//ProcedureID
QDomNode procedureIDNode = commonDOM.createElement("procedureID");
reportItemNode.appendChild(procedureIDNode);
procedureIDNode.toElement().setAttribute("doc", reportItem.procedure.doc);
procedureIDNode.toElement().setAttribute("title", reportItem.procedure.title);
procedureIDNode.toElement().setAttribute("dmCode", reportItem.procedure.dmCode);
procedureIDNode.toElement().setAttribute("result", reportItem.procedure.result);
}
for(FIMReportWarehouseItem reportWhItem : task.report.warehouseItemList)
{//FIMReportWarehouseItem
QDomNode reportWhItemNode = commonDOM.createElement("reportWHItem");
reportNode.appendChild(reportWhItemNode);
reportWhItemNode.toElement().setAttribute("wh_item_id", reportWhItem.id);
reportWhItemNode.toElement().setAttribute("status", reportWhItem.status);
reportWhItemNode.toElement().setAttribute("goName", reportWhItem.goName);
reportWhItemNode.toElement().setAttribute("objName", reportWhItem.objName);
reportWhItemNode.toElement().setAttribute("code", reportWhItem.code);
}
}
}
}
Tools::saveDOMtoFileXML("ListsTasksFIMofAllTrainees.xml", &commonDOM);
return commonDOM.toByteArray();
}

View File

@@ -23,6 +23,9 @@ public:
QByteArray listTasksAMMofTrainee(bool result, QList<TaskAmmFim> *listTasks, int trainee_id, bool full_list);
QByteArray listTasksFIMofTrainee(bool result, QList<TaskAmmFim> *listTasks, int trainee_id, bool full_list);
QByteArray listsTasksAMMofAllTrainees(QMap<int, QList<TaskAmmFim> > *mapOfLists);
QByteArray listsTasksFIMofAllTrainees(QMap<int, QList<TaskAmmFim> > *mapOfLists);
signals:
private:

View File

@@ -1,12 +1,16 @@
#include <QThread>
#include <QXmlStreamReader>
#include "assetsmanager.h"
AssetsManager::AssetsManager(QObject *parent) : QObject(parent)
{
qDebug() << "AssetsManager init thread ID " << QThread::currentThreadId();
}
void AssetsManager::initialize(UpdateController* updateContoller,DataParser *dataParser)
void AssetsManager::initialize(UpdateController* updateContoller)
{
qDebug() << "AssetsManager::initialize thread ID " << QThread::currentThreadId();
this->updateController = updateContoller;
//connect(this,&AssetsManager::sigSaveVersion,updateContoller,&UpdateController::saveVersionToFile);
datas = new QList<StreamingVersionData*>;
@@ -110,6 +114,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();
@@ -172,7 +178,7 @@ void AssetsManager::addVersion(StreamingVersionData *data)
void AssetsManager::createCopyVersion(QString versionName,QString newVersionName,QString author)
{
qDebug() << "assetManager thread ID " << QThread::currentThreadId();
qDebug() << "AssetsManager::createCopyVersion thread ID " << QThread::currentThreadId();
StreamingVersionData* data = new StreamingVersionData;
data->setAbsolutePath(Tools::createSharedPath("/" + newVersionName));

View File

@@ -5,13 +5,14 @@
#include <Systems/updatecontroller.h>
#include <Data/StreamingVersionData.h>
class UpdateController;
class AssetsManager : public QObject
{
Q_OBJECT
public:
explicit AssetsManager(QObject *parent = nullptr);
void initialize(UpdateController* updateContoller,DataParser *dataParser);
void initialize(UpdateController* updateContoller);
void addVersion(StreamingVersionData *data);
void createCopyVersion(QString versionName,QString newName,QString author);
void deleteVersion(QString version);

View File

@@ -2,11 +2,13 @@
ChatSystem::ChatSystem()
{
qDebug() << "ChatSystem init thread ID " << QThread::currentThreadId();
}
void ChatSystem::initialize(CommonClientHandler *commonClientHandler, DataParser *dataParser, QMap<int, ClientHandler*> *clientsMap)
{
qDebug() << "ChatSystem::initialize thread ID " << QThread::currentThreadId();
this->commonClientHandler = commonClientHandler;
this->dataParser = dataParser;
this->clientsMap = clientsMap;

View File

@@ -5,6 +5,8 @@
#include <QObject>
#include <Data/typesDataServerClient.h>
class CommonClientHandler;
class ChatSystem : public QObject
{
Q_OBJECT

View File

@@ -2,11 +2,13 @@
CommonClientHandler::CommonClientHandler(QObject *parent) : QObject(parent)
{
qDebug() << "CommonClientHandler init thread ID " << QThread::currentThreadId();
}
void CommonClientHandler::initialize(QMap<int, ClientHandler *> *clientsMap, ProcessingSystem *processingSystem, DataParser *dataParser)
{
qDebug() << "CommonClientHandler::initialize thread ID " << QThread::currentThreadId();
this->clientsMap = clientsMap;
this->processingSystem = processingSystem;
this->dataParser = dataParser;
@@ -36,7 +38,32 @@ void CommonClientHandler::sendCurrentVersionToAllClient()
}
}
void CommonClientHandler::slot_ListsInstructorsTraineesChanged()
void CommonClientHandler::slot_ListsInstructorsTraineesChanged_forUserID(int id_user)
{
//Проходим все открытые сокеты
foreach(int idSocket, clientsMap->keys())
{
ClientHandler *handler = clientsMap->value(idSocket);
//Проверяем, есть ли клиенты TYPE_GUI с нужным ID
if(handler->getClient()->getTypeClient() == TypeClientAutorization::TYPE_GUI &&
handler->getClient()->getId() == QString::number(id_user))
{//Отправляем этому клиенту обновление списков
ClientQueryToDB queryToDB;
queryToDB.typeQuery = TypeQueryToDB::TYPE_QUERY_GET_ALL_LISTS;
processingSystem->processingClientQueryToDB(handler, queryToDB);
}
/*
if(handler->getClient()->getClientType() == TypeClientAutorization::TYPE_UNITY_CLIENT)
{
ClientQueryToDB queryToDB;
queryToDB.typeQuery = TypeQueryToDB::TYPE_QUERY_GET_CONTACT_LIST;
processingSystem->processingClientQueryToDB(handler, queryToDB);
}*/
}
}
void CommonClientHandler::slot_ListInstructorsChanged()
{
//Проходим все открытые сокеты
foreach(int idSocket, clientsMap->keys())
@@ -46,7 +73,53 @@ void CommonClientHandler::slot_ListsInstructorsTraineesChanged()
if(handler->getClient()->getTypeClient() == TypeClientAutorization::TYPE_GUI)
{//Отправляем этому клиенту обновление списков
ClientQueryToDB queryToDB;
queryToDB.typeQuery = TypeQueryToDB::TYPE_QUERY_GET_ALL_LISTS;
queryToDB.typeQuery = TypeQueryToDB::TYPE_QUERY_GET_ALL_INSTRUCTORS;
processingSystem->processingClientQueryToDB(handler, queryToDB);
}
if(handler->getClient()->getClientType() == TypeClientAutorization::TYPE_UNITY_CLIENT)
{
ClientQueryToDB queryToDB;
queryToDB.typeQuery = TypeQueryToDB::TYPE_QUERY_GET_CONTACT_LIST;
processingSystem->processingClientQueryToDB(handler, queryToDB);
}
}
}
void CommonClientHandler::slot_ListTraineesChanged()
{
//Проходим все открытые сокеты
foreach(int idSocket, clientsMap->keys())
{
ClientHandler *handler = clientsMap->value(idSocket);
//Проверяем, есть ли клиенты TYPE_GUI
if(handler->getClient()->getTypeClient() == TypeClientAutorization::TYPE_GUI)
{//Отправляем этому клиенту обновление списков
ClientQueryToDB queryToDB;
queryToDB.typeQuery = TypeQueryToDB::TYPE_QUERY_GET_ALL_TRAINEES;
processingSystem->processingClientQueryToDB(handler, queryToDB);
}
if(handler->getClient()->getClientType() == TypeClientAutorization::TYPE_UNITY_CLIENT)
{
ClientQueryToDB queryToDB;
queryToDB.typeQuery = TypeQueryToDB::TYPE_QUERY_GET_CONTACT_LIST;
processingSystem->processingClientQueryToDB(handler, queryToDB);
}
}
}
void CommonClientHandler::slot_ListGroupsChanged()
{
//Проходим все открытые сокеты
foreach(int idSocket, clientsMap->keys())
{
ClientHandler *handler = clientsMap->value(idSocket);
//Проверяем, есть ли клиенты TYPE_GUI
if(handler->getClient()->getTypeClient() == TypeClientAutorization::TYPE_GUI)
{//Отправляем этому клиенту обновление списков
ClientQueryToDB queryToDB;
queryToDB.typeQuery = TypeQueryToDB::TYPE_QUERY_GET_ALL_GROUPS;
processingSystem->processingClientQueryToDB(handler, queryToDB);
}

View File

@@ -6,6 +6,7 @@
class ProcessingSystem;
class DataParser;
class ClientHandler;
class Logger;
class CommonClientHandler : public QObject
@@ -19,7 +20,10 @@ public:
void sendNewVersionListToAllClient();
void sendCurrentVersionToAllClient();
void slot_ListsInstructorsTraineesChanged();
void slot_ListsInstructorsTraineesChanged_forUserID(int id_user);
void slot_ListInstructorsChanged();
void slot_ListTraineesChanged();
void slot_ListGroupsChanged();
void slot_StatusTasksAMMofTraineeChanged(int trainee_id);
void slot_StatusTasksFIMofTraineeChanged(int trainee_id);

View File

@@ -8,7 +8,7 @@ DocsUpdater::DocsUpdater(UpdateController* updateController, QObject *parent):
updateController(updateController),
flagStop(false)
{
qDebug() << "DocsUpdater init thread ID " << QThread::currentThreadId();
}
DocsUpdater::~DocsUpdater()
@@ -37,8 +37,10 @@ QList<SubProc> DocsUpdater::getListSubProcForDMcode(QString dmCode)
return listSubProcMap.value(dmCode);
}
bool DocsUpdater::updateDocsXML()
bool DocsUpdater::slot_updateDocsXML()
{
qDebug() << "DocsUpdater::slot_updateDocsXML thread ID " << QThread::currentThreadId();
QMutexLocker locker(&mtxAccess);
QString pathDocsFile = updateController->getPathAdditionalFile(tasksAMMfileName);
@@ -97,6 +99,8 @@ bool DocsUpdater::updateDocsXML()
}
}
emit signal_DocsChanged();
emit signal_UpdateDocsCompleted();
return true;
}

View File

@@ -16,9 +16,10 @@ public:
void lockAccessToDocsXML();
void unLockAccessToDocsXML();
QList<SubProc> getListSubProcForDMcode(QString dmCode);
QList<SubProc> getListSubProcForDMcode(QString dmCode);
bool updateDocsXML();
public slots:
bool slot_updateDocsXML();
private:
void domElementParserAMM(QDomElement element, Module* moduleParent);
@@ -27,6 +28,10 @@ private:
void selectSubProc(QDomElement& modeElement, QList<SubProc>& listSubProc);
DM* getDMmoduleByDMcode(QString dmCode);
signals:
void signal_DocsChanged();
void signal_UpdateDocsCompleted();
private:
UpdateController* updateController;

View File

@@ -2,6 +2,7 @@
#include "providerdblms.h"
#include <clienthandler.h>
#include <QMap>
ProcessingSystem::ProcessingSystem(ProviderDBLMS* providerDBLMS, UpdateController* updateController, DocsUpdater* docsUpdater, CfiController* cfiController, QObject *parent):
QObject(parent),
@@ -10,6 +11,8 @@ ProcessingSystem::ProcessingSystem(ProviderDBLMS* providerDBLMS, UpdateControlle
cfiController(nullptr),
providerDBLMS(nullptr)
{
qDebug() << "ProcessingSystem init thread ID " << QThread::currentThreadId();
this->providerDBLMS = providerDBLMS;
this->updateController = updateController;
this->docsUpdater = docsUpdater;
@@ -21,13 +24,18 @@ void ProcessingSystem::initialize(MultiThreadServer *server, DataParser *dataPar
UpdateController *updateController,
ChatSystem *chatSystem)
{
qDebug() << "ProcessingSystem::initialize thread ID " << QThread::currentThreadId();
this->commonClientServer = commonClientHandler;
this->dataParser = dataParser;
this->server = server;
this->updateController = updateController;
this->chatSystem = chatSystem;
connect(this,&ProcessingSystem::sigListsInstructorsTraineesChanged,commonClientHandler, &CommonClientHandler::slot_ListsInstructorsTraineesChanged,Qt::AutoConnection);
connect(this,&ProcessingSystem::sigListsInstructorsTraineesChanged_forUserID,commonClientHandler, &CommonClientHandler::slot_ListsInstructorsTraineesChanged_forUserID,Qt::AutoConnection);
connect(this,&ProcessingSystem::sigListInstructorsChanged,commonClientHandler, &CommonClientHandler::slot_ListInstructorsChanged,Qt::AutoConnection);
connect(this,&ProcessingSystem::sigListTraineesChanged,commonClientHandler, &CommonClientHandler::slot_ListTraineesChanged,Qt::AutoConnection);
connect(this,&ProcessingSystem::sigListGroupsChanged,commonClientHandler, &CommonClientHandler::slot_ListGroupsChanged,Qt::AutoConnection);
connect(this,&ProcessingSystem::sigStatusTasksAMMofTraineeChanged,commonClientHandler, &CommonClientHandler::slot_StatusTasksAMMofTraineeChanged,Qt::AutoConnection);
connect(this,&ProcessingSystem::sigStatusTasksFIMofTraineeChanged,commonClientHandler, &CommonClientHandler::slot_StatusTasksFIMofTraineeChanged,Qt::AutoConnection);
@@ -98,6 +106,18 @@ void ProcessingSystem::processingClientAutorization(ClientHandler *client, Clien
{
client->sendVersion();
if(clientAutorization.TypeClient == TypeClientAutorization::TYPE_GUI)
{//Отправляем этому клиенту обновление ВСЕХ списков
emit sigListsInstructorsTraineesChanged_forUserID(clientID);
ClientQueryTasksXML clientQueryTasksXML;
clientQueryTasksXML.Type = "fim";
processingClientQueryTasksXML(client, clientQueryTasksXML);
clientQueryTasksXML.Type = "amm";
processingClientQueryTasksXML(client, clientQueryTasksXML);
}
//Отправляем состояние блокировки
/*
if(server->getStateBlockAutorization() == EStateBlockAutorization::blocked)
@@ -110,7 +130,13 @@ void ProcessingSystem::processingClientAutorization(ClientHandler *client, Clien
//client->sendPacketType(PacketType::FREE);
//Извещаем об изменениях в авторизации
emit sigListsInstructorsTraineesChanged();
if(client->getClient()->getAccessType() == UserType::INSTRUCTOR)
{
//emit sigListGroupsChanged();
emit sigListInstructorsChanged();
}
else if(client->getClient()->getAccessType() == UserType::TRAINEE)
emit sigListTraineesChanged();
}
else
{
@@ -169,7 +195,7 @@ void ProcessingSystem::processingClientDeAutorization(ClientHandler *client, Cli
client->sendXmlAnswer(arrayAnswer);
//Извещаем об изменениях в авторизации
emit sigListsInstructorsTraineesChanged();
emit sigListTraineesChanged();
}
else if(providerDBLMS->deAuthorizationInstructor(clientDeAutorization.Login))
{//ДеАвторизуется инструктор
@@ -187,7 +213,7 @@ void ProcessingSystem::processingClientDeAutorization(ClientHandler *client, Cli
providerDBLMS->signal_BlockAutorization(false, fullName, "DeAuthorizationInstructor");
//Извещаем об изменениях в авторизации
emit sigListsInstructorsTraineesChanged();
emit sigListInstructorsChanged();
}
else
{//Никто не ДеАвторизовался
@@ -277,7 +303,7 @@ void ProcessingSystem::processingExitUnityClient(ClientHandler *client)
void ProcessingSystem::processingClientQueryToDB(ClientHandler *client, ClientQueryToDB clientQueryToDB, int id, void* data)
{
qDebug() << "ProcessingQueryThread " << QThread::currentThreadId();
qDebug() << "ProcessingSystem::processingClientQueryToDB thread ID " << QThread::currentThreadId();
switch (clientQueryToDB.typeQuery)
{
@@ -301,16 +327,53 @@ void ProcessingSystem::processingClientQueryToDB(ClientHandler *client, ClientQu
//client->sendXmlAnswer(arrayAnswer, PacketType::TYPE_XMLANSWER_QUERY_DB__LIST_TRAINEES);
client->sendFileBlockByteArray(arrayAnswer, PacketType::TYPE_XMLANSWER_QUERY_DB__LIST_TRAINEES);
for(Trainee trainee : listTrainees)
if(listTrainees.count())
{
//Отправка списка задач AMM этого обучаемого клиенту GUI
sendListTasksAMMofTraineetoClient(client, trainee.getID());
//Отправка списка задач FIM этого обучаемого клиенту GUI
sendListTasksFIMofTraineetoClient(client, trainee.getID());
//Отправка списка задач FIM всех обучаемых клиенту GUI
sendListsTasksFIMofAllTraineestoClient(client, listTrainees);
//Отправка списка задач AMM всех обучаемых клиенту GUI
sendListsTasksAMMofAllTraineestoClient(client, listTrainees);
}
break;
}
case TypeQueryToDB::TYPE_QUERY_GET_ALL_INSTRUCTORS:
{
QList<Instructor> listInstructors = providerDBLMS->GetListAllInstructors();
QByteArray arrayAnswer;
arrayAnswer = dataParser->DbAnswer()->listInstructors(true, &listInstructors);
//client->sendXmlAnswer(arrayAnswer, PacketType::TYPE_XMLANSWER_QUERY_DB__LIST_INSTRUCTORS);
client->sendFileBlockByteArray(arrayAnswer, PacketType::TYPE_XMLANSWER_QUERY_DB__LIST_INSTRUCTORS);
break;
}
case TypeQueryToDB::TYPE_QUERY_GET_ALL_TRAINEES:
{
QList<Trainee> listTrainees = providerDBLMS->GetListAllTrainees();
QByteArray arrayAnswer;
arrayAnswer = dataParser->DbAnswer()->listTrainees(true, &listTrainees);
//client->sendXmlAnswer(arrayAnswer, PacketType::TYPE_XMLANSWER_QUERY_DB__LIST_TRAINEES);
client->sendFileBlockByteArray(arrayAnswer, PacketType::TYPE_XMLANSWER_QUERY_DB__LIST_TRAINEES);
break;
}
case TypeQueryToDB::TYPE_QUERY_GET_ALL_GROUPS:
{
QList<Group> listGroups = providerDBLMS->GetListAllGroups();
QByteArray arrayAnswer;
arrayAnswer = dataParser->DbAnswer()->listGroups(true, &listGroups);
//client->sendXmlAnswer(arrayAnswer, PacketType::TYPE_XMLANSWER_QUERY_DB__LIST_GROUPS);
client->sendFileBlockByteArray(arrayAnswer, PacketType::TYPE_XMLANSWER_QUERY_DB__LIST_GROUPS);
break;
}
case TypeQueryToDB::TYPE_QUERY_NEW_INSTRUCTOR:
{
int id_new;
@@ -320,19 +383,19 @@ void ProcessingSystem::processingClientQueryToDB(ClientHandler *client, ClientQu
(*(Instructor*)data).setID(id_new);
providerDBLMS->editInstructor(*(Instructor*)data);
}
emit sigListsInstructorsTraineesChanged();
emit sigListInstructorsChanged();
break;
}
case TypeQueryToDB::TYPE_QUERY_DEL_INSTRUCTOR:
{
providerDBLMS->delInstructor(id);
emit sigListsInstructorsTraineesChanged();
emit sigListInstructorsChanged();
break;
}
case TypeQueryToDB::TYPE_QUERY_EDIT_INSTRUCTOR:
{
providerDBLMS->editInstructor(*(Instructor*)data);
emit sigListsInstructorsTraineesChanged();
emit sigListInstructorsChanged();
break;
}
@@ -345,19 +408,19 @@ void ProcessingSystem::processingClientQueryToDB(ClientHandler *client, ClientQu
(*(Trainee*)data).setID(id_new);
providerDBLMS->editTrainee(*(Trainee*)data);
}
emit sigListsInstructorsTraineesChanged();
emit sigListTraineesChanged();
break;
}
case TypeQueryToDB::TYPE_QUERY_DEL_TRAINEE:
{
providerDBLMS->delTrainee(id);
emit sigListsInstructorsTraineesChanged();
emit sigListTraineesChanged();
break;
}
case TypeQueryToDB::TYPE_QUERY_EDIT_TRAINEE:
{
providerDBLMS->editTrainee(*(Trainee*)data);
emit sigListsInstructorsTraineesChanged();
emit sigListTraineesChanged();
break;
}
@@ -370,19 +433,19 @@ void ProcessingSystem::processingClientQueryToDB(ClientHandler *client, ClientQu
(*(Group*)data).setID(id_new);
providerDBLMS->editGroup(*(Group*)data);
}
emit sigListsInstructorsTraineesChanged();
emit sigListGroupsChanged();
break;
}
case TypeQueryToDB::TYPE_QUERY_DEL_GROUP:
{
providerDBLMS->delGroup(id);
emit sigListsInstructorsTraineesChanged();
emit sigListGroupsChanged();
break;
}
case TypeQueryToDB::TYPE_QUERY_EDIT_GROUP:
{
providerDBLMS->editGroup(*(Group*)data);
emit sigListsInstructorsTraineesChanged();
emit sigListGroupsChanged();
break;
}
@@ -637,8 +700,6 @@ void ProcessingSystem::processingClientNotify(ClientHandler *client, ClientNotif
}
else if(clientNotify.Code == commandDisableClient)
{
qDebug() << "processing thread: " << QThread::currentThreadId();
//Фиксируем время выхода Юнити-клиента
if (clientData->getClientType() == TypeClientAutorization::TYPE_UNITY_CLIENT)
{
@@ -697,6 +758,36 @@ void ProcessingSystem::sendListTasksFIMofTraineetoClient(ClientHandler *client,
client->sendFileBlockByteArray(arrayAnswer, PacketType::TYPE_XMLANSWER_QUERY_TASKS_FIM_OF_TRAINEE);
}
void ProcessingSystem::sendListsTasksAMMofAllTraineestoClient(ClientHandler *client, QList<Trainee> listTrainees)
{
QMap<int, QList<TaskAmmFim>> mapOfLists;
for(Trainee trainee : listTrainees)
{
int id_trainee = trainee.getID();
QList<TaskAmmFim> listTasksOneTrainee = providerDBLMS->GetListTasksAMMofTrainee(id_trainee);
if(listTasksOneTrainee.count())
mapOfLists.insert(id_trainee, listTasksOneTrainee);
}
QByteArray arrayAnswer = dataParser->DbAnswer()->listsTasksAMMofAllTrainees(&mapOfLists);
client->sendFileBlockByteArray(arrayAnswer, PacketType::TYPE_XMLANSWER_QUERY_TASKS_AMM_OF_ALL_TRAINEES);
}
void ProcessingSystem::sendListsTasksFIMofAllTraineestoClient(ClientHandler *client, QList<Trainee> listTrainees)
{
QMap<int, QList<TaskAmmFim>> mapOfLists;
for(Trainee trainee : listTrainees)
{
int id_trainee = trainee.getID();
QList<TaskAmmFim> listTasksOneTrainee = providerDBLMS->GetListTasksFIMofTrainee(id_trainee);
if(listTasksOneTrainee.count())
mapOfLists.insert(id_trainee, listTasksOneTrainee);
}
QByteArray arrayAnswer = dataParser->DbAnswer()->listsTasksFIMofAllTrainees(&mapOfLists);
client->sendFileBlockByteArray(arrayAnswer, PacketType::TYPE_XMLANSWER_QUERY_TASKS_FIM_OF_ALL_TRAINEES);
}
void ProcessingSystem::sendListTasksAMMofTraineeByIDtoClient(ClientHandler *client, int id_trainee, QList<int> listID)
{
QList<TaskAmmFim> listTasksNeed;

View File

@@ -5,7 +5,6 @@
#include <Data/typesDataServerClient.h>
#include <clienthandler.h>
#include <serverlmswidget.h>
#include "multithreadserver.h"
//#include "instructorsandtraineeswidget.h"
#include "chatsystem.h"
@@ -22,6 +21,7 @@ class ClientHandler;
class CommonClientHandler;
class MultiThreadServer;
class CfiController;
class ChatSystem;
class ProcessingSystem : public QObject
{
@@ -50,6 +50,10 @@ public:
void sendListTasksAMMofTraineetoClient(ClientHandler* client, int id_trainee);
void sendListTasksFIMofTraineetoClient(ClientHandler* client, int id_trainee);
void sendListsTasksAMMofAllTraineestoClient(ClientHandler *client, QList<Trainee> listTrainees);
void sendListsTasksFIMofAllTraineestoClient(ClientHandler* client, QList<Trainee> listTrainees);
void sendListTasksAMMofTraineeByIDtoClient(ClientHandler* client, int id_trainee, QList<int> listID);
void sendListTasksFIMofTraineeByIDtoClient(ClientHandler* client, int id_trainee, QList<int> listID);
@@ -65,7 +69,10 @@ public:
void processingExitUnityClient(ClientHandler *client);
signals:
void sigUpdateListClients();
void sigListsInstructorsTraineesChanged();
void sigListsInstructorsTraineesChanged_forUserID(int id_user);
void sigListInstructorsChanged();
void sigListTraineesChanged();
void sigListGroupsChanged();
void sigStatusTasksAMMofTraineeChanged(int trainee_id);
void sigStatusTasksFIMofTraineeChanged(int trainee_id);
void sigAddToMessanger(QString login,QString text);

View File

@@ -13,12 +13,12 @@ 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)
{
qDebug() << "RecognizeSystem::initialize thread ID " << QThread::currentThreadId();
this->updateController = updateController;
this->dataParser = dataParser;
this->server = server;
this->clientHandler = handler;
this->sendSystem = sendSystem;
socket = handler->getSocket();
@@ -28,16 +28,14 @@ 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::sigSendDocs,sendSystem,&SendSystem::sendDocs,Qt::AutoConnection);
qDebug() << "Recognize init thread ID " << QThread::currentThreadId();
//connect(this,&RecognizeSystem::sigRecalculateDocs,server,&ServerLMSWidget::slot_UpdateDocs,Qt::AutoConnection);
connect(this,&RecognizeSystem::sigSendDocs,sendSystem,&SendSystem::sendDocs,Qt::AutoConnection);
}
void RecognizeSystem::recognize()
{
QMutexLocker locker(mutex);
qDebug() << "Recognize thread ID " << QThread::currentThreadId();
qDebug() << "RecognizeSystem::recognize thread ID " << QThread::currentThreadId();
QMutexLocker locker(mutex);
QDataStream stream(socket);
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
QByteArray data;
@@ -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)

View File

@@ -12,10 +12,7 @@
#include <Data/Client.h>
#include <Data/PacketType.h>
#include "serverlmswidget.h"
class UpdateController;
class ServerLMSWidget;
class ClientHandler;
class RecognizeSystem : public QObject
@@ -25,8 +22,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 +33,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;

View File

@@ -7,12 +7,13 @@ SendSystem::SendSystem(QObject *parent) : QObject(parent)
void SendSystem::initialize(DataParser *dataParser,QMutex *globalMutex)
{
this->dataParser = dataParser;
connect(this,&SendSystem::sigSendXMLmessage,dataParser->ClientAnswer(),&ClientAnswerParser::message,Qt::AutoConnection);
connect(this,&SendSystem::sigSendNotify,dataParser->ClientAnswer(),&ClientAnswerParser::notify,Qt::DirectConnection); //потому что возвращает значение
connect(this,&SendSystem::sigSendVersion,dataParser->ClientAnswer(),&ClientAnswerParser::currentVersion,Qt::AutoConnection);
qDebug() << "SendSystem::initialize thread ID " << QThread::currentThreadId();
this->dataParser = dataParser;
//connect(this,&SendSystem::sigSendXMLmessage,dataParser->ClientAnswer(),&ClientAnswerParser::message,Qt::AutoConnection); //сигнал не используется
connect(this,&SendSystem::sigSendNotify,dataParser->ClientAnswer(),&ClientAnswerParser::notify,Qt::DirectConnection); //потому что возвращает значение
//connect(this,&SendSystem::sigSendVersion,dataParser->ClientAnswer(),&ClientAnswerParser::currentVersion,Qt::AutoConnection); //сигнал не используется
qDebug() << "SendSystem thread: " << QThread::currentThreadId();
mutex = globalMutex;
}
@@ -26,7 +27,8 @@ void SendSystem::setClient(Client *client,QTcpSocket *socket)
void SendSystem::sendNotify(QString notify)
{
qDebug() << "SendNotify thread: " << QThread::currentThreadId();
qDebug() << "SendSystem::sendNotify thread ID " << QThread::currentThreadId();
auto answer = emit sigSendNotify(notify);
sendXmlAnswer(answer);
}
@@ -85,7 +87,7 @@ void SendSystem::sendFileBlockByteArray(QByteArray array, PacketType packetType)
QDataStream stream(socket);
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
quint64 size = array.size();
qint64 size = array.size();
qint64 bytesSended = 0;
if (size == 0)
@@ -97,19 +99,18 @@ void SendSystem::sendFileBlockByteArray(QByteArray array, PacketType packetType)
stream << packetType; //Отправляем тип блока
stream << size;
while (size > 0)
while (bytesSended < size)
{
QByteArray chunk = array.mid(bytesSended,sendFileBlockSize);
stream << chunk;
bytesSended += chunk.length();
size -= bytesSended;
}
}
else
{
sendPacketType(packetType);
quint64 size = array.size();
qint64 size = array.size();
qint64 bytesSended = 0;
if (size == 0)
@@ -141,7 +142,7 @@ void SendSystem::sendVersion()
void SendSystem::sendFileBlockWithRename(QString path, QString newName)
{
qDebug() << "sendFileBlockWithRename thread: " << QThread::currentThreadId();
qDebug() << "SendSystem::sendFileBlockWithRename thread ID " << QThread::currentThreadId();
QDataStream stream(socket);
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
@@ -233,7 +234,8 @@ void SendSystem::sendPacketType(PacketType packetType)
void SendSystem::sendXmlAnswer(QByteArray array, PacketType packetType)
{
qDebug() << "SendSystemThread: " << QThread::currentThreadId();
qDebug() << "SendSystem::sendXmlAnswer thread ID " << QThread::currentThreadId();
Logger::instance().log("SEND TO: "+ client->getLogin() + " " + enumToString(packetType) + "\n Text: " +
QString(array),LogLevel::DEBUG);
@@ -316,11 +318,6 @@ void SendSystem::socketClose()
socket->close();
}
bool SendSystem::socketFlush() //TODO: проверить использование
{
return socket->flush();
}
void SendSystem::sendStop()
{
isSendStopped = true;

View File

@@ -35,7 +35,6 @@ public:
void sendXmlAnswer(QByteArray array, PacketType packetType = PacketType::TYPE_XMLANSWER);
void sendNeedUpdate(bool flag,quint64 size,quint64 fileCount,quint64 deleteCount);
void updateFiles(QList<FileData> fileSendList, QList<FileData> deleteList);
bool socketFlush();
bool getIsSendStopped() const;
@@ -49,9 +48,9 @@ public slots:
signals:
void sigLoadHash();
QByteArray sigSendXMLmessage(QString loginFrom, QString loginTo, QString text, QString userType);
//QByteArray sigSendXMLmessage(QString loginFrom, QString loginTo, QString text, QString userType); //сигнал не используется
QByteArray sigSendNotify(QString message);
QByteArray sigSendVersion();
//QByteArray sigSendVersion(); //сигнал не используется
private:
Client *client;

View File

@@ -1,3 +1,4 @@
#include <QThread>
#include "updatecontroller.h"
@@ -5,16 +6,19 @@ UpdateController::UpdateController(QObject *parent) :
QObject(parent),
commonClientHandler(nullptr)
{
qDebug() << "UpdateController init thread ID " << QThread::currentThreadId();
buildPath = QDir::currentPath() + "/" + applicationFolderName;
sharedDataPath = QDir::currentPath() + "/" + sharedDataFolderName;
Logger::instance().log(buildPath);
qDebug() << hashFileName;
}
void UpdateController::initialize(CommonClientHandler *commonClientHandler,DataParser *dataParser,AssetsManager *assetManager)
void UpdateController::initialize(CommonClientHandler *commonClientHandler,AssetsManager *assetManager)
{
qDebug() << "UpdateController::initialize thread ID " << QThread::currentThreadId();
this->commonClientHandler = commonClientHandler;
this->dataParser = dataParser;
this->assetManager = assetManager;
hashCalculator = new FastHashCalculator;
@@ -24,7 +28,7 @@ void UpdateController::initialize(CommonClientHandler *commonClientHandler,DataP
}
sizeToSend = 0;
assetManager->initialize(this,dataParser);
assetManager->initialize(this);
if (!checkRequiredFolder())
{
@@ -37,19 +41,20 @@ void UpdateController::initialize(CommonClientHandler *commonClientHandler,DataP
setUpCurrentServerHash();
mutex = new QMutex;
qDebug() << "UpdateController init thread ID " << QThread::currentThreadId();
emit sigInitializeFinished();
}
void UpdateController::changeAssetVersion(QString versionName)
{
qDebug() << "UpdateController::changeAssetVersion thread ID " << QThread::currentThreadId();
//commonClientHandler->slot_sendPacketToAllClients(PacketType::BUSY);
bool res = emit signal_BlockAutorization(true, "SERVER", "ChangeAssetVersion");
qDebug() << "UpdateController thread ID " << QThread::currentThreadId();
currentStreamingPath = assetManager->setVersion(versionName);
setUpCurrentServerHash();
emit sigUpdateDocs();
emit sigUpdateDocsXML();
commonClientHandler->slot_sendPacketToAllClients(PacketType::HASH_READY, false);
commonClientHandler->sendCurrentVersionToAllClient();

View File

@@ -10,14 +10,14 @@
#include <QMutex>
#include <QApplication>
#include <QMessageBox>
#include <Systems/Parsers/dataparser.h>
#include <Data/typesDataServerClient.h>
#include <Data/StreamingVersionData.h>
#include "fasthashcalculator.h"
#include "assetsmanager.h"
#include "commonclienthandler.h"
class TCPServer;
class SendSystem;
class DataParser;
class ClientHandler;
class AssetsManager;
class ServerLMSWidget;
@@ -30,7 +30,7 @@ class UpdateController : public QObject
public:
explicit UpdateController(QObject *parent = 0);
void initialize(CommonClientHandler* commonClientHandler,DataParser *dataParser,AssetsManager *assetManager);
void initialize(CommonClientHandler* commonClientHandler,AssetsManager *assetManager);
void compareFiles(ClientHandler* handler, QByteArray array);
void showHash();
void calculateFullHash();
@@ -67,7 +67,7 @@ public slots:
signals:
void sigErrorRequired(int code);
void sigUpdateDocs();
void sigUpdateDocsXML();
void sigInitializeFinished();
@@ -85,7 +85,6 @@ private:
QString sharedDataPath;
CommonClientHandler *commonClientHandler;
FastHashCalculator *hashCalculator;
DataParser *dataParser;
AssetsManager *assetManager;
quint64 sizeToSend;
QMutex *mutex;

View File

@@ -5,6 +5,8 @@ CfiController::CfiController(UpdateController* updateController, QObject *parent
updateController(updateController),
germanLocale(nullptr)
{
qDebug() << "CfiController init thread ID " << QThread::currentThreadId();
germanLocale = new QLocale(QLocale::German);
}

View File

@@ -1,4 +1,5 @@
#include "clienthandler.h"
#include "recognizesystem.h"
#include <QThread>
@@ -7,10 +8,11 @@
ClientHandler::ClientHandler( QObject *parent):
QObject(parent)
{
qDebug() << "ClientHandler init thread ID " << QThread::currentThreadId();
}
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;
@@ -18,7 +20,7 @@ void ClientHandler::initialize(int descriptor,ServerLMSWidget *serverWidget,
socket->setParent(nullptr);
socket->setSocketDescriptor(descriptor);
qDebug() << "Client thread: " << QThread::currentThreadId();
qDebug() << "ClientHandler::initialize thread ID " << QThread::currentThreadId();
sendSystem = new SendSystem;
recognizeSystem = new RecognizeSystem;
@@ -30,7 +32,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,28 +39,30 @@ 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);
connect(this,&ClientHandler::sigFileBlockByteArray,sendSystem,&SendSystem::sendFileBlockByteArray,Qt::AutoConnection);
connect(this,&ClientHandler::sigFolderBlock,sendSystem,&SendSystem::sendFolderBlock,Qt::AutoConnection);
connect(this,&ClientHandler::sigGetIsSendStopped,sendSystem,&SendSystem::getIsSendStopped,Qt::AutoConnection);
connect(this,&ClientHandler::sigGetIsSendStopped,sendSystem,&SendSystem::getIsSendStopped,/*Qt::AutoConnection*/Qt::DirectConnection); //Возвращает значение
connect(this,&ClientHandler::sigSendDeleteBlock,sendSystem,&SendSystem::sendDeleteBlock,Qt::AutoConnection);
connect(this,&ClientHandler::sigNeedUpdate,sendSystem,&SendSystem::sendNeedUpdate,Qt::AutoConnection);
connect(this,&ClientHandler::sigSendNotify,sendSystem,&SendSystem::sendNotify,Qt::AutoConnection);
connect(this,&ClientHandler::sigSendFileBlockWithRename,sendSystem,&SendSystem::sendFileBlockWithRename,Qt::AutoConnection);
connect(this,&ClientHandler::sigSendVersion,sendSystem,&SendSystem::sendVersion,Qt::AutoConnection);
connect(this,&ClientHandler::sigSocketClose,sendSystem,&SendSystem::socketClose,Qt::AutoConnection);
connect(this,&ClientHandler::sigSocketFlush,sendSystem,&SendSystem::socketFlush,Qt::AutoConnection);
//connect(this,&ClientHandler::sigSocketFlush,sendSystem,&SendSystem::socketFlush,Qt::AutoConnection); //не используется
connect(this,&ClientHandler::sigSendPacketType,sendSystem,&SendSystem::sendPacketType,Qt::AutoConnection);
connect(this,&ClientHandler::sigSendStop,sendSystem,&SendSystem::sendStop,Qt::DirectConnection);
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");
}

View File

@@ -64,17 +64,19 @@ signals:
void sigSendNotify(QString notify);
void sigSendFileBlockWithRename (QString path,QString newName);
void sigSocketClose();
bool sigSocketFlush();
//bool sigSocketFlush(); //не используется
void sigSendVersion();
void sigSendPacketType(PacketType packetType);
void sigSendStop();
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);

View File

@@ -6,4 +6,11 @@ void registerMetaType()
qRegisterMetaType<PacketType>("PacketType");
qRegisterMetaType<UserType>("UserType");
qRegisterMetaType<LogLevel>("LogLevel");
qRegisterMetaType<QStringList>("QStringList");
qRegisterMetaType<DataBaseSettings>("DataBaseSettings");
qRegisterMetaType<EStateServer>("EStateServer");
qRegisterMetaType<EStateBlockAutorization>("EStateBlockAutorization");
qRegisterMetaType<CheckResult>("CheckResult");
}

View File

@@ -4,11 +4,20 @@
#include "Data/PacketType.h"
#include "Data/typesDataServerClient.h"
#include "Systems/logger.h"
#include "databaselms.h"
#include "providerdblms.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)
Q_DECLARE_METATYPE(CheckResult)
#endif // METATYPES_H

View File

@@ -1,27 +1,41 @@
#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)
{
qDebug() << "MultiThreadServer init thread ID " << QThread::currentThreadId();
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 +54,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;
stateServer = started;
slot_BlockAutorization(false, "SERVER", "StopServer");
emit signal_StateServer(stateServer, stateBlockAutorization);
Logger::instance().log("SERVER: start OK");
return true;
}
@@ -71,6 +84,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 +97,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 +176,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 +284,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());
}

View File

@@ -1,27 +1,34 @@
#ifndef MULTITHREADSERVER_H
#define MULTITHREADSERVER_H
#include "serverlmswidget.h"
#include "Systems/processingsystem.h"
#include "clienthandler.h"
#include "Data/PacketType.h"
#include "updatecontroller.h"
#include "Parsers/dataparser.h"
#include <QObject>
class ProcessingSystem;
class ClientHandler;
class DocsUpdater;
class DataParser;
class UpdateController;
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 +37,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;

View File

@@ -2,13 +2,15 @@
#include <QThread>
#include <QMessageBox>
#include "specialmessagebox.h"
ProviderDBLMS::ProviderDBLMS(QWidget *parentWidget, QObject *parent) :
ProviderDBLMS::ProviderDBLMS(QObject *parent) :
QObject(parent),
dbLMS(nullptr),
parentWidget(parentWidget)
dbLMS(nullptr)
{
dbLMS = new InterfaceDataBaseLMS(parentWidget);
qDebug() << "ProviderDBLMS init thread ID " << QThread::currentThreadId();
dbLMS = new InterfaceDataBaseLMS();
connect(dbLMS, &InterfaceDataBaseLMS::signal_ErrorPostgreSQL, this, &ProviderDBLMS::signal_ErrorPostgreSQL);
}
@@ -17,6 +19,55 @@ ProviderDBLMS::~ProviderDBLMS()
DisConnectionFromDB();
}
void ProviderDBLMS::slot_TryConnectionToDB()
{
ConnectionToDB();
}
void ProviderDBLMS::slot_TryDisConnectionFromDB()
{
DisConnectionFromDB();
}
void ProviderDBLMS::slot_CheckDB()
{
CheckResult result;
result.resDriver = ProviderDBLMS::checkDriverQPSQLavailable();
result.resUser = this->checkUserLMSexist();
result.resDB = this->checkDataBaseLMSexist();
emit signal_CheckDBResult(result);
}
void ProviderDBLMS::slot_RepareDB(CheckResult result)
{
if(!result.resUser)
{
if(!this->createUser())
{
result.resUser = false;
emit signal_RepareDBResult(result);
}
else
result.resUser = true;
}
if(!result.resDB)
{
if(!this->createDB())
{
result.resDB = false;
emit signal_RepareDBResult(result);
}
else
result.resDB = true;
}
emit signal_RepareDBResult(result);
}
bool ProviderDBLMS::ConnectionToDB()
{
mtxAccess.lock();
@@ -26,15 +77,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 +113,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();
}
@@ -62,17 +141,17 @@ bool ProviderDBLMS::DBisConnected()
DataBaseSettings ProviderDBLMS::getDBSettings()
{
return dbLMS->getDataBaseSettings();
return InterfaceDataBaseLMS::getDataBaseSettings();
}
bool ProviderDBLMS::setUserPasswordPostgres(QString userName, QString password)
{
return dbLMS->setUserPasswordPostgres(userName, password);
return InterfaceDataBaseLMS::setUserPasswordPostgres(userName, password);
}
bool ProviderDBLMS::checkDriverQPSQLavailable()
{
return dbLMS->checkDriverQPSQLavailable();
return InterfaceDataBaseLMS::checkDriverQPSQLavailable();
}
bool ProviderDBLMS::checkUserLMSexist()

View File

@@ -6,11 +6,19 @@
#include "interfacedatabaselms.h"
#include "tasksAmmFim.h"
class CheckResult
{
public:
bool resDriver = false;
bool resUser = false;
bool resDB = false;
};
class ProviderDBLMS : public QObject
{
Q_OBJECT
public:
explicit ProviderDBLMS(QWidget *parentWidget, QObject *parent = nullptr);
explicit ProviderDBLMS(QObject *parent = nullptr);
~ProviderDBLMS();
public:
QString getMainInstructorName();
@@ -75,16 +83,32 @@ 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);
void signal_CheckDBResult(CheckResult result);
void signal_RepareDBResult(CheckResult result);
public slots:
void slot_TryConnectionToDB();
void slot_TryDisConnectionFromDB();
void slot_CheckDB();
void slot_RepareDB(CheckResult result);
private:
bool ConnectionToDB();
void DisConnectionFromDB();
public:
bool DBisConnected();
DataBaseSettings getDBSettings();
static DataBaseSettings getDBSettings();
//PostgreSQL
bool setUserPasswordPostgres(QString userName, QString password);
bool checkDriverQPSQLavailable();
static bool checkDriverQPSQLavailable();
static bool setUserPasswordPostgres(QString userName, QString password);
bool checkUserLMSexist();
bool checkDataBaseLMSexist();
@@ -94,7 +118,6 @@ public:
private:
InterfaceDataBaseLMS* dbLMS;
QMutex mtxAccess;
QWidget *parentWidget;
};
#endif // PROVIDERDBLMS_H

View File

@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<ListsTasksAMMofAllTrainees>
</ListsTasksAMMofAllTrainees>

View File

@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<ListsTasksFIMofAllTrainees>
</ListsTasksFIMofAllTrainees>

View File

@@ -1,40 +1,43 @@
#include <QXmlStreamWriter>
#include <QXmlStreamReader>
#include <QXmlStreamAttribute>
#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),
server(nullptr),
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),
language(languageENG),
errorCode(0),
versionStr("..."),
flStartInitialization(false)
state_VersionMaterials("..."),
state_dbIsConnected(false),
state_Server(EStateServer::stoped),
state_BlockAutorization(EStateBlockAutorization::unblocked),
flStartInitialization(false),
flTryConnectionToDB(false),
flNeedReconnectDB(false),
flTryUpdateDocs(false)
{
ui->setupUi(this);
@@ -49,53 +52,88 @@ 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);
waitAnimationWidget->showWithPlay();
updateStateOnlyVersion();
}
ServerLMSWidget::~ServerLMSWidget()
{
if(flStartInitialization)
{
server->stopServer();
if(server)
emit signal_StopServer();
if(updateThread)
{
updateThread->quit();
updateThread->wait();
delete updateThread;
}
if(serverThread)
{
serverThread->quit();
serverThread->wait();
delete serverThread;
}
if(server)
delete server;
if(commonClientHandler)
delete commonClientHandler;
if(dataParser)
delete dataParser;
if(processingSystem)
delete processingSystem;
if(updateController)
delete updateController;
if(cfiController)
delete cfiController;
if(docsUpdater)
delete docsUpdater;
if(assetsManager)
delete assetsManager;
if(chatSystem)
delete chatSystem;
delete mutex;
if(loggerThread)
{
loggerThread->quit();
loggerThread->wait();
delete loggerThread;
delete providerDBLMS;
}
waitAnimationWidget->hideWithStop();
delete waitAnimationWidget;
if(providerDBLMS)
delete providerDBLMS;
if(waitAnimationWidget)
{
waitAnimationWidget->hideWithStop();
delete waitAnimationWidget;
}
delete ui;
}
//INTERFACE
void ServerLMSWidget::startInitialization()
{
startInitialization_step0();
}
QString ServerLMSWidget::getLanguage()
{
return language;
}
//EVENT
void ServerLMSWidget::changeEvent(QEvent *event)
{
// В случае получения события изменения языка приложения
@@ -103,9 +141,10 @@ void ServerLMSWidget::changeEvent(QEvent *event)
{
ui->retranslateUi(this); // переведём окно заново
//И все состояния
updateStateOnlyServer();
updateStateOnlyDB();
updateStateOnlyVersion();
updateStateOnlyVersionMaterials();
}
}
@@ -115,218 +154,8 @@ void ServerLMSWidget::resizeEvent(QResizeEvent *event)
waitAnimationWidget->resize(size);
}
void ServerLMSWidget::slot_UpdateListClients()
{
//Очищаем список
ui->listWidget_Clients->clear();
for (const ClientHandler *handler : server->getClientsMap()->values())
{
QString strClient = handler->getClient()->getFullName();
ui->listWidget_Clients->addItem(strClient);
ui->listWidget_Clients->scrollToBottom();
ui->listWidget_Clients->setCurrentRow(ui->listWidget_Clients->count() - 1);
}
int countClients = (*server->getClientsMap()).count();
Logger::instance().log("SERVER: countClients = " + QString::number(countClients));
}
void ServerLMSWidget::slot_AddMessageToLog(QString message)
{
//ui->loggerTextField->appendPlainText(message);
ui->loggerTextField->appendHtml(message);
}
void ServerLMSWidget::slot_ErrorPostgreSQL(QString text)
{
emit signal_Menu_ShowWindow();
SpecMsgBox::CriticalClose(this, tr("Error PostgreSQL!") + "\n" + text);
}
void ServerLMSWidget::slot_UpdateDocs()
{
QApplication::setOverrideCursor(Qt::WaitCursor);
if(docsUpdater->updateDocsXML())
emit signal_DocsChanged();
QApplication::restoreOverrideCursor();
//TODO для теста
//cfiController->test();
}
void ServerLMSWidget::slot_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();
updateStateOnlyVersion();
QApplication::restoreOverrideCursor();
if(hasError() == 100)
return;
Logger::instance().log("Try connection to DB...");
tryConnectionToDB();
waitAnimationWidget->hideWithStop();
}
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)
{
if(block)
{
//server->blockAutorization();
Logger::instance().log(QString("BLOCK from: %1").arg(blocker), LogLevel::INFO);
//if(type != "")
Logger::instance().log(QString("Blockers: %1").arg(types), LogLevel::DEBUG);
}
else
{
//server->unBlockAutorization();
Logger::instance().log(QString("UNBLOCK from: %1").arg(blocker), LogLevel::INFO);
//if(type != "")
Logger::instance().log(QString("Blockers: %1").arg(types), LogLevel::DEBUG);
}
updateStateOnlyServer();
}
void ServerLMSWidget::slot_LanguageChanged(QString language)
{
qtLanguageTranslator.load(QString("translations/RRJServer_") + language, ".");
qApp->installTranslator(&qtLanguageTranslator);
emit signal_LanguageChanged(language);
}
void ServerLMSWidget::on_btnStartServer_clicked()
{
if(server->startServer())
{
QApplication::setOverrideCursor(Qt::WaitCursor);
ui->btnStartServer->setEnabled(false);
ui->btnStopServer->setEnabled(true);
//slot_BlockAutorizationIndicate(false, "SERVER");
//updateStateOnlyServer();
emit signal_Tray_ShowMessage(tr("Server is started!"));
QApplication::restoreOverrideCursor();
}
}
void ServerLMSWidget::on_btnStopServer_clicked()
{
if(server->stopServer())
{
QApplication::setOverrideCursor(Qt::WaitCursor);
ui->btnStopServer->setEnabled(false);
ui->btnStartServer->setEnabled(true);
//slot_BlockAutorizationIndicate(true, "SERVER");
//updateStateOnlyServer();
emit signal_Tray_ShowMessage(tr("Server is stoped!"));
QApplication::restoreOverrideCursor();
}
}
void ServerLMSWidget::on_btnSettings_clicked()
{
ServerDBSettings settingsTemp;
if(!DialogSettingsTray::loadSettings(&settingsTemp))
{
SpecMsgBox::CriticalClose(this, tr("Settings file could not be opened:") + "'config/settings.xml'");
return;
}
DialogSettingsTray dlg(providerDBLMS, this);
dlg.setWindowFlags(dlg.windowFlags() & ~Qt::WindowContextHelpButtonHint);
connect(&dlg, &DialogSettingsTray::signal_LanguageChanged, this, &ServerLMSWidget::slot_LanguageChanged);
//connect(&dlg, &DialogSettingsTray::signal_UpdateStyleSheet, this, &ServerLMSWidget::slot_UpdateStyleSheet);
connect(&dlg, &DialogSettingsTray::signal_UpdateDocs, this, &ServerLMSWidget::slot_UpdateDocs);
switch( dlg.exec() )
{
case QDialog::Accepted:
{
language = dlg.getSettings().Language;
if(dlg.settingsDBisChanged())
{
on_btnStopServer_clicked();
providerDBLMS->deAuthorizationAll();
providerDBLMS->DisConnectionFromDB();
updateStateOnlyDB();
SpecMsgBox::WarningClose(this, tr("Database settings have been changed.\nThe server will be restarted."));
tryConnectionToDB();
}
break;
}
case QDialog::Rejected:
break;
default:
break;
}
}
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);
}
//STYLESHEET
void ServerLMSWidget::updateMyStyleSheet()
{
@@ -355,49 +184,390 @@ QString ServerLMSWidget::loadStyleSheet()
}
}
//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(state_Server == EStateServer::started)
{
if(state_BlockAutorization == 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_Tray_UpdateStateServer(state_Server, state_BlockAutorization);
}
void ServerLMSWidget::updateStateOnlyDB()
{
if(state_dbIsConnected)
{
//Настройки БД
QString strDBsettings = tr("connected") + QString(" [%1 (%2) %3 : %4]").arg(state_dbSettings.dbName,
state_dbSettings.dbType,
state_dbSettings.dbHostName,
QString::number(state_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(state_VersionMaterials);
}
//SLOTS
void ServerLMSWidget::slot_UpdateListClients(QStringList listFullName)
{
//Очищаем список
ui->listWidget_Clients->clear();
for (const QString clientFullName : listFullName)
{
ui->listWidget_Clients->addItem(clientFullName);
ui->listWidget_Clients->scrollToBottom();
ui->listWidget_Clients->setCurrentRow(ui->listWidget_Clients->count() - 1);
}
int countClients = listFullName.count();
Logger::instance().log("SERVER: countClients = " + QString::number(countClients));
}
void ServerLMSWidget::slot_AddMessageToLog(QString message)
{
ui->loggerTextField->appendHtml(message);
}
void ServerLMSWidget::slot_ErrorPostgreSQL(QString text)
{
emit signal_Menu_ShowWindow();
SpecMsgBox::CriticalClose(this, tr("Error PostgreSQL!") + "\n" + text);
}
void ServerLMSWidget::slot_StateConnectionToDB(bool dbIsConnected, DataBaseSettings dbSettings)
{
this->state_dbIsConnected = dbIsConnected;
this->state_dbSettings = dbSettings;
updateStateOnlyDB();
}
void ServerLMSWidget::slot_StateServer(EStateServer stateServer, EStateBlockAutorization stateBlockAutorization)
{
if(this->state_Server != stateServer)
{
this->state_Server = stateServer;
this->state_BlockAutorization = stateBlockAutorization;
updateStateOnlyServer();
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!"));
}
}
else
{
this->state_Server = stateServer;
this->state_BlockAutorization = stateBlockAutorization;
updateStateOnlyServer();
}
}
void ServerLMSWidget::slot_StateVersionMaterials(QString versionStr)
{
this->state_VersionMaterials = 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();
if(flStartInitialization)
{
flStartInitialization = false;
startInitialization_step3();
}
}
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_SetError(int code)
{
if(code == 100)
{
QString textError = tr("No Client files found!") + "\n\n" +
tr("* check Application for the presence of a folder with a build \n"
"* check SharedData for a folder with the base version and the name base");
SpecMsgBox::CriticalClose(this, textError);
}
errorCode = code;
emit signal_StartInitHasError(code);
}
void ServerLMSWidget::slot_UpdateDocsCompleted()
{
if(flTryUpdateDocs)
{
flTryUpdateDocs = false;
startInitialization_step2();
}
}
void ServerLMSWidget::slot_UpdateControllerInitializeFinished()
{
startInitialization_step1();
}
void ServerLMSWidget::slot_BlockAutorizationIndicate(bool block, QString blocker, QString types)
{
if(block)
{
Logger::instance().log(QString("BLOCK from: %1").arg(blocker), LogLevel::INFO);
Logger::instance().log(QString("Blockers: %1").arg(types), LogLevel::DEBUG);
}
else
{
Logger::instance().log(QString("UNBLOCK from: %1").arg(blocker), LogLevel::INFO);
Logger::instance().log(QString("Blockers: %1").arg(types), LogLevel::DEBUG);
}
updateStateOnlyServer();
}
void ServerLMSWidget::slot_LanguageChanged(QString language)
{
qtLanguageTranslator.load(QString("translations/RRJServer_") + language, ".");
qApp->installTranslator(&qtLanguageTranslator);
emit signal_LanguageChanged(language);
}
//ON_BTN
void ServerLMSWidget::on_btnStartServer_clicked()
{
emit signal_StartServer();
ui->btnStartServer->setEnabled(false);
ui->btnStopServer->setEnabled(true);
}
void ServerLMSWidget::on_btnStopServer_clicked()
{
emit signal_StopServer();
ui->btnStopServer->setEnabled(false);
ui->btnStartServer->setEnabled(true);
}
void ServerLMSWidget::on_btnSettings_clicked()
{
ServerDBSettings settingsTemp;
if(!DialogSettingsTray::loadSettings(&settingsTemp))
{
SpecMsgBox::CriticalClose(this, tr("Settings file could not be opened:") + "'config/settings.xml'");
return;
}
DialogSettingsTray dlg(providerDBLMS, this);
dlg.setWindowFlags(dlg.windowFlags() & ~Qt::WindowContextHelpButtonHint);
connect(&dlg, &DialogSettingsTray::signal_LanguageChanged, this, &ServerLMSWidget::slot_LanguageChanged);
connect(&dlg, &DialogSettingsTray::signal_UpdateDocs, docsUpdater, &DocsUpdater::slot_updateDocsXML);
switch( dlg.exec() )
{
case QDialog::Accepted:
{
language = dlg.getSettings().Language;
if(dlg.settingsDBisChanged())
{
on_btnStopServer_clicked();
flNeedReconnectDB = true;
flTryConnectionToDB = false;
emit signal_TryDisConnectionFromDB();
break;
}
break;
}
case QDialog::Rejected:
break;
default:
break;
}
}
//INIT
void ServerLMSWidget::startInitialization_step0()
{
QApplication::setOverrideCursor(Qt::WaitCursor);
emit signal_Tray_ShowMessage(tr("Starting the server..."));
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 = new AssetsManager();
assetsManager->moveToThread(updateThread);
updateController = new UpdateController;
updateController = new UpdateController();
updateController->moveToThread(updateThread);
docsUpdater = new DocsUpdater(updateController/*, this*/);
docsUpdater = new DocsUpdater(updateController);
docsUpdater->moveToThread(updateThread);
cfiController = new CfiController(updateController/*, this*/);
connect(docsUpdater, &DocsUpdater::signal_UpdateDocsCompleted, this, &ServerLMSWidget::slot_UpdateDocsCompleted);
cfiController = new CfiController(updateController);
cfiController->moveToThread(updateThread);
processingSystem = new ProcessingSystem(providerDBLMS, updateController, docsUpdater, cfiController);
processingSystem->moveToThread(serverThread);
dataParser = new DataParser(assetsManager, processingSystem);
dataParser = new DataParser(processingSystem);
dataParser->moveToThread(serverThread);
commonClientHandler = new CommonClientHandler;
connect(this, &ServerLMSWidget::signal_DocsChanged, commonClientHandler, &CommonClientHandler::slot_DocsChanged);
//connect(commonClientHandler, &CommonClientHandler::sigSetServerState, this, &ServerLMSWidget::slot_trySetServerState);
commonClientHandler = new CommonClientHandler();
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(updateController, &UpdateController::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 /*Тут именно 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);
@@ -407,107 +577,60 @@ void ServerLMSWidget::startInitialization_step0()
Logger::instance().setLoggingType(LoggingType::WIDGET);
Logger::instance().setLogToFile(true);
connect(this, &ServerLMSWidget::sigUpdateControllerInitialize, updateController, &UpdateController::initialize);
connect(updateController, &UpdateController::sigInitializeFinished, this, &ServerLMSWidget::slot_startInitialization_step1);
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(this, &ServerLMSWidget::signal_UpdateControllerInitialize, updateController, &UpdateController::initialize);
connect(updateController, &UpdateController::sigInitializeFinished, this, &ServerLMSWidget::slot_UpdateControllerInitializeFinished);
connect(updateController, &UpdateController::sigErrorRequired, this, &ServerLMSWidget::slot_SetError);
connect(updateController, &UpdateController::sigUpdateDocsXML, docsUpdater, &DocsUpdater::slot_updateDocsXML);
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);
emit sigUpdateControllerInitialize(commonClientHandler, dataParser, assetsManager);
connect(this, &ServerLMSWidget::signal_UpdateDocsXML, docsUpdater, &DocsUpdater::slot_updateDocsXML);
emit signal_UpdateControllerInitialize(commonClientHandler, assetsManager);
}
void ServerLMSWidget::startInitialization_step1()
{
if(errorCode == 100)
return;
Logger::instance().log("Update docs.xml...");
flTryUpdateDocs = true;
emit signal_UpdateDocsXML();
}
void ServerLMSWidget::startInitialization_step2()
{
Logger::instance().log("Update docs.xml completed!");
ui->btnStopServer->setEnabled(false);
ui->btnStartServer->setEnabled(true);
flStartInitialization = true;
updateStateOnlyServer();
updateStateOnlyDB();
updateStateOnlyVersionMaterials();
Logger::instance().log("Try connection to DB...");
tryConnectionToDB();
}
void ServerLMSWidget::startInitialization_step3()
{
waitAnimationWidget->hideWithStop();
emit signal_StartInitFinished();
}
//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;
}

View File

@@ -1,36 +1,25 @@
#ifndef SERVERLMSWIDGET_H
#define SERVERLMSWIDGET_H
#include "ServerLMS_global.h"
#include <QWidget>
#include <QTcpServer>
#include <QTcpSocket>
#include <QXmlStreamWriter>
#include <QMap>
#include <QTranslator>
#include <QMutex>
#include <QSystemTrayIcon>
#include <Systems/Parsers/dataparser.h>
#include <Systems/sendsystem.h>
#include <Systems/processingsystem.h>
#include <Systems/updatecontroller.h>
#include <Systems/assetsmanager.h>
#include <Systems/recognizesystem.h>
#include <Systems/logger.h>
#include <Systems/commonclienthandler.h>
#include <Systems/assetsmanager.h>
#include <Data/typesDataServerClient.h>
#include <Data/Client.h>
#include "multithreadserver.h"
#include "providerdblms.h"
#include "docsupdater.h"
#include "ServerLMS_global.h"
#include "logger.h"
#include "waitanimationwidget.h"
#include "specialmessagebox.h"
#include "Parsers/dataparser.h"
#include "processingsystem.h"
#include "updatecontroller.h"
#include "assetsmanager.h"
#include "commonclienthandler.h"
#include "assetsmanager.h"
#include "multithreadserver.h"
#include "providerdblms.h"
#include "docsupdater.h"
#include "cficontroller.h"
@@ -39,11 +28,9 @@ class ServerLMSWidget;
}
class DataParser;
class SendSystem;
class ProcessingSystem;
class Logger;
class UpdateController;
class RecognizeSystem;
class ClientHandler;
class MultiThreadServer;
class AssetsManager;
@@ -51,114 +38,99 @@ 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:
//INTERFACE
void startInitialization();
QString getLanguage();
protected:
//EVENT
void changeEvent(QEvent * event) override;
void resizeEvent(QResizeEvent *event) override;
signals:
//MAINWINDOW, ТРЕЙ
//сигнал смены языка
void signal_LanguageChanged(QString language);
//сигнал вывода сообщения из трея
void signal_Tray_ShowMessage(QString textMsg, QSystemTrayIcon::MessageIcon iconMsg = QSystemTrayIcon::Information);
//синал обновления состояния сервера (иконка в трее)
void signal_Tray_UpdateStateServer(EStateServer state_Server, EStateBlockAutorization state_BlockAutorization);
//сигналы меню трея
void signal_Menu_ShowWindow();
void signal_Menu_HideWindow();
//сигнал о наличии ошибок начальной инициализации
void signal_StartInitHasError(int code);
//сигнал об окончании начальной инициализации
void signal_StartInitFinished();
void sigRecognize();
void sigCalculateFullHash();
void sigUpdateControllerInitialize(CommonClientHandler* commonClientHandler,DataParser *dataParser,AssetsManager *assetManager);
//Для инициализации
void signal_UpdateControllerInitialize(CommonClientHandler* commonClientHandler,AssetsManager *assetManager);
void signal_UpdateDocsXML();
void signal_DocsChanged();
void signal_hasError(int code);
//Соединение с БД
void signal_TryConnectionToDB();
void signal_TryDisConnectionFromDB();
void signal_updateStateServer(EStateServer stateServer, EStateBlockAutorization stateBlockAutorization);
//Сервер
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 state_dbIsConnected, DataBaseSettings state_dbSettings);
void slot_StateServer(EStateServer state_Server, EStateBlockAutorization state_BlockAutorization);
void slot_StateVersionMaterials(QString state_VersionMaterials);
void slot_UpdateDocs();
//Для инициализации
void slot_UpdateControllerInitializeFinished();
void slot_UpdateDocsCompleted();
void slot_SetError(int code);
void slot_startInitialization_step1();
void slot_setVersion(QString versionStr);
public:
QString getLanguage()
{
return language;
}
void setError(int code)
{
if(code == 100)
{
QString textError = tr("No Client files found!") + "\n\n" +
tr("* check Application for the presence of a folder with a build \n"
"* check SharedData for a folder with the base version and the name base");
SpecMsgBox::CriticalClose(this, textError);
}
errorCode = code;
emit signal_hasError(code);
}
int hasError() const
{
return errorCode;
}
ProcessingSystem* getProcessingSystem()
{
return processingSystem;
}
QMutex *getMutex() const
{
return mutex;
}
void removeClient(int socketId);
//Соединение с БД
void slot_ResultTryConnectDb(bool result);
void slot_ResultTryDisConnectDb(bool result);
private slots:
void on_btnStartServer_clicked();
void on_btnStopServer_clicked();
void on_btnSettings_clicked();
private:
void setLanguageInterfase();
private:
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 startInitialization_step2();
void startInitialization_step3();
void tryConnectionToDB();
private:
Ui::ServerLMSWidget *ui;
@@ -166,31 +138,37 @@ private:
private:
WaitAnimationWidget *waitAnimationWidget;
MultiThreadServer *server;
QThread *updateThread;
QThread *loggerThread;
QMutex *mutex;
QThread *serverThread;
DataParser *dataParser;
ProcessingSystem *processingSystem;
UpdateController *updateController;
AssetsManager *assetsManager;
CommonClientHandler *commonClientHandler;
ChatSystem *chatSystem;
MultiThreadServer *server; //serverThread
DataParser *dataParser; //serverThread
ProcessingSystem *processingSystem; //serverThread
CommonClientHandler *commonClientHandler; //serverThread
ChatSystem *chatSystem; //serverThread
ProviderDBLMS* providerDBLMS; //serverThread
DocsUpdater* docsUpdater;
CfiController* cfiController;
ProviderDBLMS* providerDBLMS;
bool first = true; // для тестов Unity
UpdateController *updateController; //updateThread
AssetsManager *assetsManager; //updateThread
DocsUpdater* docsUpdater; //updateThread
CfiController* cfiController; //updateThread
QTranslator qtLanguageTranslator;
QString language;
int errorCode;
QString versionStr;
QString state_VersionMaterials;
bool state_dbIsConnected;
DataBaseSettings state_dbSettings;
EStateServer state_Server;
EStateBlockAutorization state_BlockAutorization;
bool flStartInitialization;
bool flTryConnectionToDB;
bool flNeedReconnectDB;
bool flTryUpdateDocs;
};
#endif // SERVERLMSWIDGET_H

View File

@@ -1,6 +1,7 @@
#include <QMessageBox>
#include <QProcess>
#include <QFile>
#include <QResizeEvent>
#include "specialmessagebox.h"
#include "dialogcheckdb.h"
#include "ui_dialogcheckdb.h"
@@ -8,33 +9,78 @@
DialogCheckDB::DialogCheckDB(ProviderDBLMS* providerDBLMS, QWidget *parent) :
QDialog(parent),
ui(new Ui::DialogCheckDB),
providerDBLMS(providerDBLMS),
resDriver(false),
resUser(false),
resDB(false)
waitAnimationWidget(nullptr),
providerDBLMS(providerDBLMS)
{
ui->setupUi(this);
connect(this, &DialogCheckDB::signal_CheckDB, providerDBLMS, &ProviderDBLMS::slot_CheckDB);
connect(providerDBLMS, &ProviderDBLMS::signal_CheckDBResult, this, &DialogCheckDB::slot_CheckDBResult);
connect(this, &DialogCheckDB::signal_RepareDB, providerDBLMS, &ProviderDBLMS::slot_RepareDB);
connect(providerDBLMS, &ProviderDBLMS::signal_RepareDBResult, this, &DialogCheckDB::slot_RepareDBResult);
waitAnimationWidget = new WaitAnimationWidget;
QMovie *movie = new QMovie(":/resources/icons/762.gif");
waitAnimationWidget->setParent(this);
waitAnimationWidget->initialize(movie,this);
ui->btnRepare->setObjectName("btnRepare");
ui->btnRepare->setEnabled(false);
check();
ui->btnRepare->setEnabled(false);
}
DialogCheckDB::~DialogCheckDB()
{
if(waitAnimationWidget)
{
waitAnimationWidget->hideWithStop();
delete waitAnimationWidget;
}
delete ui;
}
void DialogCheckDB::initialize()
{
check();
}
void DialogCheckDB::resizeEvent(QResizeEvent *event)
{
QSize size = event->size();
waitAnimationWidget->resize(size);
}
void DialogCheckDB::check()
{
resDriver = false;
resUser = false;
resDB = false;
waitAnimationWidget->showWithPlay();
resDriver = providerDBLMS->checkDriverQPSQLavailable();
if(resDriver)
emit signal_CheckDB();
return;
}
void DialogCheckDB::on_btnRepare_clicked()
{
waitAnimationWidget->showWithPlay();
if(!checkResult.resDriver)
{
SpecMsgBox::CriticalClose(this, tr("Install PostgreSQL."));
this->reject();
return;
}
emit signal_RepareDB(checkResult);
}
void DialogCheckDB::slot_CheckDBResult(CheckResult result)
{
checkResult = result;
if(result.resDriver)
{
ui->lblDriverRes->setText(tr("Installed"));
ui->lblDriverResIco->setPixmap(QPixmap(QStringLiteral(":/resources/icons/circleGreen.png")));
@@ -45,8 +91,7 @@ void DialogCheckDB::check()
ui->lblDriverResIco->setPixmap(QPixmap(QStringLiteral(":/resources/icons/circleRed.png")));
}
resUser = providerDBLMS->checkUserLMSexist();
if(resUser)
if(result.resUser)
{
ui->lblUserRes->setText(tr("Exist"));
ui->lblUserResIco->setPixmap(QPixmap(QStringLiteral(":/resources/icons/circleGreen.png")));
@@ -57,8 +102,7 @@ void DialogCheckDB::check()
ui->lblUserResIco->setPixmap(QPixmap(QStringLiteral(":/resources/icons/circleRed.png")));
}
resDB = providerDBLMS->checkDataBaseLMSexist();
if(resDB)
if(result.resDB)
{
ui->lblDBRes->setText(tr("Exist"));
ui->lblDBResIco->setPixmap(QPixmap(QStringLiteral(":/resources/icons/circleGreen.png")));
@@ -69,48 +113,39 @@ void DialogCheckDB::check()
ui->lblDBResIco->setPixmap(QPixmap(QStringLiteral(":/resources/icons/circleRed.png")));
}
if(!resDriver || !resUser || !resDB)
if(!result.resDriver || !result.resUser || !result.resDB)
{
ui->btnRepare->setEnabled(true);
}
else
ui->btnRepare->setEnabled(false);
waitAnimationWidget->hideWithStop();
}
void DialogCheckDB::on_btnRepare_clicked()
void DialogCheckDB::slot_RepareDBResult(CheckResult result)
{
if(!resDriver)
checkResult = result;
if(!checkResult.resUser)
{
SpecMsgBox::CriticalClose(this, tr("Install PostgreSQL."));
slot_CheckDBResult(checkResult);
SpecMsgBox::CriticalClose(this, tr("Failed to create user!"));
this->reject();
return;
}
if(!resUser)
if(!checkResult.resDB)
{
if(!providerDBLMS->createUser())
{
check();
SpecMsgBox::CriticalClose(this, tr("Failed to create user!"));
this->reject();
return;
}
}
if(!resDB)
{
if(!providerDBLMS->createDB())
{
check();
SpecMsgBox::CriticalClose(this, tr("Failed to create Database!"));
this->reject();
return;
}
slot_CheckDBResult(checkResult);
SpecMsgBox::CriticalClose(this, tr("Failed to create Database!"));
this->reject();
return;
}
check();
if(resDriver && resUser && resDB)
if(checkResult.resDriver && checkResult.resUser && checkResult.resDB)
{
SpecMsgBox::InfoOk(this, tr("The database has been successfully restored!"));
this->accept();

View File

@@ -3,6 +3,7 @@
#include <QDialog>
#include "providerdblms.h"
#include "waitanimationwidget.h"
namespace Ui {
class DialogCheckDB;
@@ -16,9 +17,22 @@ public:
explicit DialogCheckDB(ProviderDBLMS* providerDBLMS, QWidget *parent = nullptr);
~DialogCheckDB();
void initialize();
protected:
void resizeEvent(QResizeEvent *event) override;
private slots:
void on_btnRepare_clicked();
signals:
void signal_CheckDB();
void signal_RepareDB(CheckResult result);
public slots:
void slot_CheckDBResult(CheckResult result);
void slot_RepareDBResult(CheckResult result);
private:
void check();
void prepareRestoreDBscript();
@@ -26,11 +40,11 @@ private:
private:
Ui::DialogCheckDB *ui;
WaitAnimationWidget *waitAnimationWidget;
ProviderDBLMS* providerDBLMS;
bool resDriver;
bool resUser;
bool resDB;
CheckResult checkResult;
};
#endif // DIALOGCHECKDB_H

View File

@@ -24,7 +24,13 @@ DialogSettingsTray::DialogSettingsTray(ProviderDBLMS* providerDBLMS, QWidget *pa
#ifndef PROJECT_TYPE_DEBUG
ui->checkLocalhost->setEnabled(false);
ui->btnUpdateDocs->setVisible(false);
#endif
#endif
#ifdef PROJECT_TYPE_DEBUG
ui->editNameDB->setEnabled(true);
ui->editUserName->setEnabled(true);
ui->editPassword->setEnabled(true);
#endif
/* Создаем строку для регулярного выражения */
QString ipRange = "(?:[0-1]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])";
@@ -298,7 +304,7 @@ void DialogSettingsTray::on_checkLocalhost_stateChanged(int arg1)
void DialogSettingsTray::on_btnCheckDB_clicked()
{
//Проверяем, установлен ли PostgreSQL
if(!providerDBLMS->checkDriverQPSQLavailable())
if(!ProviderDBLMS::checkDriverQPSQLavailable())
{
SpecMsgBox::CriticalClose(this, tr("Driver PostgreSQL is not installed!"));
return;
@@ -332,10 +338,11 @@ void DialogSettingsTray::on_btnCheckDB_clicked()
return;
}
if(providerDBLMS->setUserPasswordPostgres(UserNamePostgres, PasswordPostgres))
if(ProviderDBLMS::setUserPasswordPostgres(UserNamePostgres, PasswordPostgres))
{
DialogCheckDB dlgCheckDB(providerDBLMS, this);
dlgCheckDB.setWindowFlags(dlgCheckDB.windowFlags() & ~Qt::WindowContextHelpButtonHint);
dlgCheckDB.initialize();
switch( dlgCheckDB.exec() )
{