# 1) Copy the simulate.asc and curl.exe in the library # 2) Add in the ON_EVENT AppInitialized the line: EXECUTE file:"db:\\simulate.asc" # 3) Create a menu item: ITEM "Remote Simulation" simulation PERFORM_SIMULATION PROCEDURE global PERFORM_SIMULATION { SETL host:("http://127.0.0.1:8080/simulation") SETL numExecutions:("1000") CC "AdoScript" EDITFIELD title:"Enter the simulation REST URL" caption:"Simulation service URL:" text:(host) IF (ecode != 0) { EXIT } SETL host:(text) CC "AdoScript" EDITFIELD title:"Enter the number of executions" caption:"Number of executions to simulate:" text:(numExecutions) IF (ecode != 0) { EXIT } SETL numExecutions:(text) CC "AdoScript" GET_TEMP_FILENAME SETL sTempFilename: (filename) SETL nPosFileName: (bsearch ( sTempFilename , "\\" , (LEN sTempFilename)-1 )) SETL sTempFolder: (copy ( sTempFilename , 0 , nPosFileName+1 )) SETL sRestClientName: ("curl.exe") SETL curlPath:(sTempFolder+sRestClientName) CC "AdoScript" FILE_COPY from: ("db:\\"+sRestClientName) to: (curlPath) #choose the models CC "ImportExport" SHOW_EXPORT_DLG mode: "xml" title: "Select a Model Set to simulate" filedescription: "xml" fileextension: "*.xml" filename: (sTempFilename+".xml") IF (endbutton != "ok") { EXIT } SETL sModelIDList:(modelids) SETL sTempModelSetPath:(filename) #Export the whole xml CC "Documentation" XML_MODELS modelids: (sModelIDList) mgroupids: ("") attrprofs: ("") apgroups: ("") IF (ecode != 0) { CC "AdoScript" ERRORBOX ("Error exporting the models") EXIT } SETL sFullXml:(xml) CC "AdoScript" FWRITE file: (sTempModelSetPath) text: (sFullXml) append: 0 binary: 0 base64: 0 CC "AdoScript" FREAD file: (sTempModelSetPath) IF (text = "") { CC "AdoScript" ERRORBOX ("Failure on the creation of the file: " + sTempModelSetPath) EXIT } #Launch the simulation and get the result GET_SIMULATION_RESULTS host:(host) curlPath:(curlPath) sModelPath:(sTempModelSetPath) numExecutions:(numExecutions) result:sSimulationResults IF (sSimulationResults = "") { CC "AdoScript" ERRORBOX ("Error performing the simulation") EXIT } CC "AdoScript" VIEWBOX text:(sSimulationResults) title:("Simulation raw results") fontheight:15 } #The GET_SIMULATION_RESULTS procedure call the simulation REST service using CURL. PROCEDURE global GET_SIMULATION_RESULTS host: string curlPath: string sModelPath: string numExecutions: string result: reference { CC "AdoScript" GET_TEMP_FILENAME SETL sTempOutputFilePath:(filename+".SIM_OUTPUT") SETL sTempTraceFilePath:(filename+".SIM_TRACE") SYSTEM ( "cmd /c "+curlPath+" -X POST --trace-ascii \""+sTempTraceFilePath+"\" -H \"Content-Type: application/xml\" --compress --data-binary @\""+sModelPath+"\" \""+host+"/rest/simulator/pathanalysis?numExecutions="+numExecutions+"\">"+sTempOutputFilePath) CC "AdoScript" FREAD file: (sTempOutputFilePath) SETL result:(text) IF (result != "") { CC "AdoScript" FILE_DELETE file: (sTempOutputFilePath) CC "AdoScript" FILE_DELETE file: (sTempTraceFilePath) } ELSE { CC "AdoScript" FREAD file: (sTempTraceFilePath) SETL result:(text) } }