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.

736 lines
23 KiB

  1. <% '==================================================
  2. ' Microsoft Server Appliance
  3. '
  4. ' Serves task wizard/propsheet
  5. '
  6. ' Copyright (c) Microsoft Corporation. All rights reserved.
  7. '================================================== %>
  8. <!-- #include file="sh_page.asp" -->
  9. <!-- #include file="tabs.asp" -->
  10. <!-- #include file="sh_statusbar.asp" -->
  11. <% ' Copyright (c) Microsoft Corporation. All rights reserved.
  12. 'Task module-level variables
  13. Dim mstrPageName ' used as page identifier, e.g., "Intro"
  14. Dim mstrTaskTitle ' e.g., "Add User"
  15. Dim mstrWizPageTitle ' e.g., "Add User"
  16. Dim mstrPageTitle ' e.g., "Username and Password"
  17. Dim mstrTaskType ' "wizard", "prop"
  18. Dim mstrWizardPageType ' "intro", "standard", "finish"
  19. Dim mstrMethod ' "BACK", "NEXT", "FINISH", etc
  20. Dim mstrReturnURL ' URL to return to after ending task
  21. Dim mstrFrmwrkFormStrings ' framework form values, list of strings to exclude
  22. Dim mstrIconPath ' image for upper right header
  23. Dim mstrPanelPath ' image for left panel of intro and finish pg
  24. ' Dim mintElementIndex ' index of embedded wizard page (0 - n, -1 = no extensions)
  25. ' Dim mintElementCount ' number of embedded pages in wizard
  26. Dim mstrErrMsg ' used by SetErrMsg and GetErrMsg
  27. Dim mstrAsyncTaskName ' Task EXE name - empty if task is synchronous
  28. Dim mstrTabPropSheetTabs()
  29. Dim mintTabSelected
  30. Dim intCaptionIDTask
  31. Dim gm_sPageTitle ' SAK 2.0 Page Title variable
  32. Dim gm_sBannerText ' SAK 2.0 Banner Text
  33. mintTabSelected = CInt(Request.Form("TabSelected"))
  34. Set objLocMgr = Server.CreateObject("ServerAppliance.LocalizationManager")
  35. strSourceName = "sakitmsg.dll"
  36. If Err.number <> 0 Then
  37. If ( Err.number = &H800401F3 ) Then
  38. Response.Write("<H1>Problem:<H1>")
  39. Response.Write("Unable to locate a software component on the Server Appliance.<BR>")
  40. Response.Write("The Server Appliance core software components do not appear to be installed correctly.")
  41. Else
  42. Response.Write("<H1>Problem:<H1>")
  43. Response.Write("Server.CreateObject(ServerAppliance.LocalizationManager) failed with error code: " + CStr(Hex(Err.Number)) + " " + Err.Description)
  44. End If
  45. Call SA_TraceOut("SH_TASK", "Server.CreateObject(ServerAppliance.LocalizationManager) failed with error code: " + CStr(Hex(Err.Number)) )
  46. Response.End
  47. End If
  48. '-----------------------------------------------------
  49. 'START of localization content
  50. Dim L_BACK_BUTTON
  51. Dim L_BACKIE_BUTTON
  52. Dim L_NEXT_BUTTON
  53. Dim L_NEXTIE_BUTTON
  54. Dim L_FINISH_BUTTON
  55. Dim L_OK_BUTTON
  56. Dim L_CANCEL_BUTTON
  57. Dim L_BACK_ACCESSKEY
  58. Dim L_NEXT_ACCESSKEY
  59. Dim L_FINISH_ACCESSKEY
  60. L_BACK_BUTTON = objLocMgr.GetString(strSourceName, "&H4001001C",varReplacementStrings)
  61. L_BACKIE_BUTTON = objLocMgr.GetString(strSourceName, "&H4001001D",varReplacementStrings)
  62. L_NEXT_BUTTON = objLocMgr.GetString(strSourceName, "&H4001001E",varReplacementStrings)
  63. L_NEXTIE_BUTTON = objLocMgr.GetString(strSourceName, "&H4001001F",varReplacementStrings)
  64. L_FINISH_BUTTON = objLocMgr.GetString(strSourceName, "&H40010020",varReplacementStrings)
  65. L_OK_BUTTON = objLocMgr.GetString(strSourceName, "&H40010021",varReplacementStrings)
  66. L_CANCEL_BUTTON = objLocMgr.GetString(strSourceName, "&H40010022",varReplacementStrings)
  67. L_BACK_ACCESSKEY = objLocMgr.GetString(strSourceName, "&H40010039",varReplacementStrings)
  68. L_NEXT_ACCESSKEY = objLocMgr.GetString(strSourceName, "&H4001003A",varReplacementStrings)
  69. L_FINISH_ACCESSKEY = objLocMgr.GetString(strSourceName, "&H4001003B",varReplacementStrings)
  70. 'End of localization content
  71. '-----------------------------------------------------
  72. 'Task Constants
  73. Const PROPERTY_TASK_NICE_NAME = "TaskNiceName"
  74. Const PROPERTY_TASK_URL = "TaskURL"
  75. Const WBEM_E_PROVIDER_NOT_CAPABLE = "&H80041024"
  76. Const WIZARD_TASK = "wizard"
  77. Const PROPSHEET_TASK = "prop"
  78. Const TAB_PROPSHEET = "TabPropSheet"
  79. Const BODY_PAGE = "standard"
  80. Const INTRO_PAGE = "intro"
  81. Const FINISH_PAGE = "finish"
  82. Const BACK_METHOD = "BACK"
  83. Const NEXT_METHOD = "NEXT"
  84. Const FINISH_METHOD = "FINISH"
  85. Const CANCEL_METHOD = "CANCEL"
  86. 'Get standard task values and initialize
  87. mstrMethod = Request.Form("Method")
  88. mstrPageName = Request("PageName")
  89. mstrReturnURL = Request("ReturnURL")
  90. If mstrReturnURL = "" Then
  91. mstrReturnURL = GetCurrentPrimaryTabURL()
  92. End If
  93. ' mintElementIndex = -1 ' set later in ServeWizardEmbeds()
  94. ' mintElementCount = Request.Form("EmbedPageCount") ' get previous value, if any
  95. ' If mintElementCount="" Then
  96. ' mintElementCount=0
  97. ' End If
  98. mstrFrmwrkFormStrings = "!method!pagename!pagetype!tasktype!returnurl!embedpageindex!embedpagecount!commonvalues!embedvalues0!embedvalues1!embedvalues2!embedvalues3!embedvalues4!"
  99. Set objLocMgr = Server.CreateObject("ServerAppliance.LocalizationManager")
  100. '----------------------------------------------------------------------------
  101. '
  102. ' Function : SA_IsAsyncTaskBusy
  103. '
  104. ' Synopsis : Determine if the async task is currently being executed
  105. '
  106. ' Arguments: TaskName(IN) - async task name
  107. '
  108. ' Returns : true/false
  109. '
  110. '----------------------------------------------------------------------------
  111. Public Function SA_IsAsyncTaskBusy(ByVal TaskName)
  112. SA_IsAsyncTaskBusy = AsyncTaskBusy(TaskName)
  113. End Function
  114. Private Function AsyncTaskBusy(ByVal TaskName)
  115. Dim objTask
  116. Set objTask = GetObject("WINMGMTS:" & SA_GetWMIConnectionAttributes() &"!\\" & GetServerName & "\root\cimv2:Microsoft_SA_Task.TaskName=" & Chr(34) & TaskName & Chr(34) )
  117. If ( Err.Number <> 0 ) Then
  118. Call SA_TraceOut(SA_GetScriptFileName(), "Get Microsoft_SA_Task failed: " + CStr(Hex(Err.Number)) + " " + Err.Description)
  119. Exit Function
  120. End If
  121. If Not objTask.IsAvailable Then
  122. AsyncTaskBusy = True
  123. Else
  124. AsyncTaskBusy = False
  125. End If
  126. Set objTask = Nothing
  127. End Function
  128. Public Function SAI_GetBannerText()
  129. If ( SA_GetVersion() < gc_V2 ) Then
  130. SAI_GetBannerText = mstrTaskTitle
  131. Else
  132. SAI_GetBannerText = gm_sBannerText
  133. End If
  134. End Function
  135. Public Function SAI_GetPageTitle()
  136. If ( SA_GetVersion() < gc_V2 ) Then
  137. SAI_GetPageTitle = mstrTaskTitle
  138. Else
  139. SAI_GetPageTitle = gm_sPageTitle
  140. End If
  141. End Function
  142. '----------------------------------------------------------------------------
  143. '
  144. ' Function : SA_SetErrMsg
  145. '
  146. ' Synopsis : Sets framework error message string
  147. '
  148. ' Arguments: Message(IN) - error message text
  149. '
  150. ' Returns : Nothing
  151. '
  152. '----------------------------------------------------------------------------
  153. Public Function SA_SetErrMsg(ByVal Message)
  154. mstrErrMsg = Message
  155. End Function
  156. Private Function SetErrMsg(ByVal Message)
  157. mstrErrMsg = Message
  158. End Function
  159. '----------------------------------------------------------------------------
  160. '
  161. ' Function : GetErrMsg
  162. '
  163. ' Synopsis : Gets the current framework error message string
  164. '
  165. ' Arguments: None
  166. '
  167. ' Returns : None
  168. '
  169. '----------------------------------------------------------------------------
  170. Private Function GetErrMsg()
  171. GetErrMsg = mstrErrMsg
  172. End Function
  173. '----------------------------------------------------------------------------
  174. '
  175. ' Function : ServeTaskHeader
  176. '
  177. ' Synopsis : Serve the task header based on page type
  178. '
  179. ' Arguments: None
  180. '
  181. ' Returns : None
  182. '
  183. '----------------------------------------------------------------------------
  184. Function ServeTaskHeader()
  185. Dim objItem
  186. Dim i
  187. Dim intSlack
  188. Response.Buffer = True
  189. %>
  190. <html>
  191. <!-- Microsoft(R) Server Appliance Platform
  192. Copyright (c) Microsoft Corporation. All rights reserved.
  193. -------------------------------------------------
  194. Web Framework <%=SA_TaskToPageType()%>
  195. -------------------------------------------------
  196. -->
  197. <meta http-equiv="Content-Type" content="text/html; charset=<%=GetCharSet()%>">
  198. <head>
  199. <title><%=Server.HTMLEncode(SAI_GetPageTitle())%></title>
  200. <script language=JavaScript src="<%=m_VirtualRoot%>sh_page.js"></script>
  201. <script language=JavaScript>
  202. var VirtualRoot = '<%=m_VirtualRoot%>';
  203. function HandleClickEvent()
  204. {
  205. if ( IsIE() )
  206. {
  207. if (window.event.srcElement.tagName == "INPUT")
  208. return true;
  209. else
  210. return false;
  211. }
  212. else return true;
  213. }
  214. </script>
  215. <script language=JavaScript src="<%=m_VirtualRoot%>sh_task.js"></script>
  216. <%
  217. If (mstrTaskType = PROPSHEET_TASK) then
  218. If ( SA_GetVersion() < gc_V2 ) Then
  219. Call SA_EmitAdditionalStyleSheetReferences("")
  220. End If
  221. End If
  222. %>
  223. </head>
  224. <BODY onload="PageInit();" onDragDrop="return false;" xoncontextmenu="return false;">
  225. <%
  226. If (mstrTaskType= TAB_PROPSHEET) then
  227. If ( SA_GetVersion() < gc_V2 ) Then
  228. Call ServeTabBar()
  229. End If
  230. End If
  231. If( (mstrTaskType="wizard") AND (mstrWizardPageType="intro" OR mstrWizardPageType="finish")) Then
  232. %>
  233. <div class='PageBodyIndent'>
  234. <%
  235. Call ServeStandardHeaderBar(SAI_GetBannerText(), mstrIconPath)
  236. %>
  237. <br>
  238. <TABLE width=87% height=65% border=0 cellspacing=0 cellpadding=0 ID=TASKTABLE>
  239. <TR valign=TOP style="background-color:#FFFFFF">
  240. <TD height=100% xwidth="10%" align="right" valign=TOP class=PageHeaderBar style="width:130px; xbackground-color: #313163" rowspan="2">
  241. <%
  242. If ( Len(Trim(mstrPanelPath)) > 0 ) Then
  243. %>
  244. <IMG width=130 border=0 src='<% =m_VirtualRoot + mstrPanelPath %>' >
  245. <%
  246. End If
  247. %>
  248. </td>
  249. <td width=10>&nbsp;</td>
  250. <TD valign=TOP class="TasksBody">
  251. <div class="PageTitleText"><%=Server.HTMLEncode(mstrWizPageTitle)%></div>
  252. <br>
  253. <%
  254. Else
  255. If (mstrTaskType= TAB_PROPSHEET) Then
  256. %>
  257. <div class='PageBodyIndent'>
  258. <%
  259. Call ServeStandardHeaderBar(SAI_GetBannerText(), mstrIconPath)
  260. %>
  261. <br>
  262. <div class='PageBodyInnerIndent'>
  263. <TABLE width=87% border=0 height="65%" cellspacing=0 cellpadding=0 ID=TASKTABLE >
  264. <TR height="100%" width="100%" valign=TOP>
  265. <TD>
  266. <%
  267. If IsIE() Then
  268. %>
  269. <TABLE class="TabPropTabTable" height="100%" width="100%" border=0 cellspacing=0 cellpadding=0>
  270. <%
  271. Else
  272. %>
  273. <TABLE class="TabPropTabTable" height="500px" width="100%" border=0 cellspacing=0 cellpadding=0>
  274. <%
  275. End If
  276. %>
  277. <TR valign=TOP>
  278. <TD width="20%" height=100%>
  279. <TABLE xheight="100%" width="100%" border=0 cellspacing=0 cellpadding=0>
  280. <%
  281. intSlack = UBound(mstrTabPropSheetTabs) - LBound(mstrTabPropSheetTabs)
  282. intSlack = 100 - (2 * intSlack)
  283. If intSlack <= 0 Then
  284. intSlack = 5
  285. End If
  286. For i = LBound(mstrTabPRopSheetTabs) to UBound(mstrTabPropSheetTabs)-1
  287. Response.Write("<TR align=left height=20>"+vbCrLf)
  288. If mintTabSelected=i Then
  289. Response.Write("<TD nowrap class=TabPropTabSelected>"+vbCrLf)
  290. Else
  291. Response.Write("<TD nowrap class=TabPropTab>"+vbCrLf)
  292. End If
  293. 'Response.Write("<a href=""javascript:if (ValidatePage()) {SetData(); top.main.document.forms['frmTask'].TabSelected.value="+ CStr(i) +"; top.main.document.forms['frmTask'].submit();}"">"+vbCrLf)
  294. Response.Write("<a onmouseover=""window.status=''; return true;"" href=""javascript:SA_OnClickTab("+ CStr(i) +");"">")
  295. If mintTabSelected=i Then
  296. Response.Write("<span id='PropTab_"+CStr(i)+"' style=""overflow:visible;"" class=TabPropTabSelectedNoBorder>")
  297. Else
  298. Response.Write("<span id='PropTab_"+CStr(i)+"' style=""overflow:visible;"" class=TabPropTabNoBorder>")
  299. End If
  300. Response.Write(Server.HTMLEncode(mstrTabPropSheetTabs(i)))
  301. Response.Write("</span>")
  302. Response.Write("</a>"+vbCrLf)
  303. Response.Write("</TD>"+vbCrLf)
  304. Response.Write("</TR>"+vbCrLf)
  305. Next
  306. %>
  307. </TABLE>
  308. <TABLE height="<%=intSlack%>%" width="100%" border=0 cellspacing=0 cellpadding=0>
  309. <TR xheight="<%=intSlack%>%">
  310. <TD class="TabPropTab">&nbsp;</TD>
  311. </TR>
  312. </TABLE>
  313. </TD>
  314. <TD height="100%">
  315. <div>
  316. <%
  317. If IsIE() Then
  318. %>
  319. <TABLE onClick='return HandleClickEvent();' height="100%" width="100%" border=0 cellspacing=0>
  320. <%
  321. Else
  322. %>
  323. <TABLE onClick='return HandleClickEvent();' height="500px" width="100%" border=0 cellspacing=0>
  324. <%
  325. End If
  326. %>
  327. <TR height="100%" width="100%"><TD class=TabPropTabTaskCell valign=top>
  328. <%
  329. '
  330. ' Wizard Page Type
  331. '
  332. ElseIf (mstrTaskType="wizard") Then
  333. %>
  334. <div class='PageBodyIndent'>
  335. <%
  336. Call ServeStandardHeaderBar(SAI_GetBannerText(), mstrIconPath)
  337. %>
  338. <div class='PageBodyInnerIndent'>
  339. <TABLE width=100% border=0 height="58%" cellspacing=0 cellpadding=0 ID=TASKTABLE >
  340. <TR valign=TOP height="10%" style="xbackground-color:#FFFFFF">
  341. <TD valign=TOP>
  342. <div class="PageTitleText"><%=Server.HTMLEncode(mstrWizPageTitle)%></div>
  343. </TD>
  344. </TR>
  345. <TR height="80%" valign=TOP>
  346. <TD valign="top" height="70%">
  347. <table onClick='return HandleClickEvent();' width=90% class="TasksBody"><tr><td class="TasksBody" width=100% height=100%>
  348. <%
  349. '
  350. ' Property page
  351. '
  352. Else
  353. If ( SA_GetVersion() < gc_V2 ) Then
  354. Call SA_ServeStatusBar()
  355. Call ServeTabBar()
  356. End If
  357. %>
  358. <TABLE width=100% border=0 height="58%" cellspacing=0 cellpadding=0 ID=TASKTABLE >
  359. <TR valign=TOP height="10%" >
  360. <TD valign=TOP>
  361. <div class='PageBodyIndent'>
  362. <%
  363. Call ServeStandardHeaderBar(SAI_GetBannerText(), mstrIconPath)
  364. %>
  365. <div class="PageTitleText"><% =mstrPageTitle %></div>
  366. </div>
  367. </TD>
  368. </TR>
  369. <TR height="80%" valign=TOP>
  370. <TD valign="top" height="70%">
  371. <div class='PageBodyIndent'>
  372. <table onClick='return HandleClickEvent();' width=90% class="TasksBody"><tr><td class="TasksBody" width=100% height=100%>
  373. <div class='PageBodyInnerIndent'>
  374. <%
  375. End If
  376. End If
  377. %>
  378. <FORM name="frmTask" onSubmit="return Next();" action="<% =GetScriptFileName %>" method="POST">
  379. <INPUT name="<%=SAI_FLD_PAGEKEY%>" type="hidden" value="<%=SAI_GetPageKey()%>">
  380. <INPUT name="PageName" type="hidden" value="<% =mstrPageName %>">
  381. <INPUT name="Method" type="hidden" value="<% =mstrMethod %>">
  382. <INPUT name="ReturnURL" type="hidden" value="<% =mstrReturnURL %>">
  383. <INPUT name="TaskType" type="hidden" value="<% =mstrTaskType %>">
  384. <INPUT name="PageType" type="hidden" value="<% =mstrWizardPageType %>">
  385. <INPUT name="TabSelected" type="hidden" value="<% =mintTabSelected%>">
  386. <INPUT name="Tab1" type="hidden" value="<% =GetTab1() %>">
  387. <INPUT name="Tab2" type="hidden" value="<% =GetTab2() %>">
  388. <%
  389. ServeTaskHeader = True
  390. End Function
  391. '----------------------------------------------------------------------------
  392. '
  393. ' Function : ServeTaskFooter
  394. '
  395. ' Synopsis : Serve the task footer (navigation buttons & error div)
  396. ' Note: The function relies on the following module-level variables:
  397. ' mstrTaskType - prop wizard
  398. ' mstrWizardPageType - standard intro finish failure
  399. '
  400. ' Arguments: None
  401. '
  402. ' Returns : None
  403. '
  404. '----------------------------------------------------------------------------
  405. Function ServeTaskFooter()
  406. dim ErrMessage
  407. Response.write("</td></tr>")
  408. If GetErrMsg <> "" Then
  409. ErrMessage = "<table class='ErrMsg'><tr><td><img src='" & m_VirtualRoot & "images/critical_error.gif' border=0></td><td>" & GetErrMsg & "</td></tr></table>"
  410. SetErrMsg ""
  411. else
  412. ErrMessage =""
  413. End If
  414. If( (mstrWizardPageType<>"intro_xxx") AND (mstrWizardPageType<>"finish_zzzz") ) Then
  415. If (IsIE()) Then %>
  416. <tr><td colspan=2>
  417. <DIV name="divErrMsg" ID="divErrMsg" class="ErrMsg"><%=ErrMessage%></DIV>
  418. </td></tr>
  419. <% End If %>
  420. <% If (mstrTaskType= TAB_PROPSHEET) then %>
  421. </table>
  422. </div>
  423. </td></tr></table>
  424. </td></tr></table>
  425. </div>
  426. </div>
  427. <% Else %>
  428. </table>
  429. </td></tr></table>
  430. </div>
  431. </div>
  432. <% End If %>
  433. <% End If %>
  434. <% If Not IsIE() Then %>
  435. <layer name="layErrMsg" class="ErrMsg"><%=ErrMessage%></layer>
  436. <% End If %>
  437. <%
  438. Response.Write "</form></BODY></HTML>"
  439. End Function
  440. '----------------------------------------------------------------------------
  441. '
  442. ' Function : ServeFailurePage
  443. '
  444. ' Synopsis : Serve the page which redirects the browser to the err_view.asp
  445. ' failure page
  446. '
  447. ' Arguments: Message(IN) - message to be displayed by err_view.asp
  448. ' intTab(IN) - Tab to be highlighted by err_view.asp
  449. '
  450. ' Returns : None
  451. '
  452. '----------------------------------------------------------------------------
  453. Function ServeFailurePage(Message, intTab)
  454. Call SA_ServeFailurePage(Message)
  455. Exit Function
  456. End Function
  457. '----------------------------------------------------------------------------
  458. '
  459. ' Function : ServeClose
  460. '
  461. ' Synopsis : Redirect user to the page from which the wizard was launched
  462. '
  463. ' Arguments: None
  464. '
  465. ' Returns : None
  466. '
  467. '----------------------------------------------------------------------------
  468. Sub ServeClose
  469. %>
  470. <html>
  471. <!-- Copyright (c) Microsoft Corporation. All rights reserved.-->
  472. <head>
  473. <SCRIPT language=JavaScript>
  474. function Redirect()
  475. {
  476. top.location='<%=EscapeQuotes(mstrReturnURL)%>';
  477. }
  478. </SCRIPT>
  479. </head>
  480. <BODY onLoad="Redirect();">
  481. &nbsp;
  482. </BODY>
  483. </html>
  484. <%
  485. End Sub
  486. '----------------------------------------------------------------------------
  487. '
  488. ' Function SA_ExecuteTask
  489. '
  490. ' Synopsis Executes an Appliance Task backend object. Normally, backend Tasks
  491. ' are executed synchronously. The bExecuteAsync parameter allows overriding
  492. ' the default behavior.
  493. '
  494. ' If the oTaskContext object has not been created and initialized, this function
  495. ' will create a default oTaskContext and will initialize it by creating task
  496. ' parameters using all input form fields from the current Request object. This
  497. ' makes it easy to pass an HTML form to the appliance task.
  498. '
  499. ' If an error is encountered the really is no reasonable recovery that a
  500. ' scripting client can make.
  501. '
  502. ' Arguments [in] TaskName Name of task to execute
  503. '
  504. ' [in] bExecuteAsync Flag indicating if Task should be executed
  505. ' synchronisly (default, FALSE) or async (TRUE).
  506. '
  507. ' [in/out] oTaskContext TaskContext object for the appliance task. The TaskContext
  508. ' object can be used to pass input arguments to the Task.
  509. '
  510. ' Returns:
  511. ' SA_NO_ERROR
  512. ' The call succeeded, no errors occured
  513. '
  514. ' SA_ERROR_CREATE_OBJECT_FAILED
  515. ' Unable to create one of the required backend objects, this indicates that either the
  516. ' components were not installed correctly or that the Appliance Manager service
  517. ' is not running.
  518. '
  519. ' SA_ERROR_INITIALIZE_OBJECT_FAILED
  520. ' The Task object encountered an unrecoverable error during it's internal initialization.
  521. ' This is probably not recoverable and likely indicates a problem with either the expected
  522. ' inputs or the current state of the Appliance task.
  523. '
  524. ' All other cases
  525. ' The HRESULT return value recieved from the Task
  526. '
  527. '
  528. ' Example 1 - Create TaskContext and set input parameters:
  529. ' Dim oTaskContext
  530. ' Dim rc
  531. '
  532. ' Set oTaskContext = CreateObject("Taskctx.TaskContext")
  533. ' If Err.Number <> 0 Then
  534. ' ' Handle the error
  535. ' Exit Function
  536. ' End If
  537. '
  538. ' Call oTaskContext.SetParameter("Method Name", strMethodName)
  539. ' Call oTaskContext.SetParameter("LanguageID", strLANGID)
  540. ' Call oTaskContext.SetParameter("AutoConfig", "y")
  541. '
  542. ' rc = SA_ExecuteTask("ChangeLanguage", FALSE, oTaskContext)
  543. ' If ( rc <> SA_NO_ERROR ) Then
  544. ' ' Handle the error
  545. ' End If
  546. '
  547. ' Example 2 - Use the current input form (Request object) as input to the task
  548. ' Dim rc
  549. ' Dim oTaskContext
  550. ' Set oTaskContext = nothing
  551. ' rc = SA_ExecuteTask("MyApplianceTask", FALSE, oTaskContext)
  552. ' If ( rc <> SA_NO_ERROR ) Then
  553. ' ' Handle the error
  554. ' End If
  555. '----------------------------------------------------------------------------
  556. '
  557. ' Following signature has been deprecated in SAK 2.0 - See SA_ExecuteTask
  558. Private Function ExecuteTask(ByVal TaskName, ByRef oTaskContext)
  559. ExecuteTask = SA_ExecuteTask(TaskName, FALSE, oTaskContext)
  560. End Function
  561. Public Function SA_ExecuteTask(ByVal TaskName, ByVal bExecuteAsync, ByRef oTaskContext)
  562. on error resume next
  563. Err.Clear
  564. Dim objAS
  565. Dim objValue
  566. Dim objElementCol
  567. Dim objElement
  568. Dim oField
  569. Dim rc
  570. SA_ExecuteTask = SA_NO_ERROR
  571. '
  572. ' Create default TaskContext object if necessary
  573. '
  574. If (NOT IsObject(oTaskContext)) Then
  575. Call SA_TraceOut("SH_TASK", "SA_ExecuteTask - Creating default TaskContext")
  576. Set oTaskContext = Server.CreateObject("Taskctx.TaskContext")
  577. If (Err.Number <> 0) Then
  578. Call SA_TraceErrorOut(SA_GetScriptFileName(), "Server.CreateObject(Taskctx.TaskContext) failed: " + CStr(Hex(Err.Number)) + " " + Err.Description)
  579. SA_ExecuteTask = SA_ERROR_CREATE_OBJECT_FAILED
  580. Exit Function
  581. End If
  582. '
  583. ' Set default value of parameters
  584. For Each oField in Request.Form
  585. oTaskContext.SetParameter oField, CStr(Request.Form(oField))
  586. Next
  587. End If
  588. '
  589. ' Get interface to ApplianceServices interface, the object that allows us to invoke tasks
  590. Set objAS = Server.CreateObject("Appsrvcs.ApplianceServices")
  591. If (Err.Number <> 0) Then
  592. Call SA_TraceErrorOut(SA_GetScriptFileName(), "Server.CreateObject(Appsrvcs.ApplianceServices) failed: " + CStr(Hex(Err.Number)) + " " + Err.Description)
  593. SA_ExecuteTask = SA_ERROR_CREATE_OBJECT_FAILED
  594. Exit Function
  595. End If
  596. '
  597. ' Initialize ApplianceServices object
  598. objAS.Initialize()
  599. If (Err.Number <> 0) Then
  600. Call SA_TraceErrorOut(SA_GetScriptFileName(), "objAS.Initialize() for object Appsrvcs.ApplianceServices failed: " + CStr(Hex(Err.Number)) + " " + Err.Description)
  601. SA_ExecuteTask = SA_ERROR_INITIALIZE_OBJECT_FAILED
  602. Exit Function
  603. End If
  604. '
  605. ' Initialize context parameters
  606. oTaskContext.SetParameter PROPERTY_TASK_NICE_NAME, mstrTaskTitle
  607. oTaskContext.SetParameter PROPERTY_TASK_URL, m_VirtualRoot + GetScriptPath()
  608. Err.Clear
  609. If ( TRUE = bExecuteAsync ) Then
  610. 'Call SA_TraceOut("SH_TASK", "Calling objAS.ExecuteTaskAsync("+TaskName+", oTaskContext)")
  611. Call objAS.ExecuteTaskAsync(TaskName, oTaskContext)
  612. Else
  613. 'Call SA_TraceOut("SH_TASK", "Calling objAS.ExecuteTask("+TaskName+", oTaskContext)")
  614. Call objAS.ExecuteTask(TaskName, oTaskContext)
  615. End If
  616. If ( Err.Number <> 0 ) Then
  617. SA_ExecuteTask = Err.Number
  618. Call SA_TraceErrorOut(SA_GetScriptFileName(), "Task execution returned failure code: " + CStr(Hex(Err.Number)) + " " + Err.Description)
  619. End If
  620. objAS.Shutdown()
  621. Err.Clear
  622. Set objAS = Nothing
  623. End Function
  624. Private Function SA_TaskToPageType()
  625. If ( mstrTaskType = "prop" ) Then
  626. SA_TaskToPageType = "Property Page"
  627. ElseIf ( mstrTaskType = TAB_PROPSHEET) Then
  628. SA_TaskToPageType = "Tabbed Property Page"
  629. ElseIf ( mstrTaskType = "wizard") Then
  630. SA_TaskToPageType = "Wizard Page"
  631. Else
  632. SA_TaskToPageType = "Unknown Page Type"
  633. End If
  634. End Function
  635. %>