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.

291 lines
5.0 KiB

  1. #include "StdAfx.h"
  2. #include "ADMTScript.h"
  3. #include "ReportGeneration.h"
  4. #include "Error.h"
  5. #include "VarSetOptions.h"
  6. #include "VarSetReports.h"
  7. //---------------------------------------------------------------------------
  8. // Report Class
  9. //---------------------------------------------------------------------------
  10. CReportGeneration::CReportGeneration() :
  11. m_lType(admtReportMigratedAccounts)
  12. {
  13. }
  14. CReportGeneration::~CReportGeneration()
  15. {
  16. }
  17. // IReport Implementation ----------------------------------------
  18. // Type Property
  19. STDMETHODIMP CReportGeneration::put_Type(long lType)
  20. {
  21. HRESULT hr = S_OK;
  22. if (IsReportTypeValid(lType))
  23. {
  24. m_lType = lType;
  25. }
  26. else
  27. {
  28. hr = AdmtSetError(CLSID_Migration, IID_IReportGeneration, E_INVALIDARG, IDS_E_REPORT_TYPE_INVALID);
  29. }
  30. return hr;
  31. }
  32. STDMETHODIMP CReportGeneration::get_Type(long* plType)
  33. {
  34. *plType = m_lType;
  35. return S_OK;
  36. }
  37. // Folder Property
  38. STDMETHODIMP CReportGeneration::put_Folder(BSTR bstrFolder)
  39. {
  40. HRESULT hr = S_OK;
  41. try
  42. {
  43. _bstr_t strFolder = bstrFolder;
  44. if (strFolder.length() > 0)
  45. {
  46. _TCHAR szPath[_MAX_PATH];
  47. LPTSTR pszFilePart;
  48. DWORD cchPath = GetFullPathName(strFolder, _MAX_PATH, szPath, &pszFilePart);
  49. if ((cchPath == 0) || (cchPath >= _MAX_PATH))
  50. {
  51. AdmtThrowError(
  52. GUID_NULL,
  53. GUID_NULL,
  54. HRESULT_FROM_WIN32(GetLastError()),
  55. IDS_E_REPORT_FOLDER,
  56. (LPCTSTR)strFolder
  57. );
  58. }
  59. DWORD dwAttributes = GetFileAttributes(szPath);
  60. if (dwAttributes == DWORD(-1))
  61. {
  62. AdmtThrowError(
  63. GUID_NULL,
  64. GUID_NULL,
  65. HRESULT_FROM_WIN32(GetLastError()),
  66. IDS_E_REPORT_FOLDER,
  67. (LPCTSTR)strFolder
  68. );
  69. }
  70. if (!(dwAttributes & FILE_ATTRIBUTE_DIRECTORY))
  71. {
  72. AdmtThrowError(
  73. GUID_NULL,
  74. GUID_NULL,
  75. HRESULT_FROM_WIN32(ERROR_DIRECTORY),
  76. IDS_E_REPORT_FOLDER,
  77. (LPCTSTR)strFolder
  78. );
  79. }
  80. m_bstrFolder = szPath;
  81. }
  82. else
  83. {
  84. m_bstrFolder = strFolder;
  85. }
  86. }
  87. catch (_com_error& ce)
  88. {
  89. hr = AdmtSetError(CLSID_Migration, IID_IReportGeneration, ce);
  90. }
  91. catch (...)
  92. {
  93. hr = AdmtSetError(CLSID_Migration, IID_IReportGeneration, E_FAIL);
  94. }
  95. return hr;
  96. }
  97. STDMETHODIMP CReportGeneration::get_Folder(BSTR* pbstrFolder)
  98. {
  99. HRESULT hr = S_OK;
  100. try
  101. {
  102. *pbstrFolder = m_bstrFolder.copy();
  103. }
  104. catch (_com_error& ce)
  105. {
  106. hr = AdmtSetError(CLSID_Migration, IID_IReportGeneration, ce);
  107. }
  108. catch (...)
  109. {
  110. hr = AdmtSetError(CLSID_Migration, IID_IReportGeneration, E_FAIL);
  111. }
  112. return hr;
  113. }
  114. // Generate Method
  115. STDMETHODIMP CReportGeneration::Generate(long lOptions, VARIANT vntInclude, VARIANT vntExclude)
  116. {
  117. HRESULT hr = S_OK;
  118. MutexWait();
  119. bool bLogOpen = _Module.OpenLog();
  120. try
  121. {
  122. _Module.Log(ErrI, IDS_STARTED_REPORT_GENERATION);
  123. InitSourceDomainAndContainer();
  124. InitTargetDomainAndContainer();
  125. DoOption(lOptions, vntInclude, vntExclude);
  126. }
  127. catch (_com_error& ce)
  128. {
  129. hr = AdmtSetError(CLSID_Migration, IID_IReportGeneration, ce, IDS_E_CANT_GENERATE_REPORT);
  130. }
  131. catch (...)
  132. {
  133. hr = AdmtSetError(CLSID_Migration, IID_IReportGeneration, E_FAIL, IDS_E_CANT_GENERATE_REPORT);
  134. }
  135. if (bLogOpen)
  136. {
  137. _Module.CloseLog();
  138. }
  139. MutexRelease();
  140. return hr;
  141. }
  142. // Implementation -----------------------------------------------------------
  143. // DoNone Method
  144. void CReportGeneration::DoNone()
  145. {
  146. CVarSet aVarSet;
  147. SetOptions(aVarSet);
  148. SetReports(aVarSet);
  149. aVarSet.Put(_T("PlugIn.%ld"), 0, _T("None"));
  150. PerformMigration(aVarSet);
  151. }
  152. // DoNames Method
  153. void CReportGeneration::DoNames()
  154. {
  155. CDomainAccounts aComputers;
  156. m_SourceDomain.QueryComputersAcrossDomains(GetSourceContainer(), true, m_setIncludeNames, m_setExcludeNames, aComputers);
  157. DoComputers(aComputers);
  158. }
  159. // DoDomain Method
  160. void CReportGeneration::DoDomain()
  161. {
  162. DoContainers(GetSourceContainer());
  163. }
  164. // DoContainers Method
  165. void CReportGeneration::DoContainers(CContainer& rSource)
  166. {
  167. DoComputers(rSource);
  168. }
  169. // DoComputers Method
  170. void CReportGeneration::DoComputers(CContainer& rSource)
  171. {
  172. CDomainAccounts aComputers;
  173. rSource.QueryComputers(true, m_nRecurseMaintain >= 1, m_setExcludeNames, aComputers);
  174. DoComputers(aComputers);
  175. }
  176. // DoComputers Method
  177. void CReportGeneration::DoComputers(CDomainAccounts& rComputers)
  178. {
  179. if (rComputers.size() > 0)
  180. {
  181. CVarSet aVarSet;
  182. SetOptions(aVarSet);
  183. SetReports(aVarSet);
  184. FillInVarSetForComputers(rComputers, false, false, false, 0, aVarSet);
  185. aVarSet.Put(_T("PlugIn.%ld"), 0, _T("None"));
  186. rComputers.clear();
  187. PerformMigration(aVarSet);
  188. aVarSet.Put(DCTVS_GatherInformation, false);
  189. SaveSettings(aVarSet);
  190. }
  191. }
  192. // SetOptions Method
  193. void CReportGeneration::SetOptions(CVarSet& rVarSet)
  194. {
  195. CVarSetOptions aOptions(rVarSet);
  196. aOptions.SetWizard(_T("reporting"));
  197. aOptions.SetIntraForest(m_spInternal->IntraForest ? true : false);
  198. aOptions.SetSourceDomain(m_SourceDomain.NameFlat(), m_SourceDomain.NameDns());
  199. aOptions.SetTargetDomain(m_TargetDomain.NameFlat(), m_TargetDomain.NameDns());
  200. }
  201. // SetReports Method
  202. void CReportGeneration::SetReports(CVarSet& rVarSet)
  203. {
  204. CVarSetReports aReports(rVarSet);
  205. aReports.SetType(m_lType);
  206. aReports.SetReportsDirectory(m_bstrFolder);
  207. }