Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

261 lines
6.5 KiB

  1. #include "ClusterConnectIndirectPage.h"
  2. #include "LeftView.h"
  3. #include "CommonUtils.h"
  4. #include "CommonNLB.h"
  5. #include "MWmiError.h"
  6. #include "IpSubnetMaskControl.h"
  7. #include "MIPAddress.h"
  8. #include "ResourceString.h"
  9. BEGIN_MESSAGE_MAP( ClusterConnectIndirectPage, CPropertyPage )
  10. ON_BN_CLICKED(IDC_ADD_MACHINE, OnButtonAdd)
  11. ON_BN_CLICKED(IDC_DEL_MACHINE, OnButtonDel)
  12. ON_WM_HELPINFO()
  13. ON_WM_CONTEXTMENU()
  14. END_MESSAGE_MAP()
  15. ClusterConnectIndirectPage::ClusterConnectIndirectPage( ClusterData* clusterData,
  16. CWnd* parent )
  17. :
  18. CPropertyPage( IDD ),
  19. DataSinkI(),
  20. m_clusterData( clusterData ),
  21. myParent( parent ),
  22. dataStore(L" ")
  23. {}
  24. void
  25. ClusterConnectIndirectPage::DoDataExchange( CDataExchange* pDX )
  26. {
  27. CPropertyPage::DoDataExchange( pDX );
  28. DDX_Control( pDX, IDC_CLUSTER_IP, clusterIP);
  29. DDX_Control( pDX, IDC_MACHINE, machineIP );
  30. DDX_Control( pDX, IDC_MACHINE_IP_LIST, machineIPList );
  31. DDX_Control( pDX, IDC_ADD_MACHINE, addButton );
  32. DDX_Control( pDX, IDC_DEL_MACHINE, removeButton );
  33. DDX_Control( pDX, IDC_CLUSTER_CONNECTION_STATUS, connectionStatus );
  34. }
  35. void
  36. ClusterConnectIndirectPage::OnOK()
  37. {
  38. CPropertyPage::OnOK();
  39. }
  40. BOOL
  41. ClusterConnectIndirectPage::OnKillActive()
  42. {
  43. // clear the old status if any.
  44. dataStore = L" ";
  45. // get cluster ip.
  46. //
  47. _bstr_t clusterIPAddress =
  48. CommonUtils::getCIPAddressCtrlString( clusterIP );
  49. // validate this ip.
  50. bool isIPValid = MIPAddress::checkIfValid( clusterIPAddress );
  51. if( isIPValid == false )
  52. {
  53. // invalid ip.
  54. dataSink( GETRESOURCEIDSTRING( IDS_WARNING_IP_INVALID ) + clusterIPAddress );
  55. CPropertyPage::OnCancel();
  56. return 0;
  57. }
  58. // check if this cluster already exists in view.
  59. if( myParent != 0 )
  60. {
  61. bool isClusterDuplicate = ( (LeftView * )myParent)->doesClusterExistInView( clusterIPAddress );
  62. if( isClusterDuplicate == true )
  63. {
  64. dataSink( clusterIPAddress + L":" + GETRESOURCEIDSTRING (IDS_CLUSTER_ALREADY ) );
  65. CPropertyPage::OnCancel();
  66. return 0;
  67. }
  68. }
  69. // get all the ips in the machine ip list.
  70. // this list should not be empty.
  71. if( machineIPList.GetCount() == 0 )
  72. {
  73. // machine ip list is empty
  74. dataSink( GETRESOURCEIDSTRING (IDS_MACHINE_LIST_EMPTY ) );
  75. CPropertyPage::OnCancel();
  76. return 0;
  77. }
  78. wchar_t ipBuf[1000];
  79. vector<_bstr_t> connectionIPS;
  80. for( int i = 0; i < machineIPList.GetCount(); ++i )
  81. {
  82. machineIPList.GetText( i, ipBuf );
  83. connectionIPS.push_back( ipBuf );
  84. }
  85. try
  86. {
  87. #if 1
  88. CommonNLB::connectToClusterIndirect( clusterIPAddress,
  89. connectionIPS,
  90. m_clusterData,
  91. this );
  92. #else
  93. vector<ClusterData> clusterDataStore;
  94. bool clusterPropertiesMatched;
  95. CommonNLB::connectToClusterIndirectNew( clusterIPAddress,
  96. connectionIPS,
  97. &clusterDataStore,
  98. clusterPropertiesMatched,
  99. this );
  100. *(m_clusterData) = clusterDataStore[0];
  101. #endif
  102. }
  103. catch( _com_error e )
  104. {
  105. _bstr_t errText;
  106. GetErrorCodeText( e.Error(), errText );
  107. dataSink( errText );
  108. CPropertyPage::OnCancel();
  109. return 0;
  110. }
  111. return CPropertyPage::OnKillActive();
  112. }
  113. BOOL
  114. ClusterConnectIndirectPage::OnInitDialog()
  115. {
  116. CPropertyPage::OnInitDialog();
  117. // fill in cluster ip but only if not null.
  118. //
  119. if( m_clusterData->cp.cIP != _bstr_t( L"0.0.0.0" ) )
  120. {
  121. CommonUtils::fillCIPAddressCtrlString( clusterIP,
  122. m_clusterData->cp.cIP );
  123. // fill in machine ip list.
  124. // connect to each host.
  125. map<_bstr_t, HostData >::iterator top;
  126. for( top = m_clusterData->hosts.begin();
  127. top != m_clusterData->hosts.end();
  128. ++top )
  129. {
  130. machineIPList.InsertString( -1, (*top).second.connectionIP );
  131. }
  132. // select the first ip in machine IP list.
  133. machineIPList.SetCurSel( 0 );
  134. }
  135. return TRUE;
  136. }
  137. void
  138. ClusterConnectIndirectPage::dataSink( _bstr_t data )
  139. {
  140. dataStore += data;
  141. dataStore += L"\r\n";
  142. connectionStatus.SetWindowText( dataStore );
  143. UpdateWindow();
  144. }
  145. void ClusterConnectIndirectPage::OnButtonAdd()
  146. {
  147. // get and check if machine ip is valid.
  148. _bstr_t machineIPAddress =
  149. CommonUtils::getCIPAddressCtrlString( machineIP );
  150. bool isIPValid = MIPAddress::checkIfValid( machineIPAddress );
  151. if( isIPValid == false )
  152. {
  153. // invalid ip.
  154. dataSink( GETRESOURCEIDSTRING( IDS_WARNING_IP_INVALID ) + machineIPAddress );
  155. return;
  156. }
  157. // check if machine ip to add already exists in list.
  158. //
  159. wchar_t ipBuf[1000];
  160. for( int i = 0; i < machineIPList.GetCount(); ++i )
  161. {
  162. machineIPList.GetText( i, ipBuf );
  163. if( machineIPAddress == _bstr_t( ipBuf ) )
  164. {
  165. // duplicate, cannot add.
  166. dataSink( GETRESOURCEIDSTRING( IDS_MACHINE_ALREADY ) + L":" + machineIPAddress );
  167. // select this duplicate string in list.
  168. machineIPList.SetCurSel( i );
  169. return;
  170. }
  171. }
  172. // add it to list.
  173. int index = machineIPList.InsertString( -1, machineIPAddress );
  174. // select this string.
  175. machineIPList.SetCurSel( index );
  176. }
  177. void ClusterConnectIndirectPage::OnButtonDel()
  178. {
  179. // delete the ip selected from the list.
  180. int index = machineIPList.GetCurSel();
  181. if( index != LB_ERR )
  182. {
  183. machineIPList.DeleteString( index );
  184. }
  185. }
  186. BOOL
  187. ClusterConnectIndirectPage::OnHelpInfo (HELPINFO* helpInfo )
  188. {
  189. if( helpInfo->iContextType == HELPINFO_WINDOW )
  190. {
  191. ::WinHelp( static_cast<HWND> ( helpInfo->hItemHandle ),
  192. CVY_CTXT_HELP_FILE,
  193. HELP_WM_HELP,
  194. (ULONG_PTR ) g_aHelpIDs_IDD_CLUSTER_CONNECT_INDIRECT_PAGE);
  195. }
  196. return TRUE;
  197. }
  198. void
  199. ClusterConnectIndirectPage::OnContextMenu( CWnd* pWnd, CPoint point )
  200. {
  201. ::WinHelp( m_hWnd,
  202. CVY_CTXT_HELP_FILE,
  203. HELP_CONTEXTMENU,
  204. (ULONG_PTR ) g_aHelpIDs_IDD_CLUSTER_CONNECT_INDIRECT_PAGE);
  205. }