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.

355 lines
11 KiB

  1. // DPComPlusPage.cpp : implementation file
  2. //
  3. // 03/05/00 v-marfin bug 59643 : Make this the default starting page.
  4. // 03/29/00 v-marfin bug 62585 : Set new Data collector's ENABLED to TRUE if user presses OK.
  5. // 03/30/00 v-marfin bug 59237 : If user does not change the default name of the data
  6. // collector when they first create it, change it for
  7. // them to a more meaningful name based on the data
  8. // they select in the property pages.
  9. // 04/07/00 v-marfin bug 63011 Changed path to Com+ namespace
  10. #include "stdafx.h"
  11. #include "snapin.h"
  12. #include "DPComPlusPage.h"
  13. #include "WMIBrowseDlg.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. // CDPComPlusPage property page
  24. IMPLEMENT_DYNCREATE(CDPComPlusPage, CHMPropertyPage)
  25. CDPComPlusPage::CDPComPlusPage() : CHMPropertyPage(CDPComPlusPage::IDD)
  26. {
  27. //{{AFX_DATA_INIT(CDPComPlusPage)
  28. m_sAppName = _T("");
  29. m_bRequireReset = FALSE;
  30. //}}AFX_DATA_INIT
  31. }
  32. CDPComPlusPage::~CDPComPlusPage()
  33. {
  34. }
  35. void CDPComPlusPage::UpdateProperties()
  36. {
  37. m_Properties.DeleteAllItems();
  38. CWbemClassObject classobject;
  39. CString sNamespace;
  40. sNamespace.Format(IDS_STRING_MOF_COMPLUS_NAMESPACE,GetObjectPtr()->GetSystemName()); // 63011b
  41. classobject.SetNamespace(sNamespace);
  42. HRESULT hr = classobject.GetObject(IDS_STRING_MOF_ACS_APPSTATS);
  43. if( hr != S_OK )
  44. {
  45. return;
  46. }
  47. CStringArray saNames;
  48. classobject.GetPropertyNames(saNames);
  49. classobject.Destroy();
  50. for( int i = 0; i < saNames.GetSize(); i++ )
  51. {
  52. m_Properties.InsertItem(0,saNames[i]);
  53. }
  54. m_Properties.SetColumnWidth(0,LVSCW_AUTOSIZE_USEHEADER);
  55. }
  56. void CDPComPlusPage::DoDataExchange(CDataExchange* pDX)
  57. {
  58. CHMPropertyPage::DoDataExchange(pDX);
  59. //{{AFX_DATA_MAP(CDPComPlusPage)
  60. DDX_Control(pDX, IDC_LIST_PROPERTIES, m_Properties);
  61. DDX_Text(pDX, IDC_EDIT_NAME, m_sAppName);
  62. DDX_Check(pDX, IDC_CHECK_REQUIRE_RESET, m_bRequireReset);
  63. //}}AFX_DATA_MAP
  64. }
  65. BEGIN_MESSAGE_MAP(CDPComPlusPage, CHMPropertyPage)
  66. //{{AFX_MSG_MAP(CDPComPlusPage)
  67. ON_BN_CLICKED(IDC_BUTTON_BROWSE_NAMESPACE, OnButtonBrowseNamespace)
  68. ON_WM_DESTROY()
  69. //}}AFX_MSG_MAP
  70. END_MESSAGE_MAP()
  71. /////////////////////////////////////////////////////////////////////////////
  72. // CDPComPlusPage message handlers
  73. void CDPComPlusPage::OnButtonBrowseNamespace()
  74. {
  75. CWmiInstanceBrowseDlg dlg;
  76. // set the dialog window title
  77. CString sItem;
  78. sItem.LoadString(IDS_STRING_INSTANCES);
  79. dlg.m_sDlgTitle.Format(IDS_STRING_WMI_BROWSE_TITLE,sItem,GetObjectPtr()->GetSystemName());
  80. // set the namespace
  81. CString sNamespace;
  82. sNamespace.Format(IDS_STRING_MOF_COMPLUS_NAMESPACE,GetObjectPtr()->GetSystemName()); // 63011b
  83. dlg.m_ClassObject.SetNamespace(sNamespace);
  84. BSTR bsTemp = ::SysAllocString(L"MicrosoftComPlus_AppName");
  85. if( ! CHECKHRESULT(dlg.m_ClassObject.CreateEnumerator(bsTemp)) )
  86. {
  87. ::SysFreeString(bsTemp);
  88. return;
  89. }
  90. ::SysFreeString(bsTemp);
  91. // set the listbox title
  92. dlg.m_sTitle.LoadString(IDS_STRING_COM_PLUS_APPS);
  93. // display the dialog
  94. if( dlg.DoModal() == IDOK )
  95. {
  96. m_sAppName = dlg.m_sSelectedItem;
  97. int iIndex = m_sAppName.Find(_T("\""));
  98. if( iIndex != -1 )
  99. {
  100. m_sAppName = m_sAppName.Right(m_sAppName.GetLength()-iIndex);
  101. m_sAppName.TrimLeft(_T("\""));
  102. m_sAppName.TrimRight(_T("\""));
  103. }
  104. UpdateData(FALSE);
  105. SetModified();
  106. }
  107. }
  108. BOOL CDPComPlusPage::OnInitDialog()
  109. {
  110. // v-marfin : bug 59643 : This will be the default starting page for the property
  111. // sheet so call CnxPropertyPageCreate() to unmarshal the
  112. // connection for this thread. This function must be called
  113. // by the first page of the property sheet. It used to
  114. // be called by the "General" page and its call still remains
  115. // there as well in case the general page is loaded by a
  116. // different code path that does not also load this page.
  117. // The CnxPropertyPageCreate function has been safeguarded
  118. // to simply return if the required call has already been made.
  119. // CnxPropertyPageDestory() must be called from this page's
  120. // OnDestroy function.
  121. // unmarshal connmgr
  122. CnxPropertyPageCreate();
  123. CHMPropertyPage::OnInitDialog();
  124. // initialize the list view
  125. m_Properties.SetExtendedStyle(LVS_EX_CHECKBOXES);
  126. CString sColumnTitle;
  127. sColumnTitle.LoadString(IDS_STRING_NAME);
  128. m_Properties.InsertColumn(0,sColumnTitle);
  129. UpdateProperties();
  130. CWbemClassObject* pClassObject = GetObjectPtr()->GetClassObject();
  131. if( ! GfxCheckObjPtr(pClassObject,CWbemClassObject) )
  132. {
  133. return TRUE;
  134. }
  135. //-------------------------------------------------------------------------
  136. // v-marfin 59237 : Store original name in case this data collector is
  137. // just being created. When they save, we will modify the
  138. // name if they haven't.
  139. pClassObject->GetProperty(IDS_STRING_MOF_NAME,m_sOriginalName);
  140. //-------------------------------------------------------------------------
  141. pClassObject->GetProperty(IDS_STRING_MOF_PATH,m_sAppName);
  142. int iIndex = m_sAppName.Find(_T("AppName="));
  143. if( iIndex != -1 )
  144. {
  145. m_sAppName = m_sAppName.Right(m_sAppName.GetLength()-iIndex-8);
  146. iIndex = m_sAppName.Find(_T(","));
  147. if( iIndex != -1 )
  148. {
  149. m_sAppName = m_sAppName.Left(iIndex);
  150. }
  151. m_sAppName.TrimLeft(_T("\""));
  152. m_sAppName.TrimRight(_T("\""));
  153. }
  154. CStringArray saProperties;
  155. pClassObject->GetProperty(IDS_STRING_MOF_STATISTICSPROPERTYNAMES,saProperties);
  156. for( int i=0; i < saProperties.GetSize(); i++ )
  157. {
  158. LVFINDINFO lvfi;
  159. ZeroMemory(&lvfi,sizeof(LVFINDINFO));
  160. lvfi.flags = LVFI_WRAP|LVFI_STRING;
  161. lvfi.psz = saProperties[i];
  162. int iListIndex = m_Properties.FindItem(&lvfi);
  163. if( iListIndex >= 0 )
  164. {
  165. m_Properties.SetCheck(iListIndex);
  166. }
  167. }
  168. delete pClassObject;
  169. UpdateData(FALSE);
  170. return TRUE; // return TRUE unless you set the focus to a control
  171. // EXCEPTION: OCX Property Pages should return FALSE
  172. }
  173. BOOL CDPComPlusPage::OnApply()
  174. {
  175. if( ! CHMPropertyPage::OnApply() )
  176. {
  177. return FALSE;
  178. }
  179. // v-marfin 62585 : So we can set the collector's state to enabled when OK pressed.
  180. m_bOnApplyUsed=TRUE;
  181. UpdateData();
  182. CWbemClassObject* pClassObject = GetObjectPtr()->GetClassObject();
  183. if( ! GfxCheckObjPtr(pClassObject,CWbemClassObject) )
  184. {
  185. return TRUE;
  186. }
  187. // 63011 : Change path
  188. // pClassObject->SetProperty(IDS_STRING_MOF_TARGETNAMESPACE,CString(_T("\\\\.\\root\\cimv2\\applications\\MicrosoftACS")));
  189. // 63011b
  190. CString sNamespace;
  191. sNamespace.Format(IDS_STRING_MOF_COMPLUS_NAMESPACE,GetObjectPtr()->GetSystemName());
  192. // 63011b pClassObject->SetProperty(IDS_STRING_MOF_TARGETNAMESPACE,CString(_T("\\\\.\\root\\cimv2\\MicrosoftHealthmonitor")));
  193. pClassObject->SetProperty(IDS_STRING_MOF_TARGETNAMESPACE,sNamespace);
  194. CString sPath;
  195. sPath.Format(IDS_STRING_MOF_ACS_APPSTATS_FMT,m_sAppName,180);
  196. pClassObject->SetProperty(IDS_STRING_MOF_PATH,sPath);
  197. CStringArray saProperties;
  198. for( int i = 0; i < m_Properties.GetItemCount(); i++ )
  199. {
  200. if( m_Properties.GetCheck(i) )
  201. {
  202. saProperties.Add(m_Properties.GetItemText(i,0));
  203. }
  204. }
  205. pClassObject->SetProperty(IDS_STRING_MOF_STATISTICSPROPERTYNAMES,saProperties);
  206. bool bReset = m_bRequireReset ? true : false;
  207. pClassObject->SetProperty(IDS_STRING_MOF_REQUIRERESET,bReset);
  208. pClassObject->SaveAllProperties();
  209. delete pClassObject;
  210. SetModified(FALSE);
  211. return TRUE;
  212. }
  213. void CDPComPlusPage::OnDestroy()
  214. {
  215. // v-marfin 62585 : For this new data collector, set its Enabled property to TRUE, but
  216. // only if the user is not cancelling these property pages.
  217. if (m_bOnApplyUsed)
  218. {
  219. ClearStatistics(); // 62548
  220. CDataElement* pElement = (CDataElement*)GetObjectPtr();
  221. if (pElement && pElement->IsStateSetToEnabledOnOK())
  222. {
  223. TRACE(_T("CDPComPlusPage::OnDestroy - New Perfmon Collector: Setting to Enabled\n"));
  224. pElement->SetStateToEnabledOnOK(FALSE); // don't do this again
  225. CWbemClassObject* pClassObject = GetObjectPtr()->GetClassObject();
  226. if( ! GfxCheckObjPtr(pClassObject,CWbemClassObject) )
  227. {
  228. TRACE(_T("ERROR: CDPComPlusPage::OnDestroy - Failed to GetClassObject()\n"));
  229. return;
  230. }
  231. // Set the new collector to enabled.
  232. BOOL bEnabled=TRUE;
  233. HRESULT hr = pClassObject->GetProperty(IDS_STRING_MOF_ENABLE,bEnabled);
  234. hr = pClassObject->SetProperty(IDS_STRING_MOF_ENABLE,TRUE);
  235. if (!CHECKHRESULT(hr))
  236. {
  237. TRACE(_T("ERROR: CDPComPlusPage::OnDestroy - Failed to set ENABLED property on new collector\n"));
  238. }
  239. //-------------------------------------------------------------------
  240. // v-marfin 59237 : If the user has not changed the original default
  241. // name, do so for them. Compare against original
  242. // name we fetched during OnInitDialog.
  243. CString sName;
  244. pClassObject->GetProperty(IDS_STRING_MOF_NAME,sName);
  245. // Did the user change the default name?
  246. if (m_sOriginalName.CompareNoCase(sName)==0)
  247. {
  248. // No, so set the new name
  249. if (!m_sAppName.IsEmpty())
  250. {
  251. // Use parent to ensure name is unique
  252. //CDataGroup* pParent = (CDataGroup*) pElement->GetCollectorsParentClassObject();
  253. if(pElement->GetScopeItemCount())
  254. {
  255. CDataElementScopeItem* pItem = (CDataElementScopeItem*)pElement->GetScopeItem(0);
  256. if( pItem )
  257. {
  258. CDataGroupScopeItem* pDGItem = (CDataGroupScopeItem*)pItem->GetParent();
  259. sName = pDGItem->GetUniqueDisplayName(m_sAppName);
  260. }
  261. }
  262. // Set the local element's object data
  263. pElement->SetName(sName);
  264. // Set its WMI property
  265. pClassObject->SetProperty(IDS_STRING_MOF_NAME,sName);
  266. // Refresh to show the new name in the IU
  267. //pElement->Refresh(); // 63005
  268. pElement->UpdateStatus(); // 63005
  269. }
  270. }
  271. //-------------------------------------------------------------------
  272. pClassObject->SaveAllProperties();
  273. delete pClassObject;
  274. } // if (pElement && pElement->IsStateSetToEnabledOnOK())
  275. } // if (m_bOnApplyUsed)
  276. CHMPropertyPage::OnDestroy();
  277. // v-marfin : bug 59643 : CnxPropertyPageDestory() must be called from this page's
  278. // OnDestroy function.
  279. CnxPropertyPageDestroy();
  280. }