Exemplo n.º 1
0
void CreateProc::_ResizeFiles()
{
    AppSetting *setting = AppSetting::Instance();

    JsonObject *projData = new JsonObject();
    projData->Add("pid",_pid);

    JsonArray *pages = new JsonArray();
    projData->AddObject("pages", pages);

    for (auto fileItor = _filesMapping->begin(); fileItor != _filesMapping->end(); ++fileItor)
    {
        JsonObject *singleFile = new JsonObject();

        string srcFilename = FileSys::GetFilename(fileItor->first);
        string saveFilename = FileSys::GetFilename(fileItor->second);
        string fileExtension = FileSys::GetFileExtension(fileItor->first);

        singleFile->Add("filename", srcFilename);
        singleFile->Add("imagedir", fileItor->first);

        for (auto sizeItor = setting->pic_size->begin(); sizeItor != setting->pic_size->end(); ++sizeItor)
        {
            string optDir = FileSys::FormatDir(setting->file_save_dir + _zipRandName + "/" + sizeItor->first);
            FileSys::CreateDirectory(optDir);

            //  Resize Picture, but need to rename
            saveFilename = Assist::GenerateRandomFilename(saveFilename) + fileExtension;
            OpencvEx::ResizePictureFile(fileItor->second, optDir + saveFilename, sizeItor->second->x, sizeItor->second->y);

            singleFile->Add("image" + sizeItor->first, optDir + saveFilename);
        }

        pages->AddObject(singleFile);
        safe_del(singleFile);
    }

    //  push to server
    _PushJsonToServer(projData->ToString());

    safe_del(pages);
    safe_del(projData);
}
Exemplo n.º 2
0
    bool test()
    {
      JsonObject j;
      j.Add(new JsonString("first_name"), new JsonString("john"));
      j.Add(new JsonString("last_name"), new JsonString("doe"));
      j.Add(new JsonString("age"), new JsonNumber(22));
      j.Add(new JsonString("full_time"), new JsonBool(true));
      j.Add(new JsonString("work_phone"), new JsonString("123-456-7890"));
      j.Add(new JsonString("mobile_phone"), new JsonNull());

      JsonArray* ja1 = new JsonArray();
      ja1->Add(new JsonString("orange"));
      ja1->Add(new JsonString("banana"));
      ja1->Add(new JsonString("apple"));

      SmartPointer<JsonValue> sp1(ja1);
      j.Add(new JsonString("fruits"), sp1);

      JsonObject* j2 = new JsonObject();
      JsonArray* ja2 = new JsonArray();

      ja2->Add(new JsonString("blue"));
      ja2->Add(new JsonString("red"));
      ja2->Add(new JsonString("orange"));

      SmartPointer<JsonValue> sp2(ja2);
      j2->Add(new JsonString("colors"), sp2);

      SmartPointer<JsonValue> sp3(j2);
      j.Add(new JsonString("shirts"), sp3);

      String result = "{\"first_name\":\"john\",\"last_name\":\"doe\","
        "\"age\":22,\"full_time\":true,\"work_phone\":\"123-456-7890\","
        "\"mobile_phone\":null,\"fruits\":[\"orange\",\"banana\",\"apple"
        "\"],\"shirts\":{\"colors\":[\"blue\",\"red\",\"orange\"]}}";
      return (result == *j.ToString());
    }