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.

420 lines
14 KiB

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