mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/RRJServer.git
synced 2026-03-27 19:45:43 +03:00
Передача больших файлов xml с задачами кусками
This commit is contained in:
@@ -276,6 +276,86 @@ void RecognizeSystem::recognize(QTcpSocket *socket)
|
|||||||
case TYPE_XMLANSWER_QUERY_TASKS_AMM_FOR_TRAINEE:
|
case TYPE_XMLANSWER_QUERY_TASKS_AMM_FOR_TRAINEE:
|
||||||
case TYPE_XMLANSWER_QUERY_TASKS_FIM_FOR_TRAINEE:
|
case TYPE_XMLANSWER_QUERY_TASKS_FIM_FOR_TRAINEE:
|
||||||
{
|
{
|
||||||
|
//ПОЛУЧЕНИЕ РАЗМЕРА ФАЙЛА
|
||||||
|
forever
|
||||||
|
{
|
||||||
|
stream.startTransaction();
|
||||||
|
stream >> fileSize;
|
||||||
|
|
||||||
|
if(!stream.commitTransaction()){
|
||||||
|
emit sigSendDebugLog(Tools::getTime() + "CLIENT: fileSize - FAIL commitTransaction");
|
||||||
|
|
||||||
|
if (!socket->waitForReadyRead(TCP_READ_TIMEOUT)) {
|
||||||
|
emit sigSendDebugLog(Tools::getTime() + "CLIENT: ERROR! readyRead timeout - fileSize!!!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
emit sigSendDebugLog("CLIENT: filesize: " + QString::number(fileSize));
|
||||||
|
|
||||||
|
socket->waitForReadyRead(100);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//ПОЛУЧЕНИЕ САМОГО ФАЙЛА
|
||||||
|
emit sigSendDebugLog(Tools::getTime() + "AfterRead size and path BytesAvailable: " + socket->bytesAvailable());
|
||||||
|
|
||||||
|
QByteArray array;
|
||||||
|
|
||||||
|
forever
|
||||||
|
{
|
||||||
|
stream.startTransaction();
|
||||||
|
stream >> tmpBlock;
|
||||||
|
|
||||||
|
if(!stream.commitTransaction()){
|
||||||
|
|
||||||
|
if(socket->state() == QAbstractSocket::UnconnectedState){
|
||||||
|
emit sigSocketDisabled();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(socket->waitForReadyRead(TCP_READ_TIMEOUT)){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
array.append(tmpBlock);
|
||||||
|
|
||||||
|
emit sigSendDebugLog(Tools::getTime() + "CLIENT: toFile :" + array.size());
|
||||||
|
|
||||||
|
sizeReceiveData += array.size();
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
emit sigSendDebugLog(Tools::getTime() + "File loaded");
|
||||||
|
|
||||||
|
//ОЧИСТКА ПОСЛЕ ПЕРЕДАЧИ
|
||||||
|
fileSize = 0;
|
||||||
|
tmpBlock.clear();
|
||||||
|
sizeReceiveData = 0;
|
||||||
|
countSend = 0;
|
||||||
|
|
||||||
|
xmlParserQueryToDB(packetType, array);
|
||||||
|
|
||||||
|
packetType = PacketType::TYPE_NONE;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
QByteArray array;
|
QByteArray array;
|
||||||
stream.startTransaction();
|
stream.startTransaction();
|
||||||
stream >> array;
|
stream >> array;
|
||||||
@@ -286,6 +366,7 @@ void RecognizeSystem::recognize(QTcpSocket *socket)
|
|||||||
xmlParserQueryToDB(packetType, array);
|
xmlParserQueryToDB(packetType, array);
|
||||||
|
|
||||||
packetType = PacketType::TYPE_NONE;
|
packetType = PacketType::TYPE_NONE;
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -41,13 +41,13 @@ AMMtasksWidget::AMMtasksWidget(ConnectorToServer* connectorToServer, TypeList ty
|
|||||||
connect(this, &AMMtasksWidget::signal_prepareListItemsForTrainee, taskTreePreparation, &TaskTreePreparation::slot_prepareListItemsForTrainee);
|
connect(this, &AMMtasksWidget::signal_prepareListItemsForTrainee, taskTreePreparation, &TaskTreePreparation::slot_prepareListItemsForTrainee);
|
||||||
connect(taskTreePreparation, &TaskTreePreparation::signal_listItemsReady, this, &AMMtasksWidget::slot_listItemsReady);
|
connect(taskTreePreparation, &TaskTreePreparation::signal_listItemsReady, this, &AMMtasksWidget::slot_listItemsReady);
|
||||||
|
|
||||||
threadAnimation = new QThread();
|
//threadAnimation = new QThread();
|
||||||
waitAnimationWidget = new WaitAnimationWidget;
|
waitAnimationWidget = new WaitAnimationWidget;
|
||||||
QMovie *movie = new QMovie(":/resources/icons/762.gif");
|
QMovie *movie = new QMovie(":/resources/icons/762.gif");
|
||||||
waitAnimationWidget->setParent(this);
|
waitAnimationWidget->setParent(this);
|
||||||
waitAnimationWidget->initialize(movie,this);
|
waitAnimationWidget->initialize(movie,this);
|
||||||
waitAnimationWidget->moveToThread(threadAnimation);
|
//waitAnimationWidget->moveToThread(threadAnimation);
|
||||||
threadAnimation->start();
|
//threadAnimation->start();
|
||||||
|
|
||||||
ui->btnDelete->setObjectName("btnDelete");
|
ui->btnDelete->setObjectName("btnDelete");
|
||||||
ui->btnDelete->setEnabled(false);
|
ui->btnDelete->setEnabled(false);
|
||||||
@@ -84,13 +84,13 @@ AMMtasksWidget::~AMMtasksWidget()
|
|||||||
waitAnimationWidget->hideWithStop();
|
waitAnimationWidget->hideWithStop();
|
||||||
taskTreePreparation->stopParser();
|
taskTreePreparation->stopParser();
|
||||||
|
|
||||||
threadAnimation->quit();
|
//threadAnimation->quit();
|
||||||
threadAnimation->wait();
|
//threadAnimation->wait();
|
||||||
|
|
||||||
threadPreparation->quit();
|
threadPreparation->quit();
|
||||||
threadPreparation->wait();
|
threadPreparation->wait();
|
||||||
|
|
||||||
delete threadAnimation;
|
//delete threadAnimation;
|
||||||
delete threadPreparation;
|
delete threadPreparation;
|
||||||
|
|
||||||
delete taskTreePreparation;
|
delete taskTreePreparation;
|
||||||
@@ -374,5 +374,6 @@ void AMMtasksWidget::on_btnCheck_clicked()
|
|||||||
|
|
||||||
void AMMtasksWidget::on_btnAssignTask_clicked()
|
void AMMtasksWidget::on_btnAssignTask_clicked()
|
||||||
{
|
{
|
||||||
assignTaskAMMtoTrainee();
|
if(QMessageBox::question(this, tr("New task"), tr("Assign this task?"), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok)
|
||||||
|
assignTaskAMMtoTrainee();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,13 +33,13 @@ FIMtasksWidget::FIMtasksWidget(ConnectorToServer* connectorToServer, TypeList ty
|
|||||||
|
|
||||||
preparationTreeWidget();
|
preparationTreeWidget();
|
||||||
|
|
||||||
threadAnimation = new QThread();
|
//threadAnimation = new QThread();
|
||||||
waitAnimationWidget = new WaitAnimationWidget;
|
waitAnimationWidget = new WaitAnimationWidget;
|
||||||
QMovie *movie = new QMovie(":/resources/icons/762.gif");
|
QMovie *movie = new QMovie(":/resources/icons/762.gif");
|
||||||
waitAnimationWidget->setParent(this);
|
waitAnimationWidget->setParent(this);
|
||||||
waitAnimationWidget->initialize(movie,this);
|
waitAnimationWidget->initialize(movie,this);
|
||||||
waitAnimationWidget->moveToThread(threadAnimation);
|
//waitAnimationWidget->moveToThread(threadAnimation);
|
||||||
threadAnimation->start();
|
//threadAnimation->start();
|
||||||
|
|
||||||
ui->btnDelete->setObjectName("btnDelete");
|
ui->btnDelete->setObjectName("btnDelete");
|
||||||
ui->btnDelete->setEnabled(false);
|
ui->btnDelete->setEnabled(false);
|
||||||
@@ -80,10 +80,10 @@ FIMtasksWidget::~FIMtasksWidget()
|
|||||||
|
|
||||||
waitAnimationWidget->hideWithStop();
|
waitAnimationWidget->hideWithStop();
|
||||||
|
|
||||||
threadAnimation->quit();
|
//threadAnimation->quit();
|
||||||
threadAnimation->wait();
|
//threadAnimation->wait();
|
||||||
|
|
||||||
delete threadAnimation;
|
//delete threadAnimation;
|
||||||
|
|
||||||
delete waitAnimationWidget;
|
delete waitAnimationWidget;
|
||||||
delete treeWidget;
|
delete treeWidget;
|
||||||
@@ -565,5 +565,6 @@ void FIMtasksWidget::on_btnCheck_clicked()
|
|||||||
|
|
||||||
void FIMtasksWidget::on_btnAssignTask_clicked()
|
void FIMtasksWidget::on_btnAssignTask_clicked()
|
||||||
{
|
{
|
||||||
assignTaskFIMtoTrainee();
|
if(QMessageBox::question(this, tr("New task"), tr("Assign this task?"), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok)
|
||||||
|
assignTaskFIMtoTrainee();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -157,13 +157,16 @@ void ProcessingSystem::processingClientQueryToDB(ClientHandler *client, ClientQu
|
|||||||
QByteArray arrayAnswer;
|
QByteArray arrayAnswer;
|
||||||
|
|
||||||
arrayAnswer = dataParser->DbAnswer()->listInstructors(true, &listInstructors);
|
arrayAnswer = dataParser->DbAnswer()->listInstructors(true, &listInstructors);
|
||||||
client->sendXmlAnswer(arrayAnswer, PacketType::TYPE_XMLANSWER_QUERY_DB__LIST_INSTRUCTORS);
|
//client->sendXmlAnswer(arrayAnswer, PacketType::TYPE_XMLANSWER_QUERY_DB__LIST_INSTRUCTORS);
|
||||||
|
client->sendFileBlockByteArray(arrayAnswer, PacketType::TYPE_XMLANSWER_QUERY_DB__LIST_INSTRUCTORS);
|
||||||
|
|
||||||
arrayAnswer = dataParser->DbAnswer()->listGroups(true, &listGroups);
|
arrayAnswer = dataParser->DbAnswer()->listGroups(true, &listGroups);
|
||||||
client->sendXmlAnswer(arrayAnswer, PacketType::TYPE_XMLANSWER_QUERY_DB__LIST_GROUPS);
|
//client->sendXmlAnswer(arrayAnswer, PacketType::TYPE_XMLANSWER_QUERY_DB__LIST_GROUPS);
|
||||||
|
client->sendFileBlockByteArray(arrayAnswer, PacketType::TYPE_XMLANSWER_QUERY_DB__LIST_GROUPS);
|
||||||
|
|
||||||
arrayAnswer = dataParser->DbAnswer()->listTrainees(true, &listTrainees);
|
arrayAnswer = dataParser->DbAnswer()->listTrainees(true, &listTrainees);
|
||||||
client->sendXmlAnswer(arrayAnswer, PacketType::TYPE_XMLANSWER_QUERY_DB__LIST_TRAINEES);
|
//client->sendXmlAnswer(arrayAnswer, PacketType::TYPE_XMLANSWER_QUERY_DB__LIST_TRAINEES);
|
||||||
|
client->sendFileBlockByteArray(arrayAnswer, PacketType::TYPE_XMLANSWER_QUERY_DB__LIST_TRAINEES);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TypeQueryToDB::TYPE_QUERY_NEW_INSTRUCTOR:
|
case TypeQueryToDB::TYPE_QUERY_NEW_INSTRUCTOR:
|
||||||
@@ -449,14 +452,16 @@ void ProcessingSystem::sendListTasksAMMofTraineetoClient(ClientHandler *client,
|
|||||||
{
|
{
|
||||||
QList<TaskAmmFim> listTasks = providerDBLMS->GetListTasksAMMofTrainee(id_trainee);
|
QList<TaskAmmFim> listTasks = providerDBLMS->GetListTasksAMMofTrainee(id_trainee);
|
||||||
QByteArray arrayAnswer = dataParser->DbAnswer()->listTasksAMMofTrainee(true, &listTasks, id_trainee);
|
QByteArray arrayAnswer = dataParser->DbAnswer()->listTasksAMMofTrainee(true, &listTasks, id_trainee);
|
||||||
client->sendXmlAnswer(arrayAnswer, PacketType::TYPE_XMLANSWER_QUERY_TASKS_AMM_OF_TRAINEE);
|
//client->sendXmlAnswer(arrayAnswer, PacketType::TYPE_XMLANSWER_QUERY_TASKS_AMM_OF_TRAINEE);
|
||||||
|
client->sendFileBlockByteArray(arrayAnswer, PacketType::TYPE_XMLANSWER_QUERY_TASKS_AMM_OF_TRAINEE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProcessingSystem::sendListTasksFIMofTraineetoClient(ClientHandler *client, int id_trainee)
|
void ProcessingSystem::sendListTasksFIMofTraineetoClient(ClientHandler *client, int id_trainee)
|
||||||
{
|
{
|
||||||
QList<TaskAmmFim> listTasks = providerDBLMS->GetListTasksFIMofTrainee(id_trainee);
|
QList<TaskAmmFim> listTasks = providerDBLMS->GetListTasksFIMofTrainee(id_trainee);
|
||||||
QByteArray arrayAnswer = dataParser->DbAnswer()->listTasksFIMofTrainee(true, &listTasks, id_trainee);
|
QByteArray arrayAnswer = dataParser->DbAnswer()->listTasksFIMofTrainee(true, &listTasks, id_trainee);
|
||||||
client->sendXmlAnswer(arrayAnswer, PacketType::TYPE_XMLANSWER_QUERY_TASKS_FIM_OF_TRAINEE);
|
//client->sendXmlAnswer(arrayAnswer, PacketType::TYPE_XMLANSWER_QUERY_TASKS_FIM_OF_TRAINEE);
|
||||||
|
client->sendFileBlockByteArray(arrayAnswer, PacketType::TYPE_XMLANSWER_QUERY_TASKS_FIM_OF_TRAINEE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProcessingSystem::sendTaskListToUnity(ClientHandler *client)
|
void ProcessingSystem::sendTaskListToUnity(ClientHandler *client)
|
||||||
|
|||||||
@@ -85,7 +85,28 @@ void SendSystem::sendFileBlock(QString path)
|
|||||||
file.close();
|
file.close();
|
||||||
countSend = 0;
|
countSend = 0;
|
||||||
// socket->waitForBytesWritten(10);
|
// socket->waitForBytesWritten(10);
|
||||||
// socket->waitForReadyRead(20);
|
// socket->waitForReadyRead(20);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SendSystem::sendFileBlockByteArray(QByteArray array, PacketType packetType)
|
||||||
|
{
|
||||||
|
qDebug() << "sendFileBlockByteArray thread: " << QThread::currentThreadId();
|
||||||
|
|
||||||
|
QDataStream stream(socket);
|
||||||
|
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
|
||||||
|
|
||||||
|
fileSize = array.size();
|
||||||
|
|
||||||
|
if(fileSize == 0){
|
||||||
|
emit sigSendToLogger(Tools::getTime() + " WARNING! Zero size ");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
stream << packetType; //Отправляем тип блока
|
||||||
|
|
||||||
|
stream << fileSize;
|
||||||
|
|
||||||
|
stream << array;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SendSystem::sendVersion()
|
void SendSystem::sendVersion()
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ public:
|
|||||||
void setClient(Client* client,QTcpSocket *socket);
|
void setClient(Client* client,QTcpSocket *socket);
|
||||||
void sendMessageBlock(QString message);
|
void sendMessageBlock(QString message);
|
||||||
void sendFileBlock(QString path);
|
void sendFileBlock(QString path);
|
||||||
|
void sendFileBlockByteArray(QByteArray array, PacketType packetType);
|
||||||
void sendFileBlockWithRename(QString path,QString newName);
|
void sendFileBlockWithRename(QString path,QString newName);
|
||||||
void sendFolderBlock(QString path);
|
void sendFolderBlock(QString path);
|
||||||
void sendDeleteBlock(QString path);
|
void sendDeleteBlock(QString path);
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ void ClientHandler::initialize(int descriptor,ServerLMSWidget *serverWidget,
|
|||||||
connect(this,&ClientHandler::sigSendXmlAnswer,sendSystem,&SendSystem::sendXmlAnswer,Qt::AutoConnection);
|
connect(this,&ClientHandler::sigSendXmlAnswer,sendSystem,&SendSystem::sendXmlAnswer,Qt::AutoConnection);
|
||||||
connect(this,&ClientHandler::sigInitSender,sendSystem,&SendSystem::initialize,Qt::AutoConnection);
|
connect(this,&ClientHandler::sigInitSender,sendSystem,&SendSystem::initialize,Qt::AutoConnection);
|
||||||
connect(this,&ClientHandler::sigFileBlock,sendSystem,&SendSystem::sendFileBlock,Qt::AutoConnection);
|
connect(this,&ClientHandler::sigFileBlock,sendSystem,&SendSystem::sendFileBlock,Qt::AutoConnection);
|
||||||
|
connect(this,&ClientHandler::sigFileBlockByteArray,sendSystem,&SendSystem::sendFileBlockByteArray,Qt::AutoConnection);
|
||||||
connect(this,&ClientHandler::sigFolderBlock,sendSystem,&SendSystem::sendFolderBlock,Qt::AutoConnection);
|
connect(this,&ClientHandler::sigFolderBlock,sendSystem,&SendSystem::sendFolderBlock,Qt::AutoConnection);
|
||||||
connect(this,&ClientHandler::sigGetIsSendStopped,sendSystem,&SendSystem::getIsSendStopped,Qt::AutoConnection);
|
connect(this,&ClientHandler::sigGetIsSendStopped,sendSystem,&SendSystem::getIsSendStopped,Qt::AutoConnection);
|
||||||
connect(this,&ClientHandler::sigSendDeleteBlock,sendSystem,&SendSystem::sendDeleteBlock,Qt::AutoConnection);
|
connect(this,&ClientHandler::sigSendDeleteBlock,sendSystem,&SendSystem::sendDeleteBlock,Qt::AutoConnection);
|
||||||
@@ -113,6 +114,11 @@ void ClientHandler::sendFileBlock(QString path)
|
|||||||
emit sigFileBlock(path);
|
emit sigFileBlock(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ClientHandler::sendFileBlockByteArray(QByteArray array, PacketType packetType)
|
||||||
|
{
|
||||||
|
emit sigFileBlockByteArray(array, packetType);
|
||||||
|
}
|
||||||
|
|
||||||
bool ClientHandler::getIsSendStopped()
|
bool ClientHandler::getIsSendStopped()
|
||||||
{
|
{
|
||||||
return emit sigGetIsSendStopped();
|
return emit sigGetIsSendStopped();
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ public:
|
|||||||
void sendXmlAnswer(QByteArray array, PacketType packetType = PacketType::TYPE_XMLANSWER);
|
void sendXmlAnswer(QByteArray array, PacketType packetType = PacketType::TYPE_XMLANSWER);
|
||||||
void sendFolderBlock(QString path);
|
void sendFolderBlock(QString path);
|
||||||
void sendFileBlock(QString path);
|
void sendFileBlock(QString path);
|
||||||
|
void sendFileBlockByteArray(QByteArray array, PacketType packetType);
|
||||||
bool getIsSendStopped();
|
bool getIsSendStopped();
|
||||||
void sendDeleteBlock(QString path);
|
void sendDeleteBlock(QString path);
|
||||||
void sendFinish();
|
void sendFinish();
|
||||||
@@ -53,6 +54,7 @@ signals:
|
|||||||
void sigInitSender (DataParser *dataParse,Logger *logger);
|
void sigInitSender (DataParser *dataParse,Logger *logger);
|
||||||
void sigFolderBlock(QString path);
|
void sigFolderBlock(QString path);
|
||||||
void sigFileBlock(QString path);
|
void sigFileBlock(QString path);
|
||||||
|
void sigFileBlockByteArray(QByteArray array, PacketType packetType);
|
||||||
bool sigGetIsSendStopped();
|
bool sigGetIsSendStopped();
|
||||||
void sigSendDeleteBlock(QString path);
|
void sigSendDeleteBlock(QString path);
|
||||||
void sigSendFinish(PacketType packetType);
|
void sigSendFinish(PacketType packetType);
|
||||||
|
|||||||
Reference in New Issue
Block a user