mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-04 00:45:46 +08:00
Ref T118, formatting database writer and utility
This commit is contained in:
@@ -59,7 +59,7 @@ namespace BlackCore
|
|||||||
|
|
||||||
if (this->isReplyOverdue())
|
if (this->isReplyOverdue())
|
||||||
{
|
{
|
||||||
bool killed = this->killPendingReply();
|
const bool killed = this->killPendingReply();
|
||||||
if (killed)
|
if (killed)
|
||||||
{
|
{
|
||||||
const CStatusMessage msg(CStatusMessage::SeverityWarning, "Aborted outdated pending reply");
|
const CStatusMessage msg(CStatusMessage::SeverityWarning, "Aborted outdated pending reply");
|
||||||
@@ -88,7 +88,7 @@ namespace BlackCore
|
|||||||
QNetworkRequest request(url);
|
QNetworkRequest request(url);
|
||||||
CNetworkUtils::ignoreSslVerification(request);
|
CNetworkUtils::ignoreSslVerification(request);
|
||||||
const int logId = m_writeLog.addPendingUrl(url);
|
const int logId = m_writeLog.addPendingUrl(url);
|
||||||
m_pendingReply = sApp->postToNetwork(request, logId, multiPart, { this, &CDatabaseWriter::ps_postModelsResponse});
|
m_pendingReply = sApp->postToNetwork(request, logId, multiPart, { this, &CDatabaseWriter::postedModelsResponse});
|
||||||
m_replyPendingSince = QDateTime::currentMSecsSinceEpoch();
|
m_replyPendingSince = QDateTime::currentMSecsSinceEpoch();
|
||||||
return msgs;
|
return msgs;
|
||||||
}
|
}
|
||||||
@@ -105,7 +105,7 @@ namespace BlackCore
|
|||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CDatabaseWriter::ps_postModelsResponse(QNetworkReply *nwReplyPtr)
|
void CDatabaseWriter::postedModelsResponse(QNetworkReply *nwReplyPtr)
|
||||||
{
|
{
|
||||||
static const CLogCategoryList cats(CLogCategoryList(this).join({ CLogCategory::swiftDbWebservice()}));
|
static const CLogCategoryList cats(CLogCategoryList(this).join({ CLogCategory::swiftDbWebservice()}));
|
||||||
QScopedPointer<QNetworkReply, QScopedPointerDeleteLater> nwReply(nwReplyPtr);
|
QScopedPointer<QNetworkReply, QScopedPointerDeleteLater> nwReply(nwReplyPtr);
|
||||||
@@ -125,7 +125,7 @@ namespace BlackCore
|
|||||||
if (dataFileData.isEmpty())
|
if (dataFileData.isEmpty())
|
||||||
{
|
{
|
||||||
const CStatusMessageList msgs({CStatusMessage(cats, CStatusMessage::SeverityError, "No response data from " + urlString)});
|
const CStatusMessageList msgs({CStatusMessage(cats, CStatusMessage::SeverityError, "No response data from " + urlString)});
|
||||||
emit publishedModels(CAircraftModelList(), CAircraftModelList(), msgs, false, false);
|
emit this->publishedModels(CAircraftModelList(), CAircraftModelList(), msgs, false, false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,14 +134,14 @@ namespace BlackCore
|
|||||||
CStatusMessageList msgs;
|
CStatusMessageList msgs;
|
||||||
bool directWrite;
|
bool directWrite;
|
||||||
const bool sendingSuccessful = CDatastoreUtility::parseSwiftPublishResponse(dataFileData, modelsPublished, modelsSkipped, msgs, directWrite);
|
const bool sendingSuccessful = CDatastoreUtility::parseSwiftPublishResponse(dataFileData, modelsPublished, modelsSkipped, msgs, directWrite);
|
||||||
emit publishedModels(modelsPublished, modelsSkipped, msgs, sendingSuccessful, directWrite);
|
emit this->publishedModels(modelsPublished, modelsSkipped, msgs, sendingSuccessful, directWrite);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const QString error = nwReply->errorString();
|
const QString error = nwReply->errorString();
|
||||||
nwReply->close(); // close asap
|
nwReply->close(); // close asap
|
||||||
const CStatusMessageList msgs( {CStatusMessage(cats, CStatusMessage::SeverityError, "HTTP error: " + error)});
|
const CStatusMessageList msgs( {CStatusMessage(cats, CStatusMessage::SeverityError, "HTTP error: " + error)});
|
||||||
emit publishedModels(CAircraftModelList(), CAircraftModelList(), msgs, false, false);
|
emit this->publishedModels(CAircraftModelList(), CAircraftModelList(), msgs, false, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -62,10 +62,6 @@ namespace BlackCore
|
|||||||
const BlackMisc::CStatusMessageList &messages,
|
const BlackMisc::CStatusMessageList &messages,
|
||||||
bool sendingSuccessful, bool directWrite);
|
bool sendingSuccessful, bool directWrite);
|
||||||
|
|
||||||
private slots:
|
|
||||||
//! Post response
|
|
||||||
void ps_postModelsResponse(QNetworkReply *nwReplyPtr);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BlackMisc::Network::CUrlLogList m_writeLog;
|
BlackMisc::Network::CUrlLogList m_writeLog;
|
||||||
BlackMisc::Network::CUrl m_modelPublishUrl;
|
BlackMisc::Network::CUrl m_modelPublishUrl;
|
||||||
@@ -73,6 +69,9 @@ namespace BlackCore
|
|||||||
qint64 m_replyPendingSince = -1;
|
qint64 m_replyPendingSince = -1;
|
||||||
bool m_shutdown = false;
|
bool m_shutdown = false;
|
||||||
|
|
||||||
|
//! Post response
|
||||||
|
void postedModelsResponse(QNetworkReply *nwReplyPtr);
|
||||||
|
|
||||||
//! Kill the pending reply
|
//! Kill the pending reply
|
||||||
bool killPendingReply();
|
bool killPendingReply();
|
||||||
|
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ namespace BlackMisc
|
|||||||
|
|
||||||
bool CDatastoreUtility::parseSwiftPublishResponse(const QString &jsonResponse, CAircraftModelList &publishedModels, CAircraftModelList &skippedModels, CStatusMessageList &messages, bool &directWrite)
|
bool CDatastoreUtility::parseSwiftPublishResponse(const QString &jsonResponse, CAircraftModelList &publishedModels, CAircraftModelList &skippedModels, CStatusMessageList &messages, bool &directWrite)
|
||||||
{
|
{
|
||||||
static const CLogCategoryList cats({ CLogCategory::swiftDbWebservice()});
|
static const CLogCategoryList cats({CLogCategory::swiftDbWebservice()});
|
||||||
directWrite = false;
|
directWrite = false;
|
||||||
|
|
||||||
if (jsonResponse.isEmpty())
|
if (jsonResponse.isEmpty())
|
||||||
@@ -92,7 +92,7 @@ namespace BlackMisc
|
|||||||
// array of messages only
|
// array of messages only
|
||||||
if (jsonDoc.isArray())
|
if (jsonDoc.isArray())
|
||||||
{
|
{
|
||||||
CStatusMessageList msgs(CStatusMessageList::fromDatabaseJson(jsonDoc.array()));
|
const CStatusMessageList msgs(CStatusMessageList::fromDatabaseJson(jsonDoc.array()));
|
||||||
messages.push_back(msgs);
|
messages.push_back(msgs);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -110,8 +110,8 @@ namespace BlackMisc
|
|||||||
bool hasData = false;
|
bool hasData = false;
|
||||||
if (json.contains("msgs"))
|
if (json.contains("msgs"))
|
||||||
{
|
{
|
||||||
QJsonValue msgJson(json.take("msgs"));
|
const QJsonValue msgJson(json.take("msgs"));
|
||||||
CStatusMessageList msgs(CStatusMessageList::fromDatabaseJson(msgJson.toArray()));
|
const CStatusMessageList msgs(CStatusMessageList::fromDatabaseJson(msgJson.toArray()));
|
||||||
if (!msgs.isEmpty())
|
if (!msgs.isEmpty())
|
||||||
{
|
{
|
||||||
messages.push_back(msgs);
|
messages.push_back(msgs);
|
||||||
@@ -122,14 +122,14 @@ namespace BlackMisc
|
|||||||
// direct write means models written, otherwise CRs
|
// direct write means models written, otherwise CRs
|
||||||
if (json.contains("directWrite"))
|
if (json.contains("directWrite"))
|
||||||
{
|
{
|
||||||
QJsonValue dw(json.take("directWrite"));
|
const QJsonValue dw(json.take("directWrite"));
|
||||||
directWrite = dw.toBool(false);
|
directWrite = dw.toBool(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (json.contains("publishedModels"))
|
if (json.contains("publishedModels"))
|
||||||
{
|
{
|
||||||
QJsonValue publishedJson(json.take("publishedModels"));
|
const QJsonValue publishedJson(json.take("publishedModels"));
|
||||||
CAircraftModelList published = CAircraftModelList::fromDatabaseJson(publishedJson.toArray(), "");
|
const CAircraftModelList published = CAircraftModelList::fromDatabaseJson(publishedJson.toArray(), "");
|
||||||
if (!published.isEmpty())
|
if (!published.isEmpty())
|
||||||
{
|
{
|
||||||
publishedModels.push_back(published);
|
publishedModels.push_back(published);
|
||||||
@@ -139,8 +139,8 @@ namespace BlackMisc
|
|||||||
|
|
||||||
if (json.contains("skippedModels"))
|
if (json.contains("skippedModels"))
|
||||||
{
|
{
|
||||||
QJsonValue skippedJson(json.take("skippedModels"));
|
const QJsonValue skippedJson(json.take("skippedModels"));
|
||||||
CAircraftModelList skipped = CAircraftModelList::fromDatabaseJson(skippedJson.toArray(), "");
|
const CAircraftModelList skipped = CAircraftModelList::fromDatabaseJson(skippedJson.toArray(), "");
|
||||||
if (!skipped.isEmpty())
|
if (!skipped.isEmpty())
|
||||||
{
|
{
|
||||||
skippedModels.push_back(skipped);
|
skippedModels.push_back(skipped);
|
||||||
|
|||||||
@@ -20,8 +20,8 @@
|
|||||||
namespace BlackMisc
|
namespace BlackMisc
|
||||||
{
|
{
|
||||||
class CStatusMessageList;
|
class CStatusMessageList;
|
||||||
namespace Simulation { class CAircraftModelList; }
|
|
||||||
|
|
||||||
|
namespace Simulation { class CAircraftModelList; }
|
||||||
namespace Db
|
namespace Db
|
||||||
{
|
{
|
||||||
/*!
|
/*!
|
||||||
|
|||||||
Reference in New Issue
Block a user