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.

438 lines
14 KiB

  1. // DPSmtpPage.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 61372 : show user err msgbox for any required field in OnApply().
  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 "DPSmtpPage.h"
  13. #include "HMDataElementConfiguration.h"
  14. #include "HMObject.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. // CDPSmtpPage dialog
  24. CDPSmtpPage::CDPSmtpPage()
  25. : CHMPropertyPage(CDPSmtpPage::IDD)
  26. {
  27. //{{AFX_DATA_INIT(CDPSmtpPage)
  28. m_bRequireReset = FALSE;
  29. m_sData = _T("");
  30. m_sFrom = _T("");
  31. m_sServer = _T("");
  32. m_sTo = _T("");
  33. m_sTimeout = _T("");
  34. m_sSubject = _T("");
  35. //}}AFX_DATA_INIT
  36. m_sHelpTopic = _T("HMon21.chm::/dDEsmpt.htm");
  37. }
  38. void CDPSmtpPage::DoDataExchange(CDataExchange* pDX)
  39. {
  40. CHMPropertyPage::DoDataExchange(pDX);
  41. //{{AFX_DATA_MAP(CDPSmtpPage)
  42. DDX_Control(pDX, IDC_SPIN9, m_SpinCtrl);
  43. DDX_Check(pDX, IDC_CHECK_REQUIRE_RESET, m_bRequireReset);
  44. DDX_Text(pDX, IDC_EDIT_DATA, m_sData);
  45. DDX_Text(pDX, IDC_EDIT_FROM, m_sFrom);
  46. DDX_Text(pDX, IDC_EDIT_SERVER, m_sServer);
  47. DDX_Text(pDX, IDC_EDIT_TO, m_sTo);
  48. DDX_Text(pDX, IDC_EDIT_TIMEOUT, m_sTimeout);
  49. DDX_Text(pDX, IDC_EDIT_SUBJECT, m_sSubject);
  50. //}}AFX_DATA_MAP
  51. }
  52. BEGIN_MESSAGE_MAP(CDPSmtpPage, CHMPropertyPage)
  53. //{{AFX_MSG_MAP(CDPSmtpPage)
  54. ON_BN_CLICKED(IDC_CHECK_REQUIRE_RESET, OnCheckRequireReset)
  55. ON_EN_CHANGE(IDC_EDIT_DATA, OnChangeEditData)
  56. ON_EN_CHANGE(IDC_EDIT_FROM, OnChangeEditFrom)
  57. ON_EN_CHANGE(IDC_EDIT_SERVER, OnChangeEditServer)
  58. ON_EN_CHANGE(IDC_EDIT_TIMEOUT, OnChangeEditTimeout)
  59. ON_EN_CHANGE(IDC_EDIT_TO, OnChangeEditTo)
  60. ON_EN_CHANGE(IDC_EDIT_SUBJECT, OnChangeEditSubject)
  61. ON_WM_DESTROY()
  62. //}}AFX_MSG_MAP
  63. END_MESSAGE_MAP()
  64. /////////////////////////////////////////////////////////////////////////////
  65. // CDPSmtpPage message handlers
  66. BOOL CDPSmtpPage::OnInitDialog()
  67. {
  68. // v-marfin : bug 59643 : This will be the default starting page for the property
  69. // sheet so call CnxPropertyPageCreate() to unmarshal the
  70. // connection for this thread. This function must be called
  71. // by the first page of the property sheet. It used to
  72. // be called by the "General" page and its call still remains
  73. // there as well in case the general page is loaded by a
  74. // different code path that does not also load this page.
  75. // The CnxPropertyPageCreate function has been safeguarded
  76. // to simply return if the required call has already been made.
  77. // CnxPropertyPageDestory() must be called from this page's
  78. // OnDestroy function.
  79. // unmarshal connmgr
  80. CnxPropertyPageCreate();
  81. CHMPropertyPage::OnInitDialog();
  82. CWbemClassObject* pClassObject = GetObjectPtr()->GetClassObject();
  83. if( ! GfxCheckObjPtr(pClassObject,CWbemClassObject) )
  84. {
  85. return TRUE;
  86. }
  87. //-------------------------------------------------------------------------
  88. // v-marfin 59237 : Store original name in case this data collector is
  89. // just being created. When they save, we will modify the
  90. // name if they haven't.
  91. pClassObject->GetProperty(IDS_STRING_MOF_NAME,m_sOriginalName);
  92. //-------------------------------------------------------------------------
  93. bool bReset;
  94. pClassObject->GetProperty(IDS_STRING_MOF_REQUIRERESET,bReset);
  95. m_bRequireReset = bReset;
  96. COleSafeArray arguments;
  97. HMContextArray Arguments;
  98. HRESULT hr = pClassObject->GetProperty(IDS_STRING_MOF_ARGUMENTS,arguments);
  99. if( hr != S_FALSE )
  100. {
  101. CHMPolledMethodDataElementConfiguration::CopyArgsFromSafeArray(arguments,Arguments);
  102. }
  103. if( Arguments.GetSize() == 6 )
  104. {
  105. m_sServer = Arguments[0]->m_sValue;
  106. m_sFrom = Arguments[1]->m_sValue;
  107. m_sTo = Arguments[2]->m_sValue;
  108. m_sSubject = Arguments[3]->m_sValue;
  109. m_sData = Arguments[4]->m_sValue;
  110. m_sTimeout = Arguments[5]->m_sValue;
  111. }
  112. CHMPolledMethodDataElementConfiguration::DestroyArguments(Arguments);
  113. delete pClassObject;
  114. UpdateData(FALSE);
  115. SendDlgItemMessage(IDC_SPIN9,UDM_SETRANGE32,0,INT_MAX-1);
  116. return TRUE; // return TRUE unless you set the focus to a control
  117. // EXCEPTION: OCX Property Pages should return FALSE
  118. }
  119. void CDPSmtpPage::OnOK()
  120. {
  121. CHMPropertyPage::OnOK();
  122. }
  123. BOOL CDPSmtpPage::OnApply()
  124. {
  125. if( ! CHMPropertyPage::OnApply() )
  126. {
  127. return FALSE;
  128. }
  129. // v-marfin 62585 : So we can set the collector's state to enabled when OK pressed.
  130. m_bOnApplyUsed=TRUE;
  131. UpdateData();
  132. //---------------------------------------------------------------------
  133. // v-marfin : 61372 : show user err msgbox for any required field.
  134. /*if( m_sServer.IsEmpty() || m_sFrom.IsEmpty() || m_sTo.IsEmpty() ||
  135. m_sData.IsEmpty() || m_sTimeout.IsEmpty() )
  136. {
  137. return FALSE;
  138. }*/
  139. m_sServer.TrimRight();
  140. m_sServer.TrimLeft();
  141. if (m_sServer.IsEmpty())
  142. {
  143. AfxMessageBox(IDS_ERR_SMTP_REQ_SERVER);
  144. UpdateData(FALSE);
  145. GetDlgItem(IDC_EDIT_SERVER)->SetFocus();
  146. return FALSE;
  147. }
  148. m_sFrom.TrimRight();
  149. m_sFrom.TrimLeft();
  150. if (m_sFrom.IsEmpty())
  151. {
  152. AfxMessageBox(IDS_ERR_SMTP_REQ_FROM);
  153. UpdateData(FALSE);
  154. GetDlgItem(IDC_EDIT_FROM)->SetFocus();
  155. return FALSE;
  156. }
  157. m_sTo.TrimRight();
  158. m_sTo.TrimLeft();
  159. if (m_sTo.IsEmpty())
  160. {
  161. AfxMessageBox(IDS_ERR_SMTP_REQ_TO);
  162. UpdateData(FALSE);
  163. GetDlgItem(IDC_EDIT_TO)->SetFocus();
  164. return FALSE;
  165. }
  166. m_sData.TrimRight();
  167. m_sData.TrimLeft();
  168. if (m_sData.IsEmpty())
  169. {
  170. AfxMessageBox(IDS_ERR_SMTP_REQ_MESSAGE);
  171. UpdateData(FALSE);
  172. GetDlgItem(IDC_EDIT_DATA)->SetFocus();
  173. return FALSE;
  174. }
  175. m_sTimeout.TrimRight();
  176. m_sTimeout.TrimLeft();
  177. if (m_sTimeout.IsEmpty())
  178. {
  179. AfxMessageBox(IDS_ERR_SMTP_REQ_TIMEOUT);
  180. UpdateData(FALSE);
  181. GetDlgItem(IDC_EDIT_TIMEOUT)->SetFocus();
  182. return FALSE;
  183. }
  184. //---------------------------------------------------------------------
  185. CWbemClassObject* pClassObject = GetObjectPtr()->GetClassObject();
  186. if( ! GfxCheckObjPtr(pClassObject,CWbemClassObject) )
  187. {
  188. return FALSE;
  189. }
  190. HRESULT hr = S_OK;
  191. HMContextArray Arguments;
  192. CHMPolledMethodDataElementConfiguration::AddArgument(Arguments,GetObjectPtr()->GetSystemName(),_T("Server"),CIM_STRING,m_sServer);
  193. CHMPolledMethodDataElementConfiguration::AddArgument(Arguments,GetObjectPtr()->GetSystemName(),_T("From"),CIM_STRING,m_sFrom);
  194. CHMPolledMethodDataElementConfiguration::AddArgument(Arguments,GetObjectPtr()->GetSystemName(),_T("To"),CIM_STRING,m_sTo);
  195. CHMPolledMethodDataElementConfiguration::AddArgument(Arguments,GetObjectPtr()->GetSystemName(),_T("Subject"),CIM_STRING,m_sSubject);
  196. CHMPolledMethodDataElementConfiguration::AddArgument(Arguments,GetObjectPtr()->GetSystemName(),_T("Data"),CIM_STRING,m_sData);
  197. CHMPolledMethodDataElementConfiguration::AddArgument(Arguments,GetObjectPtr()->GetSystemName(),_T("Timeout"),CIM_UINT32,m_sTimeout);
  198. COleSafeArray arguments;
  199. CHMPolledMethodDataElementConfiguration::CopyArgsToSafeArray(Arguments,arguments);
  200. hr = pClassObject->SetProperty(IDS_STRING_MOF_ARGUMENTS,arguments);
  201. CHMPolledMethodDataElementConfiguration::DestroyArguments(Arguments);
  202. CString sNamespace = _T("root\\cimv2\\MicrosoftHealthmonitor");
  203. pClassObject->SetProperty(IDS_STRING_MOF_TARGETNAMESPACE,sNamespace);
  204. pClassObject->SetProperty(IDS_STRING_MOF_PATH,CString(_T("Microsoft_IPPExecution")));
  205. pClassObject->SetProperty(IDS_STRING_MOF_METHODNAME,CString(_T("ExecuteSMTP")));
  206. /* 63128
  207. CStringArray saProperties;
  208. saProperties.Add(_T("ResponseTime"));
  209. saProperties.Add(_T("OverallResultCode"));
  210. pClassObject->SetProperty(IDS_STRING_MOF_STATISTICSPROPERTYNAMES,saProperties);*/
  211. bool bReset = m_bRequireReset ? true : false;
  212. pClassObject->SetProperty(IDS_STRING_MOF_REQUIRERESET,bReset);
  213. pClassObject->SaveAllProperties();
  214. delete pClassObject;
  215. SetModified(FALSE);
  216. return TRUE;
  217. }
  218. void CDPSmtpPage::OnCheckRequireReset()
  219. {
  220. SetModified();
  221. }
  222. void CDPSmtpPage::OnChangeEditData()
  223. {
  224. // TODO: If this is a RICHEDIT control, the control will not
  225. // send this notification unless you override the CHMPropertyPage::OnInitDialog()
  226. // function and call CRichEditCtrl().SetEventMask()
  227. // with the ENM_CHANGE flag ORed into the mask.
  228. SetModified();
  229. }
  230. void CDPSmtpPage::OnChangeEditFrom()
  231. {
  232. // TODO: If this is a RICHEDIT control, the control will not
  233. // send this notification unless you override the CHMPropertyPage::OnInitDialog()
  234. // function and call CRichEditCtrl().SetEventMask()
  235. // with the ENM_CHANGE flag ORed into the mask.
  236. SetModified();
  237. }
  238. void CDPSmtpPage::OnChangeEditServer()
  239. {
  240. // TODO: If this is a RICHEDIT control, the control will not
  241. // send this notification unless you override the CHMPropertyPage::OnInitDialog()
  242. // function and call CRichEditCtrl().SetEventMask()
  243. // with the ENM_CHANGE flag ORed into the mask.
  244. SetModified();
  245. }
  246. void CDPSmtpPage::OnChangeEditTimeout()
  247. {
  248. // TODO: If this is a RICHEDIT control, the control will not
  249. // send this notification unless you override the CHMPropertyPage::OnInitDialog()
  250. // function and call CRichEditCtrl().SetEventMask()
  251. // with the ENM_CHANGE flag ORed into the mask.
  252. SetModified();
  253. }
  254. void CDPSmtpPage::OnChangeEditTo()
  255. {
  256. // TODO: If this is a RICHEDIT control, the control will not
  257. // send this notification unless you override the CHMPropertyPage::OnInitDialog()
  258. // function and call CRichEditCtrl().SetEventMask()
  259. // with the ENM_CHANGE flag ORed into the mask.
  260. SetModified();
  261. }
  262. void CDPSmtpPage::OnChangeEditSubject()
  263. {
  264. // TODO: If this is a RICHEDIT control, the control will not
  265. // send this notification unless you override the CHMPropertyPage::OnInitDialog()
  266. // function and call CRichEditCtrl().SetEventMask()
  267. // with the ENM_CHANGE flag ORed into the mask.
  268. SetModified();
  269. }
  270. void CDPSmtpPage::OnDestroy()
  271. {
  272. // v-marfin 62585 : For this new data collector, set its Enabled property to TRUE, but
  273. // only if the user is not cancelling these property pages.
  274. if (m_bOnApplyUsed)
  275. {
  276. ClearStatistics(); // 62548
  277. CDataElement* pElement = (CDataElement*)GetObjectPtr();
  278. if (pElement && pElement->IsStateSetToEnabledOnOK())
  279. {
  280. TRACE(_T("CDPSmtpPage::OnDestroy - New Perfmon Collector: Setting to Enabled\n"));
  281. pElement->SetStateToEnabledOnOK(FALSE); // don't do this again
  282. CWbemClassObject* pClassObject = GetObjectPtr()->GetClassObject();
  283. if( ! GfxCheckObjPtr(pClassObject,CWbemClassObject) )
  284. {
  285. TRACE(_T("ERROR: CDPSmtpPage::OnDestroy - Failed to GetClassObject()\n"));
  286. return;
  287. }
  288. // Set the new collector to enabled.
  289. BOOL bEnabled=TRUE;
  290. HRESULT hr = pClassObject->GetProperty(IDS_STRING_MOF_ENABLE,bEnabled);
  291. hr = pClassObject->SetProperty(IDS_STRING_MOF_ENABLE,TRUE);
  292. if (!CHECKHRESULT(hr))
  293. {
  294. TRACE(_T("ERROR: CDPPerfMonPage::OnOK - Failed to set ENABLED property on new collector\n"));
  295. }
  296. //-------------------------------------------------------------------
  297. // v-marfin 59237 : If the user has not changed the original default
  298. // name, do so for them. Compare against original
  299. // name we fetched during OnInitDialog.
  300. CString sName;
  301. pClassObject->GetProperty(IDS_STRING_MOF_NAME,sName);
  302. // Did the user change the default name?
  303. if (m_sOriginalName.CompareNoCase(sName)==0)
  304. {
  305. CString sObject;
  306. sObject.Format(IDS_STRING_FORMAT_SMTPNAME,m_sServer);
  307. // No, so set the new name
  308. if (!sObject.IsEmpty())
  309. {
  310. // Use parent to ensure name is unique
  311. //CDataGroup* pParent = (CDataGroup*) pElement->GetCollectorsParentClassObject();
  312. if(pElement->GetScopeItemCount())
  313. {
  314. CDataElementScopeItem* pItem = (CDataElementScopeItem*)pElement->GetScopeItem(0);
  315. if( pItem )
  316. {
  317. CDataGroupScopeItem* pDGItem = (CDataGroupScopeItem*)pItem->GetParent();
  318. sName = pDGItem->GetUniqueDisplayName(sObject);
  319. }
  320. }
  321. // Set the local element's object data
  322. pElement->SetName(sName);
  323. // Set its WMI property
  324. pClassObject->SetProperty(IDS_STRING_MOF_NAME,sName);
  325. // Refresh to show the new name in the IU
  326. //pElement->Refresh(); // 63005
  327. pElement->UpdateStatus(); // 63005
  328. }
  329. }
  330. //-------------------------------------------------------------------
  331. pClassObject->SaveAllProperties();
  332. delete pClassObject;
  333. } // if (pElement && pElement->IsStateSetToEnabledOnOK())
  334. } // if (m_bOnApplyUsed)
  335. CHMPropertyPage::OnDestroy();
  336. // v-marfin : bug 59643 : CnxPropertyPageDestory() must be called from this page's
  337. // OnDestroy function.
  338. CnxPropertyPageDestroy();
  339. }