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.

197 lines
4.8 KiB

  1. #include "ClusterConnectPage.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( ClusterConnectPage, CPropertyPage )
  10. ON_WM_CONTEXTMENU()
  11. ON_WM_HELPINFO()
  12. END_MESSAGE_MAP()
  13. ClusterConnectPage::ClusterConnectPage( ClusterData* clusterData,
  14. CWnd* parent )
  15. :
  16. CPropertyPage( IDD ),
  17. DataSinkI(),
  18. m_clusterData( clusterData ),
  19. myParent( parent ),
  20. dataStore(L" ")
  21. {}
  22. void
  23. ClusterConnectPage::DoDataExchange( CDataExchange* pDX )
  24. {
  25. CPropertyPage::DoDataExchange( pDX );
  26. DDX_Control( pDX, IDC_CLUSTER_IP, clusterIP);
  27. DDX_Control( pDX, IDC_CLUSTER_MEMBER, clusterMemberName );
  28. DDX_Control( pDX, IDC_CLUSTER_CONNECTION_STATUS, connectionStatus );
  29. }
  30. void
  31. ClusterConnectPage::OnOK()
  32. {
  33. CPropertyPage::OnOK();
  34. }
  35. BOOL
  36. ClusterConnectPage::OnKillActive()
  37. {
  38. // clear the old status if any.
  39. dataStore = L" ";
  40. // get cluster ip.
  41. //
  42. _bstr_t clusterIPAddress =
  43. CommonUtils::getCIPAddressCtrlString( clusterIP );
  44. // validate this ip.
  45. bool isIPValid = MIPAddress::checkIfValid( clusterIPAddress );
  46. if( isIPValid == false )
  47. {
  48. // invalid ip.
  49. dataSink( GETRESOURCEIDSTRING( IDS_WARNING_IP_INVALID ) + clusterIPAddress );
  50. CPropertyPage::OnCancel();
  51. return 0;
  52. }
  53. // get member of this cluster
  54. //
  55. _bstr_t clusterMember =
  56. CommonUtils::getCIPAddressCtrlString( clusterMemberName );
  57. // validate this ip.
  58. isIPValid = MIPAddress::checkIfValid( clusterMember );
  59. if( isIPValid == false )
  60. {
  61. // invalid ip.
  62. dataSink( GETRESOURCEIDSTRING( IDS_WARNING_IP_INVALID ) + clusterMember );
  63. CPropertyPage::OnCancel();
  64. return 0;
  65. }
  66. // the member ip should not be the cluster ip.
  67. if( clusterMember == clusterIPAddress )
  68. {
  69. // cluster ip and member are same.
  70. // This is not allowed.
  71. // invalid ip.
  72. dataSink( GETRESOURCEIDSTRING( IDS_WARNING_CL_CONN_SAME ) );
  73. CPropertyPage::OnCancel();
  74. return 0;
  75. }
  76. // check if this cluster already exists in view, but ensure that pointer is valid.
  77. if( myParent != 0 )
  78. {
  79. bool isClusterDuplicate = ( (LeftView * )myParent)->doesClusterExistInView( clusterIPAddress );
  80. if( isClusterDuplicate == true )
  81. {
  82. dataSink( clusterIPAddress + L":" + GETRESOURCEIDSTRING (IDS_CLUSTER_ALREADY ) );
  83. CPropertyPage::OnCancel();
  84. return 0;
  85. }
  86. }
  87. try
  88. {
  89. CommonNLB::connectToClusterDirect( clusterIPAddress,
  90. clusterMember,
  91. m_clusterData,
  92. this
  93. );
  94. }
  95. catch( _com_error e )
  96. {
  97. _bstr_t errText;
  98. GetErrorCodeText( e.Error(), errText );
  99. dataSink( errText );
  100. CPropertyPage::OnCancel();
  101. return 0;
  102. }
  103. return CPropertyPage::OnKillActive();
  104. }
  105. BOOL
  106. ClusterConnectPage::OnInitDialog()
  107. {
  108. /* Limit the zeroth field of the dedicated IP address between 1 and 223. */
  109. CPropertyPage::OnInitDialog();
  110. // fill in cluster ip but only if not null.
  111. //
  112. if( m_clusterData->cp.cIP != _bstr_t( L"0.0.0.0" ) )
  113. {
  114. CommonUtils::fillCIPAddressCtrlString( clusterIP,
  115. m_clusterData->cp.cIP );
  116. // fill in machine ip list.
  117. // connect to each host.
  118. map<_bstr_t, HostData >::iterator top;
  119. for( top = m_clusterData->hosts.begin();
  120. top != m_clusterData->hosts.end();
  121. ++top )
  122. {
  123. // just use the first hosts connection ip.
  124. CommonUtils::fillCIPAddressCtrlString( clusterMemberName,
  125. (*top).second.connectionIP );
  126. break;
  127. }
  128. }
  129. return TRUE;
  130. }
  131. void
  132. ClusterConnectPage::dataSink( _bstr_t data )
  133. {
  134. dataStore += data;
  135. dataStore += L"\r\n";
  136. connectionStatus.SetWindowText( dataStore );
  137. UpdateWindow();
  138. }
  139. BOOL
  140. ClusterConnectPage::OnHelpInfo (HELPINFO* helpInfo )
  141. {
  142. if( helpInfo->iContextType == HELPINFO_WINDOW )
  143. {
  144. ::WinHelp( static_cast<HWND> ( helpInfo->hItemHandle ),
  145. CVY_CTXT_HELP_FILE,
  146. HELP_WM_HELP,
  147. (ULONG_PTR ) g_aHelpIDs_IDD_CLUSTER_CONNECT_PAGE );
  148. }
  149. return TRUE;
  150. }
  151. void
  152. ClusterConnectPage::OnContextMenu( CWnd* pWnd, CPoint point )
  153. {
  154. ::WinHelp( m_hWnd,
  155. CVY_CTXT_HELP_FILE,
  156. HELP_CONTEXTMENU,
  157. (ULONG_PTR ) g_aHelpIDs_IDD_CLUSTER_CONNECT_PAGE );
  158. }