mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/RRJServer.git
synced 2026-03-28 19:55:48 +03:00
Сделал коннект и логин
This commit is contained in:
@@ -21,6 +21,7 @@ find_package(Qt5 COMPONENTS Widgets REQUIRED)
|
||||
find_package(Qt5 COMPONENTS Sql REQUIRED)
|
||||
find_package(Qt5 COMPONENTS LinguistTools REQUIRED)
|
||||
find_package(Qt5 COMPONENTS Xml REQUIRED)
|
||||
find_package(Qt5 COMPONENTS Network REQUIRED)
|
||||
|
||||
add_library(InstructorsAndTrainees SHARED
|
||||
instructorsAndTrainees_global.h
|
||||
@@ -67,6 +68,20 @@ add_library(InstructorsAndTrainees SHARED
|
||||
docTasks/doctaskswidget.ui
|
||||
docTasks/module.cpp
|
||||
docTasks/module.h
|
||||
connectorToServer/connectortoserver.cpp
|
||||
connectorToServer/connectortoserver.h
|
||||
connectorToServer/Core/sendsystem.cpp
|
||||
connectorToServer/Core/sendsystem.h
|
||||
connectorToServer/Core/dataparser.cpp
|
||||
connectorToServer/Core/dataparser.h
|
||||
connectorToServer/Core/recognizesystem.cpp
|
||||
connectorToServer/Core/recognizesystem.h
|
||||
connectorToServer/Core/tcpclient.cpp
|
||||
connectorToServer/Core/tcpclient.h
|
||||
connectorToServer/Core/tools.cpp
|
||||
connectorToServer/Core/tools.h
|
||||
connectorToServer/Core/FileData.h
|
||||
connectorToServer/Datas.h
|
||||
resources.qrc
|
||||
)
|
||||
|
||||
@@ -74,10 +89,13 @@ target_include_directories(InstructorsAndTrainees PUBLIC ${CMAKE_CURRENT_SOURCE_
|
||||
target_include_directories(InstructorsAndTrainees PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/trainees)
|
||||
target_include_directories(InstructorsAndTrainees PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/tasks)
|
||||
target_include_directories(InstructorsAndTrainees PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/docTasks)
|
||||
target_include_directories(InstructorsAndTrainees PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/connectorToServer)
|
||||
target_include_directories(InstructorsAndTrainees PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/connectorToServer/Core)
|
||||
|
||||
target_link_libraries(InstructorsAndTrainees PRIVATE Qt5::Widgets)
|
||||
target_link_libraries(InstructorsAndTrainees PRIVATE Qt5::Sql)
|
||||
target_link_libraries(InstructorsAndTrainees PRIVATE Qt5::Xml)
|
||||
target_link_libraries(InstructorsAndTrainees PRIVATE Qt5::Network)
|
||||
|
||||
target_compile_definitions(InstructorsAndTrainees PRIVATE INSTRUCTORSANDTRAINEES_LIBRARY)
|
||||
|
||||
@@ -91,4 +109,8 @@ endif()
|
||||
target_link_libraries(InstructorsAndTrainees PRIVATE libDataBaseLMS.dll)
|
||||
|
||||
|
||||
target_include_directories(InstructorsAndTrainees PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../testDB/testDBpgSQL)
|
||||
target_include_directories(InstructorsAndTrainees PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../testDB/testDBpgSQL/Core)
|
||||
|
||||
|
||||
#install(TARGETS InstructorsAndTrainees DESTINATION ${VEYON_LIB_DIR})
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
|
||||
#ifndef FILEDATA_H
|
||||
#define FILEDATA_H
|
||||
|
||||
struct FileData
|
||||
{
|
||||
QString path;
|
||||
QString hash;
|
||||
|
||||
bool operator==(const FileData& other)const{
|
||||
if(this->path==(other.path)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
}; //путь
|
||||
|
||||
struct SAttribute
|
||||
{
|
||||
QString name;
|
||||
QString value;
|
||||
|
||||
};
|
||||
|
||||
struct SXmlAnswerTag{
|
||||
QString elementName;
|
||||
QList<SAttribute> attr;
|
||||
};
|
||||
|
||||
#endif // FILEDATA_H
|
||||
|
||||
@@ -0,0 +1,341 @@
|
||||
#include "Core/dataparser.h"
|
||||
|
||||
#include "FileData.h"
|
||||
#include "tools.h"
|
||||
|
||||
#include <QDir>
|
||||
|
||||
DataParser::DataParser(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
if(!QDir(staticDataFolderName).exists()){
|
||||
QDir().mkdir(staticDataFolderName);
|
||||
}
|
||||
}
|
||||
|
||||
QByteArray DataParser::slotGetXmlAnswer(QString answerCode)
|
||||
{
|
||||
if(answerCode == "END"){
|
||||
return xmlAnswer_notify(answerCode);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void DataParser::createFileDataList(QList<FileData> fileDataList,QString filename)
|
||||
{
|
||||
|
||||
QFile file(filename);
|
||||
file.open(QIODevice::WriteOnly);
|
||||
QXmlStreamWriter xmlWriter(&file);
|
||||
|
||||
xmlWriter.setAutoFormatting(true);
|
||||
xmlWriter.writeStartDocument();
|
||||
xmlWriter.writeStartElement("FileDataList");
|
||||
|
||||
foreach (FileData data,fileDataList)
|
||||
{
|
||||
xmlWriter.writeStartElement("FileData");
|
||||
|
||||
xmlWriter.writeAttribute("Path",data.path);
|
||||
xmlWriter.writeAttribute("Hash",data.hash);
|
||||
|
||||
xmlWriter.writeEndElement();
|
||||
}
|
||||
|
||||
xmlWriter.writeEndElement();
|
||||
xmlWriter.writeEndDocument();
|
||||
|
||||
file.close();
|
||||
}
|
||||
|
||||
void DataParser::createAuthMessage(ClientAutorization *auth)
|
||||
{
|
||||
authPassCache = auth; //кэширование даных авторизации, для сохранения при успешном заходе
|
||||
|
||||
QFile file(tempName);
|
||||
file.open(QIODevice::WriteOnly);
|
||||
QXmlStreamWriter xmlWriter(&file);
|
||||
|
||||
xmlWriter.setAutoFormatting(true);
|
||||
xmlWriter.writeStartDocument();
|
||||
xmlWriter.writeStartElement("ClientAutorization");
|
||||
|
||||
xmlWriter.writeAttribute("Login",auth->Login);
|
||||
xmlWriter.writeAttribute("Password",auth->Password);
|
||||
|
||||
xmlWriter.writeEndElement();
|
||||
xmlWriter.writeEndElement();
|
||||
xmlWriter.writeEndDocument();
|
||||
|
||||
file.close();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void DataParser::createServerSettings(QString address, QString port)
|
||||
{
|
||||
QFile file(settingsName);
|
||||
|
||||
file.open(QIODevice::WriteOnly);
|
||||
|
||||
QXmlStreamWriter xmlWriter(&file);
|
||||
|
||||
xmlWriter.setAutoFormatting(true);
|
||||
xmlWriter.writeStartDocument();
|
||||
|
||||
xmlWriter.writeStartElement("ServerSettingsContainer");
|
||||
xmlWriter.writeStartElement("ServerSettings");
|
||||
|
||||
xmlWriter.writeAttribute("Address",address);
|
||||
xmlWriter.writeAttribute("Port",port);
|
||||
xmlWriter.writeAttribute("Language","RUS");
|
||||
xmlWriter.writeAttribute("AutoStart",QString::number(false));
|
||||
|
||||
xmlWriter.writeEndElement();
|
||||
xmlWriter.writeEndElement();
|
||||
|
||||
xmlWriter.writeEndDocument();
|
||||
|
||||
file.close();
|
||||
|
||||
}
|
||||
|
||||
void DataParser::createAuthData(ServerAuthorization *serverAuth)
|
||||
{
|
||||
QFile file(authTempName);
|
||||
file.open(QIODevice::WriteOnly);
|
||||
|
||||
QXmlStreamWriter xmlWriter(&file);
|
||||
|
||||
xmlWriter.setAutoFormatting(true);
|
||||
xmlWriter.writeStartDocument();
|
||||
xmlWriter.writeStartElement("AuthData");
|
||||
xmlWriter.writeAttribute("Login",authPassCache->Login);
|
||||
xmlWriter.writeAttribute("Password",authPassCache->Password);
|
||||
xmlWriter.writeAttribute("InstructorName",serverAuth->InstructorName);
|
||||
xmlWriter.writeAttribute("ClientName",serverAuth->ClientName);
|
||||
xmlWriter.writeAttribute("AccessType",serverAuth->AccessType);
|
||||
|
||||
xmlWriter.writeEndElement();
|
||||
file.close();
|
||||
|
||||
}
|
||||
|
||||
void DataParser::createAuthDataOffline(QString username, QString pass)
|
||||
{
|
||||
QFile file(authTempName);
|
||||
file.open(QIODevice::WriteOnly);
|
||||
|
||||
QXmlStreamWriter xmlWriter(&file);
|
||||
|
||||
xmlWriter.setAutoFormatting(true);
|
||||
xmlWriter.writeStartDocument();
|
||||
xmlWriter.writeStartElement("AuthData");
|
||||
xmlWriter.writeAttribute("Login",username);
|
||||
xmlWriter.writeAttribute("Password",pass);
|
||||
xmlWriter.writeAttribute("InstructorName","empty");
|
||||
xmlWriter.writeAttribute("ClientName","Offline");
|
||||
xmlWriter.writeAttribute("AccessType","Offline");
|
||||
|
||||
xmlWriter.writeEndElement();
|
||||
file.close();
|
||||
}
|
||||
|
||||
QByteArray DataParser::xmlAnswer_notify(QString code)
|
||||
{
|
||||
|
||||
QList<SXmlAnswerTag> listTag;
|
||||
|
||||
SAttribute attribute1 = {"Code", code};
|
||||
QList<SAttribute> listAttr = {attribute1};
|
||||
SXmlAnswerTag tag = {"ClientNotify", listAttr};
|
||||
|
||||
listTag.append(tag);
|
||||
|
||||
return xmlAnswer(listTag);
|
||||
}
|
||||
|
||||
void DataParser::addRunData(QList<int> displays)
|
||||
{
|
||||
QFile file(displayTemp);
|
||||
file.open(QIODevice::ReadWrite);
|
||||
|
||||
QXmlStreamWriter xmlWriter(&file);
|
||||
xmlWriter.setAutoFormatting(true);
|
||||
xmlWriter.writeStartElement("DisplayInfo");
|
||||
xmlWriter.writeAttribute("DisplayCount",QString::number(displays.length()));
|
||||
xmlWriter.writeEndElement();
|
||||
file.close();
|
||||
|
||||
}
|
||||
|
||||
ServerSettings *DataParser::getServerSettings()
|
||||
{
|
||||
ServerSettings *settings = new ServerSettings;
|
||||
QFile file(settingsName);
|
||||
file.open(QIODevice::ReadOnly);
|
||||
QXmlStreamReader xmlReader(&file);
|
||||
|
||||
while (!xmlReader.atEnd()){
|
||||
|
||||
if(xmlReader.isStartElement()){
|
||||
|
||||
if(xmlReader.name() == "ServerSettings"){
|
||||
|
||||
foreach(const QXmlStreamAttribute &attr, xmlReader.attributes()){
|
||||
QString name = attr.name().toString();
|
||||
QString value = attr.value().toString();
|
||||
|
||||
if(name == "Address"){
|
||||
settings->Address = value;
|
||||
}
|
||||
|
||||
if(name == "Port"){
|
||||
settings->Port = value;
|
||||
}
|
||||
|
||||
if(name == "Language"){
|
||||
settings->Language = value;
|
||||
}
|
||||
|
||||
if(name == "AutoStart"){
|
||||
settings->isAutoStart = value.toInt();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
xmlReader.readNext();
|
||||
}
|
||||
|
||||
file.close();
|
||||
return settings;
|
||||
}
|
||||
|
||||
void DataParser::saveClientSettrings(QString language, bool isAutoStart)
|
||||
{
|
||||
QFile file(settingsName);
|
||||
file.open(QIODevice::ReadOnly | QIODevice::Text);
|
||||
|
||||
QString settings = file.readAll();
|
||||
|
||||
file.close();
|
||||
file.remove();
|
||||
|
||||
file.open(QIODevice::WriteOnly | QIODevice::Text);
|
||||
|
||||
auto languagePos = settings.indexOf(XMLLanguageProperty) + XMLLanguageProperty.length();
|
||||
settings = settings.replace(languagePos,language.size(),language);
|
||||
|
||||
auto autoStartPos = settings.indexOf(XMLAutoStartProperty) + XMLAutoStartProperty.length();
|
||||
settings = settings.replace(autoStartPos,1,QString::number(isAutoStart));
|
||||
|
||||
file.write(settings.toUtf8());
|
||||
file.close();
|
||||
}
|
||||
|
||||
QList<FileData>* DataParser::xmlFileDataParse(QByteArray array, QString filter = "")
|
||||
{
|
||||
QXmlStreamReader xmlReader(array);
|
||||
QList<FileData> *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;
|
||||
}
|
||||
|
||||
if(data.path.contains(filter))
|
||||
|
||||
datas->append(data);
|
||||
}
|
||||
}
|
||||
|
||||
xmlReader.readNext();
|
||||
}
|
||||
|
||||
return datas;
|
||||
}
|
||||
|
||||
QByteArray DataParser::xmlAnswer(QList<SXmlAnswerTag> listTag, QString elemUp1, QString elemUp2)
|
||||
{
|
||||
/* Открываем файл для Записи*/
|
||||
QFile file(tempName);
|
||||
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;
|
||||
|
||||
/* Открываем файл для Чтения*/
|
||||
QFile fileR(tempName);
|
||||
if (!fileR.open(QFile::ReadOnly | QFile::Text))
|
||||
{
|
||||
QString str = "Не удалось открыть файл";
|
||||
qDebug() << "xmlAnswer: " << str;
|
||||
}
|
||||
else
|
||||
{
|
||||
array = fileR.readAll();
|
||||
fileR.close(); // Закрываем файл
|
||||
}
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
|
||||
DataParser::~DataParser()
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
#ifndef DATAPARSER_H
|
||||
#define DATAPARSER_H
|
||||
|
||||
#include "FileData.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <Datas.h>
|
||||
#include <QFile>
|
||||
#include <QXmlStreamWriter>
|
||||
|
||||
class DataParser : public QObject
|
||||
{
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit DataParser(QObject *parent = 0);
|
||||
~DataParser();
|
||||
ServerSettings* getServerSettings();
|
||||
void createServerSettings(QString server,QString port);
|
||||
void saveClientSettrings(QString language,bool isAutoStart);
|
||||
void createFileDataList(QList<FileData> fileDataList,QString filename);
|
||||
void createAuthMessage(ClientAutorization *auth);
|
||||
void createAuthData(ServerAuthorization *serverAuth);
|
||||
void createAuthDataOffline(QString username,QString pass);
|
||||
void addRunData(QList<int> displays);
|
||||
QByteArray xmlAnswer_notify(QString code);
|
||||
QByteArray xmlAnswer(QList<SXmlAnswerTag> listTag, QString elemUp1 = "", QString elemUp2 = "");
|
||||
|
||||
QList<FileData>* xmlFileDataParse(QByteArray array,QString filter);
|
||||
public slots:
|
||||
QByteArray slotGetXmlAnswer(QString);
|
||||
|
||||
|
||||
private:
|
||||
const QString XMLLanguageProperty = "Language=\"";
|
||||
const QString XMLAutoStartProperty = "AutoStart=\"";
|
||||
ClientAutorization *authPassCache;
|
||||
|
||||
};
|
||||
|
||||
#endif // DATAPARSER_H
|
||||
@@ -0,0 +1,337 @@
|
||||
#include "Core/recognizesystem.h"
|
||||
#include <QThread>
|
||||
#include <QDir>
|
||||
|
||||
|
||||
RecognizeSystem::RecognizeSystem(QObject *parent):
|
||||
QObject(parent)
|
||||
{
|
||||
packetType = PacketType::TYPE_NONE;
|
||||
filePath.clear();
|
||||
fileSize = 0;
|
||||
message.clear();
|
||||
sizeReceiveData = 0;
|
||||
tmpBlock.clear();
|
||||
countSend = 0;
|
||||
folderList = new QList<QString>;
|
||||
}
|
||||
|
||||
RecognizeSystem::~RecognizeSystem()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void RecognizeSystem::initialize(DataParser *dataParser/*,MainWindow *mainWindow*/)
|
||||
{
|
||||
this->dataParser = dataParser;
|
||||
//this->mainWindow = mainWindow;
|
||||
connect(this,&RecognizeSystem::sigSaveLoginData,dataParser,&DataParser::createAuthData);
|
||||
}
|
||||
|
||||
void RecognizeSystem::recognize(QTcpSocket *socket)
|
||||
{
|
||||
qDebug() << "RecognizeThreadId " << QThread::currentThreadId();
|
||||
|
||||
QDataStream stream(socket);
|
||||
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
|
||||
|
||||
while(socket->bytesAvailable())
|
||||
{
|
||||
|
||||
if (socket->state() != QTcpSocket::ConnectedState) return;
|
||||
|
||||
if(packetType == PacketType::TYPE_NONE){ //определение первичного пакета
|
||||
|
||||
stream.startTransaction();
|
||||
stream >> packetType;
|
||||
|
||||
if(!stream.commitTransaction()){
|
||||
emit sigSendDebugLog(Tools::getTime() + " CLIENT: packetType - FAIL commitTransaction");
|
||||
|
||||
if(socket->waitForReadyRead(TCP_READ_TIMEOUT)){
|
||||
emit sigSendDebugLog("ERROR: PACKET TYPE READ TIMEOUT");
|
||||
return;
|
||||
}
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
//qDebug() << Tools::GetTime() << "CLIENT: type: " << packetType;
|
||||
}
|
||||
|
||||
if(packetType == PacketType::TYPE_FOLDER){ //создание папок
|
||||
stream.startTransaction();
|
||||
stream >> filePath;
|
||||
|
||||
if(!stream.commitTransaction()){
|
||||
continue;
|
||||
}
|
||||
|
||||
filePath = Tools::createFullPath(filePath);
|
||||
|
||||
QDir dir(filePath);
|
||||
if(!dir.exists()){
|
||||
if(dir.mkpath(filePath)){
|
||||
qDebug() << "Dir Created";
|
||||
}
|
||||
}
|
||||
|
||||
packetType = PacketType::TYPE_NONE;
|
||||
emit sigUpdateBytesAvailable();
|
||||
continue;
|
||||
}
|
||||
|
||||
if(packetType == PacketType::TYPE_FILE) //загрузка файлов
|
||||
{
|
||||
//ПОЛУЧЕНИЕ ПУТИ
|
||||
//ПОЛУЧЕНИЕ РАЗМЕРА ФАЙЛА
|
||||
forever
|
||||
{
|
||||
stream.startTransaction();
|
||||
stream >> filePath;
|
||||
stream >> fileSize;
|
||||
|
||||
if(!stream.commitTransaction()){
|
||||
emit sigSendDebugLog(Tools::getTime() + "CLIENT: filePath, fileSize - FAIL commitTransaction");
|
||||
|
||||
if (!socket->waitForReadyRead(TCP_READ_TIMEOUT)) {
|
||||
emit sigSendDebugLog(Tools::getTime() + "CLIENT: ERROR! readyRead timeout - filePath, fileSize!!!");
|
||||
return;
|
||||
}
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
filePath = Tools::createFullPath(filePath);
|
||||
|
||||
emit sigSendDebugLog("CLIENT: filesize: " + QString::number(fileSize));
|
||||
emit sigSendDebugLog("CLIENT: filePath: " + filePath);
|
||||
|
||||
socket->waitForReadyRead(100);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
//ПОЛУЧЕНИЕ САМОГО ФАЙЛА
|
||||
emit sigSendDebugLog(Tools::getTime() + "AfterRead size and path BytesAvailable: " + socket->bytesAvailable());
|
||||
|
||||
//УКАЗАНИЕ ПУТИ ФАЙЛА
|
||||
QFile file(filePath);
|
||||
|
||||
if (file.exists())
|
||||
{
|
||||
file.remove(); //удаление файла, если он уже есть, но необходимо обновить
|
||||
emit sigSendDebugLog(Tools::getTime() + "Delete exist file: " + filePath);
|
||||
socket->waitForReadyRead(100);
|
||||
}
|
||||
|
||||
|
||||
|
||||
file.open(QFile::Append);
|
||||
|
||||
forever
|
||||
{
|
||||
stream.startTransaction();
|
||||
stream >> tmpBlock;
|
||||
|
||||
if(!stream.commitTransaction()){
|
||||
|
||||
if(socket->state() == QAbstractSocket::UnconnectedState){
|
||||
emit sigSocketDisabled();
|
||||
return;
|
||||
}
|
||||
if(socket->waitForReadyRead(TCP_READ_TIMEOUT)){
|
||||
continue;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
quint64 toFile = file.write(tmpBlock);
|
||||
emit sigSendDebugLog(Tools::getTime() + "CLIENT: toFile :" + toFile);
|
||||
|
||||
sizeReceiveData += toFile;
|
||||
countSend++;
|
||||
|
||||
tmpBlock.clear();
|
||||
|
||||
if(sizeReceiveData == fileSize){
|
||||
emit sigSendDebugLog(Tools::getTime() + "FINAL Count send: " + QString::number(countSend));
|
||||
emit sigSendDebugLog(Tools::getTime() + "FINAL Size received: " + QString::number(sizeReceiveData));
|
||||
emit sigSendDebugLog(Tools::getTime() + "FINAL File size" + QString::number(fileSize));
|
||||
emit sigUpdateBytesAvailable();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
file.close();
|
||||
emit sigSendDebugLog(Tools::getTime() + "File loaded");
|
||||
|
||||
//ОЧИСТКА ПОСЛЕ ПЕРЕДАЧИ
|
||||
|
||||
filePath.clear();
|
||||
fileSize = 0;
|
||||
tmpBlock.clear();
|
||||
sizeReceiveData = 0;
|
||||
countSend = 0;
|
||||
}
|
||||
|
||||
if(packetType == PacketType::TYPE_DELETE) //удаление лишних файлов (рекурсивно удаляет все содежимое)
|
||||
{
|
||||
stream.startTransaction();
|
||||
stream >> filePath;
|
||||
|
||||
if(!stream.commitTransaction()){
|
||||
continue;
|
||||
}
|
||||
|
||||
filePath = Tools::createFullPath(filePath);
|
||||
|
||||
QFileInfo fileInfo(filePath);
|
||||
|
||||
|
||||
if(fileInfo.exists())
|
||||
{
|
||||
if(fileInfo.isFile())
|
||||
{
|
||||
QFile file(filePath);
|
||||
file.remove();
|
||||
}
|
||||
|
||||
if(fileInfo.isDir()){
|
||||
QDir dir(filePath);
|
||||
dir.removeRecursively();
|
||||
}
|
||||
|
||||
qDebug() << Tools::getTime() << "Deleted: " << filePath;
|
||||
}
|
||||
|
||||
packetType = PacketType::TYPE_NONE;
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
if(packetType ==PacketType::TYPE_FINISH){ //для повторного создания хэша после загрузки
|
||||
//updateController->calculateCommonHash();
|
||||
emit sigLoadComplete();
|
||||
packetType = PacketType::TYPE_NONE;
|
||||
}
|
||||
|
||||
if(packetType == PacketType::TYPE_NEEDUPDATE){ //нужно обновление
|
||||
|
||||
bool flag = false;
|
||||
quint64 size = 0;
|
||||
quint64 fileCount = 0;
|
||||
|
||||
stream.startTransaction();
|
||||
stream >> flag;
|
||||
stream >> size;
|
||||
stream >> fileCount;
|
||||
|
||||
if(!stream.commitTransaction()){
|
||||
continue;
|
||||
}
|
||||
|
||||
emit sigNeedUpdate(flag,size,fileCount);
|
||||
packetType = PacketType::TYPE_NONE;
|
||||
}
|
||||
|
||||
if(packetType == PacketType::TYPE_XMLANSWER){ //ответы формата XML
|
||||
QByteArray array;
|
||||
stream.startTransaction();
|
||||
stream >> array;
|
||||
|
||||
if(!stream.commitTransaction()){
|
||||
continue;
|
||||
}
|
||||
|
||||
xmlParser(array);
|
||||
|
||||
packetType = PacketType::TYPE_NONE;
|
||||
}
|
||||
|
||||
packetType = PacketType::TYPE_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
void RecognizeSystem::xmlParser(QByteArray array)
|
||||
{
|
||||
QXmlStreamReader xmlReader(array);
|
||||
|
||||
xmlReader.readNext();
|
||||
|
||||
while(!xmlReader.atEnd())
|
||||
{
|
||||
if(!xmlReader.isStartElement()) {
|
||||
xmlReader.readNext();
|
||||
continue;
|
||||
}
|
||||
|
||||
if(xmlReader.name() == "ServerNotify")
|
||||
{
|
||||
foreach(const QXmlStreamAttribute &attr, xmlReader.attributes())
|
||||
{
|
||||
QString name = attr.name().toString();
|
||||
QString value = attr.value().toString();
|
||||
|
||||
if(name == "Code")
|
||||
{
|
||||
if (value == "END")
|
||||
{
|
||||
emit sigSocketDisabled();
|
||||
}
|
||||
|
||||
if(value == "BLOCKED")
|
||||
{
|
||||
emit sigServerBlocked();
|
||||
}
|
||||
|
||||
if(value == "HASHSENDCOMPLETE")
|
||||
{
|
||||
emit sigStartCompare();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(xmlReader.name() == "ServerAuthorization"){
|
||||
|
||||
ServerAuthorization *serverAuth = new ServerAuthorization;
|
||||
|
||||
foreach(const QXmlStreamAttribute &attr, xmlReader.attributes())
|
||||
{
|
||||
QString name = attr.name().toString();
|
||||
QString value = attr.value().toString();
|
||||
|
||||
if (name == "Result"){
|
||||
serverAuth->Result = value == "true" ? true : false;
|
||||
}
|
||||
|
||||
if (name == "InstructorName"){
|
||||
serverAuth->InstructorName = value;
|
||||
}
|
||||
|
||||
if (name == "ClientName"){
|
||||
serverAuth->ClientName = value;
|
||||
}
|
||||
|
||||
if (name == "AccessType"){
|
||||
serverAuth->AccessType = value;
|
||||
checkAccessType(value);
|
||||
}
|
||||
}
|
||||
|
||||
emit sigSaveLoginData(serverAuth);
|
||||
}
|
||||
|
||||
xmlReader.readNext();
|
||||
}
|
||||
}
|
||||
|
||||
void RecognizeSystem::checkAccessType(QString type)
|
||||
{
|
||||
if(type == "instructor")
|
||||
{
|
||||
//mainWindow->callUpdateList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
#ifndef RECOGNIZESYSTEM_H
|
||||
#define RECOGNIZESYSTEM_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QDataStream>
|
||||
#include <QTcpSocket>
|
||||
//#include <mainwindow.h>
|
||||
#include <Core\tools.h>
|
||||
#include "dataparser.h"
|
||||
|
||||
|
||||
class RecognizeSystem : public QObject
|
||||
{
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit RecognizeSystem(QObject *parent = 0);
|
||||
~RecognizeSystem();
|
||||
void initialize(DataParser *dataParser/*,MainWindow *mainWindow*/);
|
||||
void recognize(QTcpSocket *socket);
|
||||
|
||||
signals:
|
||||
void sigUpdateBytesAvailable();
|
||||
void sigLoadComplete();
|
||||
void sigNeedUpdate(bool flag,qint64 size,quint64 fileCount);
|
||||
void sigSendDebugLog(QString message);
|
||||
void sigSocketDisabled();
|
||||
void sigServerBlocked();
|
||||
void sigSaveLoginData(ServerAuthorization *serverAuth);
|
||||
void sigSocketWaitForReadyRead(int waitTime);
|
||||
void sigStartCompare();
|
||||
|
||||
private:
|
||||
QList<QString> *folderList;
|
||||
//MainWindow *mainWindow;
|
||||
DataParser *dataParser;
|
||||
PacketType packetType;
|
||||
QString message;
|
||||
QString filePath;
|
||||
QByteArray tmpBlock;
|
||||
|
||||
qint64 sizeReceiveData;
|
||||
qint64 fileSize;
|
||||
int countSend;
|
||||
|
||||
void xmlParser(QByteArray array);
|
||||
|
||||
void checkAccessType(QString type);
|
||||
};
|
||||
|
||||
#endif // RECOGNIZESYSTEM_H
|
||||
@@ -0,0 +1,135 @@
|
||||
#include "sendsystem.h"
|
||||
#include "tools.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QThread>
|
||||
|
||||
|
||||
|
||||
SendSystem::SendSystem(QObject *)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void SendSystem::setSocket(QTcpSocket *socket)
|
||||
{
|
||||
this->socket = socket;
|
||||
}
|
||||
|
||||
|
||||
void SendSystem::sendDisable()
|
||||
{
|
||||
QDataStream stream(socket);
|
||||
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
|
||||
|
||||
QByteArray data;
|
||||
data = emit sigGetXmlAnswer("DISABLE");
|
||||
|
||||
stream << PacketType::TYPE_XMLANSWER;
|
||||
stream << data;
|
||||
socket->waitForBytesWritten();
|
||||
}
|
||||
|
||||
void SendSystem::sendClientAutorization()
|
||||
{
|
||||
QDataStream stream(socket);
|
||||
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
|
||||
|
||||
QFile file(tempName);
|
||||
file.open(QIODevice::ReadOnly);
|
||||
|
||||
QByteArray array = file.readAll();
|
||||
|
||||
stream << PacketType::TYPE_XMLANSWER;
|
||||
stream << array;
|
||||
socket->waitForBytesWritten();
|
||||
|
||||
file.close();
|
||||
}
|
||||
|
||||
void SendSystem::sendFileBlock(QString path)
|
||||
{
|
||||
QDataStream stream(socket);
|
||||
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
|
||||
QString fullPath = Tools::createFullPath(path);
|
||||
quint64 fileSize = 0;
|
||||
int countSend = 0;
|
||||
|
||||
|
||||
QFile file(fullPath); //Открываем файл для чтения
|
||||
QFileInfo fileInfo(file);
|
||||
|
||||
fileSize = fileInfo.size();
|
||||
|
||||
stream << PacketType::TYPE_FILE; //Отправляем тип блока
|
||||
stream << path << fileSize;
|
||||
|
||||
socket->waitForReadyRead(20);
|
||||
//socket->waitForBytesWritten();
|
||||
|
||||
if(file.open(QFile::ReadOnly)){
|
||||
while(!file.atEnd()){
|
||||
QByteArray data = file.read(1025*250);
|
||||
stream << data;
|
||||
socket->waitForBytesWritten();
|
||||
countSend++;
|
||||
}
|
||||
|
||||
qDebug() << Tools::getTime() << "count end Final: " << countSend;
|
||||
}
|
||||
|
||||
file.close();
|
||||
|
||||
emit sigSend();
|
||||
//qDebug() << "Transaction after send file: " << socket->isTransactionStarted();
|
||||
countSend = 0;
|
||||
//socket->waitForBytesWritten();
|
||||
socket->waitForReadyRead(20);
|
||||
}
|
||||
|
||||
void SendSystem::sendFolderBlock(QString path)
|
||||
{
|
||||
QDataStream stream(socket);
|
||||
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
|
||||
|
||||
stream << PacketType::TYPE_FOLDER;
|
||||
stream << path;
|
||||
emit sigSend();
|
||||
socket->waitForReadyRead(100);
|
||||
}
|
||||
|
||||
|
||||
void SendSystem::sendQTConnect()
|
||||
{
|
||||
QString value = QString::number(PacketType::TYPE_QT);
|
||||
socket->write(value.toUtf8());
|
||||
socket->waitForBytesWritten();
|
||||
}
|
||||
|
||||
void SendSystem::sendXMLAnswer(QByteArray array)
|
||||
{
|
||||
QDataStream stream(socket);
|
||||
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
|
||||
|
||||
stream << PacketType::TYPE_XMLANSWER;
|
||||
stream << array;
|
||||
|
||||
socket->waitForBytesWritten();
|
||||
socket->waitForReadyRead(100);
|
||||
}
|
||||
|
||||
void SendSystem::sendFinish()
|
||||
{
|
||||
socket->waitForReadyRead(100);
|
||||
QDataStream stream(socket);
|
||||
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
|
||||
|
||||
stream << PacketType::TYPE_FINISH;
|
||||
socket->waitForReadyRead(100);
|
||||
}
|
||||
|
||||
SendSystem::~SendSystem()
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
#ifndef SENDSYSTEM_H
|
||||
#define SENDSYSTEM_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QTcpSocket>
|
||||
#include <QDataStream>
|
||||
|
||||
class SendSystem :public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SendSystem(QObject* parent = nullptr);
|
||||
void setSocket(QTcpSocket *socket);
|
||||
void sendClientAutorization();
|
||||
void sendDisable();
|
||||
void sendFileBlock(QString path);
|
||||
void sendFolderBlock(QString path);
|
||||
void sendQTConnect();
|
||||
void sendXMLAnswer(QByteArray array);
|
||||
~SendSystem();
|
||||
void sendFinish();
|
||||
signals:
|
||||
void sigSend();
|
||||
QByteArray sigGetXmlAnswer(QString);
|
||||
|
||||
private:
|
||||
QTcpSocket *socket;
|
||||
};
|
||||
|
||||
#endif // SENDSYSTEM_H
|
||||
@@ -0,0 +1,141 @@
|
||||
#include "tcpclient.h"
|
||||
|
||||
#include <QDir>
|
||||
|
||||
TCPClient::TCPClient(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void TCPClient::initialize(RecognizeSystem *recognize,SendSystem *sendSystem)
|
||||
{
|
||||
this->recognizeSystem = recognize;
|
||||
this->sendSystem = sendSystem;
|
||||
isConnected = false;
|
||||
|
||||
emit sigSendDebugLog(Tools::getTime() + " Client started");
|
||||
}
|
||||
|
||||
void TCPClient::setConnect(ServerSettings *serverSettings)
|
||||
{
|
||||
socket = new QTcpSocket();
|
||||
qDebug() << "TCPCLient thread: " << thread();
|
||||
if (socket != NULL && socket->state() == QTcpSocket::ConnectedState)
|
||||
{
|
||||
emit sigSendDebugLog("already connected");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
socket->connectToHost(serverSettings->Address,serverSettings->Port.toShort());
|
||||
emit sigSendDebugLog("Try connect...");
|
||||
isConnected = true;
|
||||
|
||||
if (socket->waitForConnected(2000))
|
||||
{
|
||||
connect(socket,&QTcpSocket::readyRead,this,&TCPClient::slotReadyRead,Qt::DirectConnection);
|
||||
connect(socket,&QTcpSocket::disconnected,this,&TCPClient::setDisconnect);
|
||||
//connect(socket,&QTcpSocket::connected,this,&TCPClient::slotConnectNotify);
|
||||
|
||||
connect(this,&TCPClient::sigRecognize,recognizeSystem,&RecognizeSystem::recognize,Qt::DirectConnection);
|
||||
connect(this,&TCPClient::sigSetSocket,sendSystem,&SendSystem::setSocket);
|
||||
|
||||
emit sigSetSocket(socket);
|
||||
slotConnectNotify();
|
||||
}
|
||||
else
|
||||
{
|
||||
isConnected = false;
|
||||
emit sigServerDisconnect();
|
||||
}
|
||||
}
|
||||
|
||||
void TCPClient::setDisconnect()
|
||||
{
|
||||
socket->disconnect();
|
||||
isConnected = false;
|
||||
emit sigServerDisconnect();
|
||||
emit sigSendDebugLog("Server disabled");
|
||||
}
|
||||
|
||||
|
||||
void TCPClient:: waitRead(int time)
|
||||
{
|
||||
socket->waitForReadyRead(time);
|
||||
}
|
||||
|
||||
QTcpSocket *TCPClient::getSocket()
|
||||
{
|
||||
return socket;
|
||||
}
|
||||
|
||||
void TCPClient::slotSendCommand(QString command)
|
||||
{
|
||||
QDataStream stream(socket);
|
||||
QByteArray data;
|
||||
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
|
||||
|
||||
if(!command.isEmpty() && socket->state() == QTcpSocket::ConnectedState){
|
||||
|
||||
if(command == "check")
|
||||
{
|
||||
stream << PacketType::TYPE_COMMAND;
|
||||
stream << command;
|
||||
socket->waitForBytesWritten();
|
||||
|
||||
sendSystem->sendFileBlock("/" + hashFilename);
|
||||
emit sigSendDebugLog(Tools::getTime() + " Local checkFile sended");
|
||||
|
||||
socket->waitForReadyRead(1000);
|
||||
}
|
||||
else if(command == "update"){
|
||||
emit sigSendDebugLog("Update started");
|
||||
stream << PacketType::TYPE_COMMAND;
|
||||
stream << command;
|
||||
socket->waitForReadyRead(1000);
|
||||
}
|
||||
else if(command == "run"){
|
||||
//externalExecuter->callApp();
|
||||
}
|
||||
}else{
|
||||
emit sigSendDebugLog("WRONG SOCKET AFTER ENTERED");
|
||||
}
|
||||
}
|
||||
|
||||
void TCPClient::slotConnectNotify()
|
||||
{
|
||||
if(socket->state() != QTcpSocket::ConnectedState)
|
||||
{
|
||||
isConnected = false;
|
||||
emit sigSendDebugLog("Connect invalid");
|
||||
emit sigConnectionState(false);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
isConnected = true;
|
||||
emit sigSendDebugLog("Connect complete");
|
||||
emit sigConnectionState(true);
|
||||
sendSystem->sendQTConnect();
|
||||
}
|
||||
}
|
||||
|
||||
void TCPClient::slotReadyRead()
|
||||
{
|
||||
if(!socket){
|
||||
emit sigSendDebugLog("WRONG SOCKET");
|
||||
return;
|
||||
}
|
||||
|
||||
emit sigRecognize(socket);
|
||||
}
|
||||
|
||||
bool TCPClient::getIsConnected() const
|
||||
{
|
||||
return isConnected;
|
||||
}
|
||||
|
||||
TCPClient::~TCPClient()
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
#ifndef TCPCLIENT_H
|
||||
#define TCPCLIENT_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QTcpSocket>
|
||||
#include <QHostAddress>
|
||||
#include <QDataStream>
|
||||
#include <QTcpServer>
|
||||
#include <QFile>
|
||||
#include <QCoreApplication>
|
||||
#include "Core\recognizesystem.h"
|
||||
#include "Core\tools.h"
|
||||
#include "sendsystem.h"
|
||||
#include "Datas.h"
|
||||
|
||||
|
||||
class RecognizeSystem;
|
||||
class SendSystem;
|
||||
|
||||
class TCPClient : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
public:
|
||||
explicit TCPClient(QObject *parent = 0);
|
||||
void initialize(RecognizeSystem *recognize,SendSystem *sendSystem);
|
||||
void setConnect(ServerSettings *serverSettings);
|
||||
|
||||
void waitRead(int time);
|
||||
QTcpSocket* getSocket();
|
||||
~TCPClient();
|
||||
|
||||
bool getIsConnected() const;
|
||||
|
||||
signals:
|
||||
void sigSendDebugLog(QString message);
|
||||
void sigRecognize(QTcpSocket *socket);
|
||||
void sigServerDisconnect();
|
||||
void sigConnectionState(bool flag);
|
||||
void sigSetSocket(QTcpSocket *socket);
|
||||
|
||||
public slots:
|
||||
void slotSendCommand(QString message);
|
||||
void slotConnectNotify();
|
||||
|
||||
private slots:
|
||||
void slotReadyRead();
|
||||
|
||||
|
||||
private:
|
||||
SendSystem *sendSystem;
|
||||
QTcpSocket *socket;
|
||||
RecognizeSystem *recognizeSystem;
|
||||
bool isConnected;
|
||||
|
||||
void setDisconnect();
|
||||
};
|
||||
|
||||
#endif // TCPCLIENT_H
|
||||
@@ -0,0 +1,58 @@
|
||||
#include "tools.h"
|
||||
|
||||
#include <qdir.h>
|
||||
|
||||
|
||||
void Tools::printTime()
|
||||
{
|
||||
qDebug() << QTime::currentTime().toString("hh:mm:ss");
|
||||
}
|
||||
|
||||
QString Tools::getTime()
|
||||
{
|
||||
return QTime::currentTime().toString(("hh:mm:ss"));
|
||||
}
|
||||
|
||||
QString Tools::createLocalPath(QString path)
|
||||
{
|
||||
qDebug() << "Full path: " << path;
|
||||
qint8 pos = path.indexOf("Application");
|
||||
|
||||
QString localPath = path.remove(0,--pos);
|
||||
|
||||
qDebug() << "Local path: " << localPath;
|
||||
return localPath;
|
||||
}
|
||||
|
||||
QString Tools::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;
|
||||
}
|
||||
|
||||
QString Tools::convertFileSize(quint64 fileSize)
|
||||
{
|
||||
quint64 megaByte = fileSize / (1024 * 1024);
|
||||
QString resultSize;
|
||||
|
||||
if (megaByte == 0)
|
||||
{
|
||||
auto kiloByte = fileSize / 1024;
|
||||
resultSize = QString::number(kiloByte) + "кб. ";
|
||||
}
|
||||
else
|
||||
{
|
||||
resultSize = QString::number(megaByte) + "мб. ";
|
||||
}
|
||||
|
||||
|
||||
QString result = resultSize;
|
||||
return result;
|
||||
}
|
||||
46
DB_IaT/InstructorsAndTrainees/connectorToServer/Core/tools.h
Normal file
46
DB_IaT/InstructorsAndTrainees/connectorToServer/Core/tools.h
Normal file
@@ -0,0 +1,46 @@
|
||||
#ifndef GLOBAL_H
|
||||
#define GLOBAL_H
|
||||
|
||||
#include <QString>
|
||||
#include <QTime>
|
||||
#include <QDebug>
|
||||
|
||||
#define TCP_READ_TIMEOUT 2000
|
||||
|
||||
static QString applicationEXEName = "RRJ.exe";
|
||||
static QString applicationFolderName = "/Application";
|
||||
static QString staticDataFolderName = "StaticData";
|
||||
static QString streamingAssetsPath = "/Application/RRJLoader/RRJ_Data/StreamingAssets";
|
||||
static QString hashFilename = staticDataFolderName + "/clientHash.xml";
|
||||
static QString settingsName = staticDataFolderName + "/settings.xml";
|
||||
static QString tempName = staticDataFolderName + "/temp.xml";
|
||||
static QString authTempName = staticDataFolderName + "/authData.xml";
|
||||
static QString displayTemp = staticDataFolderName + "/displayData.xml";
|
||||
static QString streamingHashFilename = staticDataFolderName + "/streamingHash.xml";
|
||||
static QString serverHash = staticDataFolderName + "/serverHash.xml";
|
||||
|
||||
enum PacketType{
|
||||
TYPE_NONE = 0,
|
||||
TYPE_UNITY = 1,
|
||||
TYPE_FILE = 2,
|
||||
TYPE_COMMAND = 3,
|
||||
TYPE_FOLDER = 4,
|
||||
TYPE_DELETE = 5,
|
||||
TYPE_FINISH = 6,
|
||||
TYPE_NEEDUPDATE = 7,
|
||||
TYPE_XMLANSWER = 8,
|
||||
TYPE_QT = 9,
|
||||
TYPE_DISABLE = 11
|
||||
};
|
||||
|
||||
class Tools {
|
||||
public:
|
||||
|
||||
static void printTime();
|
||||
static QString getTime();
|
||||
static QString createLocalPath(QString path);
|
||||
static QString createFullPath(QString path);
|
||||
static QString convertFileSize(quint64 fileSize);
|
||||
};
|
||||
|
||||
#endif // GLOBAL_H
|
||||
58
DB_IaT/InstructorsAndTrainees/connectorToServer/Datas.h
Normal file
58
DB_IaT/InstructorsAndTrainees/connectorToServer/Datas.h
Normal file
@@ -0,0 +1,58 @@
|
||||
#ifndef DATAS_H
|
||||
#define DATAS_H
|
||||
|
||||
#include <QString>
|
||||
|
||||
class ServerSettings{
|
||||
public:
|
||||
QString Address;
|
||||
QString Port;
|
||||
QString Language;
|
||||
bool isAutoStart;
|
||||
};
|
||||
|
||||
class ServerAuthorization{
|
||||
public:
|
||||
QString InstructorName;
|
||||
QString ClientName;
|
||||
bool Result;
|
||||
QString AccessType;
|
||||
};
|
||||
|
||||
class ClientAutorization{
|
||||
public:
|
||||
QString Login;
|
||||
QString Password;
|
||||
};
|
||||
|
||||
class ServerMessage
|
||||
{
|
||||
public:
|
||||
QString Text;
|
||||
};
|
||||
|
||||
class ClientMessage
|
||||
{
|
||||
public:
|
||||
QString Text;
|
||||
};
|
||||
|
||||
class ServerTask
|
||||
{
|
||||
public:
|
||||
QString Text;
|
||||
};
|
||||
|
||||
class ServerNotify
|
||||
{
|
||||
public:
|
||||
QString Code;
|
||||
};
|
||||
|
||||
class ClientNotify
|
||||
{
|
||||
public:
|
||||
QString Code;
|
||||
};
|
||||
|
||||
#endif // DATAS_H
|
||||
@@ -0,0 +1,86 @@
|
||||
#include "connectortoserver.h"
|
||||
#include <QThread>
|
||||
|
||||
ConnectorToServer::ConnectorToServer(QObject *parent) :
|
||||
QObject(parent),
|
||||
connectionThread(nullptr),
|
||||
client(nullptr),
|
||||
dataParser(nullptr),
|
||||
sendSystem(nullptr),
|
||||
recognizeSystem(nullptr)
|
||||
{
|
||||
initialize();
|
||||
}
|
||||
|
||||
bool ConnectorToServer::authorizationInstructorLocal(QString login, QString password)
|
||||
{
|
||||
if (!client->getIsConnected())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
ClientAutorization *autorization = new ClientAutorization;
|
||||
autorization->Login = login;
|
||||
autorization->Password = password;
|
||||
|
||||
dataParser->createAuthMessage(autorization);
|
||||
emit sigSendAutorization();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ConnectorToServer::initialize()
|
||||
{
|
||||
createObjects();
|
||||
|
||||
bindConnection();
|
||||
|
||||
emit sigInitializeClient(recognizeSystem,sendSystem,connectionThread);
|
||||
|
||||
emit sigSetConnect(dataParser->getServerSettings(),connectionThread);
|
||||
}
|
||||
|
||||
void ConnectorToServer::bindConnection()
|
||||
{
|
||||
/*
|
||||
connect(recognizeSystem,&RecognizeSystem::sigStartCompare,hashComparer,&HashComparer::CompareDeltas);
|
||||
connect(recognizeSystem,&RecognizeSystem::sigUpdateBytesAvailable,this,&MainWindow::updateProgress,Qt::QueuedConnection);
|
||||
connect(recognizeSystem,&RecognizeSystem::sigLoadComplete,this,&MainWindow::loadComplete);
|
||||
connect(recognizeSystem,&RecognizeSystem::sigNeedUpdate,this,&MainWindow::setNeedUpdate);
|
||||
connect(recognizeSystem,&RecognizeSystem::sigSocketDisabled,this,&MainWindow::lostConnection);
|
||||
connect(recognizeSystem,&RecognizeSystem::sigSaveLoginData,this,&MainWindow::checkLoginResult);
|
||||
connect(recognizeSystem,&RecognizeSystem::sigSocketWaitForReadyRead,client,&TCPClient::waitRead,Qt::DirectConnection);
|
||||
connect(recognizeSystem,&RecognizeSystem::sigServerBlocked,this,&MainWindow::serverBlocked);
|
||||
|
||||
connect(sendSystem,&SendSystem::sigSend,this,&MainWindow::updateProgress);
|
||||
connect(sendSystem,&SendSystem::sigGetXmlAnswer,dataParser,&DataParser::slotGetXmlAnswer);
|
||||
|
||||
connect(client,&TCPClient::sigConnectionState,this,&MainWindow::slotConnectionState,Qt::AutoConnection);
|
||||
connect(client,&TCPClient::sigServerDisconnect,this,&MainWindow::slotServerDisconnect);
|
||||
*/
|
||||
|
||||
connect(this,&ConnectorToServer::sigInitializeClient,client,&TCPClient::initialize,Qt::AutoConnection);
|
||||
connect(this,&ConnectorToServer::sigSetConnect,client,&TCPClient::setConnect,Qt::AutoConnection);
|
||||
connect(this,&ConnectorToServer::sigSendAutorization,sendSystem,&SendSystem::sendClientAutorization);
|
||||
|
||||
connect(recognizeSystem,&RecognizeSystem::sigSaveLoginData,this,&ConnectorToServer::sigLoginResult);
|
||||
}
|
||||
|
||||
void ConnectorToServer::createObjects()
|
||||
{
|
||||
connectionThread = new QThread;
|
||||
|
||||
client = new TCPClient;
|
||||
client->moveToThread(connectionThread);
|
||||
|
||||
dataParser = new DataParser;
|
||||
|
||||
sendSystem = new SendSystem;
|
||||
sendSystem->moveToThread(connectionThread);
|
||||
|
||||
recognizeSystem = new RecognizeSystem;
|
||||
recognizeSystem->moveToThread(connectionThread);
|
||||
|
||||
connectionThread->start();
|
||||
connectionThread->setPriority(QThread::HighestPriority);
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
#ifndef CONNECTORTOSERVER_H
|
||||
#define CONNECTORTOSERVER_H
|
||||
|
||||
#include <QObject>
|
||||
#include "Core\tcpclient.h"
|
||||
#include "Core\dataparser.h"
|
||||
#include "Core\sendsystem.h"
|
||||
#include "Core\recognizesystem.h"
|
||||
|
||||
class ConnectorToServer : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ConnectorToServer(QObject *parent = nullptr);
|
||||
|
||||
bool authorizationInstructorLocal(QString login, QString password);
|
||||
|
||||
private slots:
|
||||
|
||||
signals:
|
||||
void sigSetConnect(ServerSettings* serverSettings,QThread *thread);
|
||||
void sigInitializeClient(RecognizeSystem *recognizeSystem,
|
||||
SendSystem *sendSystem,
|
||||
QThread *thread);
|
||||
void sigSendAutorization();
|
||||
void sigLoginResult(ServerAuthorization * serverAuth);
|
||||
|
||||
private:
|
||||
void initialize();
|
||||
void bindConnection();
|
||||
void createObjects();
|
||||
|
||||
private:
|
||||
QThread *connectionThread;
|
||||
TCPClient *client;
|
||||
DataParser *dataParser;
|
||||
SendSystem *sendSystem;
|
||||
RecognizeSystem *recognizeSystem;
|
||||
|
||||
};
|
||||
|
||||
#endif // CONNECTORTOSERVER_H
|
||||
@@ -7,6 +7,7 @@
|
||||
InstructorsAndTraineesWidget::InstructorsAndTraineesWidget(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::InstructorsAndTraineesWidget),
|
||||
connectorToServer(nullptr),
|
||||
dbLMS(nullptr),
|
||||
viewerTrainees(nullptr),
|
||||
viewerInstructors(nullptr),
|
||||
@@ -15,6 +16,9 @@ InstructorsAndTraineesWidget::InstructorsAndTraineesWidget(QWidget *parent) :
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
connectorToServer = new ConnectorToServer(this);
|
||||
connect(connectorToServer,&ConnectorToServer::sigLoginResult,this,&InstructorsAndTraineesWidget::checkLoginResult);
|
||||
|
||||
dbLMS = new InterfaceDataBaseLMS(this);
|
||||
|
||||
connect(this, &InstructorsAndTraineesWidget::signal_LanguageChanged, dbLMS, &InterfaceDataBaseLMS::slot_LanguageChanged);
|
||||
@@ -37,7 +41,7 @@ InstructorsAndTraineesWidget::InstructorsAndTraineesWidget(QWidget *parent) :
|
||||
viewerTrainees->setMinimumSize(1600, 600);
|
||||
viewerInstructors->setMinimumSize(1600, 300);
|
||||
|
||||
ui->btnAuthorizationInstructor->setEnabled(false);
|
||||
//ui->btnAuthorizationInstructor->setEnabled(false);
|
||||
|
||||
//ui->btnConnectionToDB->click();
|
||||
}
|
||||
@@ -58,6 +62,7 @@ InstructorsAndTraineesWidget::~InstructorsAndTraineesWidget()
|
||||
delete viewerInstructors;
|
||||
delete viewerTrainees;
|
||||
delete dbLMS;
|
||||
delete connectorToServer;
|
||||
delete ui;
|
||||
}
|
||||
|
||||
@@ -90,6 +95,38 @@ void InstructorsAndTraineesWidget::slot_LanguageChanged(QString language)
|
||||
Q_EMIT signal_LanguageChanged(language);
|
||||
}
|
||||
|
||||
void InstructorsAndTraineesWidget::checkLoginResult(ServerAuthorization *serverAuth)
|
||||
{
|
||||
if (serverAuth->Result)
|
||||
{
|
||||
loginInstructorLoggedInLocal = serverAuth->ClientName;
|
||||
|
||||
if(loginInstructorLoggedInLocal == QStringLiteral("admin"))
|
||||
adminMode = true;
|
||||
else
|
||||
adminMode = false;
|
||||
|
||||
viewerInstructors->setAdminMode(adminMode);
|
||||
viewerTrainees->setAdminMode(adminMode);
|
||||
viewerInstructors->setAuthComplited(true);
|
||||
viewerTrainees->setAuthComplited(true);
|
||||
|
||||
//Q_EMIT signal_NeedUpdateUI(true, true);
|
||||
|
||||
ui->btnAuthorizationInstructor->setText(tr("Deauthorization Instructor"));
|
||||
|
||||
//updateLabelLoggedInInstructor();
|
||||
|
||||
//Q_EMIT signal_NeedUpdateUI(true, true);
|
||||
|
||||
QMessageBox::information(this, tr("Instructor authorization"), tr("Successfully!"));
|
||||
}
|
||||
else
|
||||
{
|
||||
QMessageBox::warning(this, tr("Instructor authorization"), tr("Invalid login or password!"));
|
||||
}
|
||||
}
|
||||
|
||||
bool InstructorsAndTraineesWidget::authorizationInstructorLocal(QWidget* parent)
|
||||
{
|
||||
DialogAuthorizationInstructor dlg(parent);
|
||||
@@ -104,30 +141,10 @@ bool InstructorsAndTraineesWidget::authorizationInstructorLocal(QWidget* parent)
|
||||
QString login = dlg.getLogin();
|
||||
QString password = dlg.getPassword();
|
||||
|
||||
if(authorizationInstructor(login, password))
|
||||
{
|
||||
loginInstructorLoggedInLocal = login;
|
||||
//if(authorizationInstructor(login, password))
|
||||
connectorToServer->authorizationInstructorLocal(login, password);
|
||||
|
||||
if(login == QStringLiteral("admin"))
|
||||
adminMode = true;
|
||||
else
|
||||
adminMode = false;
|
||||
|
||||
viewerInstructors->setAdminMode(adminMode);
|
||||
viewerTrainees->setAdminMode(adminMode);
|
||||
viewerInstructors->setAuthComplited(true);
|
||||
viewerTrainees->setAuthComplited(true);
|
||||
|
||||
//Q_EMIT signal_NeedUpdateUI(true, true);
|
||||
|
||||
QMessageBox::information(parent, tr("Instructor authorization"), tr("Successfully!"));
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
QMessageBox::warning(parent, tr("Instructor authorization"), tr("Invalid login or password!"));
|
||||
|
||||
break;
|
||||
return true;
|
||||
}
|
||||
case QDialog::Rejected:
|
||||
return false;
|
||||
@@ -366,11 +383,7 @@ void InstructorsAndTraineesWidget::on_btnAuthorizationInstructor_clicked()
|
||||
{//Авторизация Инструктора локальная (Администратора)
|
||||
if(authorizationInstructorLocal(this))
|
||||
{
|
||||
ui->btnAuthorizationInstructor->setText(tr("Deauthorization Instructor"));
|
||||
|
||||
updateLabelLoggedInInstructor();
|
||||
|
||||
Q_EMIT signal_NeedUpdateUI(true, true);
|
||||
}
|
||||
else
|
||||
ui->btnAuthorizationInstructor->setChecked(false);
|
||||
@@ -383,7 +396,7 @@ void InstructorsAndTraineesWidget::on_btnAuthorizationInstructor_clicked()
|
||||
{
|
||||
ui->btnAuthorizationInstructor->setText(tr("Authorization Instructor"));
|
||||
|
||||
updateLabelLoggedInInstructor();
|
||||
//updateLabelLoggedInInstructor();
|
||||
|
||||
Q_EMIT signal_NeedUpdateUI(true, true);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "viewerinstructors.h"
|
||||
#include "doctaskswidget.h"
|
||||
#include "interfacedatabaselms.h"
|
||||
#include "connectortoserver.h"
|
||||
|
||||
namespace Ui {
|
||||
class InstructorsAndTraineesWidget;
|
||||
@@ -27,6 +28,7 @@ private:
|
||||
public Q_SLOTS:
|
||||
//Слот обработки смены языка
|
||||
void slot_LanguageChanged(QString language);
|
||||
void checkLoginResult(ServerAuthorization * serverAuth);
|
||||
|
||||
Q_SIGNALS:
|
||||
//сигнал об изменении языка интерфейса
|
||||
@@ -79,6 +81,8 @@ private:
|
||||
private:
|
||||
Ui::InstructorsAndTraineesWidget *ui;
|
||||
|
||||
ConnectorToServer* connectorToServer;
|
||||
|
||||
InterfaceDataBaseLMS* dbLMS;
|
||||
|
||||
ViewerTrainees* viewerTrainees;
|
||||
|
||||
Reference in New Issue
Block a user