public static 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");

            RScriptExecution 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.
            //
            String console = exec.about().console;
            List<RProjectResult> plots = exec.about().results;
            List<RProjectFile> files = exec.about().artifacts;
            List<RData> objects = exec.about().workspaceObjects;

            RNumericVector xVec = (RNumericVector)objects[0];

            Console.WriteLine("AnonProjectExecuteScript - end");
        }
        private String renderScriptImp(String scriptName, String scriptDirectory, String scriptAuthor, String scriptVersion, AnonymousProjectExecutionOptions options)
        {
            StringBuilder data = new StringBuilder();

            //set the url
            String uri = Constants.RREPOSITORYSCRIPTRENDER;

            //create the input String
            data.Append(Constants.FORMAT_JSON);

            data.Append("&filename=" + HttpUtility.UrlEncode(scriptName));
            data.Append("&directory=" + HttpUtility.UrlEncode(scriptDirectory));
            data.Append("&author=" + HttpUtility.UrlEncode(scriptAuthor));
            data.Append("&version=" + HttpUtility.UrlEncode(scriptVersion));

            if (!(options == null))
            {
                data.Append("&blackbox=" + options.blackbox.ToString());
                data.Append("&recycle=" + options.recycle.ToString());
                data.Append("&csvinputs=" + HttpUtility.UrlEncode(options.csvrinputs));
                data.Append("&cluster=" + HttpUtility.UrlEncode(options.gridCluster));

                if (!(options.rinputs == null))
                {
                    if (options.rinputs.Count > 0)
                    {
                        data.Append("&inputs=");
                        String sJSON = JSONSerialize.createJSONfromRData(options.rinputs);
                        data.Append(HttpUtility.UrlEncode(sJSON));
                        if (HTTPUtilities.DEBUGMODE == true)
                        {
                            Console.Write(sJSON);
                        }
                    }
                }

                if (!(options.preloadDirectory == null))
                {
                    data.Append("&preloadfilename=" + HttpUtility.UrlEncode(options.preloadDirectory.filename));
                    data.Append("&preloadfiledirectory=" + HttpUtility.UrlEncode(options.preloadDirectory.directory));
                    data.Append("&preloadfileauthor=" + HttpUtility.UrlEncode(options.preloadDirectory.author));
                    data.Append("&preloadfileversion=" + HttpUtility.UrlEncode(options.preloadDirectory.version));
                }

                if (!(options.preloadWorkspace == null))
                {
                    data.Append("&preloadobjectname=" + HttpUtility.UrlEncode(options.preloadWorkspace.filename));
                    data.Append("&preloadobjectdirectory=" + HttpUtility.UrlEncode(options.preloadWorkspace.directory));
                    data.Append("&preloadobjectauthor=" + HttpUtility.UrlEncode(options.preloadWorkspace.author));
                    data.Append("&preloadobjectversion=" + HttpUtility.UrlEncode(options.preloadWorkspace.version));
                }

                if (!(options.adoptionOptions == null))
                {
                    data.Append("&adoptworkspace=" + HttpUtility.UrlEncode(options.adoptionOptions.adoptWorkspace));
                    data.Append("&adoptdirectory=" + HttpUtility.UrlEncode(options.adoptionOptions.adoptDirectory));
                    data.Append("&adoptpackages=" + HttpUtility.UrlEncode(options.adoptionOptions.adoptPackages));
                }

                if (!(options.storageOptions == null))
                {
                    data.Append("&storefile=" + HttpUtility.UrlEncode(options.storageOptions.files));
                    data.Append("&storedirectory=" + HttpUtility.UrlEncode(options.storageOptions.directory));
                    data.Append("&storeobject=" + HttpUtility.UrlEncode(options.storageOptions.objects));
                    data.Append("&storeworkspace=" + HttpUtility.UrlEncode(options.storageOptions.workspace));
                    data.Append("&storenewversion=" + options.storageOptions.newVersion.ToString());
                    data.Append("&storepublic=" + options.storageOptions.published.ToString());
                }

                if (!(options.routputs == null))
                {
                    if (options.routputs.Count > 0)
                    {
                        data.Append("&robjects=");
                        foreach (var s in options.routputs)
                        {
                            data.Append(HttpUtility.UrlEncode(s) + ",");
                        }
                        data.Remove(data.Length - 1, 1);
                    }
                }

                data.Append("&echooff=" + options.echooff.ToString());
                data.Append("&consoleoff=" + options.consoleoff.ToString());
                data.Append("&tag=" + HttpUtility.UrlEncode(options.tag));
                data.Append("&graphics=" + HttpUtility.UrlEncode(options.graphicsDevice));
                data.Append("&graphicswidth=" + HttpUtility.UrlEncode(options.graphicsWidth.ToString()));
                data.Append("&graphicsheight=" + HttpUtility.UrlEncode(options.graphicsHeight.ToString()));
                data.Append("&nan=" + HttpUtility.UrlEncode(options.nan));
                data.Append("&infinity=" + HttpUtility.UrlEncode(options.infinity));
                data.Append("&encodeDataFramePrimitiveAsVector=" + options.encodeDataFramePrimitiveAsVector.ToString());
                data.Append("&enableConsoleEvents=" + options.enableConsoleEvents.ToString());
                data.Append("&preloadbydirectory=" + HttpUtility.UrlEncode(options.preloadByDirectory));
            }

            //call the server
            RClient client      = this;
            String  returnValue = HTTPUtilities.callRESTHTMLGet(uri + "/" + "jsessionid=" + m_cookie.Value, data.ToString(), ref client);

            return(returnValue);
        }
        /// <summary>
        /// Execute a single repository-managed script or a chain of repository-managed scripts
        /// on an anonymous project and render the outputs to a HTML page.
        ///
        /// To execute a chain of repository-managed scripts on this call provide a comma-separated
        /// list of values on the scriptName, scriptAuthor and optionally scriptVersion parameters.
        /// Chained execution executes each of the scripts identified on the call in a sequential
        /// fashion on the R session, with execution occuring in the order specified on the parameter list.
        /// </summary>
        /// <param name="scriptName">name of valid R Script</param>
        /// <param name="scriptDirectory">directory containing R Script.</param>
        /// <param name="scriptAuthor">author of the R Script</param>
        /// <param name="scriptVersion">version of the R Script to execute</param>
        /// <param name="options">execute options associated with the R Script</param>
        /// <returns>URL to HTML page with outputs</returns>
        /// <remarks></remarks>
        public String renderScript(String scriptName, String scriptDirectory, String scriptAuthor, String scriptVersion, ref AnonymousProjectExecutionOptions options)
        {
            String returnValue = renderScriptImp(scriptName, scriptDirectory, scriptAuthor, scriptVersion, options);

            return(returnValue);
        }
        /// <summary>
        /// Execute a single script found on a URL/path or a chain of scripts found on a set of URLs/paths
        /// on an anonymous project.
        ///
        /// To execute a chain of repository-managed scripts on this call provide a comma-separated
        /// list of values on the externalSource parameter.
        /// Chained execution executes each of the scripts identified on the call in a sequential
        /// fashion on the R session, with execution occuring in the order specified on the parameter list.
        ///
        /// POWER_USER privileges are required for this call.
        /// </summary>
        /// <param name="externalSource">URL or DeployR file path</param>
        /// <param name="options">execute options associated with the external script</param>
        /// <returns>RScriptExecution object</returns>
        /// <remarks></remarks>
        public RScriptExecution executeExternal(String externalSource, AnonymousProjectExecutionOptions options)
        {
            RScriptExecution returnValue = executeScriptImp(null, null, null, null, externalSource, options);

            return(returnValue);
        }
        /// <summary>
        /// Execute a single repository-managed script or a chain of repository-managed scripts
        /// on an anonymous project.
        ///
        /// To execute a chain of repository-managed scripts on this call provide a comma-separated
        /// list of values on the scriptName, scriptAuthor and optionally scriptVersion parameters.
        /// Chained execution executes each of the scripts identified on the call in a sequential
        /// fashion on the R session, with execution occuring in the order specified on the parameter list.
        ///
        /// </summary>
        /// <param name="scriptName">name of valid R Script</param>
        /// <param name="scriptDirectory">directory containing R Script.</param>
        /// <param name="scriptAuthor">author of the R Script</param>
        /// <param name="scriptVersion">version of the R Script to execute</param>
        /// <param name="options">execute options associated with the R Script</param>
        /// <returns>RScriptExecution object</returns>
        /// <remarks></remarks>
        public RScriptExecution executeScript(String scriptName, String scriptDirectory, String scriptAuthor, String scriptVersion, AnonymousProjectExecutionOptions options)
        {
            RScriptExecution returnValue = executeScriptImp(scriptName, scriptDirectory, scriptAuthor, scriptVersion, null, options);

            return(returnValue);
        }
        public static AnonymousProjectExecutionOptions translate(DiscreteTaskOptions taskOptions)
        {
            AnonymousProjectExecutionOptions options = null;

            if (taskOptions != null)
            {

                options = new AnonymousProjectExecutionOptions();

                /*
                 * DiscreteTaskOptions to ProjectExecutionOptions.
                 */

                options.rinputs = taskOptions.rinputs;
                options.csvrinputs = taskOptions.csvrinputs;

                if (taskOptions.preloadWorkspace != null)
                {

                    options.preloadWorkspace = new ProjectPreloadOptions();
                    options.preloadWorkspace.filename = taskOptions.preloadWorkspace.filename;
                    options.preloadWorkspace.directory = taskOptions.preloadWorkspace.directory;
                    options.preloadWorkspace.author = taskOptions.preloadWorkspace.author;
                    options.preloadWorkspace.version = taskOptions.preloadWorkspace.version;
                }

                if (taskOptions.preloadDirectory != null)
                {

                    options.preloadDirectory = new ProjectPreloadOptions();
                    options.preloadDirectory.filename = taskOptions.preloadDirectory.filename;
                    options.preloadDirectory.directory = taskOptions.preloadDirectory.directory;
                    options.preloadDirectory.author = taskOptions.preloadDirectory.author;
                    options.preloadDirectory.version = taskOptions.preloadDirectory.version;
                }
                options.preloadByDirectory = taskOptions.preloadByDirectory;

                options.graphicsDevice = taskOptions.graphicsDevice;
                options.graphicsWidth = taskOptions.graphicsWidth;
                options.graphicsHeight = taskOptions.graphicsHeight;
                options.echooff = taskOptions.echooff;
                options.consoleoff = taskOptions.consoleoff;
                options.routputs = taskOptions.routputs;
                options.encodeDataFramePrimitiveAsVector = taskOptions.encodeDataFramePrimitiveAsVector;
                options.nan = taskOptions.nan;
                options.infinity = taskOptions.infinity;

                if (taskOptions.storageOptions != null)
                {

                    options.storageOptions = new ProjectStorageOptions();
                    options.storageOptions.directory = taskOptions.storageOptions.directory;
                    options.storageOptions.files = taskOptions.storageOptions.files;
                    options.storageOptions.newVersion = taskOptions.storageOptions.newVersion;
                    options.storageOptions.objects = taskOptions.storageOptions.objects;
                    options.storageOptions.published = taskOptions.storageOptions.published;
                    options.storageOptions.workspace = taskOptions.storageOptions.workspace;
                }

            }

            return options;
        }
        private String renderScriptImp(String scriptName, String scriptDirectory, String scriptAuthor, String scriptVersion, AnonymousProjectExecutionOptions options)
        {
            StringBuilder data = new StringBuilder();

            //set the url
            String uri = Constants.RREPOSITORYSCRIPTRENDER;
            //create the input String
            data.Append(Constants.FORMAT_JSON);

            data.Append("&filename=" + HttpUtility.UrlEncode(scriptName));
            data.Append("&directory=" + HttpUtility.UrlEncode(scriptDirectory));
            data.Append("&author=" + HttpUtility.UrlEncode(scriptAuthor));
            data.Append("&version=" + HttpUtility.UrlEncode(scriptVersion));

            if (!(options == null))
            {

                data.Append("&blackbox=" + options.blackbox.ToString());
                data.Append("&recycle=" + options.recycle.ToString());
                data.Append("&csvinputs=" + HttpUtility.UrlEncode(options.csvrinputs));
                data.Append("&cluster=" + HttpUtility.UrlEncode(options.gridCluster));

                if (!(options.rinputs == null))
                {
                    if (options.rinputs.Count > 0)
                    {
                        data.Append("&inputs=");
                        String sJSON = JSONSerialize.createJSONfromRData(options.rinputs);
                        data.Append(HttpUtility.UrlEncode(sJSON));
                        if (HTTPUtilities.DEBUGMODE == true)
                        {
                            Console.Write(sJSON);
                        }
                    }
                }

                if (!(options.preloadDirectory == null))
                {
                    data.Append("&preloadfilename=" + HttpUtility.UrlEncode(options.preloadDirectory.filename));
                    data.Append("&preloadfiledirectory=" + HttpUtility.UrlEncode(options.preloadDirectory.directory));
                    data.Append("&preloadfileauthor=" + HttpUtility.UrlEncode(options.preloadDirectory.author));
                    data.Append("&preloadfileversion=" + HttpUtility.UrlEncode(options.preloadDirectory.version));
                }

                if (!(options.preloadWorkspace == null))
                {
                    data.Append("&preloadobjectname=" + HttpUtility.UrlEncode(options.preloadWorkspace.filename));
                    data.Append("&preloadobjectdirectory=" + HttpUtility.UrlEncode(options.preloadWorkspace.directory));
                    data.Append("&preloadobjectauthor=" + HttpUtility.UrlEncode(options.preloadWorkspace.author));
                    data.Append("&preloadobjectversion=" + HttpUtility.UrlEncode(options.preloadWorkspace.version));
                }

                if (!(options.adoptionOptions == null))
                {
                    data.Append("&adoptworkspace=" + HttpUtility.UrlEncode(options.adoptionOptions.adoptWorkspace));
                    data.Append("&adoptdirectory=" + HttpUtility.UrlEncode(options.adoptionOptions.adoptDirectory));
                    data.Append("&adoptpackages=" + HttpUtility.UrlEncode(options.adoptionOptions.adoptPackages));
                }

                if (!(options.storageOptions == null))
                {
                    data.Append("&storefile=" + HttpUtility.UrlEncode(options.storageOptions.files));
                    data.Append("&storedirectory=" + HttpUtility.UrlEncode(options.storageOptions.directory));
                    data.Append("&storeobject=" + HttpUtility.UrlEncode(options.storageOptions.objects));
                    data.Append("&storeworkspace=" + HttpUtility.UrlEncode(options.storageOptions.workspace));
                    data.Append("&storenewversion=" + options.storageOptions.newVersion.ToString());
                    data.Append("&storepublic=" + options.storageOptions.published.ToString());
                }

                if (!(options.routputs == null))
                {
                    if (options.routputs.Count > 0)
                    {
                        data.Append("&robjects=");
                        foreach (var s in options.routputs)
                        {
                            data.Append(HttpUtility.UrlEncode(s) + ",");
                        }
                        data.Remove(data.Length - 1, 1);
                    }
                }

                data.Append("&echooff=" + options.echooff.ToString());
                data.Append("&consoleoff=" + options.consoleoff.ToString());
                data.Append("&tag=" + HttpUtility.UrlEncode(options.tag));
                data.Append("&graphics=" + HttpUtility.UrlEncode(options.graphicsDevice));
                data.Append("&graphicswidth=" + HttpUtility.UrlEncode(options.graphicsWidth.ToString()));
                data.Append("&graphicsheight=" + HttpUtility.UrlEncode(options.graphicsHeight.ToString()));
                data.Append("&nan=" + HttpUtility.UrlEncode(options.nan));
                data.Append("&infinity=" + HttpUtility.UrlEncode(options.infinity));
                data.Append("&encodeDataFramePrimitiveAsVector=" + options.encodeDataFramePrimitiveAsVector.ToString());
                data.Append("&enableConsoleEvents=" + options.enableConsoleEvents.ToString());
                data.Append("&preloadbydirectory=" + HttpUtility.UrlEncode(options.preloadByDirectory));

            }

            //call the server
            RClient client = this;
            String returnValue = HTTPUtilities.callRESTHTMLGet(uri + "/" + "jsessionid=" + m_cookie.Value, data.ToString(), ref client);
            return returnValue;
        }
        /// <summary>
        /// Execute a single repository-managed script or a chain of repository-managed scripts
        /// on an anonymous project and render the outputs to a HTML page.
        ///
        /// To execute a chain of repository-managed scripts on this call provide a comma-separated
        /// list of values on the scriptName, scriptAuthor and optionally scriptVersion parameters.
        /// Chained execution executes each of the scripts identified on the call in a sequential
        /// fashion on the R session, with execution occuring in the order specified on the parameter list.
        /// </summary>
        /// <param name="scriptName">name of valid R Script</param>
        /// <param name="scriptDirectory">directory containing R Script.</param>
        /// <param name="scriptAuthor">author of the R Script</param>
        /// <param name="scriptVersion">version of the R Script to execute</param>
        /// <param name="options">execute options associated with the R Script</param>
        /// <returns>URL to HTML page with outputs</returns>
        /// <remarks></remarks>
        public String renderScript(String scriptName, String scriptDirectory, String scriptAuthor, String scriptVersion, ref AnonymousProjectExecutionOptions options)
        {
            String returnValue = renderScriptImp(scriptName, scriptDirectory, scriptAuthor, scriptVersion, options);

            return returnValue;
        }
        /// <summary>
        /// Execute a single repository-managed script or a chain of repository-managed scripts
        /// on an anonymous project.
        ///
        /// To execute a chain of repository-managed scripts on this call provide a comma-separated
        /// list of values on the scriptName, scriptAuthor and optionally scriptVersion parameters.
        /// Chained execution executes each of the scripts identified on the call in a sequential
        /// fashion on the R session, with execution occuring in the order specified on the parameter list.
        ///
        /// </summary>
        /// <param name="scriptName">name of valid R Script</param>
        /// <param name="scriptDirectory">directory containing R Script.</param>
        /// <param name="scriptAuthor">author of the R Script</param>
        /// <param name="scriptVersion">version of the R Script to execute</param>
        /// <param name="options">execute options associated with the R Script</param>
        /// <returns>RScriptExecution object</returns>
        /// <remarks></remarks>
        public RScriptExecution executeScript(String scriptName, String scriptDirectory, String scriptAuthor, String scriptVersion, AnonymousProjectExecutionOptions options)
        {
            RScriptExecution returnValue = executeScriptImp(scriptName, scriptDirectory, scriptAuthor, scriptVersion, null, options);

            return returnValue;
        }
        /// <summary>
        /// Execute a single script found on a URL/path or a chain of scripts found on a set of URLs/paths
        /// on an anonymous project.
        ///
        /// To execute a chain of repository-managed scripts on this call provide a comma-separated
        /// list of values on the externalSource parameter.
        /// Chained execution executes each of the scripts identified on the call in a sequential
        /// fashion on the R session, with execution occuring in the order specified on the parameter list.
        ///
        /// POWER_USER privileges are required for this call.
        /// </summary>
        /// <param name="externalSource">URL or DeployR file path</param>
        /// <param name="options">execute options associated with the external script</param>
        /// <returns>RScriptExecution object</returns>
        /// <remarks></remarks>
        public RScriptExecution executeExternal(String externalSource, AnonymousProjectExecutionOptions options)
        {
            RScriptExecution returnValue = executeScriptImp(null, null, null, null, externalSource, options);

            return returnValue;
        }