コード例 #1
0
ファイル: IoWebhook.cpp プロジェクト: Orabig/machinery
    bool IoWebhook::save(Image & image, JSON & data)
    {
        // ---------------------------------------
        // Attach additional fields to JSON object
        
        JSON dataCopy;
        JSON::AllocatorType& allocator = dataCopy.GetAllocator();
        dataCopy.CopyFrom(data, allocator);
        
        JSONValue instanceName;
        instanceName.SetString(getInstanceName().c_str(), allocator);
        dataCopy.AddMember("instanceName", instanceName, allocator);
        
        // -----------------------------
        // Convert JSON object to string
        
        rapidjson::StringBuffer buffer;
        rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
        dataCopy.Accept(writer);
        
        // -------------------
        // Send a post to URL

        BINFO << "IoWebhook: post to webhook " + (std::string) getUrl();
        RestClient::response r = RestClient::post(getUrl(), "application/json", buffer.GetString());
        
        if(r.code == 200)
        {
            return true;
        }
        
        return false;
    }
コード例 #2
0
ファイル: JSONValue.cpp プロジェクト: Boshin/Urho3D
void JSONValue::AddVariant(const Variant& value)
{
    // Create child object for variant
    JSONValue child = CreateChild(JSON_OBJECT);
    // Set type
    child.SetString("type", value.GetTypeName());
    // Set value
    child.SetVariantValue("value", value);
}
コード例 #3
0
bool ModelImporter::SaveSettingsInternal()
{
    if (!AssetImporter::SaveSettingsInternal())
        return false;

    JSONValue save = jsonRoot_.CreateChild("ModelImporter");

    save.SetFloat("scale", scale_);
    save.SetBool("importAnimations", importAnimations_);

    JSONValue animInfo = save.CreateChild("animInfo", JSON_ARRAY);

    for (unsigned i = 0; i < animationInfo_.Size(); i++)
    {
        const SharedPtr<AnimationImportInfo>& info = animationInfo_[i];
        JSONValue jinfo = animInfo.CreateChild();
        jinfo.SetString("name", info->GetName());
        jinfo.SetFloat("startTime", info->GetStartTime());
        jinfo.SetFloat("endTime", info->GetEndTime());
    }

    return true;
}
コード例 #4
0
    bool IoDisk::save(Image & image, JSON & data)
    {
        // ----------------------------------------
        // The naming convention that will be used
        // for the image.
        
        std::string pathToImage = getFileFormat();

        // ------------------------------------------
        // Stringify data object: build image path
        // with data information.
        
        static const std::string kTypeNames[] = { "Null", "False", "True", "Object", "Array", "String", "Number" };
        for (JSONValue::ConstMemberIterator itr = data.MemberBegin(); itr != data.MemberEnd(); ++itr)
        {
            std::string name = itr->name.GetString();
            std::string type = kTypeNames[itr->value.GetType()];
            
            if(type == "String")
            {
                std::string value = itr->value.GetString();
                kerberos::helper::replace(pathToImage, name, value);
            }
            else if(type == "Number")
            {
                std::string value = kerberos::helper::to_string(itr->value.GetInt());
                kerberos::helper::replace(pathToImage, name, value);
            }
            else if(type == "Array")
            {
                std::string arrayString = "";
                for (JSONValue::ConstValueIterator itr2 = itr->value.Begin(); itr2 != itr->value.End(); ++itr2)
                {
                    type = kTypeNames[itr2->GetType()];
                    
                    if(type == "String")
                    {
                        arrayString += itr2->GetString();
                    }
                    else if(type == "Number")
                    {
                       arrayString += kerberos::helper::to_string(itr2->GetInt());
                    }
                    
                    arrayString += "-";
                }
                kerberos::helper::replace(pathToImage, name, arrayString.substr(0, arrayString.size()-1));
            }
        }
        
        /// ---------------------
        // Replace variables

        pathToImage = buildPath(pathToImage);

        // -------------------------------------------------------
        // Add path to JSON object, so other IO devices can use it
        
        JSONValue path;
        JSON::AllocatorType& allocator = data.GetAllocator();
        path.SetString(pathToImage.c_str(), allocator);
        data.AddMember("pathToImage", path, allocator);
        
        // ------------------
        // Draw date on image
        
        drawDateOnImage(image, data["timestamp"].GetString());
        
        // -------------------------
        // Save original version

        BINFO << "IoDisk: saving image " + pathToImage;
        return m_fileManager.save(image, pathToImage);
    }