#include "StdAfx.h"
|
#include "MBSelUserMgr.h"
|
|
|
CMBSelUserMgr::CMBSelUserMgr(void)
|
{
|
RemoveAll();
|
}
|
|
|
CMBSelUserMgr::~CMBSelUserMgr(void)
|
{
|
RemoveAll();
|
}
|
|
bool CMBSelUserMgr::GetVector( CMBSelUserVector &vector )
|
{
|
vector.clear();
|
vector = m_vector;
|
return true;
|
}
|
|
bool CMBSelUserMgr::Add(CMBSelUser *pUser)
|
{
|
if( NULL == pUser || pUser->m_strLogin.IsEmpty() )
|
return false;
|
|
CMBSelUserMap::iterator it;
|
CString strLogin;
|
|
|
strLogin = pUser->m_strLogin;
|
it = m_map.find(strLogin);
|
|
// Èç¹ûÕҵõ½ ·µ»Ø
|
if( it != m_map.end() )
|
return false;
|
|
m_map[strLogin] = pUser;
|
m_vector.push_back(pUser);
|
return true;
|
}
|
|
CMBSelUser *CMBSelUserMgr::Get( CString strLogin )
|
{
|
if( strLogin.IsEmpty() )
|
{
|
return NULL;
|
}
|
|
CMBSelUserMap::iterator it;
|
CMBSelUser *pUser = NULL;
|
|
it = m_map.find(strLogin);
|
|
if( it!= m_map.end() )
|
pUser = it->second;
|
|
return pUser;
|
}
|
|
bool CMBSelUserMgr::Remove( CMBSelUser *pUser )
|
{
|
bool bDelte = false;
|
if( NULL == pUser )
|
return false;
|
CMBSelUserMap::iterator it = m_map.find(pUser->m_strLogin);
|
|
if( it!= m_map.end() )
|
{
|
bDelte = true;
|
m_map.erase(it);
|
}
|
CMBSelUserVector::iterator it1 = std::find(m_vector.begin( ), m_vector.end( ), pUser); //²éÕÒ3
|
if( it1 != m_vector.end( ) ){
|
bDelte = true;
|
m_vector.erase(it1);
|
}
|
if( bDelte ){
|
delete pUser;
|
pUser = NULL;
|
}
|
return true;
|
}
|
|
bool CMBSelUserMgr::RemoveAll()
|
{
|
CMBSelUserMap::iterator it;
|
CMBSelUser *pUser = NULL;
|
|
for( it = m_map.begin();it != m_map.end();it++ )
|
{
|
pUser = it->second;
|
delete pUser;
|
pUser = NULL;
|
}
|
|
m_map.clear();
|
m_vector.clear();
|
|
return true;
|
}
|
|
int CMBSelUserMgr::GetCount()
|
{
|
return m_map.size();
|
}
|
|
CString CMBSelUserMgr::GetUsersXml()
|
{
|
CString strUsersXml,strUserXml;
|
CMBSelUserVector::iterator it;
|
CMBSelUser *pUser = NULL;
|
|
for( it = m_vector.begin();it != m_vector.end();it++ )
|
{
|
pUser = *it;
|
strUserXml.Format(_T("<User ID='%s' Name='%s' />"),pUser->m_strLogin,pUser->m_strName);
|
strUsersXml += strUserXml;
|
}
|
return strUsersXml;
|
}
|
|
|
bool CMBSelUserMgr::ParseShareXml( CString &strXml,CString &strErrInfo )
|
{
|
if( strXml.IsEmpty() )
|
{
|
//strErrInfo = _T("CMBSelUserMgr::ParseShareXml,²ÎÊýstrXmlΪ¿Õ£¡");
|
return true;
|
}
|
|
CString strFileSize;
|
pugi::xml_document xmlDoc;
|
|
if (!xmlDoc.load(strXml))
|
{
|
return false;
|
}
|
pugi::xml_node form = xmlDoc.child(_T("Body")).child(_T("User"));
|
for(pugi::xml_node node = form; node; node = node.next_sibling(_T("User")))
|
{
|
CMBSelUser *pUser = new CMBSelUser();
|
|
pUser->m_strLogin = node.attribute(_T("Login")).value();
|
pUser->m_strName = node.attribute(_T("Name")).value();
|
pUser->m_nType = 0;
|
|
if( !Add(pUser) )
|
{
|
delete pUser;
|
pUser = NULL;
|
}
|
}
|
|
return true;
|
}
|