mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/RRJServer.git
synced 2026-03-28 19:55:48 +03:00
Переделано под один мега-проект LMS с общим CMakeLists.txt
This commit is contained in:
126
ServerLMS/Systems/Parsers/clientanswerparser.cpp
Normal file
126
ServerLMS/Systems/Parsers/clientanswerparser.cpp
Normal file
@@ -0,0 +1,126 @@
|
||||
#include "clientanswerparser.h"
|
||||
|
||||
ClientAnswerParser::ClientAnswerParser(QObject *parent) : QObject(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ClientAnswerParser::initialize(DataParser *dataParser)
|
||||
{
|
||||
this->dataParser = dataParser;
|
||||
}
|
||||
|
||||
QByteArray ClientAnswerParser::authorization(bool result, QString instructorName,QString clientName, QString accessType, QString login)
|
||||
{
|
||||
|
||||
QList<SXmlAnswerTag> listTag;
|
||||
|
||||
SAttribute attribute1 = {"Result", result? "true" : "false"};
|
||||
SAttribute attribute2 = {"InstructorName", instructorName};
|
||||
SAttribute attribute3 = {"ClientName", clientName};
|
||||
SAttribute attribute4 = {"AccessType", accessType};
|
||||
SAttribute attribute5 = {"Login", login};
|
||||
QList<SAttribute> listAttr = {attribute1, attribute2, attribute3, attribute4, attribute5};
|
||||
SXmlAnswerTag tag = {"ServerAuthorization", listAttr};
|
||||
|
||||
listTag.append(tag);
|
||||
|
||||
return dataParser->xmlAnswer(listTag);
|
||||
}
|
||||
|
||||
QByteArray ClientAnswerParser::deAuthorization(bool result, QString login)
|
||||
{
|
||||
QList<SXmlAnswerTag> listTag;
|
||||
|
||||
SAttribute attribute1 = {"Result", result? "true" : "false"};
|
||||
SAttribute attribute2 = {"Login", login};
|
||||
QList<SAttribute> listAttr = {attribute1, attribute2};
|
||||
SXmlAnswerTag tag = {"ServerDeAuthorization", listAttr};
|
||||
|
||||
listTag.append(tag);
|
||||
|
||||
return dataParser->xmlAnswer(listTag);
|
||||
}
|
||||
|
||||
QByteArray ClientAnswerParser::message(QString text, QString login)
|
||||
{
|
||||
QList<SXmlAnswerTag> listTag;
|
||||
SAttribute attribute2;
|
||||
|
||||
SAttribute attribute1 = {"Text", text};
|
||||
QList<SAttribute> listAttr = {attribute1};
|
||||
if(login != "")
|
||||
{
|
||||
attribute2 = {"Login", login};
|
||||
listAttr.append(attribute2);
|
||||
}
|
||||
SXmlAnswerTag tag = {"ServerMessage", listAttr};
|
||||
|
||||
listTag.append(tag);
|
||||
|
||||
return dataParser->xmlAnswer(listTag);
|
||||
}
|
||||
|
||||
QByteArray ClientAnswerParser::task(QString text)
|
||||
{
|
||||
QList<SXmlAnswerTag> listTag;
|
||||
|
||||
SAttribute attribute1 = {"Text", text};
|
||||
QList<SAttribute> listAttr = {attribute1};
|
||||
SXmlAnswerTag tag = {"ServerTask", listAttr};
|
||||
|
||||
listTag.append(tag);
|
||||
|
||||
return dataParser->xmlAnswer(listTag);
|
||||
}
|
||||
|
||||
QByteArray ClientAnswerParser::notify(QString code)
|
||||
{
|
||||
QList<SXmlAnswerTag> listTag;
|
||||
|
||||
SAttribute attribute1 = {"Code", code};
|
||||
QList<SAttribute> listAttr = {attribute1};
|
||||
SXmlAnswerTag tag = {"ServerNotify", listAttr};
|
||||
|
||||
listTag.append(tag);
|
||||
|
||||
return dataParser->xmlAnswer(listTag);
|
||||
}
|
||||
|
||||
QByteArray ClientAnswerParser::tasks(QStringList listTasks)
|
||||
{
|
||||
QList<SXmlAnswerTag> listTag;
|
||||
|
||||
foreach(QString task, listTasks)
|
||||
{
|
||||
QList<SAttribute> listAttr;
|
||||
|
||||
SAttribute attribute1 = {"Head", task};
|
||||
SAttribute attribute2 = {"IsComplete", "false"};
|
||||
listAttr.append(attribute1);
|
||||
listAttr.append(attribute2);
|
||||
|
||||
SXmlAnswerTag tag = {"ServerTask", listAttr};
|
||||
listTag.append(tag);
|
||||
}
|
||||
|
||||
return dataParser->xmlAnswer(listTag, "TaskArray", "Tasks");
|
||||
}
|
||||
|
||||
QByteArray ClientAnswerParser::currentVersion()
|
||||
{
|
||||
QByteArray array;
|
||||
QFile fileR(version);
|
||||
if (!fileR.open(QFile::ReadOnly | QFile::Text))
|
||||
{
|
||||
QString str = "Не удалось открыть файл";
|
||||
qDebug() << "xmlAnswer: " << str;
|
||||
}
|
||||
else
|
||||
{
|
||||
array = fileR.readAll();
|
||||
fileR.close(); // Закрываем файл
|
||||
}
|
||||
|
||||
return array;
|
||||
}
|
||||
30
ServerLMS/Systems/Parsers/clientanswerparser.h
Normal file
30
ServerLMS/Systems/Parsers/clientanswerparser.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#ifndef CLIENTANSWERPARSER_H
|
||||
#define CLIENTANSWERPARSER_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include <Systems/Parsers/dataparser.h>
|
||||
#include <Data/typesDataServerClient.h>
|
||||
|
||||
|
||||
class ClientAnswerParser : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ClientAnswerParser(QObject *parent = nullptr);
|
||||
void initialize(DataParser *dataParser);
|
||||
|
||||
QByteArray authorization(bool result, QString instructorName, QString clientName, QString accessType, QString login);
|
||||
QByteArray deAuthorization(bool result, QString login);
|
||||
QByteArray message(QString text, QString login = "");
|
||||
QByteArray task(QString text);
|
||||
QByteArray notify(QString code);
|
||||
QByteArray tasks(QStringList listTasks);
|
||||
QByteArray currentVersion();
|
||||
signals:
|
||||
|
||||
private:
|
||||
DataParser *dataParser;
|
||||
};
|
||||
|
||||
#endif // CLIENTANSWERPARSER_H
|
||||
163
ServerLMS/Systems/Parsers/dataparser.cpp
Normal file
163
ServerLMS/Systems/Parsers/dataparser.cpp
Normal file
@@ -0,0 +1,163 @@
|
||||
#include "dataparser.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QDomDocument>
|
||||
|
||||
DataParser::DataParser(AssetsManager *assetManager,ProcessingSystem *processingSystem,QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
this->processingSystem = processingSystem;
|
||||
this->assetsManager = assetManager;
|
||||
|
||||
clientAnswer = new ClientAnswerParser;
|
||||
clientAnswer->initialize(this);
|
||||
|
||||
dbAnswer = new DBAnswerParser;
|
||||
dbAnswer->initialize(this);
|
||||
|
||||
processParser = new ProcessParser;
|
||||
processParser->initialize(processingSystem);
|
||||
|
||||
mutex = new QMutex;
|
||||
|
||||
if (!QDir(staticDataFolderName).exists()){
|
||||
QDir().mkdir(staticDataFolderName);
|
||||
}
|
||||
qDebug() << "ParserThread: " << QThread::currentThreadId();
|
||||
}
|
||||
|
||||
|
||||
|
||||
QByteArray DataParser::xmlAnswer(QList<SXmlAnswerTag> listTag, QString elemUp1, QString elemUp2)
|
||||
{
|
||||
try {
|
||||
|
||||
mutex->lock();
|
||||
/* Открываем файл для Записи*/
|
||||
QFile file(tempFile);
|
||||
file.open(QIODevice::WriteOnly);
|
||||
|
||||
/* Создаем объект, с помощью которого осуществляется запись в файл */
|
||||
QXmlStreamWriter xmlWriter(&file);
|
||||
|
||||
xmlWriter.setAutoFormatting(true); // Устанавливаем автоформатирование текста
|
||||
|
||||
xmlWriter.writeStartDocument(); // Запускаем запись в документ
|
||||
|
||||
if(elemUp1 != "")
|
||||
xmlWriter.writeStartElement(elemUp1); // Записываем тег
|
||||
|
||||
if(elemUp2 != "")
|
||||
xmlWriter.writeStartElement(elemUp2); // Записываем тег
|
||||
|
||||
//Записываем все элементы
|
||||
foreach(SXmlAnswerTag tag, listTag)
|
||||
{
|
||||
xmlWriter.writeStartElement(tag.elementName); // Записываем тег
|
||||
|
||||
// Записываем атрибуты
|
||||
foreach(SAttribute attr, tag.attr)
|
||||
xmlWriter.writeAttribute(attr.name, attr.value);
|
||||
|
||||
xmlWriter.writeEndElement(); // Закрываем тег
|
||||
}
|
||||
|
||||
if(elemUp1 != "")
|
||||
xmlWriter.writeEndElement(); // Закрываем тег
|
||||
|
||||
if(elemUp1 != "")
|
||||
xmlWriter.writeEndElement(); // Закрываем тег
|
||||
|
||||
/* Завершаем запись в документ*/
|
||||
xmlWriter.writeEndDocument();
|
||||
|
||||
file.close(); // Закрываем файл
|
||||
|
||||
QByteArray array;
|
||||
|
||||
array = readTempFile();
|
||||
mutex->unlock();
|
||||
|
||||
return array;
|
||||
}
|
||||
catch(const std::exception& e)
|
||||
|
||||
{
|
||||
qDebug() << e.what();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool DataParser::loadBlankXML(QString nameFile, QDomDocument *commonDOM)
|
||||
{
|
||||
QFile blankFile(nameFile);
|
||||
|
||||
if (! blankFile.open(QFile::ReadOnly | QFile::Text)) {
|
||||
qDebug() << "loadBlankXML: Couldn't read the file: " + nameFile;
|
||||
return false;
|
||||
}
|
||||
|
||||
commonDOM->setContent(blankFile.readAll());
|
||||
blankFile.close();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DataParser::saveDOMtoXML(QString nameFile, QDomDocument *commonDOM)
|
||||
{
|
||||
QFile xmlOutFile(nameFile);
|
||||
if (!xmlOutFile.open(QFile::WriteOnly | QFile::Text))
|
||||
{
|
||||
qDebug() << "saveDOMtoXML: Failed to write a file: " + nameFile;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
QTextStream outFile(&xmlOutFile);
|
||||
commonDOM->save(outFile, 4);
|
||||
xmlOutFile.close();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
QByteArray DataParser::readTempFile()
|
||||
{
|
||||
QByteArray array;
|
||||
QFile fileR(tempFile);
|
||||
if (!fileR.open(QFile::ReadOnly | QFile::Text))
|
||||
{
|
||||
QString str = "Не удалось открыть файл";
|
||||
qDebug() << "xmlAnswer: " << str;
|
||||
}
|
||||
else
|
||||
{
|
||||
array = fileR.readAll();
|
||||
fileR.close();
|
||||
}
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
ClientAnswerParser *DataParser::ClientAnswer() const
|
||||
{
|
||||
return clientAnswer;
|
||||
}
|
||||
|
||||
DBAnswerParser *DataParser::DbAnswer() const
|
||||
{
|
||||
return dbAnswer;
|
||||
}
|
||||
|
||||
ProcessParser *DataParser::getProcessParser() const
|
||||
{
|
||||
return processParser;
|
||||
}
|
||||
|
||||
DataParser::~DataParser()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
62
ServerLMS/Systems/Parsers/dataparser.h
Normal file
62
ServerLMS/Systems/Parsers/dataparser.h
Normal file
@@ -0,0 +1,62 @@
|
||||
#ifndef DATAPARSER_H
|
||||
#define DATAPARSER_H
|
||||
|
||||
#include "Systems/processingsystem.h"
|
||||
#include "Systems/tools.h"
|
||||
#include "Systems/assetsmanager.h"
|
||||
#include "Systems/logger.h"
|
||||
#include "Systems/Parsers/clientanswerparser.h"
|
||||
#include "dbanswerparser.h"
|
||||
#include "processparser.h"
|
||||
#include "serverlmswidget.h"
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QXmlStreamReader>
|
||||
#include <QDebug>
|
||||
#include <QDomDocument>
|
||||
|
||||
#include <Data/typesDataServerClient.h>
|
||||
#include <Data/StreamingVersionData.h>
|
||||
|
||||
class ProcessingSystem;
|
||||
class ClientHandler;
|
||||
class AssetsManager;
|
||||
class ClientAnswerParser;
|
||||
class DBAnswerParser;
|
||||
class ProcessParser;
|
||||
|
||||
class DataParser : public QObject
|
||||
{
|
||||
|
||||
Q_OBJECT
|
||||
public:
|
||||
DataParser(AssetsManager *assetManager,ProcessingSystem *processingSystem,QObject* parent = nullptr);
|
||||
void xmlParser(ClientHandler *client, QByteArray array);
|
||||
void xmlFileDataParse(QByteArray array);
|
||||
|
||||
QByteArray xmlAnswer(QList<SXmlAnswerTag> listTag,QString elemUp1 = "", QString elemUp2 = "");
|
||||
|
||||
bool loadBlankXML(QString nameFile, QDomDocument* commonDOM);
|
||||
bool saveDOMtoXML(QString nameFile, QDomDocument* commonDOM);
|
||||
~DataParser();
|
||||
|
||||
ClientAnswerParser *ClientAnswer() const;
|
||||
DBAnswerParser *DbAnswer() const;
|
||||
ProcessParser *getProcessParser() const;
|
||||
|
||||
signals:
|
||||
void sigLogMessage(QString log);
|
||||
|
||||
|
||||
private:
|
||||
QMutex *mutex;
|
||||
|
||||
ProcessingSystem *processingSystem;
|
||||
AssetsManager *assetsManager;
|
||||
ClientAnswerParser *clientAnswer;
|
||||
DBAnswerParser *dbAnswer;
|
||||
ProcessParser *processParser;
|
||||
QByteArray readTempFile();
|
||||
};
|
||||
|
||||
#endif // DATAPARSER_H
|
||||
109
ServerLMS/Systems/Parsers/dbanswerparser.cpp
Normal file
109
ServerLMS/Systems/Parsers/dbanswerparser.cpp
Normal file
@@ -0,0 +1,109 @@
|
||||
#include "dbanswerparser.h"
|
||||
|
||||
|
||||
|
||||
DBAnswerParser::DBAnswerParser(QObject *parent) : QObject(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void DBAnswerParser::initialize(DataParser *dataParser)
|
||||
{
|
||||
this->dataParser = dataParser;
|
||||
}
|
||||
|
||||
QByteArray DBAnswerParser::listInstructors(bool result, QList<Instructor> *listInstructors)
|
||||
{
|
||||
QDomDocument commonDOM;
|
||||
if(! dataParser->loadBlankXML(":/resources/blankXML/ListInstructors.xml", &commonDOM))
|
||||
return QByteArray();
|
||||
|
||||
QDomNode listNode = commonDOM.namedItem("ListInstructors");
|
||||
|
||||
for(Instructor instructor : *listInstructors)
|
||||
{
|
||||
//Инструктор
|
||||
QDomNode instructorNode = commonDOM.createElement("Instructor");
|
||||
listNode.appendChild(instructorNode);
|
||||
instructorNode.toElement().setAttribute("instructor_id", QString::number(instructor.getID()));
|
||||
instructorNode.toElement().setAttribute("name", instructor.getName());
|
||||
instructorNode.toElement().setAttribute("login", instructor.getLogin());
|
||||
instructorNode.toElement().setAttribute("password", instructor.getPassword());
|
||||
instructorNode.toElement().setAttribute("is_admin", instructor.getIsAdmin());
|
||||
instructorNode.toElement().setAttribute("archived", instructor.getArchived());
|
||||
instructorNode.toElement().setAttribute("logged_in", instructor.getLoggedIn());
|
||||
}
|
||||
|
||||
dataParser->saveDOMtoXML("ListInstructors.xml", &commonDOM);
|
||||
|
||||
return commonDOM.toByteArray();
|
||||
}
|
||||
|
||||
QByteArray DBAnswerParser::listGroups(bool result, QList<Group> *listGroups)
|
||||
{
|
||||
QDomDocument commonDOM;
|
||||
if(! dataParser->loadBlankXML(":/resources/blankXML/ListGroups.xml", &commonDOM))
|
||||
return QByteArray();
|
||||
|
||||
QDomNode listNode = commonDOM.namedItem("ListGroups");
|
||||
|
||||
for(Group group : *listGroups)
|
||||
{
|
||||
//Группа
|
||||
QDomNode groupNode = commonDOM.createElement("Group");
|
||||
listNode.appendChild(groupNode);
|
||||
groupNode.toElement().setAttribute("group_id", QString::number(group.getID()));
|
||||
groupNode.toElement().setAttribute("name", group.getName());
|
||||
}
|
||||
|
||||
dataParser->saveDOMtoXML("ListGroups.xml", &commonDOM);
|
||||
|
||||
return commonDOM.toByteArray();
|
||||
}
|
||||
|
||||
QByteArray DBAnswerParser::listTrainees(bool result, QList<Trainee> *listTrainees)
|
||||
{
|
||||
QDomDocument commonDOM;
|
||||
if(! dataParser->loadBlankXML(":/resources/blankXML/ListTrainees.xml", &commonDOM))
|
||||
return QByteArray();
|
||||
|
||||
QDomNode listNode = commonDOM.namedItem("ListTrainees");
|
||||
|
||||
for(Trainee trainee : *listTrainees)
|
||||
{
|
||||
//Обучаемый
|
||||
QDomNode traineeNode = commonDOM.createElement("Trainee");
|
||||
listNode.appendChild(traineeNode);
|
||||
traineeNode.toElement().setAttribute("trainee_id", trainee.getID());
|
||||
traineeNode.toElement().setAttribute("name", trainee.getName());
|
||||
traineeNode.toElement().setAttribute("login", trainee.getLogin());
|
||||
traineeNode.toElement().setAttribute("password", trainee.getPassword());
|
||||
traineeNode.toElement().setAttribute("archived", trainee.getArchived());
|
||||
traineeNode.toElement().setAttribute("logged_in", trainee.getLoggedIn());
|
||||
traineeNode.toElement().setAttribute("group_trainee", trainee.getGroup().getID());
|
||||
traineeNode.toElement().setAttribute("computer_trainee", trainee.getComputer().getID());
|
||||
//trainee.setTasks()
|
||||
}
|
||||
|
||||
dataParser->saveDOMtoXML("ListTrainees.xml", &commonDOM);
|
||||
|
||||
return commonDOM.toByteArray();
|
||||
}
|
||||
|
||||
QByteArray DBAnswerParser::listComputers(bool result, QList<Computer> *listComputers)
|
||||
{
|
||||
//TODO
|
||||
return QByteArray();
|
||||
}
|
||||
|
||||
QByteArray DBAnswerParser::listClassrooms(bool result, QList<Classroom> *listClassrooms)
|
||||
{
|
||||
//TODO
|
||||
return QByteArray();
|
||||
}
|
||||
|
||||
QByteArray DBAnswerParser::listTasks(bool result, QList<Task> *listTasks)
|
||||
{
|
||||
//TODO
|
||||
return QByteArray();
|
||||
}
|
||||
29
ServerLMS/Systems/Parsers/dbanswerparser.h
Normal file
29
ServerLMS/Systems/Parsers/dbanswerparser.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef DBANSWERPARSER_H
|
||||
#define DBANSWERPARSER_H
|
||||
|
||||
#include "dataparser.h"
|
||||
#include "serverlmswidget.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QDomDocument>
|
||||
|
||||
class DBAnswerParser : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit DBAnswerParser(QObject *parent = nullptr);
|
||||
void initialize(DataParser *dataParser);
|
||||
QByteArray listInstructors(bool result, QList<Instructor> *listInstructors);
|
||||
QByteArray listGroups(bool result, QList<Group> *listGroups);
|
||||
QByteArray listTrainees(bool result, QList<Trainee> *listTrainees);
|
||||
QByteArray listComputers(bool result, QList<Computer> *listComputers);
|
||||
QByteArray listClassrooms(bool result, QList<Classroom> *listClassrooms);
|
||||
QByteArray listTasks(bool result, QList<Task> *listTasks);
|
||||
signals:
|
||||
|
||||
private:
|
||||
DataParser *dataParser;
|
||||
|
||||
};
|
||||
|
||||
#endif // DBANSWERPARSER_H
|
||||
261
ServerLMS/Systems/Parsers/processparser.cpp
Normal file
261
ServerLMS/Systems/Parsers/processparser.cpp
Normal file
@@ -0,0 +1,261 @@
|
||||
#include "processparser.h"
|
||||
|
||||
ProcessParser::ProcessParser(QObject *parent) : QObject(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ProcessParser::initialize(ProcessingSystem *processingSystem)
|
||||
{
|
||||
this->processingSystem = processingSystem;
|
||||
}
|
||||
|
||||
void ProcessParser::read(ClientHandler *client, QByteArray array)
|
||||
{
|
||||
QXmlStreamReader xmlReader(array);
|
||||
|
||||
xmlReader.readNext(); // Переходим к первому элементу в файле
|
||||
|
||||
//Крутимся в цикле до тех пор, пока не достигнем конца документа
|
||||
while(!xmlReader.atEnd())
|
||||
{
|
||||
//Проверяем, является ли элемент началом тега
|
||||
if(xmlReader.isStartElement())
|
||||
{
|
||||
//Анализируем теги
|
||||
if(xmlReader.name() == "ClientAutorization")
|
||||
{//Запрос авторизации от клиента
|
||||
|
||||
clientAuth(xmlReader,client);
|
||||
}
|
||||
else if(xmlReader.name() == "ClientDeAutorization")
|
||||
{//Запрос ДеАвторизации от клиента
|
||||
|
||||
clientDeAuth(xmlReader,client);
|
||||
}
|
||||
else if(xmlReader.name() == "ToClientMessage")
|
||||
{//Отправка сообщения Клиенту
|
||||
|
||||
toClientMessage(xmlReader,client);
|
||||
}
|
||||
else if(xmlReader.name() == "QueryToDB")
|
||||
{//Запрос к базе данных от клиента
|
||||
|
||||
queryToDb(xmlReader,client);
|
||||
}
|
||||
else if(xmlReader.name() == "ClientMessage")
|
||||
{//Сообщение от клиента
|
||||
|
||||
clientMessage(xmlReader,client);
|
||||
}
|
||||
else if(xmlReader.name() == "ClientNotify")
|
||||
{//Уведомление от клиента
|
||||
|
||||
clientNotify(xmlReader,client);
|
||||
}
|
||||
else
|
||||
{
|
||||
emit sigLogMessage("XmlParser: unrecognized tag");
|
||||
}
|
||||
|
||||
}
|
||||
xmlReader.readNext(); // Переходим к следующему элементу файла
|
||||
}//while(!xmlReader.atEnd())
|
||||
}
|
||||
|
||||
void ProcessParser::clientAuth(QXmlStreamReader &xmlReader,ClientHandler *client)
|
||||
{
|
||||
ClientAutorization clientAutorization;
|
||||
|
||||
/*Перебираем все атрибуты тега*/
|
||||
foreach(const QXmlStreamAttribute &attr, xmlReader.attributes())
|
||||
{
|
||||
QString name = attr.name().toString();
|
||||
QString value = attr.value().toString();
|
||||
//addTextToLogger(name + ": " + value);
|
||||
|
||||
if(name == "Login")
|
||||
clientAutorization.Login = value;
|
||||
else if(name == "Password")
|
||||
clientAutorization.Password = value;
|
||||
else if(name == "NumberOfScreen")
|
||||
clientAutorization.NumberOfScreen = value.toInt();
|
||||
else if(name == "TypeClient")
|
||||
clientAutorization.TypeClient = (TypeClientAutorization)value.toInt();
|
||||
}
|
||||
|
||||
processingSystem->processingClientAutorization(client, clientAutorization);
|
||||
}
|
||||
|
||||
void ProcessParser::clientDeAuth(QXmlStreamReader &xmlReader,ClientHandler *client)
|
||||
{
|
||||
ClientDeAutorization clientDeAutorization;
|
||||
|
||||
/*Перебираем все атрибуты тега*/
|
||||
foreach(const QXmlStreamAttribute &attr, xmlReader.attributes())
|
||||
{
|
||||
QString name = attr.name().toString();
|
||||
QString value = attr.value().toString();
|
||||
//addTextToLogger(name + ": " + value);
|
||||
|
||||
if(name == "Login")
|
||||
clientDeAutorization.Login = value;
|
||||
}
|
||||
|
||||
processingSystem->processingClientDeAutorization(client, clientDeAutorization);
|
||||
}
|
||||
|
||||
void ProcessParser::toClientMessage(QXmlStreamReader &xmlReader,ClientHandler *client)
|
||||
{
|
||||
ToClientMessage toClientMessage;
|
||||
|
||||
/*Перебираем все атрибуты тега*/
|
||||
foreach(const QXmlStreamAttribute &attr, xmlReader.attributes())
|
||||
{
|
||||
QString name = attr.name().toString();
|
||||
QString value = attr.value().toString();
|
||||
//addTextToLogger(name + ": " + value);
|
||||
|
||||
if(name == "id")
|
||||
toClientMessage.id = value.toInt();
|
||||
else if(name == "Text")
|
||||
toClientMessage.Text = value;
|
||||
else if(name == "Login")
|
||||
toClientMessage.Login = value;
|
||||
}
|
||||
|
||||
processingSystem->processingToClientMessage(client, toClientMessage);
|
||||
}
|
||||
|
||||
void ProcessParser::queryToDb(QXmlStreamReader &xmlReader,ClientHandler *client)
|
||||
{
|
||||
ClientQueryToDB queryToDB;
|
||||
int id = 0;
|
||||
Instructor instructor;
|
||||
Trainee trainee;
|
||||
Group group;
|
||||
void* data = nullptr;
|
||||
|
||||
/*Перебираем все атрибуты тега*/
|
||||
foreach(const QXmlStreamAttribute &attr, xmlReader.attributes())
|
||||
{
|
||||
QString name = attr.name().toString();
|
||||
QString value = attr.value().toString();
|
||||
//addTextToLogger(name + ": " + value);
|
||||
|
||||
if(name == "TypeQuery")
|
||||
queryToDB.typeQuery = (TypeQueryToDB)value.toInt();
|
||||
else if(name == "id")
|
||||
id = value.toInt();
|
||||
else
|
||||
{
|
||||
switch (queryToDB.typeQuery)
|
||||
{
|
||||
case TypeQueryToDB::TYPE_QUERY_NEW_INSTRUCTOR:
|
||||
case TypeQueryToDB::TYPE_QUERY_EDIT_INSTRUCTOR:
|
||||
if(name == "instructor_id")
|
||||
instructor.setID(value.toInt());
|
||||
else if(name == "name")
|
||||
instructor.setName(value);
|
||||
else if(name == "login")
|
||||
instructor.setLogin(value);
|
||||
else if(name == "password")
|
||||
instructor.setPassword(value);
|
||||
else if(name == "is_admin")
|
||||
instructor.setIsAdmin(value.toInt());
|
||||
else if(name == "archived")
|
||||
instructor.setArchived(value.toInt());
|
||||
else if(name == "logged_in")
|
||||
instructor.setLoggedIn(value.toInt());
|
||||
break;
|
||||
case TypeQueryToDB::TYPE_QUERY_NEW_TRAINEE:
|
||||
case TypeQueryToDB::TYPE_QUERY_EDIT_TRAINEE:
|
||||
if(name == "trainee_id")
|
||||
trainee.setID(value.toInt());
|
||||
else if(name == "name")
|
||||
trainee.setName(value);
|
||||
else if(name == "login")
|
||||
trainee.setLogin(value);
|
||||
else if(name == "password")
|
||||
trainee.setPassword(value);
|
||||
else if(name == "archived")
|
||||
trainee.setArchived(value.toInt());
|
||||
else if(name == "logged_in")
|
||||
trainee.setLoggedIn(value.toInt());
|
||||
else if(name == "group_trainee")
|
||||
{
|
||||
Group group(value.toInt(), "");
|
||||
trainee.setGroup(group);
|
||||
}
|
||||
else if(name == "computer_trainee")
|
||||
{
|
||||
Computer computer(value.toInt(), "", "", Classroom());
|
||||
trainee.setComputer(computer);
|
||||
}
|
||||
break;
|
||||
case TypeQueryToDB::TYPE_QUERY_NEW_GROUP:
|
||||
case TypeQueryToDB::TYPE_QUERY_EDIT_GROUP:
|
||||
if(name == "group_id")
|
||||
group.setID(value.toInt());
|
||||
else if(name == "name")
|
||||
group.setName(value);
|
||||
break;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
switch (queryToDB.typeQuery)
|
||||
{
|
||||
case TypeQueryToDB::TYPE_QUERY_NEW_INSTRUCTOR:
|
||||
case TypeQueryToDB::TYPE_QUERY_EDIT_INSTRUCTOR:
|
||||
data = &instructor;
|
||||
break;
|
||||
case TypeQueryToDB::TYPE_QUERY_NEW_TRAINEE:
|
||||
case TypeQueryToDB::TYPE_QUERY_EDIT_TRAINEE:
|
||||
data = &trainee;
|
||||
break;
|
||||
case TypeQueryToDB::TYPE_QUERY_NEW_GROUP:
|
||||
case TypeQueryToDB::TYPE_QUERY_EDIT_GROUP:
|
||||
data = &group;
|
||||
break;
|
||||
};
|
||||
|
||||
processingSystem->processingClientQueryToDB(client, queryToDB, id, data);
|
||||
}
|
||||
|
||||
void ProcessParser::clientMessage(QXmlStreamReader &xmlReader,ClientHandler *client)
|
||||
{
|
||||
ClientMessage clientMessage;
|
||||
|
||||
/*Перебираем все атрибуты тега*/
|
||||
foreach(const QXmlStreamAttribute &attr, xmlReader.attributes())
|
||||
{
|
||||
QString name = attr.name().toString();
|
||||
QString value = attr.value().toString();
|
||||
//addTextToLogger(name + ": " + value);
|
||||
|
||||
if(name == "Text")
|
||||
clientMessage.Text = value;
|
||||
}
|
||||
|
||||
processingSystem->processingFromClientMessage(client, clientMessage);
|
||||
}
|
||||
|
||||
void ProcessParser::clientNotify(QXmlStreamReader &xmlReader,ClientHandler *client)
|
||||
{
|
||||
ClientNotify clientNotify;
|
||||
|
||||
/*Перебираем все атрибуты тега*/
|
||||
foreach(const QXmlStreamAttribute &attr, xmlReader.attributes())
|
||||
{
|
||||
QString name = attr.name().toString();
|
||||
QString value = attr.value().toString();
|
||||
|
||||
if(name == "Code")
|
||||
clientNotify.Code = value;
|
||||
}
|
||||
|
||||
processingSystem->processingClientNotify(client, clientNotify);
|
||||
}
|
||||
|
||||
|
||||
30
ServerLMS/Systems/Parsers/processparser.h
Normal file
30
ServerLMS/Systems/Parsers/processparser.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#ifndef PROCESSPARSER_H
|
||||
#define PROCESSPARSER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <Data/typesDataServerClient.h>
|
||||
#include <qxmlstream.h>
|
||||
#include <clienthandler.h>
|
||||
|
||||
class ProcessParser : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ProcessParser(QObject *parent = nullptr);
|
||||
void initialize(ProcessingSystem *processingSystem);
|
||||
void read(ClientHandler *client, QByteArray array);
|
||||
|
||||
|
||||
signals:
|
||||
void sigLogMessage(QString text);
|
||||
private:
|
||||
ProcessingSystem *processingSystem;
|
||||
void clientAuth(QXmlStreamReader &xmlReader,ClientHandler *client);
|
||||
void clientDeAuth(QXmlStreamReader &xmlReader,ClientHandler *client);
|
||||
void toClientMessage(QXmlStreamReader &xmlReader,ClientHandler *client);
|
||||
void queryToDb(QXmlStreamReader &xmlReader,ClientHandler *client);
|
||||
void clientMessage(QXmlStreamReader &xmlReader,ClientHandler *client);
|
||||
void clientNotify(QXmlStreamReader &xmlReader,ClientHandler *client);
|
||||
};
|
||||
|
||||
#endif // PROCESSPARSER_H
|
||||
220
ServerLMS/Systems/assetsmanager.cpp
Normal file
220
ServerLMS/Systems/assetsmanager.cpp
Normal file
@@ -0,0 +1,220 @@
|
||||
#include "assetsmanager.h"
|
||||
|
||||
AssetsManager::AssetsManager(QObject *parent) : QObject(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void AssetsManager::initialize(UpdateController* updateContoller,DataParser *dataParser)
|
||||
{
|
||||
this->updateController = updateContoller;
|
||||
connect(this,&AssetsManager::sigSaveVersion,updateContoller,&UpdateController::saveVersionToFile);
|
||||
datas = new QList<StreamingVersionData*>;
|
||||
}
|
||||
|
||||
void AssetsManager::setVersionList(QList<StreamingVersionData*> *streamingVersion)
|
||||
{
|
||||
datas->clear();
|
||||
datas = streamingVersion;
|
||||
}
|
||||
|
||||
bool AssetsManager::findDuplicate(QString name)
|
||||
{
|
||||
QListIterator<StreamingVersionData*> iterator(*datas);
|
||||
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
if (iterator.next()->getViewName() == name) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
QString AssetsManager::setVersion(QString versionName)
|
||||
{
|
||||
QListIterator<StreamingVersionData*> iterator(*datas);
|
||||
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
StreamingVersionData *version = iterator.next();
|
||||
|
||||
if (version->getViewName() == versionName)
|
||||
{
|
||||
currentVersionData = version;
|
||||
emit sigSaveVersion(currentVersionData);
|
||||
|
||||
return version->getAbsolutPath();
|
||||
}
|
||||
}
|
||||
|
||||
return "none";
|
||||
}
|
||||
|
||||
QList<FileData> *AssetsManager::prepareLocalPathList(QList<FileData> *fileData)
|
||||
{
|
||||
QList<FileData> *completeList = fileData;
|
||||
|
||||
for(int i = 0; i < completeList->count();i++)
|
||||
{
|
||||
FileData fileData = completeList->at(i);
|
||||
|
||||
int index = fileData.path.indexOf(currentVersionData->getViewName());
|
||||
if(index != -1)
|
||||
{
|
||||
fileData.path = Tools::createRealPath(fileData.path,currentVersionData); //делаем в полный путь
|
||||
completeList->replace(i,fileData);
|
||||
}
|
||||
else
|
||||
{
|
||||
fileData.path = Tools::createRootPath(fileData.path);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return completeList;
|
||||
}
|
||||
|
||||
QList<FileData> *AssetsManager::prepareRealPathList(QList<FileData> *fileData)
|
||||
{
|
||||
QList<FileData> *completeList = fileData;
|
||||
|
||||
for(int i = 0; i < completeList->count();i++)
|
||||
{
|
||||
FileData fileData = completeList->at(i);
|
||||
if(fileData.path.contains(streamingAssetsFolderName))
|
||||
{
|
||||
fileData.path = Tools::createStreamingToRealPath(fileData.path,currentVersionData);
|
||||
}
|
||||
else
|
||||
{
|
||||
fileData.path = Tools::createRealPath(fileData.path,currentVersionData); //делаем в полный путь
|
||||
}
|
||||
|
||||
completeList->replace(i,fileData);
|
||||
}
|
||||
|
||||
return completeList;
|
||||
}
|
||||
|
||||
void AssetsManager::addVersion(StreamingVersionData *data)
|
||||
{
|
||||
datas->push_back(data);
|
||||
}
|
||||
|
||||
void AssetsManager::createCopyVersion(QString versionName,QString newVersionName)
|
||||
{
|
||||
qDebug() << "assetManager thread ID " << QThread::currentThreadId();
|
||||
QListIterator<StreamingVersionData*> iterator(*datas);
|
||||
StreamingVersionData* data;
|
||||
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
StreamingVersionData *version = iterator.next();
|
||||
|
||||
if (version->getViewName() == versionName)
|
||||
{
|
||||
data = version;
|
||||
}
|
||||
}
|
||||
|
||||
qDebug() << "Version for copy " << versionName;
|
||||
qDebug() << "New version name " << newVersionName;
|
||||
|
||||
//берем путь до копии
|
||||
//преобразуем в реальный путь
|
||||
QString sourcePath = QDir::currentPath() + "/" + sharedDataFolderName + "/" + versionName;
|
||||
QString destinationPath = QDir::currentPath() + "/" + sharedDataFolderName + "/" + newVersionName;
|
||||
|
||||
QDir sourceDir(sourcePath);
|
||||
|
||||
if(!sourceDir.exists())
|
||||
{
|
||||
qDebug() << "Версии нет в SharedData";
|
||||
return;
|
||||
}
|
||||
|
||||
QDir destinationDir(destinationPath);
|
||||
if(destinationDir.exists())
|
||||
{
|
||||
qDebug() << "Папка уже существует";
|
||||
return;
|
||||
}
|
||||
|
||||
//Создаем папку в Shared с новым именем
|
||||
QDir().mkdir(destinationPath);
|
||||
copyAllRecurse(sourcePath,destinationPath);
|
||||
//добавляем в список текущих ассетов
|
||||
updateController->calculateFullHash();
|
||||
updateController->changeAssetVersion(newVersionName);
|
||||
updateController->sendNewVersionList();
|
||||
//повторно отправляем список версий из папки shared
|
||||
|
||||
}
|
||||
|
||||
void AssetsManager::deleteVersion(QString versionName)
|
||||
{
|
||||
QMutableListIterator<StreamingVersionData*> iterator(*datas);
|
||||
|
||||
//если версия равна текущей - игнор
|
||||
if (currentVersionData->getViewName() == versionName)
|
||||
return;
|
||||
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
StreamingVersionData *version = iterator.next();
|
||||
|
||||
//проверка на наличие указанной версии
|
||||
if (version->getViewName() == versionName)
|
||||
{
|
||||
//удаление папки
|
||||
QString verFolderPath = QDir::currentPath() + "/" + sharedDataFolderName + "/" + versionName;
|
||||
QDir dir(verFolderPath);
|
||||
dir.removeRecursively();
|
||||
|
||||
//удаление хэша
|
||||
QString hashPath = QDir::currentPath() + "/" + staticDataFolderName + "/" + versionName + "Hash.xml";
|
||||
QFile file(hashPath);
|
||||
|
||||
if(file.exists()){
|
||||
file.remove();
|
||||
}
|
||||
|
||||
//удаление
|
||||
datas->removeOne(version);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
updateController->calculateSharedHash();
|
||||
updateController->sendNewVersionList();
|
||||
}
|
||||
|
||||
void AssetsManager::copyAllRecurse(QString source,QString destination)
|
||||
{
|
||||
|
||||
//Копируем все объекты туда
|
||||
QDir sourceDir(source);
|
||||
|
||||
foreach(QString folder,sourceDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot))
|
||||
{
|
||||
QString destPath = destination + QDir::separator() + folder;
|
||||
sourceDir.mkpath(destPath);
|
||||
copyAllRecurse(source + QDir::separator() + folder,destPath);
|
||||
}
|
||||
|
||||
foreach(QString file,sourceDir.entryList(QDir::Files))
|
||||
{
|
||||
QFile::copy(source + QDir::separator() + file,destination + QDir::separator() + file);
|
||||
}
|
||||
}
|
||||
|
||||
AssetsManager::~AssetsManager()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
StreamingVersionData *AssetsManager::getCurrentVersionData() const
|
||||
{
|
||||
return currentVersionData;
|
||||
}
|
||||
|
||||
41
ServerLMS/Systems/assetsmanager.h
Normal file
41
ServerLMS/Systems/assetsmanager.h
Normal file
@@ -0,0 +1,41 @@
|
||||
#ifndef ASSETSMANAGER_H
|
||||
#define ASSETSMANAGER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <Systems/updatecontroller.h>
|
||||
#include <Data/StreamingVersionData.h>
|
||||
|
||||
|
||||
class AssetsManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit AssetsManager(QObject *parent = nullptr);
|
||||
void initialize(UpdateController* updateContoller,DataParser *dataParser);
|
||||
void addVersion(StreamingVersionData *data);
|
||||
void createCopyVersion(QString versionName,QString newName);
|
||||
void deleteVersion(QString version);
|
||||
void setVersionList(QList<StreamingVersionData *> *streamingVersion);
|
||||
bool findDuplicate(QString name);
|
||||
QString setVersion(QString versionName);
|
||||
|
||||
QList<FileData> *prepareLocalPathList(QList<FileData>*fileData);
|
||||
QList<FileData> *prepareRealPathList(QList<FileData> *fileData);
|
||||
QList<FileData> *getRealPathList();
|
||||
|
||||
~AssetsManager();
|
||||
|
||||
StreamingVersionData *getCurrentVersionData() const;
|
||||
|
||||
signals:
|
||||
void sigSaveVersion(StreamingVersionData *versionData);
|
||||
|
||||
private:
|
||||
UpdateController *updateController;
|
||||
QList<StreamingVersionData*> *datas;
|
||||
StreamingVersionData* currentVersionData;
|
||||
|
||||
void copyAllRecurse(QString source, QString destination);
|
||||
};
|
||||
|
||||
#endif // ASSETSMANAGER_H
|
||||
141
ServerLMS/Systems/commonclienthandler.cpp
Normal file
141
ServerLMS/Systems/commonclienthandler.cpp
Normal file
@@ -0,0 +1,141 @@
|
||||
#include "commonclienthandler.h"
|
||||
|
||||
CommonClientHandler::CommonClientHandler(QObject *parent) : QObject(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CommonClientHandler::initialize(QMap<int, ClientHandler *> *clientsMap, ProcessingSystem *processingSystem, DataParser *dataParser, Logger *logger)
|
||||
{
|
||||
this->clientsMap = clientsMap;
|
||||
this->processingSystem = processingSystem;
|
||||
this->dataParser = dataParser;
|
||||
this->logger = logger;
|
||||
}
|
||||
|
||||
void CommonClientHandler::sendNewVersionListToAllClient()
|
||||
{
|
||||
foreach(int idSocket,clientsMap->keys())
|
||||
{
|
||||
ClientHandler *handler = clientsMap->value(idSocket);
|
||||
|
||||
if (!handler->getClient()->getIsLoggedIn()) continue;
|
||||
|
||||
handler->sendVersionList();
|
||||
}
|
||||
}
|
||||
|
||||
void CommonClientHandler::sendCurrentVersionToAllClient()
|
||||
{
|
||||
foreach(int idSocket,clientsMap->keys())
|
||||
{
|
||||
ClientHandler *handler = clientsMap->value(idSocket);
|
||||
|
||||
if (!handler->getClient()->getIsLoggedIn()) continue;
|
||||
handler->sendVersion();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void CommonClientHandler::slot_AuthChanged()
|
||||
{
|
||||
//Проходим все открытые сокеты
|
||||
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_LISTS;
|
||||
processingSystem->processingClientQueryToDB(handler, queryToDB);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CommonClientHandler::slot_sendPacketToAllClients(PacketType packetType)
|
||||
{
|
||||
foreach(int idSocket, clientsMap->keys())
|
||||
{
|
||||
ClientHandler *handler = clientsMap->value(idSocket);
|
||||
|
||||
if (!handler->getClient()->getIsLoggedIn()) continue;
|
||||
|
||||
handler->sendPacketType(packetType);
|
||||
}
|
||||
}
|
||||
|
||||
void CommonClientHandler::slot_msgToClientFromGUI(QString login, QString text)
|
||||
{
|
||||
QString textMsg = text;
|
||||
|
||||
QByteArray byteArrayMsg = dataParser->ClientAnswer()->message(textMsg);
|
||||
|
||||
//Проходим все открытые сокеты, ищем нужный
|
||||
foreach(int idSocket, clientsMap->keys())
|
||||
{
|
||||
ClientHandler *handler = clientsMap->value(idSocket);
|
||||
if(handler->getClient()->getLogin() == login)
|
||||
{//Отправляем ему
|
||||
|
||||
handler->sendXmlAnswer(byteArrayMsg);
|
||||
|
||||
QString peerAddress = handler->getSocket()->peerAddress().toString();
|
||||
QString peerPort = QString::number(handler->getSocket()->peerPort());
|
||||
|
||||
QString str = "Msg To Client [" + peerAddress + ":" + peerPort + "] : " + textMsg;
|
||||
|
||||
logger->addTextToLogger(str);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CommonClientHandler::slot_msgToGUIfromClient(QString login, QString text)
|
||||
{
|
||||
QString textMsg = text;
|
||||
|
||||
QByteArray byteArrayMsg = dataParser->ClientAnswer()->message(textMsg, login);
|
||||
|
||||
//Проходим все открытые сокеты, ищем нужный
|
||||
foreach(int idSocket, clientsMap->keys())
|
||||
{
|
||||
ClientHandler *handler = clientsMap->value(idSocket);;
|
||||
if(handler->getClient()->getTypeClient() == TypeClientAutorization::TYPE_GUI)
|
||||
{//Отправляем GUI-клиенту для отображения в Мессенджере
|
||||
|
||||
handler->sendXmlAnswer(byteArrayMsg, PacketType::TYPE_XMLANSWER);
|
||||
|
||||
QString peerAddress = handler->getSocket()->peerAddress().toString();
|
||||
QString peerPort = QString::number(handler->getSocket()->peerPort());
|
||||
|
||||
QString str = "Msg From Client [" + peerAddress + ":" + peerPort + "] : " + textMsg;
|
||||
|
||||
logger->addTextToLogger(str);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CommonClientHandler::slot_sendTaskToClient(QString fullNameClient,QString textTask)
|
||||
{
|
||||
QByteArray byteArrayTask = dataParser->ClientAnswer()->task(textTask);
|
||||
|
||||
//Проходим все открытые сокеты
|
||||
foreach(int idSocket, clientsMap->keys())
|
||||
{
|
||||
ClientHandler *handler = clientsMap->value(idSocket);
|
||||
|
||||
if(handler->getClient()->getFullName() == fullNameClient)
|
||||
{//Отправляем ему
|
||||
handler->getSocket()->write(byteArrayTask);
|
||||
|
||||
QString peerAddress = handler->getSocket()->peerAddress().toString();
|
||||
QString peerPort = QString::number(handler->getSocket()->peerPort());
|
||||
|
||||
QString str = "Task To Client [" + peerAddress + ":" + peerPort + "] : " + textTask;
|
||||
logger->addTextToLogger(str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
39
ServerLMS/Systems/commonclienthandler.h
Normal file
39
ServerLMS/Systems/commonclienthandler.h
Normal file
@@ -0,0 +1,39 @@
|
||||
#ifndef COMMONCLIENTHANDLER_H
|
||||
#define COMMONCLIENTHANDLER_H
|
||||
|
||||
#include <QObject>
|
||||
#include "clienthandler.h"
|
||||
|
||||
class ProcessingSystem;
|
||||
class DataParser;
|
||||
class Logger;
|
||||
|
||||
class CommonClientHandler : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit CommonClientHandler(QObject *parent = nullptr);
|
||||
void initialize(QMap<int, ClientHandler*> *clientsMap,
|
||||
ProcessingSystem *processingSystem,
|
||||
DataParser *dataParser,
|
||||
Logger *logger);
|
||||
|
||||
void sendNewVersionListToAllClient();
|
||||
void sendCurrentVersionToAllClient();
|
||||
void slot_AuthChanged();
|
||||
void slot_sendPacketToAllClients(PacketType packetType);
|
||||
//слот обработки сигнала о готовности нового сообщения на отправку клиенту от мессенджера
|
||||
void slot_msgToClientFromGUI(QString login, QString text);
|
||||
void slot_msgToGUIfromClient(QString login, QString text);
|
||||
void slot_sendTaskToClient(QString fullNameClient, QString textTask);
|
||||
signals:
|
||||
|
||||
private:
|
||||
QMap<int, ClientHandler*> *clientsMap;
|
||||
ProcessingSystem *processingSystem;
|
||||
DataParser *dataParser;
|
||||
Logger *logger;
|
||||
|
||||
};
|
||||
|
||||
#endif // COMMONCLIENTHANDLER_H
|
||||
35
ServerLMS/Systems/logger.cpp
Normal file
35
ServerLMS/Systems/logger.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#include "logger.h"
|
||||
|
||||
#include <QThread>
|
||||
|
||||
|
||||
Logger::Logger(QObject *parent):
|
||||
QObject(parent)
|
||||
{
|
||||
//this->listWidget = widget;
|
||||
}
|
||||
|
||||
Logger::~Logger()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Logger::setTypeLog(QString type)
|
||||
{
|
||||
typeLogger = type;
|
||||
}
|
||||
|
||||
void Logger::addTextToLogger(QString msg)
|
||||
{
|
||||
if(typeLogger == "widget")
|
||||
{
|
||||
emit sigSendTextToLogger(msg);
|
||||
}
|
||||
else if (typeLogger == "console")
|
||||
{
|
||||
//qDebug() << msg;
|
||||
}else
|
||||
{
|
||||
emit sigSendTextToLogger(msg);
|
||||
}
|
||||
}
|
||||
25
ServerLMS/Systems/logger.h
Normal file
25
ServerLMS/Systems/logger.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef LOGGER_H
|
||||
#define LOGGER_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class Logger : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit Logger(QObject *parent = nullptr);
|
||||
~Logger();
|
||||
void setTypeLog(QString type);
|
||||
public slots:
|
||||
void addTextToLogger(QString msg);
|
||||
|
||||
signals:
|
||||
void sigSendTextToLogger(QString msg);
|
||||
|
||||
private:
|
||||
//ServerLMSWidget *listWidget;
|
||||
QString typeLogger;
|
||||
};
|
||||
|
||||
#endif // LOGGER_H
|
||||
284
ServerLMS/Systems/processingsystem.cpp
Normal file
284
ServerLMS/Systems/processingsystem.cpp
Normal file
@@ -0,0 +1,284 @@
|
||||
#include "processingsystem.h"
|
||||
|
||||
#include <clienthandler.h>
|
||||
|
||||
ProcessingSystem::ProcessingSystem(ProviderDBLMS* providerDBLMS, QObject *parent):
|
||||
QObject(parent)
|
||||
{
|
||||
this->providerDBLMS = providerDBLMS;
|
||||
}
|
||||
|
||||
void ProcessingSystem::initialize(ServerLMSWidget *server, DataParser *dataParser, CommonClientHandler *commonClientHandler,Logger *logger)
|
||||
{
|
||||
this->commonClientServer = commonClientHandler;
|
||||
this->dataParser = dataParser;
|
||||
this->server = server;
|
||||
|
||||
connect(this,&ProcessingSystem::sigAuthChanged,commonClientHandler, &CommonClientHandler::slot_AuthChanged,Qt::AutoConnection);
|
||||
connect(this,&ProcessingSystem::sigUpdateListClients,server, &ServerLMSWidget::slotUpdateListClients,Qt::AutoConnection);
|
||||
connect(this,&ProcessingSystem::signal_msgToClientReady,commonClientHandler, &CommonClientHandler::slot_msgToClientFromGUI);
|
||||
connect(this,&ProcessingSystem::signal_msgFromClientReady,commonClientHandler, &CommonClientHandler::slot_msgToGUIfromClient);
|
||||
connect(this,&ProcessingSystem::sigLogMessage,logger,&Logger::addTextToLogger,Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
void ProcessingSystem::processingClientAutorization(ClientHandler *client, ClientAutorization clientAutorization)
|
||||
{
|
||||
if(server->getStateBlockAutorization() == blocked)
|
||||
{
|
||||
QByteArray arrayAnswer = dataParser->ClientAnswer()->notify(NOTIFY_SERVER_BLOCKED);
|
||||
client->sendXmlAnswer(arrayAnswer);
|
||||
|
||||
QString str = QString(arrayAnswer);
|
||||
emit sigLogMessage("To Client: " + str);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
//Попытка авторизации клиента (проверка по БД)
|
||||
QString instructorName;
|
||||
QString traineeName;
|
||||
QByteArray arrayAnswer;
|
||||
|
||||
if(providerDBLMS->authorizationTrainee(clientAutorization.Login, clientAutorization.Password, "", ""))
|
||||
{//Авторизуется обучаемый
|
||||
|
||||
client->getClient()->setLogin(clientAutorization.Login);
|
||||
emit sigUpdateListClients();
|
||||
|
||||
//KAV redact
|
||||
instructorName = providerDBLMS->getMainInstructorName();
|
||||
traineeName = providerDBLMS->getNameTraineeByLogin(clientAutorization.Login);
|
||||
|
||||
arrayAnswer = dataParser->ClientAnswer()->authorization(true, instructorName, traineeName, "trainee", clientAutorization.Login);
|
||||
}
|
||||
else if(providerDBLMS->authorizationInstructor(clientAutorization.Login, clientAutorization.Password))
|
||||
{//Авторизуется инструктор
|
||||
|
||||
client->getClient()->setLogin(clientAutorization.Login);
|
||||
client->getClient()->setTypeClient(clientAutorization.TypeClient);
|
||||
emit sigUpdateListClients();
|
||||
|
||||
instructorName = providerDBLMS->getNameInstructorByLogin(clientAutorization.Login);
|
||||
|
||||
arrayAnswer = dataParser->ClientAnswer()->authorization(true, instructorName, instructorName, "instructor", clientAutorization.Login);
|
||||
}
|
||||
else
|
||||
{//Никто не авторизовался
|
||||
arrayAnswer = dataParser->ClientAnswer()->authorization(false, "", "", "", "");
|
||||
}
|
||||
client->sendXmlAnswer(arrayAnswer);
|
||||
client->sendVersion();
|
||||
|
||||
QString str = QString(arrayAnswer);
|
||||
//logger->addTextToLogger("To Client: " + str);
|
||||
|
||||
//Извещаем об изменениях в авторизации
|
||||
emit sigAuthChanged();
|
||||
}
|
||||
|
||||
void ProcessingSystem::processingClientDeAutorization(ClientHandler *client, ClientDeAutorization clientDeAutorization)
|
||||
{
|
||||
if(server->getStateBlockAutorization() == blocked)
|
||||
{
|
||||
QByteArray arrayAnswer = dataParser->ClientAnswer()->notify(NOTIFY_SERVER_BLOCKED);
|
||||
client->sendXmlAnswer(arrayAnswer);
|
||||
|
||||
QString str = QString(arrayAnswer);
|
||||
emit sigLogMessage("To Client: " + str);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
//Попытка ДеАвторизации клиента (проверка по БД)
|
||||
QByteArray arrayAnswer;
|
||||
|
||||
if(providerDBLMS->deAuthorizationTrainee(clientDeAutorization.Login))
|
||||
{//ДеАвторизуется обучаемый
|
||||
|
||||
client->getClient()->setLogin("");
|
||||
emit sigUpdateListClients();
|
||||
|
||||
arrayAnswer = dataParser->ClientAnswer()->deAuthorization(true, clientDeAutorization.Login);
|
||||
}
|
||||
else if(providerDBLMS->deAuthorizationInstructor(clientDeAutorization.Login))
|
||||
{//ДеАвторизуется инструктор
|
||||
|
||||
client->getClient()->setLogin("");
|
||||
emit sigUpdateListClients();
|
||||
|
||||
arrayAnswer = dataParser->ClientAnswer()->deAuthorization(true, clientDeAutorization.Login);
|
||||
}
|
||||
else
|
||||
{//Никто не ДеАвторизовался
|
||||
arrayAnswer = dataParser->ClientAnswer()->deAuthorization(false, "");
|
||||
}
|
||||
client->sendXmlAnswer(arrayAnswer);
|
||||
|
||||
QString str = QString(arrayAnswer);
|
||||
//logger->addTextToLogger("To Client: " + str);
|
||||
|
||||
//Извещаем об изменениях в авторизации
|
||||
emit sigAuthChanged();
|
||||
}
|
||||
|
||||
void ProcessingSystem::processingClientQueryToDB(ClientHandler *client, ClientQueryToDB clientQueryToDB, int id, void* data)
|
||||
{
|
||||
QByteArray arrayAnswer;
|
||||
|
||||
qDebug() << "ProcessingQueryThread " << QThread::currentThreadId();
|
||||
switch (clientQueryToDB.typeQuery)
|
||||
{
|
||||
case TypeQueryToDB::TYPE_QUERY_GET_ALL_LISTS:
|
||||
{
|
||||
QList<Instructor> listInstructors = providerDBLMS->GetListAllInstructors();
|
||||
QList<Trainee> listTrainees = providerDBLMS->GetListAllTrainees();
|
||||
QList<Group> listGroups = providerDBLMS->GetListAllGroups();
|
||||
|
||||
arrayAnswer = dataParser->DbAnswer()->listInstructors(true, &listInstructors);
|
||||
client->sendXmlAnswer(arrayAnswer, PacketType::TYPE_XMLANSWER_QUERY_DB__LIST_INSTRUCTORS);
|
||||
|
||||
arrayAnswer = dataParser->DbAnswer()->listGroups(true, &listGroups);
|
||||
client->sendXmlAnswer(arrayAnswer, PacketType::TYPE_XMLANSWER_QUERY_DB__LIST_GROUPS);
|
||||
|
||||
arrayAnswer = dataParser->DbAnswer()->listTrainees(true, &listTrainees);
|
||||
client->sendXmlAnswer(arrayAnswer, PacketType::TYPE_XMLANSWER_QUERY_DB__LIST_TRAINEES);
|
||||
break;
|
||||
}
|
||||
case TypeQueryToDB::TYPE_QUERY_NEW_INSTRUCTOR:
|
||||
{
|
||||
int id_new;
|
||||
id_new = providerDBLMS->newInstructor();
|
||||
if(id_new)
|
||||
{
|
||||
(*(Instructor*)data).setID(id_new);
|
||||
providerDBLMS->editInstructor(*(Instructor*)data);
|
||||
}
|
||||
emit sigAuthChanged();
|
||||
break;
|
||||
}
|
||||
case TypeQueryToDB::TYPE_QUERY_DEL_INSTRUCTOR:
|
||||
{
|
||||
providerDBLMS->delInstructor(id);
|
||||
emit sigAuthChanged();
|
||||
break;
|
||||
}
|
||||
case TypeQueryToDB::TYPE_QUERY_EDIT_INSTRUCTOR:
|
||||
{
|
||||
providerDBLMS->editInstructor(*(Instructor*)data);
|
||||
emit sigAuthChanged();
|
||||
break;
|
||||
}
|
||||
|
||||
case TypeQueryToDB::TYPE_QUERY_NEW_TRAINEE:
|
||||
{
|
||||
int id_new;
|
||||
id_new = providerDBLMS->newTrainee(id);
|
||||
if(id_new)
|
||||
{
|
||||
(*(Trainee*)data).setID(id_new);
|
||||
providerDBLMS->editTrainee(*(Trainee*)data);
|
||||
}
|
||||
emit sigAuthChanged();
|
||||
break;
|
||||
}
|
||||
case TypeQueryToDB::TYPE_QUERY_DEL_TRAINEE:
|
||||
{
|
||||
providerDBLMS->delTrainee(id);
|
||||
emit sigAuthChanged();
|
||||
break;
|
||||
}
|
||||
case TypeQueryToDB::TYPE_QUERY_EDIT_TRAINEE:
|
||||
{
|
||||
providerDBLMS->editTrainee(*(Trainee*)data);
|
||||
emit sigAuthChanged();
|
||||
break;
|
||||
}
|
||||
|
||||
case TypeQueryToDB::TYPE_QUERY_NEW_GROUP:
|
||||
{
|
||||
int id_new;
|
||||
id_new = providerDBLMS->newGroup();
|
||||
if(id_new)
|
||||
{
|
||||
(*(Group*)data).setID(id_new);
|
||||
providerDBLMS->editGroup(*(Group*)data);
|
||||
}
|
||||
emit sigAuthChanged();
|
||||
break;
|
||||
}
|
||||
case TypeQueryToDB::TYPE_QUERY_DEL_GROUP:
|
||||
{
|
||||
providerDBLMS->delGroup(id);
|
||||
emit sigAuthChanged();
|
||||
break;
|
||||
}
|
||||
case TypeQueryToDB::TYPE_QUERY_EDIT_GROUP:
|
||||
{
|
||||
providerDBLMS->editGroup(*(Group*)data);
|
||||
emit sigAuthChanged();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//client->sendXmlAnswer(arrayAnswer, PacketType::TYPE_XMLANSWER_QUERY_DB_LIST_INSTRUCTORS);
|
||||
|
||||
//QString str = QString(arrayAnswer);
|
||||
//logger->addTextToLogger("To Client: " + str);
|
||||
}
|
||||
|
||||
void ProcessingSystem::processingToClientMessage(ClientHandler *client, ToClientMessage toClientMessage)
|
||||
{
|
||||
signal_msgToClientReady(toClientMessage.Login, toClientMessage.Text);
|
||||
}
|
||||
|
||||
void ProcessingSystem::processingFromClientMessage(ClientHandler *client, ClientMessage clientMessage)
|
||||
{
|
||||
/*
|
||||
QString peerAddress = client->getSocket()->peerAddress().toString();
|
||||
QString peerPort = QString::number(client->getSocket()->peerPort());
|
||||
|
||||
QString str = "Msg From Client [" + peerAddress + ":" + peerPort + "] : " + clientMessage.Text;
|
||||
|
||||
emit sigLogMessage(str);
|
||||
*/
|
||||
|
||||
signal_msgFromClientReady(client->getClient()->getLogin(), clientMessage.Text);
|
||||
}
|
||||
|
||||
void ProcessingSystem::processingClientNotify(ClientHandler *client, ClientNotify clientNotify)
|
||||
{
|
||||
if(clientNotify.Code == commandReadyClient)
|
||||
{//Клиент готов принять задания
|
||||
client->getClient()->setReady(true); //скорее всего функции будут внутри хэндлера
|
||||
|
||||
//Отправляем пакет с заданиями для Обучаемого(клиента)
|
||||
|
||||
client->getSocket()->flush();
|
||||
|
||||
QStringList listTasks;
|
||||
//TODO KAV redact
|
||||
//listTasks = pInstructorsAndTrainees->getDbLMS()->getWhatItDoes(client->getClient()->getLogin());
|
||||
|
||||
QByteArray arrayAnswer = dataParser->ClientAnswer()->tasks(listTasks);
|
||||
client->sendXmlAnswer(arrayAnswer);
|
||||
|
||||
QString str = QString(arrayAnswer);
|
||||
emit sigLogMessage("To Client: " + str);
|
||||
}
|
||||
else if(clientNotify.Code == commandDisableClient)
|
||||
{
|
||||
qDebug() << "processing thread: " << QThread::currentThreadId();
|
||||
client->sendDisable();
|
||||
}
|
||||
else if(clientNotify.Code == commandGetServerDataList)
|
||||
{
|
||||
client->sendHash();
|
||||
}
|
||||
else if(clientNotify.Code == commandCheckVersionList)
|
||||
{
|
||||
client->sendVersionList();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
51
ServerLMS/Systems/processingsystem.h
Normal file
51
ServerLMS/Systems/processingsystem.h
Normal file
@@ -0,0 +1,51 @@
|
||||
#ifndef PROCESSINGSYSTEM_H
|
||||
#define PROCESSINGSYSTEM_H
|
||||
|
||||
#include <Systems/sendsystem.h>
|
||||
#include <Data/typesDataServerClient.h>
|
||||
|
||||
#include <clienthandler.h>
|
||||
#include <serverlmswidget.h>
|
||||
//#include "instructorsandtraineeswidget.h"
|
||||
#include "providerdblms.h"
|
||||
|
||||
class SendSystem;
|
||||
class ServerLMSWidget;
|
||||
class InstructorsAndTrainees;
|
||||
class Logger;
|
||||
class DataParser;
|
||||
class ClientHandler;
|
||||
class CommonClientHandler;
|
||||
|
||||
class ProcessingSystem : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ProcessingSystem(ProviderDBLMS* providerDBLMS, QObject *parent = nullptr);
|
||||
|
||||
void initialize(ServerLMSWidget *server,DataParser* dataParser,CommonClientHandler *commonClientServer,Logger *logger);
|
||||
void processingClientAutorization(ClientHandler *client, ClientAutorization clientAutorization);
|
||||
void processingClientDeAutorization(ClientHandler *client, ClientDeAutorization clientDeAutorization);
|
||||
void processingClientQueryToDB(ClientHandler *client, ClientQueryToDB clientQueryToDB, int id = 0, void* data = nullptr);
|
||||
void processingToClientMessage(ClientHandler *client, ToClientMessage toClientMessage);
|
||||
|
||||
void processingFromClientMessage(ClientHandler *client, ClientMessage clientMessage);
|
||||
void processingClientNotify(ClientHandler *client, ClientNotify clientNotify);
|
||||
|
||||
signals:
|
||||
void sigUpdateListClients();
|
||||
void sigAuthChanged();
|
||||
void sigLogMessage(QString log);
|
||||
void sigAddToMessanger(QString login,QString text);
|
||||
void signal_msgToClientReady(QString login, QString text);
|
||||
void signal_msgFromClientReady(QString login, QString text);
|
||||
|
||||
private:
|
||||
CommonClientHandler *commonClientServer;
|
||||
ServerLMSWidget *server;
|
||||
DataParser *dataParser;
|
||||
//InstructorsAndTraineesWidget *pInstructorsAndTrainees;
|
||||
ProviderDBLMS* providerDBLMS;
|
||||
};
|
||||
|
||||
#endif // PROCESSINGSYSTEM_H
|
||||
418
ServerLMS/Systems/recognizesystem.cpp
Normal file
418
ServerLMS/Systems/recognizesystem.cpp
Normal file
@@ -0,0 +1,418 @@
|
||||
#include "recognizesystem.h"
|
||||
|
||||
RecognizeSystem::RecognizeSystem(QObject *parent):
|
||||
QObject(parent)
|
||||
{
|
||||
packetType = PacketType::TYPE_NONE;
|
||||
filePath.clear();
|
||||
fileSize = 0;
|
||||
sizeReceiveData = 0;
|
||||
tmpBlock.clear();
|
||||
countSend = 0;
|
||||
mutex = new QMutex;
|
||||
|
||||
}
|
||||
|
||||
void RecognizeSystem::initialize(UpdateController *updateController,DataParser* dataParser,
|
||||
ServerLMSWidget *server,SendSystem *sendSystem, ClientHandler *handler)
|
||||
{
|
||||
this->updateController = updateController;
|
||||
this->dataParser = dataParser;
|
||||
this->server = server;
|
||||
this->clientHandler = handler;
|
||||
this->sendSystem = sendSystem;
|
||||
socket = handler->getSocket();
|
||||
|
||||
connect(this,&RecognizeSystem::sigCalculateHash,updateController,&UpdateController::calculateFullHash,Qt::AutoConnection);
|
||||
connect(this,&RecognizeSystem::sigCalculateHash,updateController,&UpdateController::setUpCurrentServerHash,Qt::AutoConnection);
|
||||
connect(this,&RecognizeSystem::sigChangeVersion,updateController,&UpdateController::changeAssetVersion,Qt::AutoConnection);
|
||||
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::read,Qt::DirectConnection);
|
||||
|
||||
qDebug() << "Recognize init thread ID " << QThread::currentThreadId();
|
||||
}
|
||||
|
||||
void RecognizeSystem::recognize()
|
||||
{
|
||||
mutex->lock();
|
||||
qDebug() << "Recognize thread ID " << QThread::currentThreadId();
|
||||
QDataStream stream(socket);
|
||||
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
|
||||
QByteArray data;
|
||||
Client *client = clientHandler->getClient();
|
||||
|
||||
while (socket->bytesAvailable() > 0)
|
||||
{
|
||||
|
||||
if (packetType == PacketType::TYPE_NONE)
|
||||
{
|
||||
stream.startTransaction();
|
||||
|
||||
if(!isPackageTypeInited) //первичная инициализация для типа клиента
|
||||
{
|
||||
char *read = new char[0];
|
||||
stream.readRawData(read,1);
|
||||
packetType = static_cast<PacketType>(QString(read[0]).toInt());
|
||||
|
||||
packetTypeInit(packetType,client);
|
||||
|
||||
if(!stream.commitTransaction()) continue;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(client->getIsUnity())
|
||||
{
|
||||
char *read = new char[0];
|
||||
stream.readRawData(read,1);
|
||||
packetType = static_cast<PacketType>(QString(read[0]).toInt());
|
||||
|
||||
if(!stream.commitTransaction()) continue;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
stream >> packetType;
|
||||
|
||||
if(!stream.commitTransaction()) continue;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (packetType == PacketType::TYPE_COMMAND) //TODO: надо переделать под какой то нормальный тип, который уже существует
|
||||
{
|
||||
stream.startTransaction();
|
||||
stream >> command;
|
||||
|
||||
if (!stream.commitTransaction()) continue;
|
||||
}
|
||||
|
||||
if (command == commandUpdateFilesClient) //запускает процесс оновления
|
||||
{
|
||||
sendSystem->updateFiles(updateController->getFileSendList(),
|
||||
updateController->getClientDataList());
|
||||
|
||||
qDebug()<< "Call update";
|
||||
packetType = PacketType::TYPE_NONE;
|
||||
command = "";
|
||||
}
|
||||
|
||||
if (packetType == PacketType::TYPE_XMLANSWER)
|
||||
{
|
||||
|
||||
if(clientHandler->getClient()->getIsUnity())
|
||||
{
|
||||
data = socket->readAll();
|
||||
}
|
||||
else
|
||||
{
|
||||
stream.startTransaction();
|
||||
stream >> data;
|
||||
|
||||
if(!stream.commitTransaction()) continue;
|
||||
}
|
||||
|
||||
qDebug() << data;
|
||||
emit sigXmlParser(clientHandler,data);
|
||||
packetType = PacketType::TYPE_NONE;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(packetType == PacketType::TYPE_FOLDER) //создание папок
|
||||
{
|
||||
if(client->getIsUnity())
|
||||
{
|
||||
filePath = socket->readAll();
|
||||
filePath = Tools::createSharedPath(filePath);
|
||||
}
|
||||
else
|
||||
{
|
||||
stream.startTransaction();
|
||||
stream >> filePath;
|
||||
|
||||
if(!stream.commitTransaction()){
|
||||
continue;
|
||||
}
|
||||
|
||||
filePath = createFullPath(filePath);
|
||||
|
||||
}
|
||||
|
||||
QDir dir(filePath);
|
||||
if(!dir.exists()){
|
||||
if(dir.mkpath(filePath)){
|
||||
qDebug() << "Dir Created";
|
||||
}
|
||||
}
|
||||
|
||||
packetType = PacketType::TYPE_NONE;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (packetType == PacketType::TYPE_FILE) //выгрузка одного файла
|
||||
{
|
||||
|
||||
if(client->getIsUnity())
|
||||
{
|
||||
DataInfo *currentFileData = updateController->getCurrentDataInfo();
|
||||
filePath = currentFileData->path;
|
||||
filePath = Tools::createSharedPath(filePath);
|
||||
|
||||
QFile file(filePath);
|
||||
|
||||
|
||||
if (file.exists())
|
||||
{
|
||||
file.remove(); //удаление файла, если он уже есть, но необходимо обновить
|
||||
qDebug() << Tools::getTime() + "Delete exist file: " + filePath;
|
||||
}
|
||||
|
||||
if (!file.open(QFile::Append))
|
||||
{
|
||||
QString folderPath = Tools::createFolderPath(filePath);
|
||||
qDebug() << "FULL PATH: " << folderPath;
|
||||
QDir dir(folderPath);
|
||||
if (!dir.exists()){
|
||||
dir.mkpath(".");
|
||||
}
|
||||
|
||||
file.open(QFile::Append);
|
||||
}
|
||||
|
||||
//socket->waitForReadyRead(1000);
|
||||
|
||||
fileSize = currentFileData->size;
|
||||
|
||||
qint64 readSize = 65535;
|
||||
forever
|
||||
{
|
||||
if(fileSize < readSize)
|
||||
{
|
||||
readSize = fileSize;
|
||||
qDebug() << "LastPackage: " << readSize;
|
||||
}
|
||||
|
||||
socket->waitForReadyRead(20);
|
||||
tmpBlock = socket->read(readSize);
|
||||
|
||||
quint64 toFile = file.write(tmpBlock);
|
||||
fileSize -= toFile;
|
||||
sizeReceiveData += toFile;
|
||||
countSend++;
|
||||
|
||||
tmpBlock.clear();
|
||||
qDebug() << "Loading progress: " << fileSize << "/" << currentFileData->size;
|
||||
|
||||
if(fileSize == 0) break;
|
||||
|
||||
}
|
||||
|
||||
file.close();
|
||||
filePath.clear();
|
||||
updateController->clearCurrentDataInfo();
|
||||
|
||||
socket->waitForReadyRead(100);
|
||||
|
||||
packetType = PacketType::TYPE_NONE;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
forever
|
||||
{
|
||||
stream.startTransaction();
|
||||
stream >> filePath;
|
||||
stream >> fileSize;
|
||||
|
||||
if(!stream.commitTransaction()) continue;
|
||||
|
||||
filePath = createFullPath(filePath);
|
||||
socket->waitForReadyRead(100);
|
||||
break;
|
||||
}
|
||||
|
||||
QFile file(filePath);
|
||||
QFileInfo fileInfo(file);
|
||||
|
||||
if(file.exists())
|
||||
{
|
||||
file.remove();
|
||||
}
|
||||
|
||||
file.open(QFile::Append);
|
||||
|
||||
forever
|
||||
{
|
||||
stream.startTransaction();
|
||||
stream >> tmpBlock;
|
||||
|
||||
if(!stream.commitTransaction()){
|
||||
|
||||
if(socket->state() == QAbstractSocket::UnconnectedState){
|
||||
qDebug() << "UNCONNECT";
|
||||
mutex->unlock();
|
||||
file.close();
|
||||
return;
|
||||
}
|
||||
if(socket->waitForReadyRead(TCP_READ_TIMEOUT)){
|
||||
continue;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
quint64 toFile = file.write(tmpBlock);
|
||||
sizeReceiveData += toFile;
|
||||
countSend++;
|
||||
|
||||
tmpBlock.clear();
|
||||
|
||||
if(sizeReceiveData == fileSize) break;
|
||||
|
||||
|
||||
}
|
||||
|
||||
QString logMessage = Tools::getTime() + " ";
|
||||
logMessage.append("Load from " + client->getLogin() + " ");
|
||||
logMessage.append(fileInfo.fileName());
|
||||
|
||||
emit sigSendToLogger(logMessage);
|
||||
|
||||
file.close();
|
||||
|
||||
if(command == "check")
|
||||
{
|
||||
QFile checkFile(filePath);
|
||||
checkFile.open(QIODevice::ReadOnly);
|
||||
updateController->compareFiles(clientHandler,checkFile.readAll());
|
||||
checkFile.close();
|
||||
}
|
||||
|
||||
filePath.clear();
|
||||
fileSize = 0;
|
||||
tmpBlock.clear();
|
||||
sizeReceiveData = 0;
|
||||
countSend = 0;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (packetType == PacketType::TYPE_FILESIZE)
|
||||
{
|
||||
fileSize = socket->readAll().toULong();
|
||||
qDebug() << fileSize;
|
||||
packetType = PacketType::TYPE_NONE;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (packetType == PacketType::TYPE_FINISH)
|
||||
{
|
||||
emit sigCalculateHash();
|
||||
packetType = PacketType::TYPE_NONE;
|
||||
}
|
||||
|
||||
if(packetType == PacketType::CHANGE_DATA_VERSION)
|
||||
{
|
||||
stream.startTransaction();
|
||||
QString versionName;
|
||||
stream >> versionName;
|
||||
|
||||
if(!stream.commitTransaction()) continue;
|
||||
|
||||
qDebug() << "For change " + versionName;
|
||||
|
||||
emit sigChangeVersion(versionName);
|
||||
|
||||
}
|
||||
|
||||
if(packetType == PacketType::COPY_VERSION)
|
||||
{
|
||||
QString source;
|
||||
QStringList result;
|
||||
|
||||
stream.startTransaction();
|
||||
stream >> source;
|
||||
|
||||
if(!stream.commitTransaction()) continue;
|
||||
|
||||
result = source.split(";");
|
||||
|
||||
if (updateController->checkDuplicate(result[1]))
|
||||
{
|
||||
sendSystem->sendNotify(commandDuplicateVerName);
|
||||
packetType = PacketType::TYPE_NONE;
|
||||
break;
|
||||
}
|
||||
|
||||
emit sigCopyVersion(result[0],result[1]);
|
||||
sendSystem->sendPacketType(PacketType::BUSY);
|
||||
}
|
||||
|
||||
if(packetType == PacketType::DELETE_DATA_VERSION)
|
||||
{
|
||||
stream.startTransaction();
|
||||
QString versionName;
|
||||
stream >> versionName;
|
||||
|
||||
if(!stream.commitTransaction()) continue;
|
||||
|
||||
qDebug() << "For delete " + versionName;
|
||||
|
||||
|
||||
if (versionName == baseNameVersion)
|
||||
{
|
||||
sendSystem->sendNotify(commandTryBaseDelete);
|
||||
}
|
||||
else if (versionName == updateController->getCurrentVersionName())
|
||||
{
|
||||
sendSystem->sendNotify(commandTryActiveDelete);
|
||||
}
|
||||
else
|
||||
{
|
||||
emit sigDeleteVersion(versionName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
packetType = PacketType::TYPE_NONE;
|
||||
}
|
||||
|
||||
mutex->unlock();
|
||||
}
|
||||
|
||||
void RecognizeSystem::packetTypeInit(PacketType packet,Client *client)
|
||||
{
|
||||
if(packet == PacketType::TYPE_QT)
|
||||
{
|
||||
client->setUnity(false);
|
||||
|
||||
qDebug() << "ConnectionType isUnity: " << client->getIsUnity();
|
||||
}
|
||||
else if (packet == PacketType::TYPE_UNITY)
|
||||
{
|
||||
client->setUnity(true);
|
||||
}
|
||||
|
||||
isPackageTypeInited = true;
|
||||
|
||||
packetType = PacketType::TYPE_NONE;
|
||||
}
|
||||
|
||||
QString RecognizeSystem::createFullPath(QString path)
|
||||
{
|
||||
QString fullPath;
|
||||
qint8 pos = path.indexOf("Application");
|
||||
|
||||
QString localPath = path.remove(0,--pos);
|
||||
|
||||
//qDebug() << "CLIENT: localPath" << localPath;
|
||||
fullPath = QDir::currentPath() + localPath;
|
||||
|
||||
return fullPath;
|
||||
}
|
||||
|
||||
RecognizeSystem::~RecognizeSystem()
|
||||
{
|
||||
|
||||
}
|
||||
65
ServerLMS/Systems/recognizesystem.h
Normal file
65
ServerLMS/Systems/recognizesystem.h
Normal file
@@ -0,0 +1,65 @@
|
||||
#ifndef RECOGNIZESYSTEM_H
|
||||
#define RECOGNIZESYSTEM_H
|
||||
|
||||
#include <QDataStream>
|
||||
#include <QTcpSocket>
|
||||
#include <QMutex>
|
||||
|
||||
#include <Systems/updatecontroller.h>
|
||||
#include <Systems/tools.h>
|
||||
#include <Systems/Parsers/dataparser.h>
|
||||
|
||||
#include <Data/Client.h>
|
||||
#include <Data/PacketType.h>
|
||||
|
||||
#include "serverlmswidget.h"
|
||||
|
||||
class UpdateController;
|
||||
class ServerLMSWidget;
|
||||
class ClientHandler;
|
||||
|
||||
class RecognizeSystem : public QObject
|
||||
{
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
RecognizeSystem(QObject *parent = nullptr);
|
||||
void initialize(UpdateController *updateController,DataParser *dataParser,
|
||||
ServerLMSWidget *server,SendSystem *sendSystem, ClientHandler *handler);
|
||||
void recognize();
|
||||
~RecognizeSystem();
|
||||
|
||||
signals:
|
||||
void sigCalculateHash();
|
||||
void sigSendToLogger(QString string);
|
||||
void sigXmlParser(ClientHandler *clientHandler,QByteArray data);
|
||||
void sigChangeVersion(QString versionName);
|
||||
void sigDeleteVersion(QString versionName);
|
||||
void sigCopyVersion(QString versionName,QString newVersionName);
|
||||
|
||||
private:
|
||||
UpdateController *updateController;
|
||||
SendSystem *sendSystem;
|
||||
DataParser *dataParser;
|
||||
ServerLMSWidget *server;
|
||||
QString command;
|
||||
PacketType packetType;
|
||||
QString filePath;
|
||||
ClientHandler *clientHandler;
|
||||
QMutex *mutex;
|
||||
|
||||
QTcpSocket *socket;
|
||||
|
||||
QByteArray tmpBlock;
|
||||
|
||||
qint64 sizeReceiveData;
|
||||
qint64 fileSize;
|
||||
int countSend;
|
||||
bool isPackageTypeInited;
|
||||
|
||||
void packetTypeInit(PacketType packet,Client *client);
|
||||
void packetTypeInit(PacketType type);
|
||||
QString createFullPath(QString path);
|
||||
};
|
||||
#endif // RECOGNIZESYSTEM_H
|
||||
279
ServerLMS/Systems/sendsystem.cpp
Normal file
279
ServerLMS/Systems/sendsystem.cpp
Normal file
@@ -0,0 +1,279 @@
|
||||
#include "sendsystem.h"
|
||||
|
||||
|
||||
SendSystem::SendSystem(QObject *parent) : QObject(parent)
|
||||
{
|
||||
isSendStopped = false;
|
||||
}
|
||||
|
||||
void SendSystem::initialize(DataParser *dataParser,Logger *logger)
|
||||
{
|
||||
this->dataParser = dataParser;
|
||||
this->logger = logger;
|
||||
|
||||
connect(this,&SendSystem::sigSendToLogger,logger,&Logger::addTextToLogger,Qt::AutoConnection);
|
||||
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();
|
||||
}
|
||||
|
||||
void SendSystem::setClient(Client *client,QTcpSocket *socket)
|
||||
{
|
||||
this->socket = socket;
|
||||
this->isUnity = client->getIsUnity();
|
||||
this->client = client;
|
||||
isSendStopped = false;
|
||||
}
|
||||
|
||||
void SendSystem::sendMessageBlock(QString message)
|
||||
{
|
||||
auto messageBlock = emit sigSendXMLmessage(message);
|
||||
sendXmlAnswer(messageBlock);
|
||||
}
|
||||
|
||||
void SendSystem::sendFileBlock(QString path)
|
||||
{
|
||||
|
||||
qDebug() << "sendFileBlock thread: " << QThread::currentThreadId();
|
||||
|
||||
QDataStream stream(socket);
|
||||
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
|
||||
|
||||
QFile file(path);
|
||||
QFileInfo fileInfo(file);
|
||||
fileSize = fileInfo.size();
|
||||
|
||||
if(fileSize == 0){
|
||||
emit sigSendToLogger(Tools::getTime() + " WARNING! Zero size " + path);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
stream << PacketType::TYPE_FILE; //Отправляем тип блока
|
||||
|
||||
stream << path << fileSize;
|
||||
|
||||
if(isSendStopped) { //Поведение на случай отключения клиента
|
||||
|
||||
file.close();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
socket->waitForBytesWritten();
|
||||
|
||||
if(file.open(QFile::ReadOnly)){
|
||||
while(!file.atEnd()){
|
||||
QByteArray data = file.read(1025*250);
|
||||
stream << data;
|
||||
socket->waitForBytesWritten();
|
||||
countSend++;
|
||||
}
|
||||
|
||||
emit sigSendToLogger(Tools::getTime() + " send file " + fileInfo.fileName());
|
||||
}
|
||||
|
||||
file.close();
|
||||
countSend = 0;
|
||||
socket->waitForBytesWritten();
|
||||
socket->waitForReadyRead(100);
|
||||
}
|
||||
|
||||
void SendSystem::sendVersion()
|
||||
{
|
||||
QByteArray data = dataParser->ClientAnswer()->currentVersion();
|
||||
sendXmlAnswer(data);
|
||||
}
|
||||
|
||||
void SendSystem::sendFileBlockWithRename(QString path, QString newName)
|
||||
{
|
||||
qDebug() << "sendFileBlockWithRename thread: " << QThread::currentThreadId();
|
||||
|
||||
QDataStream stream(socket);
|
||||
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
|
||||
|
||||
QFile file(Tools::createRootPath(path));
|
||||
QFileInfo fileInfo(file);
|
||||
fileSize = fileInfo.size();
|
||||
|
||||
if(fileSize == 0){
|
||||
emit sigSendToLogger(Tools::getTime() + " WARNING! Zero size " + path);
|
||||
return;
|
||||
}
|
||||
|
||||
QString pathForSend = Tools::createFolderPath(path) + "/" + staticDataFolderName + newName;
|
||||
|
||||
stream << PacketType::TYPE_FILE; //Отправляем тип блока
|
||||
|
||||
stream << pathForSend << fileSize;
|
||||
|
||||
if(isSendStopped) { //Поведение на случай отключения клиента
|
||||
|
||||
file.close();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
socket->waitForBytesWritten();
|
||||
|
||||
if(file.open(QFile::ReadOnly)){
|
||||
while(!file.atEnd()){
|
||||
QByteArray data = file.read(1025*250);
|
||||
stream << data;
|
||||
socket->waitForBytesWritten();
|
||||
countSend++;
|
||||
}
|
||||
|
||||
emit sigSendToLogger(Tools::getTime() + " send file " + fileInfo.fileName());
|
||||
}
|
||||
|
||||
file.close();
|
||||
countSend = 0;
|
||||
socket->waitForBytesWritten();
|
||||
socket->waitForReadyRead(100);
|
||||
|
||||
sendNotify(commandHashCompleteClient);
|
||||
}
|
||||
|
||||
void SendSystem::sendFolderBlock(QString path)
|
||||
{
|
||||
QDataStream stream(socket);
|
||||
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
|
||||
|
||||
stream << PacketType::TYPE_FOLDER;
|
||||
stream << path;
|
||||
socket->waitForReadyRead(100);
|
||||
}
|
||||
|
||||
void SendSystem::sendDeleteBlock(QString path)
|
||||
{
|
||||
QDataStream stream(socket);
|
||||
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
|
||||
|
||||
stream << PacketType::TYPE_DELETE;
|
||||
stream << path;
|
||||
socket->waitForReadyRead(100);
|
||||
}
|
||||
|
||||
void SendSystem::sendPacketType(PacketType packetType)
|
||||
{
|
||||
QDataStream stream(socket);
|
||||
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
|
||||
stream << packetType;
|
||||
socket->waitForReadyRead(100);
|
||||
}
|
||||
|
||||
void SendSystem::sendHello()
|
||||
{
|
||||
socket->write(SERVER_HELLO);
|
||||
}
|
||||
|
||||
void SendSystem::sendNotify(QString notify)
|
||||
{
|
||||
qDebug() << "SendNotify thread: " << QThread::currentThreadId();
|
||||
auto answer = emit sigSendNotify(notify);//"END");
|
||||
sendXmlAnswer(answer);
|
||||
}
|
||||
|
||||
void SendSystem::sendXmlAnswer(QByteArray array, PacketType packetType)
|
||||
{
|
||||
qDebug() << "SendSystemThread: " << QThread::currentThreadId();
|
||||
if(!client->getIsUnity())
|
||||
{
|
||||
QDataStream stream(socket);
|
||||
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
|
||||
|
||||
stream << /*PacketType::TYPE_XMLANSWER*/packetType;
|
||||
stream << array;
|
||||
}
|
||||
else
|
||||
{
|
||||
socket->write(array);
|
||||
}
|
||||
|
||||
|
||||
socket->waitForReadyRead(1000);
|
||||
}
|
||||
|
||||
void SendSystem::sendNeedUpdate(bool flag,quint64 size,quint64 fileCount,quint64 deleteCount)
|
||||
{
|
||||
QDataStream stream(socket);
|
||||
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
|
||||
stream << PacketType::TYPE_NEEDUPDATE;
|
||||
stream << flag;
|
||||
stream << size;
|
||||
stream << fileCount;
|
||||
stream << deleteCount;
|
||||
}
|
||||
|
||||
void SendSystem::updateFiles(QList<FileData> fileSendList, QList<FileData> deleteList){
|
||||
|
||||
QListIterator<FileData> clientIterator(deleteList);
|
||||
|
||||
while(clientIterator.hasNext())
|
||||
{
|
||||
FileData data = clientIterator.next();
|
||||
|
||||
sendDeleteBlock(data.path);
|
||||
if(getIsSendStopped()) return;
|
||||
}
|
||||
|
||||
QListIterator<FileData> serverIterator(fileSendList);
|
||||
|
||||
while(serverIterator.hasNext())
|
||||
{
|
||||
FileData data = serverIterator.next();
|
||||
|
||||
if (data.hash == "FOLDER")
|
||||
{
|
||||
sendFolderBlock(data.path);
|
||||
socket->waitForReadyRead(100);
|
||||
}
|
||||
else
|
||||
{
|
||||
sendFileBlock(data.path);
|
||||
socket->waitForReadyRead(100);
|
||||
}
|
||||
|
||||
if(getIsSendStopped()) return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
emit sigLoadHash();
|
||||
|
||||
sendPacketType(PacketType::TYPE_FINISH);
|
||||
}
|
||||
|
||||
void SendSystem::socketWrite(QByteArray array)
|
||||
{
|
||||
socket->write(array);
|
||||
socket->waitForBytesWritten(100);
|
||||
}
|
||||
|
||||
void SendSystem::socketClose()
|
||||
{
|
||||
socket->close();
|
||||
}
|
||||
|
||||
bool SendSystem::socketFlush() //TODO: проверить использование
|
||||
{
|
||||
return socket->flush();
|
||||
}
|
||||
|
||||
void SendSystem::sendStop()
|
||||
{
|
||||
isSendStopped = true;
|
||||
}
|
||||
|
||||
bool SendSystem::getIsSendStopped() const
|
||||
{
|
||||
return isSendStopped;
|
||||
}
|
||||
|
||||
SendSystem::~SendSystem()
|
||||
{
|
||||
|
||||
}
|
||||
70
ServerLMS/Systems/sendsystem.h
Normal file
70
ServerLMS/Systems/sendsystem.h
Normal file
@@ -0,0 +1,70 @@
|
||||
#ifndef SENDSYSTEM_H
|
||||
#define SENDSYSTEM_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QtNetwork>
|
||||
|
||||
#include <Systems/Parsers/dataparser.h>
|
||||
#include <Systems/tools.h>
|
||||
#include <Data/Client.h>
|
||||
#include <Data/PacketType.h>
|
||||
|
||||
class DataParser;
|
||||
class FileData;
|
||||
|
||||
class SendSystem : public QObject
|
||||
{
|
||||
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SendSystem(QObject* parent = nullptr);
|
||||
|
||||
void initialize(DataParser* dataParser,Logger *logger);
|
||||
void setClient(Client* client,QTcpSocket *socket);
|
||||
void sendMessageBlock(QString message);
|
||||
void sendFileBlock(QString path);
|
||||
void sendFileBlockWithRename(QString path,QString newName);
|
||||
void sendFolderBlock(QString path);
|
||||
void sendDeleteBlock(QString path);
|
||||
void sendPacketType(PacketType packet);
|
||||
void sendHello();
|
||||
void sendNotify(QString notify);
|
||||
void sendStop();
|
||||
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;
|
||||
|
||||
~SendSystem();
|
||||
|
||||
|
||||
public slots:
|
||||
void socketWrite(QByteArray array);
|
||||
void socketClose();
|
||||
void sendVersion();
|
||||
|
||||
signals:
|
||||
void sigLoadHash();
|
||||
void sigSendToLogger(QString message);
|
||||
QByteArray sigSendXMLmessage(QString message, QString login = "");
|
||||
QByteArray sigSendNotify(QString message);
|
||||
QByteArray sigSendVersion();
|
||||
|
||||
private:
|
||||
Client *client;
|
||||
QTcpSocket* socket;
|
||||
DataParser* dataParser;
|
||||
Logger *logger;
|
||||
QMutex *mutex;
|
||||
quint64 fileSize;
|
||||
int countSend;
|
||||
bool isSendStopped;
|
||||
bool isUnity;
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // SENDSYSTEM_H
|
||||
89
ServerLMS/Systems/tools.cpp
Normal file
89
ServerLMS/Systems/tools.cpp
Normal file
@@ -0,0 +1,89 @@
|
||||
#include "tools.h"
|
||||
|
||||
#include <QDir>
|
||||
|
||||
void Tools::printTime()
|
||||
{
|
||||
qDebug() << QTime::currentTime().toString("hh:mm:ss.zzz");
|
||||
}
|
||||
|
||||
|
||||
QString Tools::getTime()
|
||||
{
|
||||
return QTime::currentTime().toString("hh:mm:ss.zzz");
|
||||
}
|
||||
|
||||
QString Tools::createLocalPath(QString path)
|
||||
{
|
||||
qint8 pos = path.indexOf(applicationFolderName);
|
||||
|
||||
QString localPath = path.remove(0,--pos);
|
||||
|
||||
//qDebug() << "Local path: " << localPath;
|
||||
return localPath;
|
||||
}
|
||||
|
||||
QString Tools::createRootPath(QString path)
|
||||
{
|
||||
return QDir::currentPath() + path;
|
||||
}
|
||||
|
||||
QString Tools::createSharedPath(QString path){
|
||||
return QDir::currentPath()+ "/" + sharedDataFolderName + path;
|
||||
}
|
||||
|
||||
QString Tools::createRealPath(QString path,StreamingVersionData* currentVersionData)
|
||||
{
|
||||
QString resultPath;
|
||||
int index = path.indexOf(currentVersionData->getViewName());
|
||||
|
||||
if(index != -1)
|
||||
{
|
||||
resultPath = path.remove(0,index + currentVersionData->getViewName().length());
|
||||
resultPath.prepend(buildDataPath + streamingAssetsFolderName);
|
||||
}
|
||||
else
|
||||
{
|
||||
resultPath = Tools::createRootPath(path);
|
||||
}
|
||||
|
||||
return resultPath;
|
||||
}
|
||||
|
||||
QString Tools::createStreamingToRealPath(QString path,StreamingVersionData* streamingVersionData)
|
||||
{
|
||||
QString resultPath = path;
|
||||
int index = path.indexOf(streamingAssetsFolderName);
|
||||
|
||||
if(index != -1)
|
||||
{
|
||||
resultPath = path.remove(0,index + streamingAssetsFolderName.length());
|
||||
resultPath.prepend(QDir::currentPath() + "/" + sharedDataFolderName + "/" + streamingVersionData->getViewName());
|
||||
}
|
||||
|
||||
return resultPath;
|
||||
|
||||
|
||||
}
|
||||
|
||||
QString Tools::createUpdateFilePath(QString path)
|
||||
{
|
||||
//qDebug() << "Full path: " << path;
|
||||
qint8 pos = path.indexOf(streamingAssetsFolderName);
|
||||
|
||||
QString localPath = path.remove(0,--pos);
|
||||
|
||||
//qDebug() << "Local path: " << localPath;
|
||||
return localPath;
|
||||
}
|
||||
|
||||
QString Tools::createFolderPath(QString path)
|
||||
{
|
||||
quint8 pos = path.lastIndexOf("\\");
|
||||
|
||||
QString folderPath = path.remove(pos,path.length() - pos);
|
||||
|
||||
return folderPath;
|
||||
}
|
||||
|
||||
|
||||
53
ServerLMS/Systems/tools.h
Normal file
53
ServerLMS/Systems/tools.h
Normal file
@@ -0,0 +1,53 @@
|
||||
#ifndef TOOLS_H
|
||||
#define TOOLS_H
|
||||
|
||||
#include "logger.h"
|
||||
|
||||
#include <QString>
|
||||
#include <QDebug>
|
||||
#include <QTime>
|
||||
#include <QDir>
|
||||
|
||||
#include <Data/StreamingVersionData.h>
|
||||
|
||||
#define TCP_READ_TIMEOUT 5000
|
||||
|
||||
static const QString staticDataFolderName = "StaticData";
|
||||
static const QString applicationFolderName = "Application";
|
||||
static const QString sharedDataFolderName = "SharedData";
|
||||
static const QString streamingAssetsFolderName = "StreamingAssets";
|
||||
static const QString tempFile = staticDataFolderName + "/save.xml";
|
||||
static const QString version = staticDataFolderName + "/version.xml";
|
||||
static const QString versionListFile = staticDataFolderName + "/versionList.xml";
|
||||
static const QString hashFileName = staticDataFolderName + "/serverHash.xml";
|
||||
static const QString buildHashName = staticDataFolderName + "/buildHash.xml";
|
||||
static const QString buildDataPath = "/Application/RRJLoader/RRJ_Data/";
|
||||
|
||||
static const QString baseNameVersion = "base";//может вынести комманды куда нибудь?
|
||||
|
||||
static const QString commandTryBaseDelete = "BASEDELETETRY";
|
||||
static const QString commandTryActiveDelete = "TRYACTIVEDELETE";
|
||||
static const QString commandTryCopyWithSameNames = "SAMENAMES";
|
||||
static const QString commandGetServerDataList = "GETSERVERDATALIST";
|
||||
static const QString commandCheckVersionList = "CHECKVERSIONLIST";
|
||||
static const QString commandReadyClient = "READY";
|
||||
static const QString commandDisableClient = "DISABLE";
|
||||
static const QString commandDuplicateVerName = "DUPLICATEVERNAME";
|
||||
static const QString commandHashCompleteClient = "HASHSENDCOMPLETE";
|
||||
static const QString commandUpdateFilesClient = "update";
|
||||
|
||||
class Tools {
|
||||
public:
|
||||
static void printTime();
|
||||
static QString getTime();
|
||||
static QString createLocalPath(QString path);
|
||||
static QString createRootPath(QString path);
|
||||
static QString createUpdateFilePath(QString path);
|
||||
static QString createFolderPath(QString path);
|
||||
static QString createSharedPath(QString path);
|
||||
static QString createRealPath(QString path,StreamingVersionData* currentVersionData);
|
||||
static QString createStreamingToRealPath(QString path, StreamingVersionData *streamingVersionData);
|
||||
};
|
||||
|
||||
|
||||
#endif // TOOLS_H
|
||||
582
ServerLMS/Systems/updatecontroller.cpp
Normal file
582
ServerLMS/Systems/updatecontroller.cpp
Normal file
@@ -0,0 +1,582 @@
|
||||
#include "updatecontroller.h"
|
||||
|
||||
UpdateController::UpdateController(QObject *parent) :
|
||||
QObject(parent),
|
||||
commonClientHandler(nullptr)
|
||||
{
|
||||
buildPath = QDir::currentPath() + "/" + applicationFolderName;
|
||||
sharedDataPath = QDir::currentPath() + "/" + sharedDataFolderName;
|
||||
emit sigLogMessage(buildPath);
|
||||
qDebug() << hashFileName;
|
||||
}
|
||||
|
||||
void UpdateController::initialize(CommonClientHandler *commonClientHandler,DataParser *dataParser,AssetsManager *assetManager,Logger *logger)
|
||||
{
|
||||
this->commonClientHandler = commonClientHandler;
|
||||
this->dataParser = dataParser;
|
||||
this->assetManager = assetManager;
|
||||
|
||||
sizeToSend = 0;
|
||||
assetManager->initialize(this,dataParser);
|
||||
|
||||
connect(this,&UpdateController::sigLogMessage,logger,&Logger::addTextToLogger,Qt::AutoConnection);
|
||||
|
||||
calculateFullHash();
|
||||
currentStreamingPath = assetManager->setVersion("base");
|
||||
setUpCurrentServerHash();
|
||||
|
||||
mutex = new QMutex;
|
||||
qDebug() << "UpdateController init thread ID " << QThread::currentThreadId();
|
||||
}
|
||||
|
||||
void UpdateController::changeAssetVersion(QString versionName)
|
||||
{
|
||||
commonClientHandler->slot_sendPacketToAllClients(PacketType::BUSY);
|
||||
qDebug() << "UpdateController thread ID " << QThread::currentThreadId();
|
||||
currentStreamingPath = assetManager->setVersion(versionName);
|
||||
setUpCurrentServerHash();
|
||||
commonClientHandler->slot_sendPacketToAllClients(PacketType::HASH_READY);
|
||||
commonClientHandler->sendCurrentVersionToAllClient();
|
||||
|
||||
commonClientHandler->slot_sendPacketToAllClients(PacketType::FREE);
|
||||
}
|
||||
|
||||
void UpdateController::createCopyVersion(QString versionName,QString newVersionName)
|
||||
{
|
||||
commonClientHandler->slot_sendPacketToAllClients(PacketType::BUSY);
|
||||
assetManager->createCopyVersion(versionName,newVersionName);
|
||||
commonClientHandler->slot_sendPacketToAllClients(PacketType::FREE);
|
||||
}
|
||||
|
||||
void UpdateController::deleteAssetVersion(QString versionName)
|
||||
{
|
||||
assetManager->deleteVersion(versionName);
|
||||
}
|
||||
|
||||
void UpdateController::compareFiles(ClientHandler* handler, QByteArray array)
|
||||
{
|
||||
mutex->lock();
|
||||
loadHash();
|
||||
clientDataList.clear();
|
||||
xmlFileDataParse(array);
|
||||
clientDataList.append(*datas);
|
||||
checkNeedUpdate(handler);
|
||||
mutex->unlock();
|
||||
}
|
||||
|
||||
|
||||
void UpdateController::showHash()
|
||||
{
|
||||
for(FileData& str : serverDataList){
|
||||
emit sigLogMessage(str.hash);
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateController::calculateFullHash()
|
||||
{
|
||||
commonClientHandler->slot_sendPacketToAllClients(PacketType::BUSY);
|
||||
auto *list = calculateHash(buildPath);
|
||||
saveHash(buildHashName,list);
|
||||
calculateSharedHash();
|
||||
emit sigLogMessage("Calculate hash complete");
|
||||
commonClientHandler->slot_sendPacketToAllClients(PacketType::FREE);
|
||||
}
|
||||
|
||||
void UpdateController::saveHash(QString fileName,QList<FileData> *fileList)
|
||||
{
|
||||
QFile hashFile(fileName);
|
||||
hashFile.open(QIODevice::WriteOnly);
|
||||
QXmlStreamWriter xmlWriter(&hashFile);
|
||||
QListIterator<FileData> fileDataIterator(*fileList);
|
||||
|
||||
xmlWriter.setAutoFormatting(true);
|
||||
xmlWriter.writeStartDocument();
|
||||
xmlWriter.writeStartElement("FileDataList");
|
||||
|
||||
while (fileDataIterator.hasNext())
|
||||
{
|
||||
FileData data = fileDataIterator.next();
|
||||
xmlWriter.writeStartElement("FileData");
|
||||
|
||||
xmlWriter.writeAttribute("Path",data.path);
|
||||
xmlWriter.writeAttribute("Hash",data.hash);
|
||||
|
||||
xmlWriter.writeEndElement();
|
||||
}
|
||||
|
||||
xmlWriter.writeEndElement();
|
||||
xmlWriter.writeEndDocument();
|
||||
|
||||
hashFile.close();
|
||||
|
||||
}
|
||||
|
||||
void UpdateController::loadHash()
|
||||
{
|
||||
serverDataList.clear();
|
||||
|
||||
QFile hashFile(hashFileName);
|
||||
QByteArray array;
|
||||
if(hashFile.open(QIODevice::ReadOnly)){
|
||||
array = hashFile.readAll();
|
||||
hashFile.close();
|
||||
}
|
||||
|
||||
QXmlStreamReader xmlReader(array);
|
||||
|
||||
while (!xmlReader.atEnd())
|
||||
{
|
||||
if(xmlReader.isStartElement())
|
||||
{
|
||||
if(xmlReader.name().toUtf8() == "FileData")
|
||||
{
|
||||
FileData data;
|
||||
|
||||
foreach(const QXmlStreamAttribute &attr,xmlReader.attributes())
|
||||
{
|
||||
QString name = attr.name().toString();
|
||||
QString value = attr.value().toString();
|
||||
|
||||
if(name == "Path")
|
||||
data.path = value;
|
||||
else if(name == "Hash")
|
||||
data.hash = value;
|
||||
}
|
||||
|
||||
serverDataList.append(data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
xmlReader.readNextStartElement();
|
||||
}
|
||||
|
||||
emit sigLogMessage("Hash load from file ");
|
||||
|
||||
}
|
||||
|
||||
void UpdateController::calculateSize()
|
||||
{
|
||||
QDirIterator iterator(buildPath);
|
||||
quint64 total = 0;
|
||||
|
||||
while(iterator.hasNext()){
|
||||
if(iterator.fileInfo().isFile()){
|
||||
total += iterator.fileInfo().size();
|
||||
}
|
||||
|
||||
iterator.next();
|
||||
}
|
||||
|
||||
emit sigLogMessage("Full size: ");
|
||||
emit sigLogMessage(QString::number(total));
|
||||
}
|
||||
|
||||
QString UpdateController::getCommands()
|
||||
{
|
||||
QString commandsText;
|
||||
commandsText += "check - check version ";
|
||||
commandsText += "update - update files ";
|
||||
|
||||
return commandsText;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void UpdateController::setUpCurrentServerHash()
|
||||
{
|
||||
QList<FileData> *fileList = new QList<FileData>;
|
||||
fileList->append(*calculateHash(buildPath));
|
||||
fileList->append(*calculateHash(currentStreamingPath));
|
||||
assetManager->prepareLocalPathList(fileList);
|
||||
|
||||
saveHash(hashFileName,fileList);
|
||||
}
|
||||
|
||||
QString UpdateController::getCurrentStreamingPath() const
|
||||
{
|
||||
return currentStreamingPath;
|
||||
}
|
||||
|
||||
void UpdateController::setLocalFileData(QList<FileData> dataList)
|
||||
{
|
||||
serverDataList.append(dataList);
|
||||
}
|
||||
|
||||
bool UpdateController::checkNeedUpdate(ClientHandler *handler)
|
||||
{
|
||||
QList<FileData> *forSend = new QList<FileData>;
|
||||
QList<FileData> *forDelete = new QList<FileData>;
|
||||
|
||||
fileSendList.clear();
|
||||
fileDeleteList.clear();
|
||||
sizeToSend = 0;
|
||||
|
||||
bool needUpdate = false;
|
||||
|
||||
for (auto &item:clientDataList) //проверка на недостающие файлы по адресам
|
||||
{
|
||||
if(item.path.contains("Temp")) continue;
|
||||
|
||||
if (!serverDataList.contains(item))
|
||||
{
|
||||
forDelete->append(item);
|
||||
}
|
||||
}
|
||||
|
||||
for (auto &item:serverDataList)
|
||||
{
|
||||
if(item.path.contains("Temp")) continue;
|
||||
|
||||
if (!clientDataList.contains(item))
|
||||
{
|
||||
forSend->append(item);
|
||||
}
|
||||
}
|
||||
|
||||
if(forSend->length() > 0) //формирование сообщения об обновлении
|
||||
{
|
||||
QString log;
|
||||
log.append(Tools::getTime());
|
||||
log.append(" Client: " + handler->getClient()->getLogin());
|
||||
log.append(" Need updates: ");
|
||||
log.append(QString::number(forSend->length()));
|
||||
log.append(" objects");
|
||||
fileSendList = *forSend;
|
||||
|
||||
emit sigLogMessage(log);
|
||||
//printFileList(*forSend);
|
||||
|
||||
handler->sendMessageBlock(log);
|
||||
needUpdate = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
QString log;
|
||||
log.append(Tools::getTime());
|
||||
log.append(" Client: " + handler->getClient()->getLogin());
|
||||
log.append(" no update required");
|
||||
emit sigLogMessage(log);
|
||||
handler->sendMessageBlock(log);
|
||||
}
|
||||
|
||||
if(forDelete->length() > 0){
|
||||
QString log;
|
||||
log.append(Tools::getTime());
|
||||
log.append(" Client: " + handler->getClient()->getLogin());
|
||||
|
||||
log.append(" Need delete: ");
|
||||
log.append(QString::number(forDelete->length()));
|
||||
log.append(" objects");
|
||||
fileDeleteList = *forDelete;
|
||||
|
||||
emit sigLogMessage(log);
|
||||
//printFileList(*forDelete);
|
||||
handler->sendMessageBlock(log);
|
||||
needUpdate = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
QString log;
|
||||
log.append(Tools::getTime());
|
||||
log.append(" Client: " + handler->getClient()->getLogin());
|
||||
log.append(" no delete required");
|
||||
|
||||
emit sigLogMessage(log);
|
||||
handler->sendMessageBlock(log);
|
||||
}
|
||||
|
||||
CalculateSizeToSend(*forSend);
|
||||
handler->sendNeedUpdate(needUpdate,sizeToSend,forSend->length(),forDelete->length());
|
||||
return needUpdate;
|
||||
}
|
||||
|
||||
QList<FileData>* UpdateController::calculateHash(QString path)
|
||||
{
|
||||
serverDataList.clear();
|
||||
|
||||
QDirIterator iterator(path,QDirIterator::Subdirectories);
|
||||
if(!QDir(path).exists()){
|
||||
QDir().mkdir(path);
|
||||
}
|
||||
|
||||
QDir dir(path);
|
||||
dir.setFilter(QDir::NoDotAndDotDot);
|
||||
QString hashString;
|
||||
QList<FileData> *files = new QList<FileData>;
|
||||
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
iterator.next();
|
||||
QFileInfo fileInfo = iterator.fileInfo();
|
||||
FileData currentFile;
|
||||
QFile file(fileInfo.absoluteFilePath());
|
||||
|
||||
quint64 fileSize = file.size();
|
||||
const quint64 bufferSize = 10240;
|
||||
|
||||
if (fileInfo.isHidden()) continue;
|
||||
|
||||
if(fileInfo.isFile() && file.open(QIODevice::ReadOnly) && !fileInfo.fileName().contains(".meta"))
|
||||
{
|
||||
char buffer[bufferSize];
|
||||
int bytesRead;
|
||||
int readSize = qMin(fileSize,bufferSize);
|
||||
|
||||
QCryptographicHash hash(QCryptographicHash::Md5);
|
||||
while(readSize > 0 && (bytesRead = file.read(buffer,readSize)) > 0){
|
||||
fileSize -= bytesRead;
|
||||
hash.addData(buffer,bytesRead);
|
||||
readSize = qMin(fileSize,bufferSize);
|
||||
}
|
||||
|
||||
hashString = QString(hash.result().toHex());
|
||||
currentFile.hash = hashString;
|
||||
currentFile.path = Tools::createLocalPath(fileInfo.absoluteFilePath());
|
||||
|
||||
files->push_back(currentFile);
|
||||
file.close();
|
||||
|
||||
}
|
||||
else if(fileInfo.isDir() && fileInfo.fileName() != ".." && !fileInfo.isRoot())
|
||||
{
|
||||
currentFile.hash = "FOLDER";
|
||||
currentFile.path = Tools::createLocalPath(fileInfo.path());
|
||||
|
||||
if(!files->contains(currentFile)){
|
||||
files->push_back(currentFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::sort(files->begin(),files->end());
|
||||
serverDataList.append(*files);
|
||||
return files;
|
||||
}
|
||||
|
||||
QByteArray UpdateController::getLocalHash()
|
||||
{
|
||||
QFile hashFile(hashFileName);
|
||||
QByteArray array;
|
||||
if(hashFile.open(QIODevice::ReadOnly)){
|
||||
array = hashFile.readAll();
|
||||
hashFile.close();
|
||||
}
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
QString UpdateController::getCurrentVersionName()
|
||||
{
|
||||
return assetManager->getCurrentVersionData()->getViewName();
|
||||
}
|
||||
|
||||
void UpdateController::CalculateSizeToSend(QList<FileData> diffList)
|
||||
{
|
||||
QListIterator<FileData> serverDiffIterator(diffList);
|
||||
|
||||
while (serverDiffIterator.hasNext())
|
||||
{
|
||||
QString path;
|
||||
FileData pathForUpdate = serverDiffIterator.next();
|
||||
if(pathForUpdate.path.contains(streamingAssetsFolderName))
|
||||
{
|
||||
path = Tools::createStreamingToRealPath(pathForUpdate.path,assetManager->getCurrentVersionData());
|
||||
}
|
||||
else
|
||||
{
|
||||
path = Tools::createRootPath(pathForUpdate.path);
|
||||
}
|
||||
|
||||
QFile file(path);
|
||||
|
||||
sizeToSend += file.size();
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateController::calculateSharedHash()
|
||||
{
|
||||
QDir sharedDir(sharedDataPath);
|
||||
QDirIterator dirIterator(sharedDir);
|
||||
QList<FileData> *fileList = new QList<FileData>;
|
||||
QList<StreamingVersionData*> *versionList = new QList<StreamingVersionData*>;
|
||||
|
||||
while (dirIterator.hasNext())
|
||||
{
|
||||
dirIterator.next();
|
||||
QFileInfo fileInfo = dirIterator.fileInfo();
|
||||
if (fileInfo.fileName() == "." || fileInfo.fileName() == "..")
|
||||
continue;
|
||||
|
||||
QString fileName = staticDataFolderName + "/" + fileInfo.fileName() + "Hash.xml";
|
||||
|
||||
fileList = calculateHash(fileInfo.absoluteFilePath());
|
||||
saveHash(fileName,fileList);
|
||||
|
||||
StreamingVersionData *version = new StreamingVersionData(
|
||||
fileInfo.absoluteFilePath(),fileInfo.fileName(),
|
||||
fileInfo.birthTime(),fileInfo.size());
|
||||
|
||||
versionList->append(version);
|
||||
|
||||
}
|
||||
|
||||
createVersionListXmlAnswer(*versionList);
|
||||
assetManager->setVersionList(versionList);
|
||||
}
|
||||
|
||||
void UpdateController::createVersionListXmlAnswer(QList<StreamingVersionData *> version) //TODO: переименовать и перебросить в AssetManager
|
||||
{
|
||||
QList<SXmlAnswerTag> listTag;
|
||||
|
||||
foreach(StreamingVersionData* ver,version)
|
||||
{
|
||||
SAttribute attribute1 = {"Version", ver->getViewName()};
|
||||
SAttribute attribute2 = {"Created", ver->getCreateData().toString()};
|
||||
|
||||
QList<SAttribute> listAttr = {attribute1, attribute2};
|
||||
SXmlAnswerTag tag = {"VersionData", listAttr};
|
||||
|
||||
listTag.append(tag);
|
||||
}
|
||||
|
||||
|
||||
QFile file(versionListFile);
|
||||
file.open(QIODevice::WriteOnly);
|
||||
|
||||
QXmlStreamWriter xmlWriter(&file);
|
||||
xmlWriter.setAutoFormatting(true);
|
||||
xmlWriter.writeStartDocument();
|
||||
xmlWriter.writeStartElement("VersionList");
|
||||
|
||||
foreach(SXmlAnswerTag tag,listTag)
|
||||
{
|
||||
xmlWriter.writeStartElement(tag.elementName);
|
||||
|
||||
foreach(SAttribute attribute,tag.attr)
|
||||
{
|
||||
xmlWriter.writeAttribute(attribute.name,attribute.value);
|
||||
}
|
||||
|
||||
xmlWriter.writeEndElement();
|
||||
}
|
||||
|
||||
xmlWriter.writeEndElement();
|
||||
xmlWriter.writeEndDocument();
|
||||
file.close();
|
||||
}
|
||||
void UpdateController::saveVersionToFile(StreamingVersionData *streamingVersion) //TODO: переименовать и перебросить в AssetManager
|
||||
{
|
||||
QFile file(version);
|
||||
file.open(QFile::WriteOnly);
|
||||
|
||||
QXmlStreamWriter xmlWriter(&file);
|
||||
xmlWriter.setAutoFormatting(true);
|
||||
xmlWriter.writeStartDocument();
|
||||
|
||||
xmlWriter.writeStartElement("VersionData");
|
||||
xmlWriter.writeAttribute("Version",streamingVersion->getViewName());
|
||||
xmlWriter.writeAttribute("Created",streamingVersion->getCreateData().toString());
|
||||
|
||||
xmlWriter.writeEndElement();
|
||||
xmlWriter.writeEndDocument();
|
||||
|
||||
file.close();
|
||||
}
|
||||
|
||||
|
||||
void UpdateController::sendNewVersionList()
|
||||
{
|
||||
commonClientHandler->sendNewVersionListToAllClient();
|
||||
}
|
||||
|
||||
bool UpdateController::checkDuplicate(QString versionName)
|
||||
{
|
||||
return assetManager->findDuplicate(versionName);
|
||||
}
|
||||
|
||||
void UpdateController::xmlFileDataParse(QByteArray array)
|
||||
{
|
||||
QXmlStreamReader xmlReader(array);
|
||||
datas = new QList<FileData>;
|
||||
xmlReader.readNext();
|
||||
|
||||
//Крутимся в цикле до тех пор, пока не достигнем конца документа
|
||||
while(!xmlReader.atEnd())
|
||||
{
|
||||
//Проверяем, является ли элемент началом тега
|
||||
if(xmlReader.isStartElement())
|
||||
{
|
||||
if(xmlReader.name() == "FileData")
|
||||
{
|
||||
FileData data;
|
||||
|
||||
foreach(const QXmlStreamAttribute &attr,xmlReader.attributes())
|
||||
{
|
||||
QString name = attr.name().toString();
|
||||
QString value = attr.value().toString();
|
||||
|
||||
if(name == "Path")
|
||||
data.path = value;
|
||||
else if(name == "Hash")
|
||||
data.hash = value;
|
||||
}
|
||||
|
||||
datas->append(data);
|
||||
}
|
||||
}
|
||||
|
||||
xmlReader.readNext();
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateController::printFileList(QList<FileData> fileData)
|
||||
{
|
||||
QListIterator<FileData> iterator(fileData);
|
||||
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
auto next = iterator.next();
|
||||
emit sigLogMessage(next.path);
|
||||
}
|
||||
}
|
||||
|
||||
QList<FileData> UpdateController::getFileDeleteList() const
|
||||
{
|
||||
return fileDeleteList;
|
||||
}
|
||||
|
||||
QList<FileData> UpdateController::getFileSendList()
|
||||
{
|
||||
|
||||
QList<FileData> sendList = *assetManager->prepareRealPathList(&fileSendList);
|
||||
return sendList;
|
||||
}
|
||||
|
||||
|
||||
QList<FileData> UpdateController::getClientDataList() const
|
||||
{
|
||||
return clientDataList;
|
||||
}
|
||||
|
||||
DataInfo *UpdateController::getCurrentDataInfo()
|
||||
{
|
||||
return dataInfo;
|
||||
}
|
||||
|
||||
QList<FileData> *UpdateController::getDatas() const
|
||||
{
|
||||
return datas;
|
||||
}
|
||||
|
||||
void UpdateController::clearCurrentDataInfo()
|
||||
{
|
||||
delete dataInfo;
|
||||
}
|
||||
|
||||
UpdateController::~UpdateController()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
97
ServerLMS/Systems/updatecontroller.h
Normal file
97
ServerLMS/Systems/updatecontroller.h
Normal file
@@ -0,0 +1,97 @@
|
||||
#ifndef UPDATECONTROLLER_H
|
||||
#define UPDATECONTROLLER_H
|
||||
|
||||
|
||||
#include <QString>
|
||||
#include <QObject>
|
||||
#include <QCryptographicHash>
|
||||
#include <QDirIterator>
|
||||
#include <QDebug>
|
||||
#include <QDataStream>
|
||||
#include <QMutex>
|
||||
|
||||
#include <Systems/Parsers/dataparser.h>
|
||||
#include <Data/typesDataServerClient.h>
|
||||
#include <Data/StreamingVersionData.h>
|
||||
|
||||
class TCPServer;
|
||||
class SendSystem;
|
||||
class DataParser;
|
||||
class ClientHandler;
|
||||
class AssetsManager;
|
||||
class ServerLMSWidget;
|
||||
class CommonClientHandler;
|
||||
class Logger;
|
||||
|
||||
class UpdateController : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
explicit UpdateController(QObject *parent = 0);
|
||||
void initialize(CommonClientHandler* commonClientHandler,DataParser *dataParser,AssetsManager *assetManager,Logger *logger);
|
||||
void compareFiles(ClientHandler* handler, QByteArray array);
|
||||
void showHash();
|
||||
void calculateFullHash();
|
||||
void calculateSharedHash();
|
||||
void sendNewVersionList();
|
||||
void setCurrentStreamingPath(QString path);
|
||||
bool checkDuplicate(QString versionName);
|
||||
QList<FileData>* calculateHash(QString path);
|
||||
QByteArray getLocalHash();
|
||||
|
||||
QString getCurrentVersionName();
|
||||
QList<FileData> getFileSendList();
|
||||
QList<FileData> getClientDataList() const;
|
||||
QList<FileData> getFileDeleteList() const;
|
||||
QString getCurrentStreamingPath() const;
|
||||
|
||||
~UpdateController();
|
||||
|
||||
DataInfo *getCurrentDataInfo();
|
||||
void clearCurrentDataInfo();
|
||||
QList<FileData> *getDatas() const;
|
||||
void createVersionListXmlAnswer(QList<StreamingVersionData *> version);
|
||||
void saveVersionToFile(StreamingVersionData *streamingVersion);
|
||||
void xmlFileDataParse(QByteArray array);
|
||||
public slots:
|
||||
void changeAssetVersion(QString versionName);
|
||||
void createCopyVersion(QString versionName,QString newVersionName);
|
||||
void deleteAssetVersion(QString versionName);
|
||||
void setUpCurrentServerHash();
|
||||
|
||||
signals:
|
||||
void sigLogMessage(QString message);
|
||||
|
||||
private:
|
||||
QList<FileData> clientDataList;
|
||||
QList<FileData> serverDataList;
|
||||
|
||||
QList<FileData> fileSendList;
|
||||
QList<FileData> fileDeleteList;
|
||||
|
||||
QList<FileData> *datas;
|
||||
DataInfo *dataInfo;
|
||||
|
||||
QString buildPath;
|
||||
QString currentStreamingPath;
|
||||
QString sharedDataPath;
|
||||
CommonClientHandler *commonClientHandler;
|
||||
DataParser *dataParser;
|
||||
AssetsManager *assetManager;
|
||||
quint64 sizeToSend;
|
||||
QMutex *mutex;
|
||||
|
||||
QString getCommands();
|
||||
void printFileList(QList<FileData> fileData);
|
||||
|
||||
bool checkNeedUpdate(ClientHandler* handler);
|
||||
void setLocalFileData(QList<FileData> dataList);
|
||||
void calculateSize();
|
||||
void saveHash(QString fileName,QList<FileData> *fileList);
|
||||
void loadHash();
|
||||
void CalculateSizeToSend(QList<FileData> diffList);
|
||||
};
|
||||
|
||||
#endif // UPDATECONTROLLER_H
|
||||
Reference in New Issue
Block a user