Exemplo n.º 1
0
bool RemoveFile(const OJString &filename)
{
    if (IsFileExist(filename))
    {
        fs::path            fullpath(filename);
        sys::error_code     err;

        bool res = fs::remove(fullpath, err);

        if (!(sys::errc::success == err))
        {
            ILogger *logger = LoggerFactory::getLogger(LoggerId::AppInitLoggerId);
            OJString msg(GetOJString("[filetool] - IMUST::RemoveFile - remove failed: "));
            msg += filename;
            msg += GetOJString(" - ");
            msg += String2OJString(err.message());
            logger->logError(msg);
            return false;
        } 

        return res;
    }

    return true;
}
Exemplo n.º 2
0
bool MakeDir(const OJString &path)
{
    if (!IsDirExist(path))
    {
        fs::path            fullpath(path);
        sys::error_code     err;

        bool res = fs::create_directory(fullpath, err);

        if (!(sys::errc::success == err))
        {
            ILogger *logger = LoggerFactory::getLogger(LoggerId::AppInitLoggerId);
            OJString msg(GetOJString("[filetool] - IMUST::MakeDir - make dir failed: "));
            msg += path;
            msg += GetOJString(" - ");
            msg += String2OJString(err.message());
            logger->logError(msg);
            return false;
        } 

        return res;
    }

    return true;
}
Exemplo n.º 3
0
namespace MySql
{
    OJString    Ip(GetOJString("127.0.0.1"));
    OJInt32_t   Port                =   3306;
    OJString    User(GetOJString("root"));
    OJString    Password(GetOJString(""));
    OJString    DBName(GetOJString("acmicpc"));
}
Exemplo n.º 4
0
bool WindowsProcessInOut::createOutputFile()
{
    SAFE_CLOSE_HANDLE_AND_RESET(outputFileHandle_);

    if (outputFileName_.empty())//如果文件名为空,表示不需要此句柄
        return true;

    SECURITY_ATTRIBUTES saAttr = {0};
    saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
    saAttr.bInheritHandle = TRUE; 
    saAttr.lpSecurityDescriptor = NULL;

    outputFileHandle_ = CreateFileW(outputFileName_.c_str(),
                                GENERIC_WRITE, 
                                FILE_SHARE_READ,
                                &saAttr,                   	
                                CREATE_ALWAYS,
                                FILE_ATTRIBUTE_NORMAL,
                                NULL);

	if (INVALID_HANDLE_VALUE == outputFileHandle_)
	{
        ILogger *logger = LoggerFactory::getLogger(LoggerId::AppInitLoggerId);
        OJString msg(GetOJString("[process] - createOutputFile - can't create output file: "));
        msg += outputFileName_;
        logger->logError(msg);
        outputFileHandle_ = NULL;
	}

    return outputFileHandle_ != NULL;
}
Exemplo n.º 5
0
void JudgeDBRunThread::operator()()
{
    IMUST::ILogger *logger = IMUST::LoggerFactory::getLogger(IMUST::LoggerId::AppInitLoggerId);
    logger->logTrace(GetOJString("[DBThread] thread start..."));

    while(!g_sigExit)
    {
        if(!dbm_->run())
        {
            logger->logError(GetOJString("[DBThread] db manager was dead!"));
            break;
        }
        OJSleep(100);
    }

    logger->logTrace(GetOJString("[DBThread] thread end."));
}
Exemplo n.º 6
0
bool InitAppConfig()
{
#define READ_APP_CONFIG(fun, tag, value)     \
    if(!root->fun(OJStr(tag), value))        \
    {   \
        logger->logError(OJStr("[config] - IMUST::AppConfig::InitAppConfig: read tag faild! ")##OJStr(tag));   \
        return false; \
    }

    ILogger *logger = LoggerFactory::getLogger(LoggerId::AppInitLoggerId);
    logger->logTrace(GetOJString("[config] - IMUST::AppConfig::InitAppConfig"));

    XmlPtr root = XmlFactory::getXml(GetOJString("RapidXml"));
    if(!root->load(OJStr("config.xml")))
    {
        logger->logError(OJStr("[config] - load config file faild! "));
        return false;
    }

    root = root->read(OJStr("AppConfig"));
    if(!root)
    {
        logger->logError(OJStr("[config] - read tag 'AppConfig' faild! "));
        return false;
    }

    READ_APP_CONFIG(readInt32, "CpuInfo/NumberOfCore", CpuInfo::NumberOfCore);

    READ_APP_CONFIG(readString, "MySql/Ip", MySql::Ip);
    READ_APP_CONFIG(readInt32,  "MySql/Port", MySql::Port);
    READ_APP_CONFIG(readString, "MySql/User", MySql::User);
    READ_APP_CONFIG(readString, "MySql/Password", MySql::Password);
    READ_APP_CONFIG(readString, "MySql/DBName", MySql::DBName);

    READ_APP_CONFIG(readBool, "Compiler/HasMsC", Compiler::HasMsC);
    READ_APP_CONFIG(readBool, "Compiler/HasMsCxx", Compiler::HasMsCxx);
    READ_APP_CONFIG(readBool, "Compiler/HasGcc", Compiler::HasGcc);
    READ_APP_CONFIG(readBool, "Compiler/HasGxx", Compiler::HasGxx);
    READ_APP_CONFIG(readBool, "Compiler/HasPascal", Compiler::HasPascal);
    READ_APP_CONFIG(readBool, "Compiler/HasJava", Compiler::HasJava);
	READ_APP_CONFIG(readBool, "Compiler/HasCs", Compiler::HasCs);
    READ_APP_CONFIG(readBool, "Compiler/HasPython", Compiler::HasPython);

    READ_APP_CONFIG(readInt32, "JudgeCode/Pending", JudgeCode::Pending);
    READ_APP_CONFIG(readInt32, "JudgeCode/Rejudge", JudgeCode::Rejudge);
    READ_APP_CONFIG(readInt32, "JudgeCode/Compiling", JudgeCode::Compiling);
    READ_APP_CONFIG(readInt32, "JudgeCode/Accept", JudgeCode::Accept);
    READ_APP_CONFIG(readInt32, "JudgeCode/PresentError", JudgeCode::PresentError);
    READ_APP_CONFIG(readInt32, "JudgeCode/WrongAnswer", JudgeCode::WrongAnswer);
    READ_APP_CONFIG(readInt32, "JudgeCode/TimeLimitExceed", JudgeCode::TimeLimitExceed);
    READ_APP_CONFIG(readInt32, "JudgeCode/MemoryLimitExceed", JudgeCode::MemoryLimitExceed);
    READ_APP_CONFIG(readInt32, "JudgeCode/OutputLimited", JudgeCode::OutputLimited);
    READ_APP_CONFIG(readInt32, "JudgeCode/RuntimeError", JudgeCode::RuntimeError);
    READ_APP_CONFIG(readInt32, "JudgeCode/CompileError", JudgeCode::CompileError);
    READ_APP_CONFIG(readInt32, "JudgeCode/CompileTimeError", JudgeCode::CompileTimeError);
    READ_APP_CONFIG(readInt32, "JudgeCode/CompileOK", JudgeCode::CompileOK);
    READ_APP_CONFIG(readInt32, "JudgeCode/SystemError", JudgeCode::SystemError);
    READ_APP_CONFIG(readInt32, "JudgeCode/UnknownError", JudgeCode::UnknownError);

    READ_APP_CONFIG(readString, "Path/TestDataPath", Path::TestDataPath);

    READ_APP_CONFIG(readBool, "WindowsUser/Enable", WindowsUser::Enable);
    READ_APP_CONFIG(readString, "WindowsUser/Name", WindowsUser::Name);
    READ_APP_CONFIG(readString, "WindowsUser/Password", WindowsUser::Password);
   
#undef READ_APP_CONFIG

    return true;
}
Exemplo n.º 7
0
namespace Path
{
    OJString    TestDataPath(GetOJString("D:\\testdata"));
}