예제 #1
0
std::shared_ptr<ShoeLastTemplate> ShoeLastTemplateDao::getShoeLastTemplate(std::string templateOId)
{
    if(templateOId == "")
    {
        LoggerManager::instance()->logInfo("get Shoe Last Template failed, it's a null oid.");
        return nullptr;
    }

    mongo::BSONObjBuilder b;
    try
    {
        mongo::OID oid1(templateOId);
        b.append(mongo::StringData(DBConstant::ShoeLastTemplateOIdField), oid1);
    }
    catch(...)
    {
        LoggerManager::instance()->logInfo("exception occurs because of invalid mongo oid.");
        return nullptr;
    }
    try
    {
        const mongo::Query query = mongo::Query(b.obj());
        mongo::BSONObj obj = DatabaseUtil::instance()->findOne(DatabaseUtil::instance()->getDatabase(), DBConstant::ShoeLastTemplateCollection, query);
        std::vector<mongo::BSONElement> eles;
        obj.elems(eles);
        return convertBSONElementToTemplate(eles);
    }
    catch(...)
    {
        LoggerManager::instance()->logInfo("exception occurs in get Shoe Last Template by oid.");
    }

    return nullptr;
}
예제 #2
0
bool ShoeLastTemplateDao::updateShoeLastBottom(std::string templateOId, std::string newShoeLastBottomFileOId, bool removeOldShoeLastBottom)
{
    if(templateOId == "" || newShoeLastBottomFileOId == "")
    {
        LoggerManager::instance()->logInfo("update Shoe Last Bottom failed, it's a null oid.");
        return false;
    }

    mongo::BSONObjBuilder queryBuilder;
    try
    {
        mongo::OID oid1(templateOId);
        queryBuilder.append(mongo::StringData(DBConstant::ShoeLastTemplateOIdField), oid1);

    }
    catch(...)
    {
        LoggerManager::instance()->logInfo("exception occurs because of invalid mongo oid.");
        return false;
    }

    std::shared_ptr<ShoeLastTemplate> tmpBeforeUpdating = getShoeLastTemplate(templateOId);
    mongo::BSONObjBuilder updateBuilder, setBuilder;
    setBuilder.append(mongo::StringData(DBConstant::ShoeLastTemplateLastBottomField), newShoeLastBottomFileOId);
    updateBuilder.append(mongo::StringData("$set"), setBuilder.obj());
    bool flag = DatabaseUtil::instance()->update(queryBuilder, updateBuilder, DatabaseUtil::instance()->getDatabase(), DBConstant::ShoeLastTemplateCollection);
    if(flag)
        LoggerManager::instance()->logInfo("update Shoe Last Bottom success.");
    else
        LoggerManager::instance()->logInfo("update Shoe Last Bottom failed.");

    if(removeOldShoeLastBottom)
    {
        if(tmpBeforeUpdating != nullptr)
        {
            std::string oldShoeLastBottom = tmpBeforeUpdating->getShoeLastTemplateBottom();
            bool flag1 = DatabaseUtil::instance()->deleteFile(oldShoeLastBottom, DatabaseUtil::instance()->getDatabase());
            if(flag1)
                LoggerManager::instance()->logInfo("old shoe last bottom is removed in database.");
        }
    }
    else
    {
        LoggerManager::instance()->logInfo("old shoe last bottom is keeped in database.");
    }

    return true;
}
예제 #3
0
bool ShoeLastTemplateDao::removeTemplate(std::string templateOId)
{
    if(templateOId == "")
    {
        LoggerManager::instance()->logInfo("remove template failed, it's a null oid.");
        return false;
    }
    std::shared_ptr<ShoeLastTemplate> tmp = getShoeLastTemplate(templateOId);
    if(tmp == nullptr)
        return false;

    std::string shoeLastOId = tmp->getShoeLastTemplate();
    std::string shoeLastBottomOId = tmp->getShoeLastTemplateBottom();

    DatabaseUtil::instance()->deleteFile(shoeLastOId, DatabaseUtil::instance()->getDatabase());
    DatabaseUtil::instance()->deleteFile(shoeLastBottomOId, DatabaseUtil::instance()->getDatabase());

    mongo::BSONObjBuilder b;
    try
    {
        mongo::OID oid1(templateOId);
        b.append(mongo::StringData(DBConstant::ShoeLastTemplateOIdField), oid1);
    }
    catch(...)
    {
        LoggerManager::instance()->logInfo("exception occurs because of invalid mongo oid.");
        return false;
    }
    try
    {
        const mongo::Query query = mongo::Query(b.obj());
        DatabaseUtil::instance()->remove(DatabaseUtil::instance()->getDatabase(), DBConstant::ShoeLastTemplateCollection, query);
        LoggerManager::instance()->logInfo("Shoe Last Template: "+templateOId+" removed.");
    }
    catch(...)
    {
        LoggerManager::instance()->logInfo("exception occurs in remove shoe last template.");
        return false;
    }

    LoggerManager::instance()->logInfo("shoe last template has been removed.");
    return true;
}
예제 #4
0
void TrapList::makeAlarmTrapDatagram(Alarm_Trap_type_E type, AlarmRecord *record) {

    if( !inited ) {
        return;
    }
    if (record == NULL)
        return;

    /*检查trapbuf是否满*/
    if (endIndex != currentIndex) {
        //�Ƿ�buffer������� ����
        if ((endIndex == TrapMaxNumber - 1) && currentIndex == 0) {
            return;
        } else if ((endIndex + 1) == currentIndex) {
            return;
        }
    }

    /*VBS 初始化*/
    OIDImplTrapItem[10] = 3;
    OIDImplEventID[10] = 2;
    SNMPPdu pdu;
    pdu.commond = SNMPPdu::TRAP;
    VariableBinding vb[5];
    pdu.variableBindings.variableBinding = vb;
    pdu.variableBindings.vbsLength = 5;

    /*1.3.6.1.2.1.1.3.0 Timeticks*/
    OID oid1(OIDImplTimeticks, 9);
    pdu.variableBindings.getAt(0)->setOID(&oid1);
    TimeTicks value1(record->itsRaiseTime());
    pdu.variableBindings.getAt(0)->setValue(&value1);

    /*1.3.6.1.6.3.1.1.4.1.0 TrapOID*/
        /*1.3.6.1.4.1.25449.1.1.12.2.type alarmType*/

    OID oid2(OIDTrapFix, 11);
    pdu.variableBindings.getAt(1)->setOID(&oid2);
    OIDImplEventID[11] = record->itsAlarmType();
    if( type == alarm_clear ) {
        OIDImplEventID[11] |= 0x8000;
    }
    OID value2(OIDImplEventID, 12);
    pdu.variableBindings.getAt(1)->setValue(&value2);

    /*1.3.6.1.4.1.25449.1.1.12.3.1 alarm sn*/
    OIDImplTrapItem[11] = 1;
    OID oid3(OIDImplTrapItem, 12);
    pdu.variableBindings.getAt(2)->setOID(&oid3);
    Integer32 value3(record->itsSN());
    pdu.variableBindings.getAt(2)->setValue(&value3);

    //Alarm source ID
    /*1.3.6.1.4.1.25449.1.1.12.3.2 Alarm source ID*/
    OIDImplTrapItem[11] = 2;
    OID oid4(OIDImplTrapItem, 12);
    pdu.variableBindings.getAt(3)->setOID(&oid4);
    Integer32 value4(record->itsAlarmSource());
    pdu.variableBindings.getAt(3)->setValue(&value4);

    //Alarm level
    /*1.3.6.1.4.1.25449.1.1.12.3.3 Alarm level*/
    OIDImplTrapItem[11] = 3;
    OID oid5(OIDImplTrapItem, 12);
    pdu.variableBindings.getAt(4)->setOID(&oid5);
    Integer32 value5(record->itsAlarmLevel());
    pdu.variableBindings.getAt(4)->setValue(&value5);

    int pklen = pdu.getPDUBerLength();
    int buflen = pklen + 1 + SNMPPdu::getLengthBerLength(pklen);

    ///unsigned char *buf = new unsigned char[buflen];
    if (pdu.encode((unsigned char*) trapBuffer[endIndex].buffer, buflen,
            pklen)) {
        trapBuffer[endIndex].buffersize = buflen;
        trapBuffer[endIndex].valid = 1;
    } else {
        trapBuffer[endIndex].buffersize = 0;
        trapBuffer[endIndex].valid = 0;
    }

    pdu.variableBindings.variableBinding = NULL;
    endIndex++;
    if (endIndex >= TrapMaxNumber) {
        endIndex = 0;
    }

}