void CopySenderServer::PhysicalServerDoneNotify(int BuildID){
    QString jsonMessage = startJSONMessage();
    appendJSONValue(jsonMessage, "handler","PhysicalServerDone", true);
    appendJSONValue(jsonMessage, "BuildID", QString::number(BuildID),false);
    endJSONMessage(jsonMessage);

    sendJSONMessage(socket, jsonMessage);
}
void ProtoSlaveCurrentBuilds::RecheckBuilds(QTcpSocket *slaveSocket){
    //this is just to acknowledge that the client can recheck all builds

    QString jsonMessage = startJSONMessage();
    appendJSONValue(jsonMessage, "handler", "ProtoSlaveCurrentBuilds", true);
    appendJSONValue(jsonMessage, "subHandler", "Rechecker", false);
    endJSONMessage(jsonMessage);

    slaveSocket->write(jsonMessage.toUtf8().data());
    slaveSocket->flush();
}
void ProtoSizeCheckBuilds::invokeSizeCheckAll(QTcpSocket *slaveSocket){
    /*The following is to create a loop to continually update
      the build until the build is fully synched
      */
    QString jsonMessage = startJSONMessage();
    appendJSONValue(jsonMessage, "handler", "ProtoSizeCheckBuilds", true);
    appendJSONValue(jsonMessage, "subHandler", "SizeCheckAllBuilds", false);
    endJSONMessage(jsonMessage);

    sendJSONMessage(slaveSocket, jsonMessage);
}
void ProtoSlaveCurrentBuilds::SizeCheckAllBuilds(QTcpSocket *slaveSocket){
    /*The following is to create a loop to continually update
      the build until the information is updated
      **Same is done in the bottom of protosizecheckallbuilds
      */
    QString jsonMessage = startJSONMessage();
    appendJSONValue(jsonMessage, "handler", "ProtoSizeCheckBuilds", true);
    appendJSONValue(jsonMessage, "subHandler", "SizeCheckAllBuilds", false);
    endJSONMessage(jsonMessage);

    sendJSONMessage(slaveSocket, jsonMessage);
}
void ProtoSendStructure::BuildStructureRequest(QVariantMap jsonObject, Management *management, QTcpSocket *slaveSocket){
    //get the structure for the build and send it across the network
    QString StringBuildID = jsonObject.value("buildID").toString();

    bool ok = false;

    int buildID = StringBuildID.toInt(&ok);

    if(!ok)
        return;

    QString buildDIR = management->getBuildByID(buildID)->getBuildDirectory();


    //go and get the structure
    QStringList structure = DirectoryHandler::getDirectoryStructure(buildDIR);

    //place the structure of directories inside a json format

    QString jsonMessage = startJSONMessage();
    appendJSONValue(jsonMessage, "handler", "ProtoSendStructure", true);
    appendJSONValue(jsonMessage, "subHandler","DuplicateStructure", true);
    appendJSONValue(jsonMessage, "buildID", StringBuildID, true);

    //start a new json value and append the list to it
    QString jsonStructureValue = "\"structure\" : {";
    for(int i = 0; i < structure.size(); i++){
        //append all the values as json
        QString directoryNumber = QString::number(i);
        QString aPath;

        //there is no comma at end of json values
        if(i == structure.size()-1)
            aPath = "\"" + directoryNumber + "\" : \"" + structure.at(i) + "\"";
        else
            aPath =  "\"" + directoryNumber + "\" : \"" + structure.at(i) + "\",";

        jsonStructureValue.append(aPath);
    }
    //end the list of structures(directory paths)
    jsonStructureValue.append("}");

    //append the list of all the structures
    jsonMessage.append(jsonStructureValue);

    endJSONMessage(jsonMessage);

    sendJSONMessage(slaveSocket, jsonMessage);
}
示例#6
0
 static StringBuffer &appendJSONExceptionItem(StringBuffer &s, int code, const char *msg, const char *objname="Exceptions", const char *arrayName = "Exception")
 {
     if (objname && *objname)
         appendJSONName(s, objname).append('{');
     if (arrayName && *arrayName)
         appendJSONName(s, arrayName).append('[');
     delimitJSON(s);
     s.append('{');
     appendJSONValue(s, "Code", code);
     appendJSONValue(s, "Message", msg);
     s.append('}');
     if (arrayName && *arrayName)
         s.append(']');
     if (objname && *objname)
         s.append('}');
     return s;
 }
示例#7
0
    static void buildJsonAppendValue(IXmlType* type, StringBuffer& out, const char* tag, const char *value, unsigned flags)
    {
        JSONField_Category ct = xsdTypeToJSONFieldCategory(type->queryName());

        if (ct==JSONField_Present && (!value || !*value))
            return;

        if (tag && *tag)
            out.appendf("\"%s\": ", tag);
        StringBuffer sample;
        if ((!value || !*value) && (flags & REQSF_SAMPLE_DATA))
        {
            type->getSampleValue(sample, NULL);
            value = sample.str();
        }

        if (value)
        {
            switch (ct)
            {
            case JSONField_String:
                appendJSONValue(out, NULL, value);
                break;
            case JSONField_Integer:
                appendJSONNumericString(out, value, false);
                break;
            case JSONField_Real:
                appendJSONNumericString(out, value, true);
                break;
            case JSONField_Boolean:
                if (strieq(value, "default"))
                    out.append("null");
                else
                    appendJSONValue(out, NULL, strToBool(value));
                break;
            case JSONField_Present:
                appendJSONValue(out, NULL, true);
                break;
            }
        }
        else
            out.append("null");
    }
void CopySenderServer::SendDifferences(){
    //loop through all the directories in order to state which is different
    //on the client
    for(int i = 0; i < differentBuildIDs->size(); i++){
        //if it is the first time it is connected write to the client which builds
        //should generate the MD5classes for
        QString jsonMessage = startJSONMessage();
        appendJSONValue(jsonMessage, "handler", "BuildDifferent", true);
        appendJSONValue(jsonMessage, "differentBuildID", differentBuildIDs->at(i),false);
        endJSONMessage(jsonMessage);

        sendJSONMessage(socket, jsonMessage);
    }

    QString jsonMessage = startJSONMessage();
    appendJSONValue(jsonMessage, "handler", "EndAllDifferences", false);
    endJSONMessage(jsonMessage);

    sendJSONMessage(socket, jsonMessage);
}
void CopySenderServer::requestHandler(QString data){

    JSON *instance = &JSON::instance();

    //go and parse the json to an object concurrently...
    QFuture <QVariantMap>future = QtConcurrent::run(instance, &JSON::parse, data);

    const QVariantMap jsonObject = future.result();//finally retrieve the jsonObject after it has been parsed
    QVariant handler = jsonObject.value("handler");

    if(!handler.toString().compare("QVariant(, )")){
        qDebug()<< "invalid JSON String::"<<data;
    }

    if(firstTalk){
        if(!handler.toString().compare("HelloCopySender")){
            //check whether the machine is the right machine that should connect to it...
            if(jsonObject.value("machineID").toString().compare(QString::number(machineId))){
               socket->disconnectFromHost();
               return;
            }else{
                //if it is the right machine continue
                firstTalk = false;
                //stop the server since you don't want to allow any other connections
                stopServer();
            }
        }else{
            socket->disconnectFromHost();
            return;
        }


        QString jsonMessage = startJSONMessage();
        appendJSONValue(jsonMessage, "handler", "HelloCopyReceiver", false);
        endJSONMessage(jsonMessage);


        sendJSONMessage(socket, jsonMessage);
        return;
    }

    if(!handler.toString().compare("SendDifferences"))
        SendDifferences();
    else

    if(!handler.toString().compare("BuildFileSumMD5"))
        BuildFileSumMD5(jsonObject);
    else

    if(!handler.toString().compare("NotifyCopySuccess"))
        NotifyCopySuccess(jsonObject);

}
void ProtoSlaveCurrentBuilds::Rechecker(Management *management, QTcpSocket *masterSocket){

    for(int i = 0; i < management->getBuildCount(); i++){
        Build *build = management->getBuildAt(i);

        if(build == 0){
            return;
        }

        QString jsonMessage = startJSONMessage();
        appendJSONValue(jsonMessage, "handler", "ProtoSlaveCurrentBuilds", true);
        appendJSONValue(jsonMessage, "subHandler", "Rechecker", true);
        appendJSONValue(jsonMessage, "BuildID", QString::number(build->getBuildID()), true);
        appendJSONValue(jsonMessage, "buildName", build->getBuildName(), false);
        endJSONMessage(jsonMessage);

        masterSocket->write(jsonMessage.toUtf8().data());
        masterSocket->flush();
    }

    //notify that it is done...
    QString jsonMessage = startJSONMessage();
    appendJSONValue(jsonMessage, "handler", "ProtoSlaveCurrentBuilds", true);
    appendJSONValue(jsonMessage, "subHandler", "RecheckDone", false);
    endJSONMessage(jsonMessage);

    masterSocket->write(jsonMessage.toUtf8().data());
    masterSocket->flush();
}
void ProtoDeleteBuild::DeleteBuild(QTcpSocket *slaveSocket, QVariantMap jsonObject, Management *management){
    bool ok = false;

    //get the ID to be deleted
    int buildID = jsonObject.value("buildID").toInt(&ok);

    if(!ok)
        return;

    management->deleteBuild(buildID);


    //NOTIFY The sucessful delete
    QString jsonMessage = startJSONMessage();
    appendJSONValue(jsonMessage, "handler", "ProtoDeleteBuild", true);
    appendJSONValue(jsonMessage, "subHandler", "DeleteSuccess", true);
    appendJSONValue(jsonMessage, "buildID", QString::number(buildID), false);
    endJSONMessage(jsonMessage);

    slaveSocket->write(jsonMessage.toUtf8().data());
    slaveSocket->flush();
}