/// <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");
        }
        static public void Execute()
        {
            Console.WriteLine("AuthProjectExecuteCode - 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("AuthProjectExecuteCode: created temporary R session, rProject=" + rProject);


            // 4. Execute an analytics Web service based on an arbitrary
            // block of R code.
            //
            // Optionally:
            // ProjectExecutionOptions options = new ProjectExecutionOptions();
            //
            // Populate options as needed, then:
            //
            // exec = rProject.executeCode(rCode, options);
            //
            String rCode = "demo(graphics)";

            exec = rProject.executeCode(rCode);

            Console.WriteLine("AuthProjectExecuteCode: R code 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("AuthProjectExecuteCode - end");
        }
Beispiel #4
0
        static public void Execute()
        {
            Console.WriteLine("AuthProjectWorkspace - 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("AuthProjectWorkspace: created temporary " +
                              "R session, rProject=" + rProject);

            //
            // 4. Execute a block of R code to create an object
            // in the R session's workspace.
            //
            String rCode = "x <- T";

            exec = rProject.executeCode(rCode);

            //
            // 5. Retrieve the object "x" from the R session's workspace.
            //
            RData encodedX = rProject.getObject("x");

            if (encodedX is RBoolean)
            {
                Console.WriteLine("retrieved object x from workspace, x=" + (Boolean)encodedX.Value);
            }

            //
            // 6. Create R object data in the R sesssion's workspace
            // by pushing DeployR-encoded data from the client application.
            //
            // - Prepare sample R object vector data.
            // - Use RDataFactory to encode the sample R object vector data.
            // - Push encoded R object into the workspace.
            //
            List <Double?> vectorValues = new List <Double?>();

            vectorValues.Add(10.0);
            vectorValues.Add(11.1);
            vectorValues.Add(12.2);
            vectorValues.Add(13.3);
            vectorValues.Add(14.4);

            RData encodedY = RDataFactory.createNumericVector("y", vectorValues);

            rProject.pushObject(encodedY);

            //
            // 7. Retrieve the DeployR-encoding of the R object
            // from the R session's workspace.
            //
            encodedY = rProject.getObject("y");

            if (encodedY is RNumericVector)
            {
                List <Double?> numVectorValues = (List <Double?>)encodedY.Value;
                StringBuilder  str             = new StringBuilder();
                foreach (Double?val in numVectorValues)
                {
                    str.Append(val + " ");
                }
                Console.WriteLine("retrieved object y from workspace, encodedY=" + str.ToString());
            }

            //
            // 8. Retrieve a list of R objects in the R session's workspace.
            //
            // Optionally:
            // ProjectWorkspaceOptions options = new ProjectWorkspaceOptions();
            //
            // Populate options as needed, then:
            //
            // objs = rProject.listObjects(options);
            //
            ///
            objs = rProject.listObjects();

            //
            // 9. Cleanup
            //
            rProject.close();
            Utility.Cleanup(rUser, rClient);

            Console.WriteLine("AuthProjectWorkspace - end");
        }