Beispiel #1
0
bool UserInfoCollector::fillData(const std::string& path, const Str2StrMap& cookies, const Str2StrMap& parameter, TemplateDictionary& dict) {
	
	int uid = GetUserId(cookies, parameter);
	if (uid <= 0) {
		MCE_WARN("UserInfoCollector::fillData --> uid:" << uid << " path:" << path);
		return false;
	}
	string ticket = GetTicket(cookies, parameter);
  if (checkTicket(uid, ticket)) {
		dict.SetValue("userid", boost::lexical_cast<string>(uid));
		TalkUserPtr uPtr;
		try {
			uPtr = TalkCacheClient::instance().GetUserByIdWithLoad(uid);
		} catch (Ice::Exception& e) {
			MCE_WARN("UserInfoCollector::fillData -->TalkCacheClient::GetUserByIdWithLoad-->err : " <<e);
		}
		if(!uPtr){
			return false;
		}
		UserUrlInfoPtr urlinfo;
		try{
			urlinfo = UserUrlAdapter::instance().getUserUrl(uid);
		}catch(Ice::Exception& e){
			MCE_WARN("UserInfoCollector::fillData-->UserUrlAdapter::getUserUrl-->uid:" << uid << " error:" << e);
		}
		if(!urlinfo){
			return false;
		}
		if(uPtr && urlinfo){
			string username = uPtr->name;
			string url = urlinfo->headUrl();
			string tinyurl = PhotoUrlHelper::instance().GetFullUrl(url);
			dict.SetValue("tinyurl", tinyurl);
			dict.SetValue("username", username);
		}
		try{
			ClientScoreDataN sd = ScoreCacheNAdapter::instance().getClientScoreDataN(uid);
			dict.SetValue("historyLoginDays", boost::lexical_cast<string>(sd.historyLoginDays));
			dict.SetValue("continueLoginDays", boost::lexical_cast<string>(sd.continueLoginDays));
			Date datetime((sd.lastLoginTime+0.0) / 1000.0);
			MCE_INFO("UserInfoCollector::fillData --> userid:" << uid << " lastLoginTime:" << (sd.lastLoginTime +0.0) / 1000.0 << " datetime:" << datetime.toDateTime());
			ostringstream os;
			if(datetime.month() <= 9){
				os << "0" << datetime.month() << "-";
			}else{
				os << datetime.month() << "-";
			}
			if(datetime.day() <= 9){
				os << "0" << datetime.day();
			}else{
				os << datetime.day();
			}os << " ";
			if(datetime.hour() <= 9){
				os << "0" << datetime.hour() << ":";
			}else{
				os << datetime.hour() << ":";
			}
			if(datetime.minute() <= 9){
				os << "0" << datetime.minute();
			}else{
				os << datetime.minute();
			}
			dict.SetValue("lastLoginTime", boost::lexical_cast<string>(os.str()));
			dict.SetValue("loginType", boost::lexical_cast<string>(sd.loginType));
			dict.SetValue("score", boost::lexical_cast<string>(sd.score));
			dict.SetValue("level", boost::lexical_cast<string>(sd.level));
			dict.SetValue("nextLevelScore", boost::lexical_cast<string>(sd.nextLevelScore));
			dict.SetValue("awardCount", boost::lexical_cast<string>(sd.awardCount));
			int vip = sd.vip;
			if(vip > 0){
				MCE_INFO("UserInfoCollector::fillData --> userid:" << uid << " vip:" << vip);
				dict.ShowSection("VIP_SEC");
				dict.SetValue("vip", boost::lexical_cast<string>(vip));
			}
			ostringstream oss;
			for(vector<string>::iterator it = sd.icons.begin(); it != sd.icons.end(); ++it){
				string level = (*it);
				size_t pos = level.find("-");
				if(string::npos ==pos){
					continue;
				}
				level.erase(pos,1);
				dict.AddSectionDictionary(level);
				oss << level << "(" << (*it) << ")  ,";
			}
			MCE_INFO("UserInfoCollector::fillData --> icons:" << oss.str());
		}catch(Ice::Exception& e) {
			MCE_WARN("UserInfoCollector::fillData --> call ScoreCache err : " << e);
		}
  } else {
    return false;
  }
}
Beispiel #2
0
void GenerateParser(string _srcPath, string _folder, string _name, const Grammar& _grammar)
{
	TemplateDictionary dict(_name);
	dict.SetValue("namespace", _name);

	Defs::const_iterator i, iEnd = _grammar.defs.end();
	for (i = _grammar.defs.begin(); i != iEnd; ++i)
	{
		TemplateDictionary* pDef = dict.AddSectionDictionary("def");
		pDef->SetValue("name", i->first);
	
		if (i->second.isNode)
			pDef->ShowSection("isNode");
		else if (i->second.isMemoized)
			pDef->ShowSection("isSkip");
		
		ostringstream parseCodeStream;
		ParserGenerator parserGenerator(parseCodeStream, _grammar);
		parserGenerator.Emit(i->second, -1);
		
		string parseCodeFilename = "parseCode_" + i->first;
		string parseCode = parseCodeStream.str();
		StringToTemplateCache(parseCodeFilename, parseCode, STRIP_BLANK_LINES);
		
		pDef->AddIncludeDictionary("parseCode")->SetFilename(parseCodeFilename);
		
		ostringstream traverseCodeStream;
		ParserGenerator traverserGenerator(traverseCodeStream, _grammar, true);
		traverserGenerator.Emit(i->second, -1);
		
		string traverseCodeFilename = "traverseCode_" + i->first;
		string traverseCode = traverseCodeStream.str();
		StringToTemplateCache(traverseCodeFilename, traverseCode, STRIP_BLANK_LINES);

		pDef->AddIncludeDictionary("traverseCode")->SetFilename(traverseCodeFilename);
	}

	string headerText;
	if (!ExpandTemplate("Parser.h.tpl", STRIP_BLANK_LINES, &dict, &headerText))
		throw runtime_error("CTemplate Parser.h.tpl expansion failed!");
	
	ofstream headerFile;
	headerFile.exceptions(ofstream::failbit | ofstream::badbit);
	headerFile.open((_folder + _name + ".h").c_str());
	WriteAutoGenNotice(headerFile, _srcPath);
	headerFile << format("#ifndef %1%_H\n#define %1%_H\n\n") % to_upper_copy(_name);
	headerFile << headerText;
	headerFile << "\n#endif\n";
	
	dict.SetValue("header", headerText);

	string sourceText;
	if (!ExpandTemplate("Parser.cpp.tpl", STRIP_BLANK_LINES, &dict, &sourceText))
		throw runtime_error("CTemplate Parser.cpp.tpl expansion failed!");
	
	ofstream sourceFile;
	sourceFile.exceptions(ofstream::failbit | ofstream::badbit);
	string sourcePath = _folder + _name + ".cpp";
	sourceFile.open(sourcePath.c_str());
	WriteAutoGenNotice(sourceFile, _srcPath);
	sourceFile << sourceText;	
}