Пример #1
0
        static public void Execute()
        {
            Console.WriteLine("AnonProjectExecuteScript - start");

            //
            // 1. Connect to the DeployR Server
            //
            RClient rClient = Utility.Connect();

            //
            // 2. Execute a public analytics Web service as an anonymous
            // user based on a repository-managed R script:
            // /testuser/root/DeployR - Hello World.R
            //
            // Create the AnonymousProjectExecutionOptions object
            // to specify inputs and output to the script
            // The R object that is an input to the script is 'input_randomNum'
            // The R object that we want to retrieve after script execution is 'x'
            //

            AnonymousProjectExecutionOptions options = new AnonymousProjectExecutionOptions();

            options.rinputs.Add(RDataFactory.createNumeric("input_randomNum", 100));
            options.routputs.Add("x");

            exec = rClient.executeScript("DeployR - Hello World",
                                         "root",
                                         "testuser",
                                         "",
                                         options);

            Console.WriteLine("AnonProjectExecuteScript: public repository-managed " +
                              "script execution completed, exec=" + exec);

            //
            // 3. Retrieve script execution results.
            //
            console = exec.about().console;
            plots   = exec.about().results;
            files   = exec.about().artifacts;
            objects = exec.about().workspaceObjects;

            RNumericVector xVec = (RNumericVector)objects[0];

            Console.WriteLine("AnonProjectExecuteScript - end");
        }
        static public void Execute()
        {
            Console.WriteLine("AnonProjectExecuteScript - start");

            //
            // 1. Connect to the DeployR Server
            //
            RClient rClient = Utility.Connect();

            //
            // 2. Execute a public analytics Web service as an anonymous
            // user based on a repository-managed R script:
            // /testuser/root/Histogram of Auto Sales.R.
            //
            // Optionally:
            // AnonymousProjectExecutionOptions options = new AnonymousProjectExecutionOptions();
            //
            // Populate options as needed, then:
            //
            // RScriptExecution exec =
            // rClient.executeScript(filename, directory, author, version, options);
            //
            exec = rClient.executeScript("Histogram of Auto Sales",
                                         "root",
                                         "testuser",
                                         "",
                                         null);

            Console.WriteLine("AnonProjectExecuteScript: public repository-managed " +
                              "script execution completed, exec=" + exec);

            //
            // 3. Retrieve script execution results.
            //
            console = exec.about().console;
            plots   = exec.about().results;
            files   = exec.about().artifacts;
            objects = exec.about().workspaceObjects;

            Console.WriteLine("AnonProjectExecuteScript - end");
        }
Пример #3
0
        /// <summary>
        /// Run the acutal discrete task using Client API
        /// </summary>
        /// <returns>Results of the discrete task</returns>
        /// <remarks></remarks>
        public RTaskResult call()
        {
            RTaskResult taskResult = null;

            long timeOnCall = 0L;

            //long timeOnServer = 0L;

            try
            {
                AnonymousProjectExecutionOptions options = ROptionsTranslator.translate(m_task.options);

                long startTime = Environment.TickCount;

                RScriptExecution execResult = m_rClient.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.DISCRETE,
                                                 true,
                                                 execResult.about().timeCode,
                                                 execResult.about().timeTotal,
                                                 timeOnCall, null,
                                                 false,
                                                 generatedConsole,
                                                 generatedPlots,
                                                 generatedFiles,
                                                 generatedObjects,
                                                 storedFiles);
            }
            catch (Exception ex)
            {
                //if(ex.getCause() == typeof(InterruptedException))
                //{

                /*
                 * RTaskToken.cancel() can raise an InterruptedException.
                 * When an InterruptedException is detected the DiscreteTask
                 * executing on the server should be aborted at this point.
                 * However, there is no way to obtain DeployR reference, such
                 * as a projectId, for an stateless execution in-progress, so
                 * aborting the current RTask operation is not possible.
                 */
                //}

                taskResult = new RTaskResultImpl(null,
                                                 RTaskType.DISCRETE,
                                                 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);
        }