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.

333 lines
11 KiB

  1. // DPIcmpPage.cpp : implementation file
  2. //
  3. // 03/05/00 v-marfin bug 59643 : Make this the default starting page.
  4. // 03/24/00 v-marfin bug 60651 : Removed Hope Count from dialog.
  5. // 03/29/00 v-marfin bug 62585 : Set new Data collector's ENABLED to TRUE if user presses OK.
  6. // 03/30/00 v-marfin bug 59237 : If user does not change the default name of the data
  7. // collector when they first create it, change it for
  8. // them to a more meaningful name based on the data
  9. // they select in the property pages.
  10. #include "stdafx.h"
  11. #include "snapin.h"
  12. #include "DPIcmpPage.h"
  13. #include "HMObject.h"
  14. #include "HMDataElementConfiguration.h"
  15. #include "DataElement.h"
  16. #include "DataGroupScopeItem.h"
  17. #ifdef _DEBUG
  18. #define new DEBUG_NEW
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22. /////////////////////////////////////////////////////////////////////////////
  23. // CDPIcmpPage property page
  24. IMPLEMENT_DYNCREATE(CDPIcmpPage, CHMPropertyPage)
  25. CDPIcmpPage::CDPIcmpPage() : CHMPropertyPage(CDPIcmpPage::IDD)
  26. {
  27. //{{AFX_DATA_INIT(CDPIcmpPage)
  28. m_bRequireReset = FALSE;
  29. m_sRetryCount = _T("4");
  30. m_sServer = _T("");
  31. m_sTimeout = _T("10");
  32. //}}AFX_DATA_INIT
  33. }
  34. CDPIcmpPage::~CDPIcmpPage()
  35. {
  36. }
  37. void CDPIcmpPage::DoDataExchange(CDataExchange* pDX)
  38. {
  39. CHMPropertyPage::DoDataExchange(pDX);
  40. //{{AFX_DATA_MAP(CDPIcmpPage)
  41. DDX_Check(pDX, IDC_CHECK_REQUIRE_RESET, m_bRequireReset);
  42. DDX_Text(pDX, IDC_EDIT_RETRY_COUNT, m_sRetryCount);
  43. DDX_Text(pDX, IDC_EDIT_SERVER, m_sServer);
  44. DDX_Text(pDX, IDC_EDIT_TIMEOUT, m_sTimeout);
  45. //}}AFX_DATA_MAP
  46. }
  47. BEGIN_MESSAGE_MAP(CDPIcmpPage, CHMPropertyPage)
  48. //{{AFX_MSG_MAP(CDPIcmpPage)
  49. ON_BN_CLICKED(IDC_CHECK_REQUIRE_RESET, OnCheckRequireReset)
  50. ON_EN_CHANGE(IDC_EDIT_SERVER, OnChangeEditServer)
  51. ON_BN_CLICKED(IDC_BUTTON_BROWSE_SYSTEM, OnButtonBrowseSystem)
  52. ON_WM_DESTROY()
  53. //}}AFX_MSG_MAP
  54. END_MESSAGE_MAP()
  55. /////////////////////////////////////////////////////////////////////////////
  56. // CDPIcmpPage message handlers
  57. BOOL CDPIcmpPage::OnInitDialog()
  58. {
  59. // v-marfin : bug 59643 : This will be the default starting page for the property
  60. // sheet so call CnxPropertyPageCreate() to unmarshal the
  61. // connection for this thread. This function must be called
  62. // by the first page of the property sheet. It used to
  63. // be called by the "General" page and its call still remains
  64. // there as well in case the general page is loaded by a
  65. // different code path that does not also load this page.
  66. // The CnxPropertyPageCreate function has been safeguarded
  67. // to simply return if the required call has already been made.
  68. // CnxPropertyPageDestory() must be called from this page's
  69. // OnDestroy function.
  70. // unmarshal connmgr
  71. CnxPropertyPageCreate();
  72. CHMPropertyPage::OnInitDialog();
  73. CWbemClassObject* pClassObject = GetObjectPtr()->GetClassObject();
  74. if( ! GfxCheckObjPtr(pClassObject,CWbemClassObject) )
  75. {
  76. return TRUE;
  77. }
  78. bool bReset;
  79. pClassObject->GetProperty(IDS_STRING_MOF_REQUIRERESET,bReset);
  80. m_bRequireReset = bReset;
  81. //-------------------------------------------------------------------------
  82. // v-marfin 59237 : Store original name in case this data collector is
  83. // just being created. When they save, we will modify the
  84. // name if they haven't.
  85. pClassObject->GetProperty(IDS_STRING_MOF_NAME,m_sOriginalName);
  86. //-------------------------------------------------------------------------
  87. COleSafeArray arguments;
  88. HMContextArray Arguments;
  89. HRESULT hr = pClassObject->GetProperty(IDS_STRING_MOF_ARGUMENTS,arguments);
  90. if( hr != S_FALSE )
  91. {
  92. CHMPolledMethodDataElementConfiguration::CopyArgsFromSafeArray(arguments,Arguments);
  93. }
  94. if( Arguments.GetSize() == 3 )
  95. {
  96. m_sServer = Arguments[0]->m_sValue;
  97. m_sTimeout = Arguments[1]->m_sValue;
  98. m_sRetryCount = Arguments[2]->m_sValue;
  99. }
  100. CHMPolledMethodDataElementConfiguration::DestroyArguments(Arguments);
  101. delete pClassObject;
  102. UpdateData(FALSE);
  103. SendDlgItemMessage(IDC_SPIN1,UDM_SETRANGE32,0,999999);
  104. SendDlgItemMessage(IDC_SPIN2,UDM_SETRANGE32,0,999999);
  105. return TRUE; // return TRUE unless you set the focus to a control
  106. // EXCEPTION: OCX Property Pages should return FALSE
  107. }
  108. BOOL CDPIcmpPage::OnApply()
  109. {
  110. if( ! CHMPropertyPage::OnApply() )
  111. {
  112. return FALSE;
  113. }
  114. // v-marfin 62585 : So we can set the collector's state to enabled when OK pressed.
  115. m_bOnApplyUsed=TRUE;
  116. UpdateData();
  117. CWbemClassObject* pClassObject = GetObjectPtr()->GetClassObject();
  118. if( ! GfxCheckObjPtr(pClassObject,CWbemClassObject) )
  119. {
  120. return FALSE;
  121. }
  122. HRESULT hr = S_OK;
  123. HMContextArray Arguments;
  124. CHMPolledMethodDataElementConfiguration::AddArgument(Arguments,GetObjectPtr()->GetSystemName(),_T("IPAddress"),CIM_STRING,m_sServer);
  125. CHMPolledMethodDataElementConfiguration::AddArgument(Arguments,GetObjectPtr()->GetSystemName(),_T("TimeOut"),CIM_UINT32,m_sTimeout);
  126. CHMPolledMethodDataElementConfiguration::AddArgument(Arguments,GetObjectPtr()->GetSystemName(),_T("Tries"),CIM_UINT32,m_sRetryCount);
  127. COleSafeArray arguments;
  128. CHMPolledMethodDataElementConfiguration::CopyArgsToSafeArray(Arguments,arguments);
  129. hr = pClassObject->SetProperty(IDS_STRING_MOF_ARGUMENTS,arguments);
  130. CHMPolledMethodDataElementConfiguration::DestroyArguments(Arguments);
  131. CString sNamespace = _T("root\\cimv2\\MicrosoftHealthmonitor");
  132. pClassObject->SetProperty(IDS_STRING_MOF_TARGETNAMESPACE,sNamespace);
  133. pClassObject->SetProperty(IDS_STRING_MOF_PATH,CString(_T("PingPoller")));
  134. pClassObject->SetProperty(IDS_STRING_MOF_METHODNAME,CString(_T("Ping")));
  135. /* 63128
  136. CStringArray saProperties;
  137. saProperties.Add(_T("Status"));
  138. pClassObject->SetProperty(IDS_STRING_MOF_STATISTICSPROPERTYNAMES,saProperties);*/
  139. bool bReset = m_bRequireReset ? true : false;
  140. pClassObject->SetProperty(IDS_STRING_MOF_REQUIRERESET,bReset);
  141. pClassObject->SaveAllProperties();
  142. delete pClassObject;
  143. SetModified(FALSE);
  144. return TRUE;
  145. }
  146. void CDPIcmpPage::OnCheckRequireReset()
  147. {
  148. SetModified();
  149. }
  150. void CDPIcmpPage::OnChangeEditServer()
  151. {
  152. // TODO: If this is a RICHEDIT control, the control will not
  153. // send this notification unless you override the CHMPropertyPage::OnInitDialog()
  154. // function and call CRichEditCtrl().SetEventMask()
  155. // with the ENM_CHANGE flag ORed into the mask.
  156. SetModified();
  157. }
  158. void CDPIcmpPage::OnButtonBrowseSystem()
  159. {
  160. UpdateData();
  161. LPMALLOC pMalloc;
  162. if( ::SHGetMalloc(&pMalloc) == NOERROR )
  163. {
  164. BROWSEINFO bi;
  165. TCHAR szBuffer[MAX_PATH];
  166. LPITEMIDLIST pidlNet;
  167. LPITEMIDLIST pidl;
  168. if( ::SHGetSpecialFolderLocation(GetSafeHwnd(),CSIDL_NETWORK,&pidlNet) != NOERROR )
  169. return;
  170. CString sResString;
  171. sResString.LoadString(IDS_STRING_BROWSE_SYSTEM);
  172. bi.hwndOwner = GetSafeHwnd();
  173. bi.pidlRoot = pidlNet;
  174. bi.pszDisplayName = szBuffer;
  175. bi.lpszTitle = LPCTSTR(sResString);
  176. bi.ulFlags = BIF_BROWSEFORCOMPUTER;
  177. bi.lpfn = NULL;
  178. bi.lParam = 0;
  179. if( (pidl = ::SHBrowseForFolder(&bi)) != NULL )
  180. {
  181. m_sServer = szBuffer;
  182. UpdateData(FALSE);
  183. pMalloc->Free(pidl);
  184. }
  185. pMalloc->Free(pidlNet);
  186. pMalloc->Release();
  187. }
  188. }
  189. void CDPIcmpPage::OnDestroy()
  190. {
  191. // v-marfin 62585 : For this new data collector, set its Enabled property to TRUE, but
  192. // only if the user is not cancelling these property pages.
  193. if (m_bOnApplyUsed)
  194. {
  195. ClearStatistics(); // 62548
  196. CDataElement* pElement = (CDataElement*)GetObjectPtr();
  197. if (pElement && pElement->IsStateSetToEnabledOnOK())
  198. {
  199. TRACE(_T("CDPIcmpPage::OnDestroy - New Perfmon Collector: Setting to Enabled\n"));
  200. pElement->SetStateToEnabledOnOK(FALSE); // don't do this again
  201. CWbemClassObject* pClassObject = GetObjectPtr()->GetClassObject();
  202. if( ! GfxCheckObjPtr(pClassObject,CWbemClassObject) )
  203. {
  204. TRACE(_T("ERROR: CDPPerfMonPage::OnOK - Failed to GetClassObject()\n"));
  205. return;
  206. }
  207. // Set the new collector to enabled.
  208. BOOL bEnabled=TRUE;
  209. HRESULT hr = pClassObject->GetProperty(IDS_STRING_MOF_ENABLE,bEnabled);
  210. hr = pClassObject->SetProperty(IDS_STRING_MOF_ENABLE,TRUE);
  211. if (!CHECKHRESULT(hr))
  212. {
  213. TRACE(_T("ERROR: CDPIcmpPage::OnDestroy - Failed to set ENABLED property on new collector\n"));
  214. }
  215. //-------------------------------------------------------------------
  216. // v-marfin 59237 : If the user has not changed the original default
  217. // name, do so for them. Compare against original
  218. // name we fetched during OnInitDialog.
  219. CString sName;
  220. pClassObject->GetProperty(IDS_STRING_MOF_NAME,sName);
  221. // Did the user change the default name?
  222. if (m_sOriginalName.CompareNoCase(sName)==0)
  223. {
  224. CString sObject;
  225. sObject.Format(IDS_STRING_FORMAT_ICMPNAME,m_sServer);
  226. // No, so set the new name
  227. if (!sObject.IsEmpty())
  228. {
  229. // Use parent to ensure name is unique
  230. //CDataGroup* pParent = (CDataGroup*) pElement->GetCollectorsParentClassObject();
  231. if(pElement->GetScopeItemCount())
  232. {
  233. CDataElementScopeItem* pItem = (CDataElementScopeItem*)pElement->GetScopeItem(0);
  234. if( pItem )
  235. {
  236. CDataGroupScopeItem* pDGItem = (CDataGroupScopeItem*)pItem->GetParent();
  237. sName = pDGItem->GetUniqueDisplayName(sObject);
  238. }
  239. }
  240. // Set the local element's object data
  241. pElement->SetName(sName);
  242. // Set its WMI property
  243. pClassObject->SetProperty(IDS_STRING_MOF_NAME,sName);
  244. // Refresh to show the new name in the IU
  245. //pElement->Refresh(); // 63005
  246. pElement->UpdateStatus(); // 63005
  247. }
  248. }
  249. //-------------------------------------------------------------------
  250. pClassObject->SaveAllProperties();
  251. delete pClassObject;
  252. } // if (pElement && pElement->IsStateSetToEnabledOnOK())
  253. } // if (m_bOnApplyUsed)
  254. CHMPropertyPage::OnDestroy();
  255. // v-marfin : bug 59643 : CnxPropertyPageDestory() must be called from this page's
  256. // OnDestroy function.
  257. CnxPropertyPageDestroy();
  258. }