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.

333 lines
9.4 KiB

  1. // SrcSidUpdate.cpp : Implementation of CSrcSidUpdate
  2. #include "stdafx.h"
  3. #include "UpdateMOT.h"
  4. #include "SrcSidUpdate.h"
  5. #include "IntroDlg.h"
  6. #include "DomainListDlg.h"
  7. #include "ProgressDlg.h"
  8. #include "SummaryDlg.h"
  9. #import "DBMgr.tlb" no_namespace,named_guids
  10. #import "VarSet.tlb" no_namespace , named_guids rename("property", "aproperty")
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CSrcSidUpdate
  13. STDMETHODIMP CSrcSidUpdate::QueryForSrcSidColumn(VARIANT_BOOL *pbFound)
  14. {
  15. AFX_MANAGE_STATE(AfxGetStaticModuleState())
  16. HRESULT hr = S_OK;
  17. try
  18. {
  19. IIManageDBPtr pDB(CLSID_IManageDB);
  20. //see if column is already in the database
  21. *pbFound = pDB->SrcSidColumnInMigratedObjectsTable();
  22. }
  23. catch(_com_error& e)
  24. {
  25. hr = e.Error();
  26. }
  27. catch(...)
  28. {
  29. hr = E_FAIL;
  30. }
  31. return hr;
  32. }
  33. STDMETHODIMP CSrcSidUpdate::CreateSrcSidColumn(VARIANT_BOOL bHide, VARIANT_BOOL *pbCreated)
  34. {
  35. HRESULT hr = S_OK;
  36. BOOL bAgain = TRUE; //flag used to redo upon cancel
  37. AFX_MANAGE_STATE(AfxGetStaticModuleState())
  38. //retrieve a list of domains from the MigratedObjects table
  39. hr = FillDomainListFromMOT();
  40. if ( FAILED(hr) )
  41. {
  42. *pbCreated = VARIANT_FALSE;
  43. return E_FAIL;
  44. }
  45. //if the MOT is empty, just add the new column without the GUI
  46. if (domainList.IsEmpty())
  47. {
  48. try
  49. {
  50. IIManageDBPtr pDB(CLSID_IManageDB);
  51. //create the new column in the MigratedObjects table
  52. hr = pDB->raw_CreateSrcSidColumnInMOT(pbCreated);
  53. if ( FAILED(hr) )
  54. *pbCreated = VARIANT_FALSE; //column not created
  55. else
  56. *pbCreated = VARIANT_TRUE; //column is created
  57. }//end try
  58. catch(_com_error& e)
  59. {
  60. hr = e.Error();
  61. }
  62. catch(...)
  63. {
  64. hr = E_FAIL;
  65. }
  66. return hr;
  67. }
  68. //if hide the GUI, try populating for all domains in the MOT
  69. if (bHide)
  70. {
  71. try
  72. {
  73. IIManageDBPtr pDB(CLSID_IManageDB);
  74. //create the new column in the MigratedObjects table
  75. hr = pDB->raw_CreateSrcSidColumnInMOT(pbCreated);
  76. if ( FAILED(hr) )
  77. {
  78. *pbCreated = VARIANT_FALSE;
  79. return hr;
  80. }
  81. *pbCreated = VARIANT_TRUE; //column is created
  82. CString domainName;
  83. POSITION pos = domainList.GetHeadPosition();
  84. //while we have domains to process, populate that domain
  85. while (pos != NULL)
  86. {
  87. //get the next domain name
  88. domainName = domainList.GetNext(pos);
  89. //populate the new column for this domain
  90. pDB->PopulateSrcSidColumnByDomain(domainName.AllocSysString(), L"");
  91. }
  92. }//end try
  93. catch(_com_error& e)
  94. {
  95. hr = e.Error();
  96. }
  97. catch(...)
  98. {
  99. hr = E_FAIL;
  100. }
  101. return hr;
  102. }//end if hide
  103. //display the intro dialog
  104. CIntroDlg introDlg;
  105. if (introDlg.DoModal() == IDCANCEL)
  106. {
  107. *pbCreated = VARIANT_FALSE;
  108. return S_OK;
  109. }
  110. //do atleast once and again if cancel on the progress dialog
  111. while (bAgain)
  112. {
  113. bAgain = FALSE; //clear flag so we don't do this again
  114. //pass the list to the dialog for display
  115. CDomainListDlg domainListDlg;
  116. domainListDlg.SetDomainListPtr(&domainList);
  117. domainListDlg.SetExcludeListPtr(&excludeList);
  118. //now display the domain selection dialog
  119. if (domainListDlg.DoModal() == IDCANCEL)
  120. {
  121. *pbCreated = VARIANT_FALSE;
  122. return S_OK;
  123. }
  124. try
  125. {
  126. IIManageDBPtr pDB(CLSID_IManageDB);
  127. //create the new column in the MigratedObjects table
  128. hr = pDB->raw_CreateSrcSidColumnInMOT(pbCreated);
  129. if ( FAILED(hr) )
  130. {
  131. *pbCreated = VARIANT_FALSE;
  132. return hr;
  133. }
  134. *pbCreated = VARIANT_TRUE; //column is created
  135. //display the progress dialog
  136. CProgressDlg progressDlg;
  137. progressDlg.Create();
  138. progressDlg.ShowWindow(SW_SHOW);
  139. progressDlg.SetIncrement((int)(domainList.GetCount())); //init the progress dialog
  140. CString domainName;
  141. VARIANT_BOOL bPopulated;
  142. POSITION pos = domainList.GetHeadPosition();
  143. //process dialog's messages (looking specifically for Cancel message)
  144. progressDlg.CheckForCancel();
  145. //while we have domains to process and user has not canceled,
  146. //process each domain and control the progress dialog
  147. while ((pos != NULL) && (!progressDlg.Canceled()))
  148. {
  149. //get the next domain name
  150. domainName = domainList.GetNext(pos);
  151. //set the domain name on the progress dialog
  152. progressDlg.SetDomain(domainName);
  153. CWaitCursor wait; //Put up a wait cursor
  154. //populate the new column for this domain
  155. bPopulated = pDB->PopulateSrcSidColumnByDomain(domainName.AllocSysString(), L"");
  156. wait.~CWaitCursor();//remove the wait cursor
  157. //if populate of the column was successful, add the domain
  158. //name to the populate list
  159. if (bPopulated)
  160. populatedList.AddTail(domainName);
  161. //process dialog's messages (looking specifically for Cancel message)
  162. progressDlg.CheckForCancel();
  163. //increment the progress dialog regardless of success
  164. if (pos == NULL)
  165. {
  166. progressDlg.Done();
  167. progressDlg.DestroyWindow();
  168. }
  169. else
  170. progressDlg.Increment();
  171. }
  172. //if canceled, delete the new column, clear the lists, and
  173. //start over
  174. if (progressDlg.Canceled())
  175. {
  176. //remove the column and return to the domain list dialog
  177. VARIANT_BOOL bDeleted = pDB->DeleteSrcSidColumnInMOT();
  178. //reinitalize the lists
  179. ReInitializeLists();
  180. bAgain = TRUE; //set flag to try again
  181. }
  182. }//end try
  183. catch(_com_error& e)
  184. {
  185. hr = e.Error();
  186. }
  187. catch(...)
  188. {
  189. hr = E_FAIL;
  190. }
  191. }//end while cancel
  192. //display the summary dialog
  193. CSummaryDlg summaryDlg;
  194. summaryDlg.SetDomainListPtr(&domainList);
  195. summaryDlg.SetExcludeListPtr(&excludeList);
  196. summaryDlg.SetPopulatedListPtr(&populatedList);
  197. summaryDlg.DoModal();
  198. return hr;
  199. }
  200. /*********************************************************************
  201. * *
  202. * Written by: Paul Thompson *
  203. * Date: 18 AUG 2000 *
  204. * *
  205. * This protected member function of the CSrcSidUpdate class is *
  206. * responsible for adding domains from the Protar database's *
  207. * MigratedObjects table into the domain list. *
  208. * *
  209. *********************************************************************/
  210. //BEGIN FillDomainListFromMOT
  211. HRESULT CSrcSidUpdate::FillDomainListFromMOT()
  212. {
  213. /* local variables */
  214. HRESULT hr = S_OK;
  215. IUnknown * pUnk = NULL;
  216. long ndx, numObjects;
  217. _bstr_t srcDom;
  218. CString domainName;
  219. POSITION currentPos;
  220. WCHAR strKey[MAX_PATH];
  221. /* function body */
  222. try
  223. {
  224. IVarSetPtr pVarSet(CLSID_VarSet);
  225. IIManageDBPtr pDB(CLSID_IManageDB);
  226. hr = pVarSet->QueryInterface(IID_IUnknown,(void**)&pUnk);
  227. if ( SUCCEEDED(hr) )
  228. {
  229. //get all migrated objects into a varset
  230. hr = pDB->raw_GetMigratedObjectsFromOldMOT(-1,&pUnk);
  231. }
  232. if ( SUCCEEDED(hr) )
  233. {
  234. pVarSet = pUnk;
  235. pUnk->Release();
  236. numObjects = pVarSet->get(L"MigratedObjects");
  237. //for each migrated object, save its source domain in the list
  238. for ( ndx = 0; ndx < numObjects; ndx++ )
  239. {
  240. //get the source domain name
  241. swprintf(strKey,L"MigratedObjects.%ld.%s",ndx,L"SourceDomain");
  242. srcDom = pVarSet->get(strKey);
  243. //add the name to the list, if not already in it
  244. domainName = (WCHAR*)srcDom;
  245. currentPos = domainList.Find(domainName);
  246. if (currentPos == NULL)
  247. domainList.AddTail(domainName);
  248. }
  249. }//end if got objects
  250. }
  251. catch(_com_error& e)
  252. {
  253. hr = e.Error();
  254. }
  255. catch(...)
  256. {
  257. hr = E_FAIL;
  258. }
  259. return hr;
  260. }//END FillDomainListFromMOT
  261. /*********************************************************************
  262. * *
  263. * Written by: Paul Thompson *
  264. * Date: 22 AUG 2000 *
  265. * *
  266. * This protected member function of the CDomainListDlg class is *
  267. * responsible for taking the domain names out of the excluded list *
  268. * and placing it back into the domain list. *
  269. * *
  270. *********************************************************************/
  271. //BEGIN ReInitializeLists
  272. void CSrcSidUpdate::ReInitializeLists()
  273. {
  274. /* local variables */
  275. POSITION currentPos; //current position in the list
  276. CString domainName; //name of domain from the list
  277. /* function body */
  278. currentPos = excludeList.GetHeadPosition();
  279. while (currentPos != NULL)
  280. {
  281. domainName = excludeList.GetNext(currentPos);
  282. domainList.AddTail(domainName);
  283. }
  284. excludeList.RemoveAll();
  285. populatedList.RemoveAll();
  286. }
  287. //END ReInitializeLists