#include "Stdafx.h" #include "ConnectionInfoMngr.h" #include "XMLParser.h" #include "NetConnection.h" #include "ServiceMonitor.h" #include "MainFrm.h" #include "BasePartitionView.h" DEFINE_SINGLETON_CLASS(CConnectionInfoMngr); CConnectionInfoMngr::CConnectionInfoMngr() { } bool CConnectionInfoMngr::LoadData () { m_vConnectionList.clear(); CXMLParser parser; if (parser.Open("ConnectionList.xml") == false) return false; if (parser.FirstChildElement("ConnectionList", true)) { if (parser.FirstChildElement("Connection") == true) { do { stConnectionInfo ConInfo; memset(&ConInfo, 0, sizeof(ConInfo)); WCHAR wszTemp[1024]; wcscpy_s(wszTemp, NAMELENMAX, parser.GetAttribute("UserName")); WideCharToMultiByte(CP_ACP, 0, wszTemp, -1, ConInfo.szUserName, NAMELENMAX, NULL, NULL); wcscpy_s(wszTemp, NAMELENMAX, parser.GetAttribute("PasswordId")); WideCharToMultiByte(CP_ACP, 0, wszTemp, -1, ConInfo.szPassWord, NAMELENMAX, NULL, NULL); wcscpy_s(wszTemp, IPLENMAX, parser.GetAttribute("IP")); WideCharToMultiByte(CP_ACP, 0, wszTemp, -1, ConInfo.szIpAddress, IPLENMAX, NULL, NULL); ConInfo.wPort = (WORD)_tstoi(parser.GetAttribute("Port")); ConInfo.nConID = inet_addr((char*)ConInfo.szIpAddress); m_vConnectionList.push_back(ConInfo); } while (parser.NextSiblingElement("Connection")); } } return true; } void CConnectionInfoMngr::ConnectToServerManager () { stConnectionInfo ConInfo = {0,}; for (int i=0; i<(int)m_vConnectionList.size(); i++) { ConInfo = m_vConnectionList[i]; CNetConnection* pNetConnection = CNetConnectionMgr::GetInstancePtr()->GetConnection (ConInfo.nConID); if (pNetConnection) // ±âÁ¸¿¡ Á¢¼ÓÇÑ °æ¿ì { CNetSession* pNetSession = pNetConnection->GetSession(); if (!pNetSession) continue; DWORD dwRetVal = pNetSession->Connect(ConInfo.nConID, ConInfo.wPort); if (NOERROR != dwRetVal) continue; } else // »õ·Î¿î Á¢¼Ó { // ¾Æ·¡È£Ãâ¼ø¼­´ë·ÎÇØ¾ßÁ¤»óÀÛµ¿ÇÕ´Ï´Ù. pNetConnection = CNetConnectionMgr::GetInstancePtr()->CreateConnection(); if (!pNetConnection) continue; CNetSession* pNetSession = pNetConnection->GetSession(); if (!pNetSession) continue; CMainFrame* pMainFrame = static_cast(::AfxGetApp())->GetMainFrame(); if (!pMainFrame) continue; CBasePartitionView* pPartitionView = pMainFrame->AddPartition (pNetConnection, ConInfo.nConID); if (!pPartitionView) continue; DWORD dwRetVal = pNetSession->Connect(ConInfo.nConID, ConInfo.wPort); if (NOERROR != dwRetVal) continue; // Ä¿³¼¼Ç¾ÆÀ̵ðÀúÀå pPartitionView->SetConnectionID(ConInfo.nConID); // Ä¿³Ø¼Çµî·Ï CNetConnectionMgr::GetInstancePtr()->RegistConnection (pNetConnection); } } } bool CConnectionInfoMngr::GetConInfo (UINT nConID, stConnectionInfo& ConInfo) { for (size_t i=0; i