Leaked source code of windows server 2003
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.

265 lines
6.4 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Abstract:
  4. @doc
  5. @module Resolve.cpp | Implementation of Writer
  6. @end
  7. Author:
  8. Adi Oltean [aoltean] 08/18/1999
  9. TBD:
  10. Add comments.
  11. Revision History:
  12. Name Date Comments
  13. aoltean 08/18/1999 Created
  14. aoltean 09/22/1999 Making console output clearer
  15. --*/
  16. /////////////////////////////////////////////////////////////////////////////
  17. // Defines
  18. // C4290: C++ Exception Specification ignored
  19. #pragma warning(disable:4290)
  20. // warning C4511: 'CVssCOMApplication' : copy constructor could not be generated
  21. #pragma warning(disable:4511)
  22. // warning C4127: conditional expression is constant
  23. #pragma warning(disable:4127)
  24. /////////////////////////////////////////////////////////////////////////////
  25. // Includes
  26. #include <wtypes.h>
  27. #include <stddef.h>
  28. #include <oleauto.h>
  29. #include <comadmin.h>
  30. #include "vs_assert.hxx"
  31. // ATL
  32. #include <atlconv.h>
  33. #include <atlbase.h>
  34. extern CComModule _Module;
  35. #include <atlcom.h>
  36. #include "vs_inc.hxx"
  37. #include "comadmin.hxx"
  38. #include "vsevent.h"
  39. #include "writer.h"
  40. /////////////////////////////////////////////////////////////////////////////
  41. // User interaction functions
  42. //
  43. // During ResolveResource
  44. //
  45. void OnAddResource(IVssDependencies* pDep);
  46. void OnAddDependency(IVssDependencies* pDep);
  47. void OnCancel(IVssDependencies* pDep);
  48. void OnPrint(IVssDependencies* pDep);
  49. void AskDuringResolve(
  50. IN CVssFunctionTracer& ft,
  51. IN IDispatch* pCallback
  52. );
  53. /////////////////////////////////////////////////////////////////////////////
  54. // CVssWriter
  55. STDMETHODIMP CVssWriter::ResolveResource(
  56. IN BSTR bstrAppInstance,
  57. IN BSTR bstrResourceName,
  58. IN BSTR bstrResourceId,
  59. IN BSTR bstrProcessContext,
  60. IN BSTR bstrProcessId,
  61. IN IDispatch* pDepGraphCallback
  62. )
  63. {
  64. CVssFunctionTracer ft( VSSDBG_VSSTEST, L"CVssWriter::ResolveResource" );
  65. ft.Msg(L"\nReceived Event: ResolveResource\nParameters:");
  66. ft.Msg(L"\tstrAppInstance = %s", (LPWSTR)bstrAppInstance);
  67. ft.Msg(L"\tstrResourceName = %s", (LPWSTR)bstrResourceName);
  68. ft.Msg(L"\tstrResourceId = %s", (LPWSTR)bstrResourceId);
  69. ft.Msg(L"\tstrProcessContext = %s", (LPWSTR)bstrProcessContext);
  70. ft.Msg(L"\tstrProcessId = %s", (LPWSTR)bstrProcessId);
  71. ft.Msg(L"\tstrProcessId = %s", (LPWSTR)bstrProcessId);
  72. AskDuringResolve( ft, pDepGraphCallback );
  73. return S_OK;
  74. }
  75. /////////////////////////////////////////////////////////////////////////////
  76. // Private implementation
  77. void AskDuringResolve(
  78. IN CVssFunctionTracer& ft,
  79. IN IDispatch* pCallback
  80. )
  81. {
  82. while(true)
  83. {
  84. ft.Msg(L"\nCommands:");
  85. ft.Msg(L"\t[1] Done");
  86. ft.Msg(L"\t[2] Add Resource");
  87. ft.Msg(L"\t[3] Add Dependency");
  88. ft.Msg(L"\t[4] Cancel");
  89. ft.Msg(L"\t[5] Print graph");
  90. try
  91. {
  92. CComPtr<IVssDependencies> pDep;
  93. ft.hr = pCallback->SafeQI(IVssDependencies, &pDep);
  94. if (ft.HrFailed())
  95. ft.Err( VSSDBG_VSSTEST, E_UNEXPECTED, L"Error calling QI 0x%08lx", ft.hr );
  96. BS_ASSERT(pDep);
  97. int nOption = QueryInt(L"Option: ");
  98. switch(nOption)
  99. {
  100. case 1:
  101. return;
  102. case 2:
  103. OnAddResource(pDep);
  104. break;
  105. case 3:
  106. OnAddDependency(pDep);
  107. break;
  108. case 4:
  109. OnCancel(pDep);
  110. break;
  111. case 5:
  112. OnPrint(pDep);
  113. break;
  114. default:
  115. break;
  116. }
  117. }
  118. VSS_STANDARD_CATCH(ft)
  119. }
  120. }
  121. void OnAddResource(IVssDependencies* pDep)
  122. {
  123. CVssFunctionTracer ft( VSSDBG_VSSTEST, L"OnAddResource" );
  124. CComBSTR strNewResourceName = QueryString(L"New resource name: ");
  125. CComBSTR strAppInstance = QueryString(L"App Instance: ");
  126. WCHAR wchIsExternal = (QueryString(L"External? [y/N] "))[0];
  127. VSS_RESOURCE_TYPE eType = (towupper(wchIsExternal) == L'Y')?
  128. VSS_EXTERNAL_RESOURCE: VSS_LOCAL_RESOURCE;
  129. CComBSTR strVolumeList = QueryString(L"Volume List: ");
  130. CComBSTR strDetails = QueryString(L"Details: ");
  131. CComBSTR strResourceId;
  132. ft.hr = pDep->AddResource(
  133. strNewResourceName,
  134. strAppInstance,
  135. eType,
  136. strVolumeList,
  137. strDetails,
  138. &strResourceId
  139. );
  140. if (ft.HrFailed())
  141. ft.Err( VSSDBG_VSSTEST, E_UNEXPECTED, L"Error calling AddResource 0x%08lx", ft.hr );
  142. ft.Msg(L"Resource Id = %s ; HRESULT = 0x%08lx", strResourceId, ft.hr );
  143. }
  144. void OnAddDependency(IVssDependencies* pDep)
  145. {
  146. CVssFunctionTracer ft( VSSDBG_VSSTEST, L"OnAddDependency" );
  147. CComBSTR strFromResourceId = QueryString(L"From Resource ID: ");
  148. CComBSTR strToResourceId = QueryString(L"To Resource ID: ");
  149. CComBSTR strDescription = QueryString(L"Description: ");
  150. ft.hr = pDep->AddDependency(
  151. strFromResourceId,
  152. strToResourceId,
  153. strDescription
  154. );
  155. if (ft.HrFailed())
  156. ft.Err( VSSDBG_VSSTEST, E_UNEXPECTED, L"Error calling AddDependency 0x%08lx", ft.hr );
  157. ft.Msg(L"HRESULT = 0x%08lx", ft.hr );
  158. }
  159. void OnCancel(IVssDependencies* pDep)
  160. {
  161. CVssFunctionTracer ft( VSSDBG_VSSTEST, L"OnCancel" );
  162. HRESULT hrErrorCode = QueryInt(L"Error code: ");
  163. CComBSTR bstrCancelReason = QueryString(L"Cancel reason: ");
  164. ft.hr = pDep->Cancel( hrErrorCode, bstrCancelReason );
  165. if (ft.HrFailed())
  166. ft.Err( VSSDBG_VSSTEST, E_UNEXPECTED, L"Error calling AddDependency 0x%08lx", ft.hr );
  167. ft.Msg(L"HRESULT = 0x%08lx", ft.hr );
  168. }
  169. void OnPrint(IVssDependencies* pDep)
  170. {
  171. CVssFunctionTracer ft( VSSDBG_VSSTEST, L"OnPrint" );
  172. CComPtr<IDispatch> pDisp;
  173. ft.hr = pDep->SaveAsXML( NULL, 1, &pDisp );
  174. if (ft.HrFailed())
  175. ft.Err( VSSDBG_VSSTEST, E_UNEXPECTED, L"Error calling SaveAsXML 0x%08lx", ft.hr );
  176. BS_ASSERT(pDisp);
  177. // Get the Document interface
  178. CComPtr<IXMLDOMDocument> pDoc;
  179. ft.hr = pDisp->SafeQI( IXMLDOMDocument, &pDoc );
  180. if (ft.HrFailed())
  181. ft.Err( VSSDBG_VSSTEST, E_UNEXPECTED, L"Error calling QI 0x%08lx", ft.hr );
  182. BS_ASSERT(pDoc);
  183. /*
  184. // Get a file name
  185. CComBSTR bstrOutputFile = QueryString(L"Output file name: ");
  186. */
  187. CComBSTR bstrOutputFile = L"output.xml";
  188. if (!bstrOutputFile)
  189. ft.Err( VSSDBG_VSSTEST, E_UNEXPECTED, L"NULL file name" );
  190. // Save the document into that file
  191. CComVariant varFileName = bstrOutputFile;
  192. ft.hr = pDoc->save(varFileName);
  193. if (ft.HrFailed())
  194. ft.Err( VSSDBG_VSSTEST, E_UNEXPECTED, L"Error calling IXMLDOCDocument::save 0x%08lx", ft.hr );
  195. // Execute the command
  196. _wsystem(L"start output.xml");
  197. }