#include "StdAfx.h" #include "MBFileSvrMgr.h" #include "MBBaseDef.h" CMBFileSvrMgr::CMBFileSvrMgr(void) { RemoveAllFileSvrInfo(); } CMBFileSvrMgr::~CMBFileSvrMgr(void) { RemoveAllFileSvrInfo(); } bool CMBFileSvrMgr::AddFileSvrInfo(CMBFileSvrInfo *pFileSvrInfo) { if( NULL == pFileSvrInfo || pFileSvrInfo->m_strFlag.IsEmpty() ) return false; CMBFileSvrInfoMap::iterator it; CString strFlag; strFlag = pFileSvrInfo->m_strFlag; it = m_mapFileSvrInfo.find(strFlag); // Èç¹ûÕҵõ½ ·µ»Ø if( it != m_mapFileSvrInfo.end() ) return false; m_mapFileSvrInfo[strFlag] = pFileSvrInfo; return true; } CMBFileSvrInfo * CMBFileSvrMgr::GetFileSvrInfo( CString strFlag ) { if( strFlag.IsEmpty() ) { return NULL; } CMBFileSvrInfoMap::iterator it; CMBFileSvrInfo *pFileSvrInfo = NULL; it = m_mapFileSvrInfo.find(strFlag); if( it!= m_mapFileSvrInfo.end() ) pFileSvrInfo = it->second; return pFileSvrInfo; } bool CMBFileSvrMgr::RemoveAllFileSvrInfo() { CMBFileSvrInfoMap::iterator it; CMBFileSvrInfo *pFileSvrInfo = NULL; for( it = m_mapFileSvrInfo.begin();it != m_mapFileSvrInfo.end();it++ ) { pFileSvrInfo = it->second; delete pFileSvrInfo; pFileSvrInfo = NULL; } m_mapFileSvrInfo.clear(); return true; } void CMBFileSvrMgr::GetMapFileSvr( CMBFileSvrInfoMap &mapFileSvrInfo ) { mapFileSvrInfo.clear(); mapFileSvrInfo = m_mapFileSvrInfo; } bool CMBFileSvrMgr::ParseXml(CString strOrgServer, CString strXml,CString &strErrInfo ) { pugi::xml_document xmlDoc; if (!xmlDoc.load(strXml)) { return false; } pugi::xml_node form = xmlDoc.child(_T("Body")).child(_T("FileService")); for(pugi::xml_node node = form; node; node = node.next_sibling(_T("FileService"))) { CMBFileSvrInfo *pSvrInfo = new CMBFileSvrInfo(); pSvrInfo->m_strFlag = node.attribute(_T("Flag")).value(); pSvrInfo->m_strExterIP = node.attribute(_T("ExterIP")).value(); pSvrInfo->m_strExterPort = node.attribute(_T("ExterPort")).value(); if( _tstol(pSvrInfo->m_strExterPort) < 0) pSvrInfo->m_strExterPort.Format(_T("%d"),DEFAULTPORT_FILE); pSvrInfo->m_strInterIP = form.attribute(_T("InterIP")).value(); pSvrInfo->m_strInterPort = form.attribute(_T("InterPort")).value(); if( _tstol(pSvrInfo->m_strInterPort) < 0) pSvrInfo->m_strInterPort.Format(_T("%d"),DEFAULTPORT_FILE); pSvrInfo->m_strInterURL = node.child_value(_T("InterURL")); pSvrInfo->m_strExterURL = form.child_value(_T("ExterURL")); pSvrInfo->CheckServerInfo(strOrgServer); if( !AddFileSvrInfo(pSvrInfo) ) { delete pSvrInfo; pSvrInfo = NULL; } } return true; }