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
|
||||
Reference in New Issue
Block a user