/// <summary> /// Run the acutal discrete task using Project API /// </summary> /// <returns>Results of the pooled task</returns> /// <remarks></remarks> public RTaskResult call() { RTaskResult taskResult = null; long timeOnCall = 0L; //long timeOnServer = 0L; try { ProjectExecutionOptions options = ROptionsTranslator.translate(m_task.options); long startTime = Environment.TickCount; RProjectExecution execResult = m_rProject.executeScript(m_task.filename, m_task.directory, m_task.author, m_task.version, options); timeOnCall = Environment.TickCount - startTime; String generatedConsole = execResult.about().console; List <String> generatedPlots = new List <String>(); if (execResult.about().results != null) { foreach (RProjectResult result in execResult.about().results) { generatedPlots.Add(result.about().url); } } List <String> generatedFiles = new List <String>(); if (execResult.about().artifacts != null) { foreach (RProjectFile artifact in execResult.about().artifacts) { generatedFiles.Add(artifact.about().url); } } List <RData> generatedObjects = execResult.about().workspaceObjects; List <String> storedFiles = new List <String>(); if (execResult.about().repositoryFiles != null) { foreach (RRepositoryFile repoFile in execResult.about().repositoryFiles) { storedFiles.Add(repoFile.about().url); } } taskResult = new RTaskResultImpl(execResult.about().id, RTaskType.POOLED, true, execResult.about().timeCode, execResult.about().timeTotal, timeOnCall, null, false, generatedConsole, generatedPlots, generatedFiles, generatedObjects, storedFiles); } catch (Exception ex) { //if(ex.getCause() instanceof InterruptedException) //{ try { /* * If RTaskToken.cancel() raises InterruptedException * then ensure any corresponding execution on RProject is * also cancelled. */ m_rProject.interruptExecution(); } catch (Exception iex) { throw new Exception("Project cancel Exception occurred: " + iex.ToString()); } //} taskResult = new RTaskResultImpl(null, RTaskType.POOLED, false, 0L, 0L, 0L, ex); } finally { /* * Callback to PooledTaskBroker to release * RProject back into pool for other tasks. */ m_rBroker.callback(m_task, taskResult); } return(taskResult); }
static public void Execute() { Console.WriteLine("AuthProjectExecuteScript - start"); // // 1. Connect to the DeployR Server // RClient rClient = Utility.Connect(); // // 2. Authenticate the user // RUser rUser = Utility.Authenticate(rClient); // // 3. Create a temporary project (R session). // // Optionally: // ProjectCreationOptions options = new ProjectCreationOptions(); // // Populate options as needed, then: // // rProject = rUser.createProject(options); // RProject rProject = rUser.createProject(); Console.WriteLine("AuthProjectExecuteScript: created temporary R session, rProject=" + rProject); // // 4. Execute an analytics Web service based on a repository-managed // R script: /testuser/root/Histogram of Auto Sales.R. // // Optionally: // ProjectExecutionOptions options = new ProjectExecutionOptions(); // // Populate options as needed, then: // // exec = rProject.executeScript(filename, directory, author, version, options); // exec = rProject.executeScript("Histogram of Auto Sales", "root", "testuser", "", null); Console.WriteLine("AuthProjectExecuteScript: repository-managed script execution completed, exec=" + exec); // // 5. Retrieve code execution results. // console = exec.about().console; plots = exec.about().results; files = exec.about().artifacts; objects = exec.about().workspaceObjects; // // 6. Cleanup // rProject.close(); Utility.Cleanup(rUser, rClient); Console.WriteLine("AuthProjectExecuteScript - end"); }