static public void Execute() { Console.WriteLine("AuthRepositoryManagement - start"); // // 1. Connect to the DeployR Server // RClient rClient = Utility.Connect(); // // 2. Authenticate the user // RUser rUser = Utility.Authenticate(rClient); // // 3. Create a file in the authenticated user's private // repository and set shared access on the file so // other authenticated users can access the file. // RepoUploadOptions options = new RepoUploadOptions(); options.filename = "hello.txt"; options.sharedUser = true; String fileContent = "Hello World!"; RRepositoryFile rRepositoryFile = rUser.writeFile(fileContent, options); // // 4. Download working directory file content using // standard Java URL. // String fileURL = rRepositoryFile.download(); // // 5. Retrieve a list of files in the authenticated user's // private repository. // List <RRepositoryFile> files = rUser.listFiles(); foreach (RRepositoryFile file in files) { Console.WriteLine("AuthRepositoryManagement: private repository, " + "found file name=" + file.about().filename + ", directory=" + file.about().directory + ", access=" + file.about().access); } // // 6. Cleanup // Utility.Cleanup(rUser, rClient); Console.WriteLine("AuthRepositoryManagement - end"); }
static public void Execute() { Console.WriteLine("AuthJobStoreResultToRepository - start"); // // 1. Connect to the DeployR Server // RClient rClient = Utility.Connect(); // // 2. Authenticate the user // RUser rUser = Utility.Authenticate(rClient); // // 3. Submit a background job to execute a block of R code // that will generate a vector object. We will then use // JobExecutionOtpions to request the following behavior: // // a. Execute the job at low (default) priority. // b. Skip the persistence of results to a project. // c. Request the persistence of a named vector object // as a binary R object file to the repository. // String rCode = "tutorialVector <- rnorm(100)"; JobExecutionOptions options = new JobExecutionOptions(); options.priority = JobExecutionOptions.LOW_PRIORITY; options.noProject = true; // // 4. Use ProjectStorageOptions to identify the name of one // or more workspace objects for storage to the repository. // // In this case, the named object matches the name of the // object created the rCode being executed on the job. We // request that the binary R object file be stored into // the root directory in the repository. // options.storageOptions = new ProjectStorageOptions(); options.storageOptions.objects = "tutorialVector"; options.storageOptions.directory = "root"; RJob rJob = rUser.submitJobCode("Background Code Execution", "Demonstrate storing job results to repository.", rCode, options); Console.WriteLine("AuthJobStoreResultToRepository: submitted background job " + "for execution, rJob=" + rJob); // // 5. Query the execution status of a background job and loop until the job has finished // if (rJob != null) { while (true) { String sMsg = rJob.query().status.Value; if (sMsg == RJob.Status.COMPLETED.Value | sMsg == RJob.Status.FAILED.Value | sMsg == RJob.Status.CANCELLED.Value | sMsg == RJob.Status.ABORTED.Value) { break; } else { Thread.Sleep(500); } } } // // 6. Retrieve the RepositoryFile from completed job // RRepositoryFile rRepositoryFile = null; if (rJob != null) { // // 7. Retrieve the results of the background job // execution. Given the custom JobExecutionOptions // specified for this job (noproject=true) there will // be no RProject to hold the results. // // However, the custom JobExecutionOptions specified // for this job requested the storage of the // "tutorialVector" vector object as a binary R // object file (.rData) in the repository. // // The following code demonstrates how we can // retrieve that result from the repository: // String sUserName = rUser.about().Username; rRepositoryFile = rUser.fetchFile("tutorialVector.rData", sUserName, "root", ""); Console.WriteLine("AuthJobStoreResultToRepository: retrieved background " + "job result from repository, rRepositoryFile=" + rRepositoryFile); } // // 8. Cleanup // if (rRepositoryFile != null) { //rRepositoryFile.delete(); //un-comment if you wish to delete the RepositoryFile } if (rJob != null) { //rJob.delete(); //un-comment if you wish to delete the job } Utility.Cleanup(rUser, rClient); Console.WriteLine("AuthJobStoreResultToRepository - end"); }