bool ServerContext::Apply(std::list<std::string>& result,
                            const ::Orthanc::LookupResource& lookup,
                            size_t maxResults)
  {
    result.clear();

    std::vector<std::string> resources, instances;
    GetIndex().FindCandidates(resources, instances, lookup);

    assert(resources.size() == instances.size());

    for (size_t i = 0; i < instances.size(); i++)
    {
      Json::Value dicom;
      ReadJson(dicom, instances[i]);
      
      if (lookup.IsMatch(dicom))
      {
        if (maxResults != 0 &&
            result.size() >= maxResults)
        {
          return false;  // too many results
        }
        else
        {
          result.push_back(resources[i]);
        }
      }
    }

    return true;  // finished
  }
Exemple #2
0
int CRuleManager::MatchRule(CWebPage* web, int Range, string fileName)
{
    string ruleString;
    web->m_pageRule = new CRule;

    switch(Range)
    {
        case 0:/*All Range*/
        {
            break;
        }
        case 1:/*Local File*/
        {
            //read file
            ruleString = GetJsonToStringFromLocal(fileName);

            //turn to rule class
            ReadJson(ruleString, web->m_pageRule);

            //turn rule to string
            ruleString = "";
            WriteJson(web->m_pageRule, ruleString);

            //cout << ruleString << endl;

            //string cmd = string("echo \'") + ruleString + "\' >> "+"./b.txt";
            //system(cmd.c_str());

            break;
        }
        case 2:/*Rule DateBase*/
        {
            break;
        }
        case 3:/*Cloud*/
        {
            break;
        }
    }
    return 0;
}
Exemple #3
0
// Metoda deserializująca JSON z łańcucha znaków
// lub pliku jeśli podano ścieżkę do pliku z rozszerzeniem ".json"
Json Json::deserialize(std::string str)
{
    static const std::string ext = ".json";

    bool isPath = false;
    if (str.size() > ext.size())
        isPath = str.substr(str.size() - ext.size()) == ext;

    if (isPath)
    {
        std::ifstream file(str);
        if (file.good())
            str = std::string(std::istreambuf_iterator<char>(file),
                std::istreambuf_iterator<char>());
        else
            throw std::runtime_error(("Couldn't open file: " + str).c_str());
    }

    PropertyTree tree;
    std::istringstream istr(str);
    ReadJson(tree, istr);
    return ToJsonObject(tree);
}
int main(const int argc, const char** argv) {

    if (argc < 4) {
        printf("Usage: YServer <ip> <port> <setting/file/path>\n");
        return -1;
    }

    const char* ip = argv[1];
    const char* sport = argv[2];
    const std::string& filepath = argv[3];

    int port = 0;
    if (!GetPort(sport, port)) {
        printf("[ERROR] getting port number failed from \"%s\".\n", sport);
        return -1;
    }

    Json::Value root(Json::arrayValue);
    if (!ReadJson(filepath.c_str(), root)) {
        printf("[ERROR] read json failed from \"%s\" file.\n", filepath.c_str());
        return -1;
    }

    try {
        boost::asio::io_service io_service;
        // const Tcp::endpoint endpoint(Tcp::v4(), port);
        const Tcp::endpoint endpoint(boost::asio::ip::address::from_string(ip), port);
        LikeServer server(root, io_service, endpoint);
        printf("[INFO] run server.\n", filepath.c_str());
        io_service.run();
    } catch (std::exception& e) {
        printf("[EXCEPTION] %s\n", e.what());
    }

    return 0;
}
Waifu2x::eWaifu2xError cNet::GetInfo(const boost::filesystem::path & info_path, stInfo &info)
{
	rapidjson::Document d;
	std::vector<char> jsonBuf;

	try
	{
		Waifu2x::eWaifu2xError ret;

		ret = ReadJson(info_path, d, jsonBuf);
		if (ret != Waifu2x::eWaifu2xError_OK)
			return ret;

		const auto name = d["name"].GetString();
		const auto arch_name = d["arch_name"].GetString();
		const bool has_noise_scale = d.HasMember("has_noise_scale") && d["has_noise_scale"].GetBool() ? true : false;
		const int channels = d["channels"].GetInt();

		info.name = name;
		info.arch_name = arch_name;
		info.has_noise_scale = has_noise_scale;
		info.channels = channels;

		if (d.HasMember("offset"))
		{
			const int offset = d["offset"].GetInt();

			info.noise.offset = offset;
			info.scale.offset = offset;
			info.noise_scale.offset = offset;
		}

		if (d.HasMember("scale_factor"))
		{
			const int scale_factor = d["scale_factor"].GetInt();

			info.noise.scale_factor = scale_factor;
			info.scale.scale_factor = scale_factor;
			info.noise_scale.scale_factor = scale_factor;
		}

		if (d.HasMember("offset_noise"))
		{
			const int offset = d["offset_noise"].GetInt();
			info.noise.offset = offset;
		}

		if (d.HasMember("scale_factor_noise"))
		{
			const int scale_factor = d["scale_factor_noise"].GetInt();
			info.noise.scale_factor = scale_factor;
		}

		if (d.HasMember("offset_scale"))
		{
			const int offset = d["offset_scale"].GetInt();
			info.scale.offset = offset;
		}

		if (d.HasMember("scale_factor_scale"))
		{
			const int scale_factor = d["scale_factor_scale"].GetInt();
			info.scale.scale_factor = scale_factor;
		}

		if (d.HasMember("offset_noise_scale"))
		{
			const int offset = d["offset_noise_scale"].GetInt();
			info.noise_scale.offset = offset;
		}

		if (d.HasMember("scale_factor_noise_scale"))
		{
			const int scale_factor = d["scale_factor_noise_scale"].GetInt();
			info.noise_scale.scale_factor = scale_factor;
		}
	}
	catch (...)
	{
		return Waifu2x::eWaifu2xError_FailedParseModelFile;
	}

	return Waifu2x::eWaifu2xError_OK;
}