Пример #1
0
        /// <summary>
        /// Consumer多路复用
        /// </summary>
        /// <param name="uri"></param>
        /// <param name="links"></param>
        /// <param name="timeOut"></param>
        /// <param name="retry"></param>
        ConsumerMultiplexer(Uri uri, int links = 10, int timeOut = 10 * 1000, int retry = 5)
        {
            _uri     = uri;
            _links   = links;
            _timeOut = timeOut;
            _retry   = retry;

            if (!_hashMap.Exits(uri.ToString()))
            {
                for (int i = 0; i < links; i++)
                {
                    var rClient = new RClient(uri, timeOut);

                    rClient.OnDisconnected -= RClient_OnDisconnected;
                    rClient.OnError        -= RClient_OnError;
                    rClient.OnNoticed      -= RClient_OnNoticed;
                    rClient.OnDisconnected += RClient_OnDisconnected;
                    rClient.OnError        += RClient_OnError;
                    rClient.OnNoticed      += RClient_OnNoticed;

                    rClient.Connect();
                    rClient.KeepAlive();

                    _hashMap.Set(uri.ToString(), i, rClient);

                    _myClients.TryAdd(i, rClient);
                }
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            // 1. Establish a connection to DeployR.
            //
            // This example assumes the DeployR server is running on localhost.
            //
            String  deployrEndpoint = "http://localhost:7400/deployr";
            RClient rClient         = RClientFactory.createClient(deployrEndpoint);

            //
            // 2. Authenticate an end-user or client application.
            //
            // The RBasicAuthentication supports basic username/password authentication.
            // The RUser returned represents an authenticated end-user or application.
            //
            RAuthentication authToken = new RBasicAuthentication("testuser", "changeme");
            RUser           rUser     = rClient.login(authToken);

            //
            // 3. Logout the user
            //
            // The authenticated user is logged out from the DeployR server
            //
            rClient.logout(rUser);
        }
Пример #3
0
 static void Main(string[] args)
 {
     //
     // 1. Establish a connection to DeployR.
     //
     // This example assumes the DeployR server is running on localhost.
     //
     String  deployrEndpoint = "http://localhost:7400/deployr";
     RClient rClient         = RClientFactory.createClient(deployrEndpoint);
 }
Пример #4
0
        public RedisConnection(string ipPort, int actionTimeout = 10)
        {
            this.IPPort = ipPort;
            var address = ipPort.ToIPPort();

            _cnn                 = new RClient(102400, address.Item1, address.Item2);
            _cnn.OnActived      += _cnn_OnActived;
            _cnn.OnMessage      += _cnn_OnMessage;
            _cnn.OnDisconnected += _cnn_OnDisconnected;
            _redisCoder          = new RedisCoder(_cnn, actionTimeout);
        }
Пример #5
0
        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");
        }
Пример #6
0
        static public void Cleanup(RUser rUser, RClient rClient)
        {
            //
            // Clenaup and logout when we are finished
            //
            if (rUser != null)
            {
                Console.WriteLine("User logged out: " + rUser.about().Username);

                rClient.logout(rUser);
            }
        }
Пример #7
0
        public RedisConnection(string ipPort, int actionTimeout = 60, bool debugMode = false)
        {
            this.IPPort = ipPort;
            var address = ipPort.ToIPPort();

            _cnn                 = new RClient(102400, address.Item1, address.Item2);
            _cnn.OnActived      += _cnn_OnActived;
            _cnn.OnMessage      += _cnn_OnMessage;
            _cnn.OnDisconnected += _cnn_OnDisconnected;
            _redisCoder          = new RedisCoder(actionTimeout);
            _debugMode           = debugMode;
        }
Пример #8
0
        public static void Main(string[] args)
        {
            var readonlyHost = "observer.testnet.rchain.coop";
            var port         = 40401;
            var client       = new RClient(readonlyHost, port);

            // these param are fixed when the network starts on the genesis
            // the param will never change except hard-fork
            // but different network has different param based on the genesis block
            client.ConfigParam(Params.TestnetParam);
            var block_hash           = "7850712f679aa73cac5648867652d78337ace8066ece72edb195bedfa5f2eeef";
            var testnet_transactions = client.GetTransactions(block_hash);
        }
Пример #9
0
        static public void Execute()
        {
            Console.WriteLine("AuthProjectPackages - 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("AuthProjectPackages: created temporary R session, rProject=" + rProject);

            //
            // 4. Retrieve a list of R packages that are current
            // attached on the R session.
            //
            List <RProjectPackage> pkgs = rProject.listPackages(false);

            foreach (RProjectPackage pkg in pkgs)
            {
                Console.WriteLine("AuthProjectPackages: R session, " +
                                  "found attached R package name=" +
                                  pkg.about().name + ", repo=" +
                                  pkg.about().repo + ", version=" +
                                  pkg.about().version);
            }

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

            Console.WriteLine("AuthProjectPackages - end");
        }
Пример #10
0
 /// <summary>
 /// Constructor for specifying a Discrete Instance of RBrokerWorker
 /// </summary>
 /// <param name="task">DiscreteTask reference</param>
 /// <param name="executorTaskRef">Reserved for future use</param>
 /// <param name="isPriorityTask">Boolean indicating if this ia high priority task</param>
 /// <param name="rClient">RClient reference</param>
 /// <param name="resourceToken">integer referencing the token from the reosurce pool</param>
 /// <param name="rBroker">RBroker reference</param>
 /// <remarks></remarks>
 public DiscreteTaskWorker(DiscreteTask task,
                           long executorTaskRef,
                           Boolean isPriorityTask,
                           RClient rClient,
                           int resourceToken,
                           RBroker rBroker)
 {
     m_task            = task;
     m_executorTaskRef = executorTaskRef;
     m_isPriorityTask  = isPriorityTask;
     m_rClient         = rClient;
     m_resourceToken   = resourceToken;
     m_rBroker         = (DiscreteTaskBroker)rBroker;
 }
Пример #11
0
 /// <summary>
 /// 创建多路复用
 /// </summary>
 /// <param name="uri"></param>
 /// <param name="links"></param>
 /// <param name="timeOut"></param>
 /// <returns></returns>
 public static ConsumerMultiplexer Create(Uri uri, int links = 4, int timeOut = 10 * 1000)
 {
     if (!_hashMap.Exits(uri.ToString()))
     {
         for (int i = 0; i < links; i++)
         {
             var rClient = new RClient(uri);
             rClient.Connect();
             rClient.KeepAlive();
             _hashMap.Set(uri.ToString(), i, rClient);
         }
     }
     return(new ConsumerMultiplexer(uri, links, timeOut));
 }
Пример #12
0
        static public RUser Authenticate(RClient rClient)
        {
            //
            // Authenticate an end-user or client application.
            //
            // The RBasicAuthentication supports basic username/password authentication.
            // The RUser returned represents an authenticated end-user or application.
            //
            RAuthentication authToken = new RBasicAuthentication("testuser", "changeme");
            RUser           rUser     = rClient.login(authToken);

            Console.WriteLine("User Authenticated: user: " + rUser.about().Username);

            return(rUser);
        }
Пример #13
0
        static public RClient Connect()
        {
            //
            // Establish a connection to DeployR.
            //
            // This example assumes the DeployR server is running on localhost.
            //
            String  deployrEndpoint = "http://localhost:7400/deployr";
            RClient rClient         = RClientFactory.createClient(deployrEndpoint);

            //RClientFactory.setDebugMode(true); //un-comment if you want to have the API calls printed to the console

            Console.WriteLine("Client connection made to the DeployR Server: " + deployrEndpoint);

            return(rClient);
        }
Пример #14
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");
        }
Пример #15
0
 /// <summary>
 /// 创建多路复用
 /// </summary>
 /// <param name="uri"></param>
 /// <param name="links"></param>
 public static ConsumerMultiplexer Create(Uri uri, int links = 4)
 {
     if (!_hashMap.Exits(uri.ToString()))
     {
         for (int i = 0; i < links; i++)
         {
             var rClient = new RClient(uri);
             if (!rClient.Connect())
             {
                 throw new RPCSocketException($"连接到{uri.ToString()}失败");
             }
             rClient.KeepAlive();
             _hashMap.Set(uri.ToString(), i, rClient);
         }
     }
     return(new ConsumerMultiplexer(uri, links));
 }
        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");
        }
        static public void Execute()
        {
            Console.WriteLine("AuthProjectPoolCreate - start");

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

            //
            // 2. Authenticate the user
            //
            RUser rUser = Utility.Authenticate(rClient);

            //
            // 3. Create a pool of temporary projects (R sessions).
            //
            // Population options as needed.
            //
            int requestedPoolSize          = 4;
            ProjectCreationOptions options = new ProjectCreationOptions();
            List <RProject>        pool    = rUser.createProjectPool(requestedPoolSize, options);

            Console.WriteLine("AuthProjectPoolCreate: created pool of " +
                              pool.Count + " temporary R sessions, pool=" + pool);


            //
            //  5. Cleanup
            //
            foreach (RProject rProject in pool)
            {
                rProject.close();
            }

            Utility.Cleanup(rUser, rClient);

            Console.WriteLine("AuthProjectPoolCreate - end");
        }
Пример #18
0
        public static void Main(string[] args)
        {
            var alice = new PrivateKey("13ae0c530d4af11894910d01f770c1402d19a3ac195dede9c57caa29e6ee82ba");
            var bob   = new PrivateKey(0);

            var host         = "node0.testnet.rchain-dev.tk"; //test net
            var readonlyHost = "observer.testnet.rchain.coop";
            var port         = 40401;

            var client = new RClient(readonlyHost, port);
            var vault  = new VaultAPI(client);
            // get the balance of a vault
            // get balance can only perform in the read-only node
            var bob_balance = vault.GetBalance(bob.PublicKey.RevAddress);

            Console.WriteLine($"Bob's balance is {bob_balance}");
            var alice_balance = vault.GetBalance(alice.PublicKey.RevAddress);

            Console.WriteLine($"Alice's balance is {alice_balance}");
            var client2 = new RClient(host, port);
            // because transfer need a valid deploy
            // the transfer need the private to perform signing
            var vault2   = new VaultAPI(client2);
            var deployId = vault2.Transfer(alice.PublicKey.RevAddress, bob.PublicKey.RevAddress, 100000, alice);

            Console.WriteLine($"The deploy id is: {deployId}");
            //while (true)
            //{

            //    if(!client.IsFinalized(de))
            //}
            bob_balance = vault.GetBalance(bob.PublicKey.RevAddress);
            Console.WriteLine($"Bob's balance is {bob_balance}");
            alice_balance = vault.GetBalance(alice.PublicKey.RevAddress);
            Console.WriteLine($"Alice's balance is {alice_balance}");
        }
Пример #19
0
        static public void Execute()
        {
            Console.WriteLine("AuthProjectCreate - 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("AuthProjectCreate: created temporary R session, rProject=" + rProject);

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

            Console.WriteLine("AuthProjectCreate - end");
        }
Пример #20
0
        public ServiceConsumer(Uri uri)
        {
            _rClient          = new RClient(uri);
            _rClient.OnError += _rClient_OnError;
            _rClient.OnMsg   += _rClient_OnMsg;

            AutoResetEvent autoResetEvent = new AutoResetEvent(false);

            _rClient.ConnectAsync((s) =>
            {
                if (s == System.Net.Sockets.SocketError.Success)
                {
                    _isConnected = true;
                }
                else
                {
                    throw new RPCSocketException("ServiceConsumer.ConnectAsync 连接失败!");
                }
                autoResetEvent.Set();
            });
            autoResetEvent.WaitOne();
            autoResetEvent.Close();
            KeepAlive();
        }
        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");
        }
Пример #22
0
 /// <summary>
 /// 初始化
 /// </summary>
 /// <param name="rclient"></param>
 public RedisCoder(RClient rclient)
 {
     _rclient = rclient;
 }
Пример #23
0
 public void Stop()
 {
     RClient.Disconnect();
 }
        static public void Execute()
        {
            Console.WriteLine("AuthJobExecuteScript - 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 for execution based on a
            // repository-managed R script: /testuser/root/Histogram of Auto Sales.R
            //
            JobExecutionOptions options = new JobExecutionOptions();

            options.priority = JobExecutionOptions.HIGH_PRIORITY;  //Make this a High Priority job
            RJob rJob = rUser.submitJobScript("Background Script Execution",
                                              "Background script execution.",
                                              "Histogram of Auto Sales",
                                              "root",
                                              "testuser",
                                              "",
                                              options);

            Console.WriteLine("AuthJobExecuteScript: submitted background job " +
                              "for execution, rJob=" + rJob);

            //
            // 4. 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);
                    }
                }
            }


            //
            // 5. Retrieve the project from completed job
            //
            RProject rProject = null;

            if (rJob != null)
            {
                // make sure we have a valid project id
                if (rJob.query().project.Length > 0)
                {
                    //get the project using the project id
                    rProject = rUser.getProject(rJob.query().project);

                    Console.WriteLine("AuthJobExecuteScript: retrieved background " +
                                      "job result on project, rProject=" + rProject);
                }
            }

            //
            //  6. Cleanup
            //
            if (rProject != null)
            {
                rProject.close();
                //rProject.delete();  //un-comment if you wish to delete the project
            }

            if (rJob != null)
            {
                //rJob.delete();  //un-comment if you wish to delete the job
            }

            Utility.Cleanup(rUser, rClient);

            Console.WriteLine("AuthJobExecuteScript - end");
        }
        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");
        }
Пример #26
0
 /// <summary>
 /// 初始化
 /// </summary>
 /// <param name="rclient"></param>
 /// <param name="actionTimeout"></param>
 public RedisCoder(RClient rclient, int actionTimeout = 60)
 {
     _rclient       = rclient;
     _actionTimeout = actionTimeout * 1000;
 }
        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");
        }
Пример #28
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");
        }
        static public void Execute()
        {
            Console.WriteLine("AuthJobExecuteCode - 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 for execution based on an
            // arbitrary block of R code: [codeBlock]
            //
            String codeBlock = "demo(graphics)";

            JobExecutionOptions options = new JobExecutionOptions();

            options.priority = JobExecutionOptions.MEDIUM_PRIORITY;   //Make this a Medium Priority job

            RJob rJob = rUser.submitJobCode("Sample Job",
                                            "Sample description.",
                                            codeBlock,
                                            options);

            Console.WriteLine("AuthJobExecuteCode: submitted background job for execution, rJob=" + rJob);

            //
            // 4. 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);
                    }
                }
            }


            //
            // 5. Retrieve the project from completed job
            //
            RProject rProject = null;

            if (rJob != null)
            {
                // make sure we have a valid project id
                if (rJob.query().project.Length > 0)
                {
                    //get the project using the project id
                    rProject = rUser.getProject(rJob.query().project);

                    Console.WriteLine("AuthJobExecuteCode: retrieved background " +
                                      "job result on project, rProject=" + rProject);
                }
            }

            //
            //  6. Cleanup
            //
            if (rProject != null)
            {
                rProject.close();
                //rProject.delete();  //un-comment if you wish to delete the project
            }

            if (rJob != null)
            {
                //rJob.delete();  //un-comment if you wish to delete the job
            }

            Utility.Cleanup(rUser, rClient);

            Console.WriteLine("AuthJobExecuteCode - end");
        }
Пример #30
0
 public void Run()
 {
     RClient.Connect(Setting.Authenticate.Host, Setting.Authenticate.Port);
 }