BOOL SessionLayout::_DisplayMsgToIE(IN MessageEntity msg)
{
	CString jsInterface = _T("sendMessage");
	module::UserInfoEntity userInfo;
	if (!module::getUserListModule()->getUserInfoBySId(msg.talkerSid, userInfo))
	{
		return FALSE;
	}

	Json::Value root;
	root["name"] = util::cStringToString(userInfo.getRealName());
	root["avatar"] = userInfo.getAvatarPathWithoutOnlineState();
	root["msgtype"] = msg.msgRenderType;
	root["uuid"] = msg.talkerSid;
	root["mtype"] = msg.isMySendMsg() ? "me" : "other";
	CTime timeData(msg.msgTime);
	root["time"] = util::cStringToString(timeData.Format(_T("%Y-%m-%d %H:%M:%S")));

	//语音内容特殊处理
	if (MESSAGE_RENDERTYPE_AUDIO == msg.msgRenderType)
	{
		root["voiceid"] = msg.content;
		CString sVoicetime;
		sVoicetime.Format(_T("%d秒"), msg.msgAudioTime);
		root["voicetime"] = util::cStringToString(sVoicetime);
		root["voiceisread"] = msg.msgAudioReaded ? std::string("true") : string("false");
	}
	else
	{
		CString csContent = util::stringToCString(msg.content);
		ReceiveMsgManage::getInstance()->parseContent(csContent, FALSE, GetWidth());
		std::string content = util::cStringToString(csContent);
		root["content"] = content;
	}
	Json::StyledWriter styleWrite;
	std::string record = styleWrite.write(root);
	Json::Reader jsonRead;
	Json::Value rootRead;
	CString jsData = _T("[]");
	if (!jsonRead.parse(record, rootRead) || rootRead.isNull())
	{
		CString csError = util::stringToCString(record, CP_UTF8);
		LOG__(APP, _T("json parse error:%s"), csError);
		jsData = _T("[]");
		return FALSE;
	}
	else
		jsData = util::stringToCString(record, CP_UTF8);
	//调用页面的JS代码
	if (m_pWebBrowser)
	{
		VARIANT VarResult;
		if (!m_pWebBrowser->CallJScript(jsInterface.GetBuffer(), jsData.GetBuffer(), &VarResult))
		{
			LOG__(ERR, _T("CallJScript failed:%s"),jsData);
		}
		jsData.ReleaseBuffer();
	}
	return TRUE;
}
BOOL SessionLayout::_displayMsgToIE(IN MessageEntity msg ,IN CString jsInterface)
{
	module::UserInfoEntity userInfo;
	if (!module::getUserListModule()->getUserInfoBySId(msg.talkerSid, userInfo))
	{
		return FALSE;
	}

	Json::Value root;
	root["name"] = util::cStringToString(userInfo.getRealName());
	root["avatar"] = userInfo.getAvatarPathWithoutOnlineState();
	root["msgtype"] = msg.msgRenderType;
	root["uuid"] = msg.talkerSid;
	CString csContent = util::stringToCString(msg.content);
	ReceiveMsgManage::getInstance()->parseContent(csContent, FALSE, GetWidth(), !msg.isMySendMsg());
	root["content"] = util::cStringToString(csContent);
	if (msg.isMySendMsg())
	{
		root["mtype"] = "me";
	}
	else
	{
		root["mtype"] = "other";
	}
	CTime timeData(msg.msgTime);
	root["time"] = util::cStringToString(timeData.Format(_T("%Y-%m-%d %H:%M:%S")));
	Json::StyledWriter styleWrite;
	std::string record = styleWrite.write(root);
	Json::Reader jsonRead;
	Json::Value rootRead;
	CString jsData = _T("[]");
	if (!jsonRead.parse(record, rootRead) || rootRead.isNull())
	{
		CString csError = util::stringToCString(record, CP_UTF8);
		APP_LOG(LOG_INFO, TRUE, _T("json parse error:%s"), csError);
		jsData = _T("[]");
		return FALSE;
	}
	else
		jsData = util::stringToCString(record, CP_UTF8);
	//调用页面的JS代码
	if (m_pWebBrowser)
	{
		VARIANT VarResult;
		m_pWebBrowser->CallJScript(jsInterface.GetBuffer(), jsData.GetBuffer(), &VarResult);
		jsData.ReleaseBuffer();
	}
	return TRUE;
}
Esempio n. 3
0
    void ServerObject::UpdateTime()
    {
      try
      {
        DateTime t = OpcUa::DateTime::Current();
        DataValue timeData(t);
        timeData.SetSourceTimestamp(t);
        timeData.SetServerTimestamp(t);

        if (Debug) std::clog << "server_object| Updating server time: " << t << std::endl;
        ServerTime.SetValue(timeData);
      }
      catch (std::exception& ex)
      {
        std::cerr << "Failed to update time at server object: " << ex.what() << std::endl;
      }

    }
Esempio n. 4
0
    bool StatFile::rawUpdateBucket(Bucket const &data, RawUpdateMode mode)
    {
        if (!fileWritable_)
        {
            throw std::logic_error(std::string("Attempt to update bucket in read-only StatFile ")
                + fileHeader_->name);
        }

        //  Work out which bucket to put the data in
        int64_t targetBucketIndex = mapTimeToBucketIndex(data.time(), false);
        int64_t targetBucketTime = data.time() - data.time() % fileHeader_->cfg_interval;
        int64_t latestBucketIndex  = fileHeader_->last_bucket;
        Bucket *bp = 0;

        if (targetBucketIndex > latestBucketIndex)
        {
            //  Note: I don't clear the bucket here. It will contain
            //  old data. The user will have to detect this and discard
            //  the data instead.
            fileHeader_->last_bucket = targetBucketIndex;
            fileHeader_->last_time = targetBucketTime;
            if (fileHeader_->first_bucket + bucketCount_ <= fileHeader_->last_bucket)
            {
                fileHeader_->first_bucket = fileHeader_->last_bucket - bucketCount_ + 1;
            }
        }

        if (!StatFile::isBucketIndexInFile(targetBucketIndex))
        {
            Log(LL_Warning, "libistat") << "Cannot go back to time" << data.time() << 
                "when at" << fileHeader_->last_time << ":" << fileHeader_->name;
            return false;
        }

        if (targetBucketIndex < fileHeader_->first_bucket) {
            fileHeader_->first_bucket = targetBucketIndex;
        }

        if (fileHeader_->flags & FILE_FLAG_IS_TRAILING)
        {
            bp = getTrailingBucket(targetBucketTime);
        }
        else
        {
            bp = writableBucket(targetBucketIndex);
            if (bp->time() != targetBucketTime)
            {
                memset(bp, 0, sizeof(*bp));
            }
        }

        if((fileHeader_->flags & FILE_FLAG_IS_COLLATED)
            || mode == RAWUP_OVERWRITE
            || (mode == RAWUP_FILL_EMPTY && bp->count() == 0))
        {
            memcpy(bp, &data, sizeof(*bp));
        }
        else
        {
            Bucket timeData(data, targetBucketTime);
            bp->update(timeData);

            if(fileHeader_->flags & FILE_FLAG_IS_COUNTER_AGGREGATE)
            {
                bp->setCount(fileHeader_->fixed_count);
            }
        }
        fileHeader_->cumulative_sum += data.sum();
        fileHeader_->cumulative_sum_sq += data.sumSq();
        fileHeader_->cumulative_count += data.count();
        return true;
    }