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.

1068 lines
31 KiB

  1. /*---------------------------------------------------------------------------
  2. File: AgentDetailDlg.cpp
  3. Comments: This dialog shows the status of the agent on a single machine:
  4. It can work in one of 3 ways:
  5. 1) COM connection to the running agent on the local machine
  6. 2) DCOM connection to a running agent on another machine (this is done
  7. with help from the agent service)
  8. 3) For a remote agent that has finished, it can show the final stats,
  9. as recorded in the agent's result file.
  10. (c) Copyright 1999, Mission Critical Software, Inc., All Rights Reserved
  11. Proprietary and confidential to Mission Critical Software, Inc.
  12. REVISION LOG ENTRY
  13. Revision By: Christy Boles
  14. ---------------------------------------------------------------------------
  15. */// AgentDetail.cpp : implementation file
  16. //
  17. #include "stdafx.h"
  18. #include "resource.h"
  19. #include "DetDlg.h"
  20. #include "Common.hpp"
  21. #include "AgRpcUtl.h"
  22. #include "Monitor.h"
  23. #include "ResStr.h"
  24. //#include "..\AgtSvc\AgSvc.h"
  25. #include "AgSvc.h"
  26. #include "AgSvc_c.c"
  27. //#import "\bin\McsEADCTAgent.tlb" no_namespace , named_guids
  28. //#import "\bin\McsVarSetMin.tlb" no_namespace
  29. //#import "Engine.tlb" no_namespace, named_guids //already #imported via DetDlg.h
  30. #import "VarSet.tlb" no_namespace rename("property", "aproperty")
  31. #ifdef _DEBUG
  32. #define new DEBUG_NEW
  33. #undef THIS_FILE
  34. static char THIS_FILE[] = __FILE__;
  35. #endif
  36. HWND gSubWnd = NULL;
  37. BOOL bDetailDone = FALSE;
  38. int detailInterval = 0;
  39. extern BOOL gbCancelled;
  40. /////////////////////////////////////////////////////////////////////////////
  41. // CAgentDetailDlg dialog
  42. CAgentDetailDlg::CAgentDetailDlg(CWnd* pParent /*=NULL*/)
  43. : CDialog(CAgentDetailDlg::IDD, pParent)
  44. {
  45. //{{AFX_DATA_INIT(CAgentDetailDlg)
  46. m_Current = _T("");
  47. m_Status = _T("");
  48. m_FilesChanged = _T("0");
  49. m_FilesExamined = _T("0");
  50. m_FilesUnchanged = _T("0");
  51. m_DirectoriesChanged = _T("0");
  52. m_DirectoriesExamined = _T("0");
  53. m_DirectoriesUnchanged = _T("0");
  54. m_SharesChanged = _T("0");
  55. m_SharesExamined = _T("0");
  56. m_SharesUnchanged = _T("0");
  57. m_Operation = _T("");
  58. m_RefreshRate = _T("5");
  59. //}}AFX_DATA_INIT
  60. m_DirectoryLabelText.LoadString(IDS_DirectoriesLabel);
  61. m_FilesLabelText.LoadString(IDS_FilesLabel);
  62. m_SharesLabelText.LoadString(IDS_SharesLabel);
  63. m_ChangedLabel.LoadString(IDS_ChangedLabel);
  64. m_ExaminedLabel.LoadString(IDS_ExaminedLabel);
  65. m_UnchangedLabel.LoadString(IDS_UnchangedLabel);
  66. m_pNode = NULL;
  67. detailInterval = _wtoi(m_RefreshRate);
  68. m_bCoInitialized = FALSE;
  69. m_format = 0;
  70. m_AgentAlive = FALSE;
  71. m_StatusUnknown = FALSE;
  72. m_hBinding = 0;
  73. m_pStats = NULL;
  74. m_bGatheringInfo = FALSE;
  75. m_bAutoHide = FALSE;
  76. m_bAutoClose = FALSE;
  77. m_bAlwaysEnableClose = TRUE;
  78. }
  79. ULONG __stdcall RefreshThread(void * arg)
  80. {
  81. do {
  82. PostMessage(gSubWnd,DCT_DETAIL_REFRESH,NULL,NULL);
  83. Sleep(detailInterval*1000);
  84. }
  85. while (! bDetailDone);
  86. return 0;
  87. }
  88. void CAgentDetailDlg::DoDataExchange(CDataExchange* pDX)
  89. {
  90. CDialog::DoDataExchange(pDX);
  91. //{{AFX_DATA_MAP(CAgentDetailDlg)
  92. DDX_Control(pDX, IDC_STOPAGENT, m_StopAgentButton);
  93. DDX_Control(pDX, IDC_BTNREFRESH, m_RefreshButton);
  94. DDX_Control(pDX, IDC_VIEW_LOG, m_ViewLogButton);
  95. DDX_Control(pDX, IDC_PLUG_IN_RESULTS, m_PlugInButton);
  96. DDX_Control(pDX, IDOK, m_OKButton);
  97. DDX_Control(pDX, IDC_UnchangedLabel, m_UnchangedLabelStatic);
  98. DDX_Control(pDX, IDC_SharesLabel, m_SharesStatic);
  99. DDX_Control(pDX, IDC_FilesLabel, m_FilesStatic);
  100. DDX_Control(pDX, IDC_ExaminedLabel, m_ExaminedStatic);
  101. DDX_Control(pDX, IDC_DirectoriesLabel, m_DirStatic);
  102. DDX_Control(pDX, IDC_ChangedLabel, m_ChangedStatic);
  103. DDX_Text(pDX, IDC_CURRENT, m_Current);
  104. DDX_Text(pDX, IDC_STATUS, m_Status);
  105. DDX_Text(pDX, IDC_FilesChanged, m_FilesChanged);
  106. DDX_Text(pDX, IDC_FilesExamined, m_FilesExamined);
  107. DDX_Text(pDX, IDC_FilesU, m_FilesUnchanged);
  108. DDX_Text(pDX, IDC_DirsChanged, m_DirectoriesChanged);
  109. DDX_Text(pDX, IDC_DirsExamined, m_DirectoriesExamined);
  110. DDX_Text(pDX, IDC_DirsU, m_DirectoriesUnchanged);
  111. DDX_Text(pDX, IDC_SharesChanged, m_SharesChanged);
  112. DDX_Text(pDX, IDC_SharesExamined, m_SharesExamined);
  113. DDX_Text(pDX, IDC_SharesU, m_SharesUnchanged);
  114. DDX_Text(pDX, IDC_DirectoriesLabel, m_DirectoryLabelText);
  115. DDX_Text(pDX, IDC_FilesLabel, m_FilesLabelText);
  116. DDX_Text(pDX, IDC_OPERATION, m_Operation);
  117. DDX_Text(pDX, IDC_SharesLabel, m_SharesLabelText);
  118. DDX_Text(pDX, IDC_ChangedLabel, m_ChangedLabel);
  119. DDX_Text(pDX, IDC_ExaminedLabel, m_ExaminedLabel);
  120. DDX_Text(pDX, IDC_UnchangedLabel, m_UnchangedLabel);
  121. DDX_Text(pDX, IDC_EDIT2, m_RefreshRate);
  122. //}}AFX_DATA_MAP
  123. }
  124. BEGIN_MESSAGE_MAP(CAgentDetailDlg, CDialog)
  125. //{{AFX_MSG_MAP(CAgentDetailDlg)
  126. ON_WM_NCPAINT()
  127. ON_BN_CLICKED(IDC_BTNREFRESH, OnRefresh)
  128. ON_EN_CHANGE(IDC_EDIT2, OnChangeEdit2)
  129. ON_BN_CLICKED(IDC_STOPAGENT, OnStopAgent)
  130. ON_BN_CLICKED(IDC_VIEW_LOG, OnViewLog)
  131. ON_BN_CLICKED(IDC_PLUG_IN_RESULTS, OnPlugInResults)
  132. ON_WM_CLOSE()
  133. //}}AFX_MSG_MAP
  134. ON_MESSAGE(DCT_DETAIL_REFRESH, DoRefresh)
  135. END_MESSAGE_MAP()
  136. /////////////////////////////////////////////////////////////////////////////
  137. // CAgentDetailDlg message handlers
  138. BOOL CAgentDetailDlg::OnInitDialog()
  139. {
  140. CDialog::OnInitDialog();
  141. CString title;
  142. if ( m_JobGuid.length() )
  143. {
  144. // connect to local agent
  145. title.LoadString(IDS_PROGRESS_TITLE);
  146. }
  147. else
  148. {
  149. // connect to agent service on remote machine
  150. if ( ! m_pNode )
  151. {
  152. // if not auto closing display message box
  153. if (!m_bAutoClose)
  154. {
  155. CString message;
  156. message.LoadString(IDS_ServerNotFound);
  157. MessageBox(message);
  158. }
  159. OnOK();
  160. }
  161. m_ServerName = m_pNode->GetServer();
  162. title.FormatMessage(IDS_ServerAgentProgressTitle,m_ServerName);
  163. }
  164. SetWindowText(title);
  165. UpdateData(FALSE);
  166. //If not AR operation, set the flag to enable the close button
  167. if (m_format != 1)
  168. m_bAlwaysEnableClose = TRUE;
  169. else
  170. m_bAlwaysEnableClose = FALSE;
  171. switch (m_format)
  172. {
  173. // set the format to -1 to force a change
  174. case -1: m_format = -2; SetupOtherFormat(); break;
  175. case 0: m_format = -2; SetupFSTFormat();break;
  176. case 1: m_format = -2; SetupAcctReplFormat(); break;
  177. case 2: m_format = -2; SetupESTFormat(); break;
  178. };
  179. gSubWnd = m_hWnd;
  180. if ( m_pStats && (m_format>0) )
  181. {
  182. bDetailDone = TRUE;
  183. GetDlgItem(IDC_BTNREFRESH)->EnableWindow(FALSE);
  184. GetDlgItem(IDC_EDIT2)->EnableWindow(FALSE);
  185. GetDlgItem(IDC_REFRESH_LABEL)->EnableWindow(FALSE);
  186. GetDlgItem(IDC_STOPAGENT)->EnableWindow(FALSE);
  187. m_OKButton.EnableWindow(TRUE);
  188. // the agent has finished, show files, directories, and shares
  189. m_FilesExamined.Format(L"%ld",m_pStats->filesExamined);
  190. m_FilesChanged.Format(L"%ld",m_pStats->filesChanged);
  191. m_FilesUnchanged.Format(L"%ld",m_pStats->filesUnchanged);
  192. m_DirectoriesExamined.Format(L"%ld",m_pStats->directoriesExamined);
  193. m_DirectoriesChanged.Format(L"%ld",m_pStats->directoriesChanged);
  194. m_DirectoriesUnchanged.Format(L"%ld",m_pStats->directoriesUnchanged);
  195. m_SharesExamined.Format(L"%ld",m_pStats->sharesExamined);
  196. m_SharesChanged.Format(L"%ld",m_pStats->sharesChanged);
  197. m_SharesUnchanged.Format(L"%ld",m_pStats->sharesUnchanged);
  198. m_Status.LoadString(IDS_StatusCompleted);
  199. if ( m_PlugInText.GetLength() )
  200. {
  201. //Permanently hide the plug-in button, since our plug-ins
  202. // don't show any useful text
  203. // m_PlugInButton.ShowWindow(SW_SHOW);
  204. }
  205. UpdateData(FALSE);
  206. // if auto closing dialog
  207. if (m_bAutoClose)
  208. {
  209. OnOK();
  210. }
  211. }
  212. else
  213. {
  214. bDetailDone = FALSE;
  215. m_hBinding = NULL;
  216. DWORD threadID;
  217. HANDLE h = CreateThread(NULL,0,&RefreshThread,NULL,0,&threadID);
  218. CloseHandle(h);
  219. //hide the close button until the agent is done or stopped unless the flag is set
  220. //due to running this dialog for account replication
  221. if (m_bAlwaysEnableClose)
  222. m_OKButton.EnableWindow(TRUE);
  223. else
  224. m_OKButton.EnableWindow(FALSE);
  225. }
  226. return TRUE; // return TRUE unless you set the focus to a control
  227. // EXCEPTION: OCX Property Pages should return FALSE
  228. }
  229. DWORD
  230. DoRpcQuery(
  231. HANDLE hBinding, // in - handle to RPC binding
  232. LPUNKNOWN * ppUnk // out- pointer to remote agent COM object
  233. )
  234. {
  235. DWORD rc = 0;
  236. RpcTryExcept
  237. {
  238. rc = EaxcQueryInterface(hBinding,ppUnk);
  239. }
  240. RpcExcept(1)
  241. {
  242. rc = RpcExceptionCode();
  243. }
  244. RpcEndExcept
  245. if ( rc )
  246. {
  247. (*ppUnk ) = NULL;
  248. }
  249. return rc;
  250. }
  251. void CAgentDetailDlg::SetupAcctReplFormat()
  252. {
  253. // Changes the labels to reflect pertinent information when copying accounts
  254. UpdateData(TRUE);
  255. if ( m_format != 1 )
  256. {
  257. m_ChangedLabel.LoadString(IDS_AccountCopiedLabel);
  258. m_UnchangedLabel.LoadString(IDS_AccountErrorsLabel);
  259. m_FilesLabelText.LoadString(IDS_AccountUsersLabel);
  260. m_DirectoryLabelText.LoadString(IDS_AccountGroupsLabel);
  261. m_SharesLabelText.LoadString(IDS_AccountComputersLabel);
  262. m_format = 1;
  263. }
  264. UpdateData(FALSE);
  265. }
  266. void CAgentDetailDlg::SetupFSTFormat()
  267. {
  268. // Changes the labels to reflect pertinent information when translating security
  269. UpdateData(TRUE);
  270. if ( m_format != 0 )
  271. {
  272. if ( m_bGatheringInfo )
  273. {
  274. m_ChangedLabel.LoadString(IDS_Affected);
  275. m_UnchangedLabel.LoadString(IDS_Unaffected);
  276. }
  277. else
  278. {
  279. m_ChangedLabel.LoadString(IDS_ChangedLabel);
  280. m_UnchangedLabel.LoadString(IDS_UnchangedLabel);
  281. }
  282. m_FilesLabelText.LoadString(IDS_FilesLabel);
  283. m_DirectoryLabelText.LoadString(IDS_DirectoriesLabel);
  284. m_SharesLabelText.LoadString(IDS_SharesLabel);
  285. m_format = 0;
  286. }
  287. UpdateData(FALSE);
  288. }
  289. void CAgentDetailDlg::SetupESTFormat()
  290. {
  291. // Changes the labels to reflect pertinent information when translating exchange security
  292. UpdateData(TRUE);
  293. if ( m_format != 2 )
  294. {
  295. m_ChangedLabel.LoadString(IDS_ChangedLabel);
  296. m_UnchangedLabel.LoadString(IDS_UnchangedLabel);
  297. m_FilesLabelText.LoadString(IDS_MailboxesLabel);
  298. m_DirectoryLabelText.LoadString(IDS_ContainersLabel);
  299. m_SharesLabelText.Empty();
  300. m_format = 2;
  301. }
  302. UpdateData(FALSE);
  303. }
  304. void CAgentDetailDlg::SetupOtherFormat()
  305. {
  306. // Changes the labels to reflect pertinent information when translating exchange security
  307. UpdateData(TRUE);
  308. if ( m_format != -1 )
  309. {
  310. m_ExaminedLabel.Empty();
  311. m_ChangedLabel.Empty();
  312. m_UnchangedLabel.Empty();
  313. m_FilesLabelText.Empty();
  314. m_DirectoryLabelText.Empty();
  315. m_SharesLabelText.Empty();
  316. m_FilesExamined.Empty();
  317. m_DirectoriesExamined.Empty();
  318. m_SharesExamined.Empty();
  319. m_FilesChanged.Empty();
  320. m_DirectoriesChanged.Empty();
  321. m_SharesChanged.Empty();
  322. m_FilesUnchanged.Empty();
  323. m_DirectoriesUnchanged.Empty();
  324. m_SharesUnchanged.Empty();
  325. m_format = -1;
  326. }
  327. UpdateData(FALSE);
  328. }
  329. void CAgentDetailDlg::OnRefresh()
  330. {
  331. DWORD rc = 0;
  332. HRESULT hr = S_OK;
  333. WCHAR * sBinding = NULL;
  334. IUnknown * pUnk = NULL;
  335. IVarSetPtr pVarSet;
  336. _bstr_t jobID;
  337. try {
  338. if ( m_pNode )
  339. {
  340. jobID = m_pNode->GetJobID();
  341. }
  342. else
  343. {
  344. jobID = m_JobGuid;
  345. }
  346. m_AgentAlive = FALSE;
  347. m_StatusUnknown = FALSE;
  348. UpdateData(TRUE);
  349. if ( m_pAgent == NULL )
  350. {
  351. if ( m_pNode )
  352. {
  353. WCHAR server[40];
  354. server[0] = L'\\';
  355. server[1] = L'\\';
  356. UStrCpy(server+2,m_pNode->GetServer());
  357. rc = EaxBindCreate(server,&m_hBinding,&sBinding,TRUE);
  358. if ( ! rc )
  359. {
  360. if ( ! m_bCoInitialized )
  361. {
  362. hr = CoInitialize(NULL);
  363. m_bCoInitialized = TRUE;
  364. }
  365. if ( SUCCEEDED(hr) )
  366. {
  367. pUnk = NULL;
  368. rc = DoRpcQuery(m_hBinding,&pUnk);
  369. }
  370. else
  371. {
  372. rc = hr;
  373. }
  374. if ( (!rc) && pUnk )
  375. {
  376. try {
  377. m_pAgent = pUnk;
  378. }
  379. catch(_com_error * e)
  380. {
  381. m_StatusUnknown = TRUE;
  382. // if not auto closing display message box
  383. if (!m_bAutoClose)
  384. {
  385. MessageBox(e->Description());
  386. }
  387. }
  388. catch(...)
  389. {
  390. pUnk = NULL;
  391. }
  392. if ( pUnk )
  393. pUnk->Release();
  394. }
  395. else
  396. {
  397. if ( rc == RPC_S_SERVER_UNAVAILABLE )
  398. {
  399. m_Status.LoadString(IDS_AgentNotRunning);
  400. }
  401. else if ( rc == E_NOTIMPL )
  402. {
  403. m_StatusUnknown = TRUE;
  404. m_Status.LoadString(IDS_CantMonitorOnNt351);
  405. }
  406. else
  407. {
  408. m_StatusUnknown = TRUE;
  409. m_Status.LoadString(IDS_CannotConnectToAgent);
  410. }
  411. }
  412. }
  413. else
  414. {
  415. m_StatusUnknown = TRUE;
  416. m_Status.LoadString(IDS_RPCBindFailed);
  417. }
  418. if ( m_StatusUnknown || rc )
  419. {
  420. // if we couldn't connect to the agent, check to see if there is a result file
  421. // we can get our data from instead
  422. if ( m_pNode->IsFinished() && *m_pNode->GetJobFile() )
  423. {
  424. DetailStats detailStats;
  425. WCHAR directory[MAX_PATH];
  426. WCHAR filename[MAX_PATH];
  427. CString plugInText;
  428. gData.GetResultDir(directory);
  429. memset(&detailStats,0,(sizeof detailStats));
  430. swprintf(filename,GET_STRING(IDS_AgentResultFileFmt),m_pNode->GetJobFile());
  431. if ( SUCCEEDED(CoInitialize(NULL)) )
  432. {
  433. if ( ReadResults(m_pNode,directory,filename,&detailStats,plugInText,FALSE) )
  434. {
  435. SetStats(&detailStats);
  436. SetPlugInText(plugInText);
  437. bDetailDone = TRUE;
  438. GetDlgItem(IDC_BTNREFRESH)->EnableWindow(FALSE);
  439. GetDlgItem(IDC_EDIT2)->EnableWindow(FALSE);
  440. GetDlgItem(IDC_REFRESH_LABEL)->EnableWindow(FALSE);
  441. GetDlgItem(IDC_STOPAGENT)->EnableWindow(FALSE);
  442. // the agent has finished, show files, directories, and shares
  443. m_FilesExamined.Format(L"%ld",m_pStats->filesExamined);
  444. m_FilesChanged.Format(L"%ld",m_pStats->filesChanged);
  445. m_FilesUnchanged.Format(L"%ld",m_pStats->filesUnchanged);
  446. m_DirectoriesExamined.Format(L"%ld",m_pStats->directoriesExamined);
  447. m_DirectoriesChanged.Format(L"%ld",m_pStats->directoriesChanged);
  448. m_DirectoriesUnchanged.Format(L"%ld",m_pStats->directoriesUnchanged);
  449. m_SharesExamined.Format(L"%ld",m_pStats->sharesExamined);
  450. m_SharesChanged.Format(L"%ld",m_pStats->sharesChanged);
  451. m_SharesUnchanged.Format(L"%ld",m_pStats->sharesUnchanged);
  452. m_Status.LoadString(IDS_StatusCompleted);
  453. if ( m_PlugInText.GetLength() )
  454. {
  455. // Permanently hide the plug-in button, because our plug-ins don't
  456. // show any useful text.
  457. // m_PlugInButton.ShowWindow(SW_SHOW);
  458. }
  459. UpdateData(FALSE);
  460. }
  461. CoUninitialize();
  462. }
  463. }
  464. }
  465. }
  466. else
  467. {
  468. // local agent
  469. if ( ! m_bCoInitialized )
  470. {
  471. hr = CoInitialize(NULL);
  472. m_bCoInitialized = TRUE;
  473. }
  474. if ( SUCCEEDED(hr) )
  475. {
  476. hr = m_pAgent.GetActiveObject(CLSID_DCTAgent);
  477. if ( FAILED(hr) )
  478. {
  479. if ( hr == MK_E_UNAVAILABLE )
  480. {
  481. m_Status.LoadString(IDS_AgentNotRunning);
  482. }
  483. else
  484. {
  485. m_Status.FormatMessage(IDS_NoActiveAgent,hr);
  486. }
  487. }
  488. }
  489. }
  490. }
  491. if ( m_pAgent != NULL )
  492. {
  493. hr = m_pAgent->raw_QueryJobStatus(jobID,&pUnk);
  494. if ( SUCCEEDED(hr) && pUnk )
  495. {
  496. m_AgentAlive = TRUE;
  497. pVarSet = pUnk;
  498. pUnk->Release();
  499. _bstr_t text = pVarSet->get(GET_BSTR(DCTVS_JobStatus));
  500. m_Status = (LPCWSTR)text;
  501. text = pVarSet->get(GET_BSTR(DCTVS_CurrentPath));
  502. m_Current = (LPCWSTR)text;
  503. text = pVarSet->get(GET_BSTR(DCTVS_CurrentOperation));
  504. m_Operation = (LPCWSTR)text;
  505. // Get the stats
  506. LONG num1,num2,num3,num4;
  507. UpdateData(FALSE);
  508. if ( !UStrICmp(m_Operation,GET_STRING(IDS_ACCT_REPL_OPERATION_TEXT)) )
  509. {
  510. // Set up the labels for account replication
  511. SetupAcctReplFormat();
  512. }
  513. else if ( !UStrICmp(m_Operation,GET_STRING(IDS_FST_OPERATION_TEXT)) )
  514. {
  515. SetupFSTFormat();
  516. }
  517. else if ( ! UStrICmp(m_Operation,GET_STRING(IDS_EST_OPERATION_TEXT)) )
  518. {
  519. SetupESTFormat();
  520. }
  521. else
  522. {
  523. if ( m_Current.GetLength() &&
  524. ( _wtoi(m_FilesExamined) + _wtoi(m_DirectoriesExamined) + _wtoi(m_SharesExamined)) == 0 )
  525. {
  526. // unless some stats have already been collected, hide the stats, if the operation
  527. // is not one that we have detailed stats for.
  528. SetupOtherFormat();
  529. }
  530. }
  531. switch ( m_format )
  532. {
  533. case 0: // FST
  534. num1 = pVarSet->get(GET_BSTR(DCTVS_Stats_Files_Examined));
  535. num2 = pVarSet->get(GET_BSTR(DCTVS_Stats_Files_Changed));
  536. m_FilesExamined.Format(L"%ld",num1);
  537. if ( ! m_bGatheringInfo )
  538. {
  539. m_FilesChanged.Format(L"%ld",num2);
  540. m_FilesUnchanged.Format(L"%ld",num1-num2);
  541. }
  542. else
  543. {
  544. m_FilesChanged.Empty();
  545. m_FilesUnchanged.Empty();
  546. }
  547. num1 = pVarSet->get(GET_BSTR(DCTVS_Stats_Directories_Examined));
  548. num2 = pVarSet->get(GET_BSTR(DCTVS_Stats_Directories_Changed));
  549. m_DirectoriesExamined.Format(L"%ld",num1);
  550. if ( ! m_bGatheringInfo )
  551. {
  552. m_DirectoriesChanged.Format(L"%ld",num2);
  553. m_DirectoriesUnchanged.Format(L"%ld",num1-num2);
  554. }
  555. else
  556. {
  557. m_DirectoriesChanged.Empty();
  558. m_DirectoriesUnchanged.Empty();
  559. }
  560. num1 = pVarSet->get(GET_BSTR(DCTVS_Stats_Shares_Examined));
  561. num2 = pVarSet->get(GET_BSTR(DCTVS_Stats_Shares_Changed));
  562. m_SharesExamined.Format(L"%ld",num1);
  563. if ( ! m_bGatheringInfo )
  564. {
  565. m_SharesChanged.Format(L"%ld",num2);
  566. m_SharesUnchanged.Format(L"%ld",num1-num2);
  567. }
  568. else
  569. {
  570. m_SharesChanged.Empty();
  571. m_SharesUnchanged.Empty();
  572. }
  573. break;
  574. case 1: // AcctRepl
  575. // files = user accounts
  576. // dirs = global groups + local groups
  577. // shares = computer accounts
  578. // examined = processed
  579. // changed = created + replaced
  580. // unchanged = errors
  581. // User stats
  582. num1 = pVarSet->get(GET_BSTR(DCTVS_Stats_Users_Examined));
  583. num2 = pVarSet->get(GET_BSTR(DCTVS_Stats_Users_Created));
  584. num3 = pVarSet->get(GET_BSTR(DCTVS_Stats_Users_Replaced));
  585. num4 = pVarSet->get(GET_BSTR(DCTVS_Stats_Users_Errors));
  586. m_FilesExamined.Format(L"%ld",num1);
  587. m_FilesChanged.Format(L"%ld",num2+num3);
  588. m_FilesUnchanged.Format(L"%ld",num4);
  589. // Global group stats
  590. num1 = pVarSet->get(GET_BSTR(DCTVS_Stats_GlobalGroups_Examined));
  591. num2 = pVarSet->get(GET_BSTR(DCTVS_Stats_GlobalGroups_Created));
  592. num3 = pVarSet->get(GET_BSTR(DCTVS_Stats_GlobalGroups_Replaced));
  593. num4 = pVarSet->get(GET_BSTR(DCTVS_Stats_GlobalGroups_Errors));
  594. // local group stats
  595. LONG num5, num6,num7, num8;
  596. num5 = pVarSet->get(GET_BSTR(DCTVS_Stats_LocalGroups_Examined));
  597. num6 = pVarSet->get(GET_BSTR(DCTVS_Stats_LocalGroups_Created));
  598. num7 = pVarSet->get(GET_BSTR(DCTVS_Stats_LocalGroups_Replaced));
  599. num8 = pVarSet->get(GET_BSTR(DCTVS_Stats_LocalGroups_Errors));
  600. m_DirectoriesExamined.Format(L"%ld",num1 + num5);
  601. m_DirectoriesChanged.Format(L"%ld",num2+num3 + num6+num7);
  602. m_DirectoriesUnchanged.Format(L"%ld",num4 + num8);
  603. // computer account stats
  604. num1 = pVarSet->get(GET_BSTR(DCTVS_Stats_Computers_Examined));
  605. num2 = pVarSet->get(GET_BSTR(DCTVS_Stats_Computers_Created));
  606. num3 = pVarSet->get(GET_BSTR(DCTVS_Stats_Computers_Replaced));
  607. num4 = pVarSet->get(GET_BSTR(DCTVS_Stats_Computers_Errors));
  608. m_SharesExamined.Format(L"%ld",num1);
  609. m_SharesChanged.Format(L"%ld",num2+num3);
  610. m_SharesUnchanged.Format(L"%ld",num4);
  611. break;
  612. case 2: // EST
  613. num1 = pVarSet->get(GET_BSTR(DCTVS_Stats_Mailboxes_Examined));
  614. num2 = pVarSet->get(GET_BSTR(DCTVS_Stats_Mailboxes_Changed));
  615. m_FilesExamined.Format(L"%ld",num1);
  616. m_FilesChanged.Format(L"%ld",num2);
  617. m_FilesUnchanged.Format(L"%ld",num1-num2);
  618. num1 = pVarSet->get(GET_BSTR(DCTVS_Stats_Containers_Examined));
  619. num2 = pVarSet->get(GET_BSTR(DCTVS_Stats_Containers_Changed));
  620. m_DirectoriesExamined.Format(L"%ld",num1);
  621. m_DirectoriesChanged.Format(L"%ld",num2);
  622. m_DirectoriesUnchanged.Format(L"%ld",num1-num2);
  623. m_SharesExamined.Empty();
  624. m_SharesChanged.Empty();
  625. m_SharesUnchanged.Empty();
  626. break;
  627. case -1: // default (empty)
  628. m_FilesExamined.Empty();
  629. m_FilesChanged.Empty();
  630. m_FilesUnchanged.Empty();
  631. m_DirectoriesExamined.Empty();
  632. m_DirectoriesChanged.Empty();
  633. m_DirectoriesUnchanged.Empty();
  634. m_SharesExamined.Empty();
  635. m_SharesChanged.Empty();
  636. m_SharesUnchanged.Empty();
  637. break;
  638. }
  639. }
  640. else
  641. {
  642. if ( hr == DISP_E_UNKNOWNNAME )
  643. {
  644. m_StatusUnknown = TRUE;
  645. m_Status.FormatMessage(IDS_AgentJobNotFound,(WCHAR*)jobID);
  646. }
  647. else if ( hr == HRESULT_FROM_WIN32(RPC_S_SERVER_UNAVAILABLE) )
  648. {
  649. m_Status.LoadString(IDS_AgentNoLongerRunning);
  650. }
  651. else
  652. {
  653. m_StatusUnknown = TRUE;
  654. m_Status.FormatMessage(IDS_QueryJobStatusFailed,hr);
  655. }
  656. }
  657. }
  658. }
  659. catch ( ... )
  660. {
  661. m_StatusUnknown = TRUE;
  662. m_Status.FormatMessage(IDS_ExceptionConnectingToAgent);
  663. //m_Current = step;
  664. }
  665. if ( m_PlugInText.GetLength() )
  666. {
  667. // permanently hide the plug-in button, because our plug-ins
  668. // don't show any useful text
  669. //m_PlugInButton.ShowWindow(SW_SHOW);
  670. }
  671. //get the job log file when agent is done
  672. if ((!m_Status.CompareNoCase(GET_STRING(IDS_DCT_Status_Completed))) && (m_pNode))
  673. SetLogFile(m_pNode->GetLogPath());
  674. if ( m_LogFile.GetLength() )
  675. {
  676. m_ViewLogButton.ShowWindow(SW_SHOW);
  677. if ( ! m_AgentAlive || !m_Status.CompareNoCase(GET_STRING(IDS_DCT_Status_Completed)) )
  678. {
  679. m_ViewLogButton.EnableWindow(TRUE);
  680. }
  681. else
  682. {
  683. m_ViewLogButton.EnableWindow(FALSE);
  684. }
  685. }
  686. else
  687. {
  688. m_ViewLogButton.ShowWindow(SW_HIDE);
  689. }
  690. if ( ! m_AgentAlive || !m_Status.CompareNoCase(GET_STRING(IDS_DCT_Status_Completed)) )
  691. {
  692. // Disable the refresh button when the status changes to Completed.
  693. if ( !m_Status.CompareNoCase(GET_STRING(IDS_DCT_Status_Completed)) )
  694. {
  695. if ( GetDefID() == IDC_BTNREFRESH )
  696. {
  697. SetDefID(IDOK);
  698. }
  699. m_RefreshButton.EnableWindow(FALSE);
  700. }
  701. // disable the stop agent button any time the agent is not running
  702. m_StopAgentButton.EnableWindow(FALSE);
  703. //enable the close button any time the agent is not running
  704. m_OKButton.EnableWindow(TRUE);
  705. // if auto closing dialog
  706. if (m_bAutoClose)
  707. {
  708. OnOK();
  709. }
  710. }
  711. else
  712. {
  713. // enable the refresh and stop agent buttons when the agent is alive and running
  714. m_RefreshButton.EnableWindow(TRUE);
  715. m_StopAgentButton.EnableWindow(TRUE);
  716. }
  717. UpdateData(FALSE);
  718. }
  719. void CAgentDetailDlg::OnOK()
  720. {
  721. UpdateData(TRUE);
  722. if (!m_bAutoClose)
  723. {
  724. CString str;
  725. CString title;
  726. str = GET_STRING(IDS_DCT_Status_InProgress);
  727. title.LoadString(IDS_MessageTitle);
  728. if ( ! m_hBinding ) // only show the warning for the local agent
  729. {
  730. if ( str == m_Status )
  731. {
  732. str.LoadString(IDS_CannotCloseWhileAgentIsRunning);
  733. MessageBox(str,title,MB_ICONHAND | MB_OK);
  734. return;
  735. }
  736. }
  737. }
  738. bDetailDone = TRUE;
  739. if ( m_pAgent )
  740. {
  741. m_pAgent = NULL;
  742. CoUninitialize();
  743. }
  744. CDialog::OnOK();
  745. }
  746. void CAgentDetailDlg::OnChangeEdit2()
  747. {
  748. UpdateData(TRUE);
  749. detailInterval = _wtoi(m_RefreshRate);
  750. if ( detailInterval <= 0 )
  751. {
  752. detailInterval = 1;
  753. }
  754. }
  755. LRESULT CAgentDetailDlg::DoRefresh(UINT nID, long x)
  756. {
  757. OnRefresh();
  758. return 0;
  759. }
  760. DWORD DoRpcShutdown(HANDLE hBinding, DWORD flags)
  761. {
  762. DWORD rc = 0;
  763. RpcTryExcept
  764. {
  765. rc = EaxcShutdown(hBinding,flags);
  766. }
  767. RpcExcept(1)
  768. {
  769. rc = RpcExceptionCode();
  770. }
  771. RpcEndExcept
  772. return rc;
  773. }
  774. void CAgentDetailDlg::OnStopAgent()
  775. {
  776. DWORD rc = 0;
  777. HRESULT hr = S_OK;
  778. CString message;
  779. CString title;
  780. title.LoadString(IDS_MessageTitle);
  781. if ( m_hBinding )
  782. {
  783. message.LoadString(IDS_ConfirmStopAgent);
  784. if ( MessageBox(message,title,MB_ICONQUESTION | MB_YESNO) == IDYES )
  785. {
  786. _bstr_t jobID = m_pNode->GetJobID();
  787. if ( m_pAgent )
  788. {
  789. hr = m_pAgent->raw_CancelJob(jobID);
  790. m_pAgent = NULL;
  791. }
  792. else
  793. {
  794. message.LoadString(IDS_AgentNotRunning);
  795. MessageBox(message,NULL,MB_OK);
  796. }
  797. if ( SUCCEEDED(hr) )
  798. {
  799. //m_AgentAlive = FALSE;
  800. //rc = DoRpcShutdown(m_hBinding,0);
  801. }
  802. else
  803. {
  804. message.FormatMessage(IDS_CancelJobFailed,hr);
  805. MessageBox(message,NULL,MB_ICONERROR | MB_OK);
  806. }
  807. if ( rc )
  808. {
  809. message.FormatMessage(IDS_StopAgentFailed,rc);
  810. MessageBox(message,NULL,MB_ICONERROR|MB_OK);
  811. }
  812. if ( SUCCEEDED(hr) && !rc )
  813. {
  814. OnOK();
  815. }
  816. }
  817. }
  818. else
  819. {
  820. // Local agent here
  821. if ( m_pAgent )
  822. {
  823. message.LoadString(IDS_ConfirmCancelJob);
  824. if ( MessageBox(message,NULL,MB_ICONQUESTION | MB_YESNO) == IDYES )
  825. {
  826. hr = m_pAgent->raw_CancelJob(m_JobGuid);
  827. if ( FAILED(hr) )
  828. {
  829. message.FormatMessage(IDS_StopAgentFailedHexResult,hr);
  830. MessageBox(message,NULL,MB_ICONERROR | MB_OK);
  831. }
  832. else
  833. {
  834. gbCancelled = TRUE;
  835. }
  836. }
  837. }
  838. else
  839. {
  840. // TODO:error message
  841. }
  842. }
  843. }
  844. void CAgentDetailDlg::OnViewLog()
  845. {
  846. UpdateData(TRUE);
  847. if ( ! m_LogFile.IsEmpty() )
  848. {
  849. // Launch the logfile
  850. CString cmd;
  851. STARTUPINFO startupInfo;
  852. PROCESS_INFORMATION processInfo;
  853. memset(&startupInfo,0,(sizeof startupInfo));
  854. startupInfo.cb = (sizeof startupInfo);
  855. cmd.FormatMessage(IDS_NotepadCommandLine,m_LogFile);
  856. CreateProcess(NULL,cmd.GetBuffer(0),NULL,NULL,TRUE,0,NULL,NULL,&startupInfo,&processInfo);
  857. }
  858. }
  859. void CAgentDetailDlg::OnPlugInResults()
  860. {
  861. UpdateData(TRUE);
  862. MessageBox(m_PlugInText);
  863. }
  864. void CAgentDetailDlg::OnClose()
  865. {
  866. UpdateData(TRUE);
  867. CString str;
  868. CString title;
  869. str = GET_STRING(IDS_DCT_Status_InProgress);
  870. title.LoadString(IDS_MessageTitle);
  871. if ( ! m_hBinding ) // only show the warning for the local agent
  872. {
  873. if ( str == m_Status )
  874. {
  875. str.LoadString(IDS_ConfirmCloseWhileAgentIsRunning);
  876. if ( IDYES != MessageBox(str,title,MB_ICONQUESTION | MB_YESNO) )
  877. return;
  878. }
  879. }
  880. bDetailDone = TRUE;
  881. if ( m_pAgent )
  882. {
  883. m_pAgent = NULL;
  884. CoUninitialize();
  885. }
  886. CDialog::OnClose();
  887. }
  888. BOOL CAgentDetailDlg::OnCommand(WPARAM wParam, LPARAM lParam)
  889. {
  890. // TODO: Add your specialized code here and/or call the base class
  891. TRACE(L"Command(%lx,%lx)\n",wParam,lParam);
  892. if ( wParam == WM_DESTROY )
  893. {
  894. CString str;
  895. CString title;
  896. CString str2;
  897. str = GET_STRING(IDS_DCT_Status_InProgress);
  898. str2 = GET_STRING(IDS_DCT_Status_NotStarted);
  899. title.LoadString(IDS_MessageTitle);
  900. if ( ! m_hBinding ) // only show the warning for the local agent
  901. {
  902. if ( str == m_Status )
  903. {
  904. str.LoadString(IDS_ConfirmCloseWhileAgentIsRunning);
  905. if ( IDYES != MessageBox(str,title,MB_ICONQUESTION | MB_YESNO) )
  906. return 0;
  907. }
  908. }
  909. bDetailDone = TRUE;
  910. if ( m_pAgent )
  911. {
  912. m_pAgent = NULL;
  913. CoUninitialize();
  914. }
  915. return CDialog::OnCommand(wParam, lParam);
  916. }
  917. else
  918. {
  919. return CDialog::OnCommand(wParam, lParam);
  920. }
  921. }
  922. // OnNcPaint Handler
  923. //
  924. // This handler is being overridden to handle hiding of the dialog.
  925. // This prevents initial painting of the dialog which causes a flash
  926. // if the dialog is hidden after this message. This is the first message
  927. // where the dialog can be hidden. Trying to hide the dialog before this
  928. // point gets overridden.
  929. void CAgentDetailDlg::OnNcPaint()
  930. {
  931. if (m_bAutoHide)
  932. {
  933. if (IsWindowVisible())
  934. {
  935. ShowWindow(SW_HIDE);
  936. }
  937. }
  938. else
  939. {
  940. CDialog::OnNcPaint();
  941. }
  942. }