Ejemplo n.º 1
0
 public void OnNewUser(RUser user)
 {
     if (Common.UIElementCollectionToList(users.Children).FirstOrDefault((x) => ((CCheckUserItem)x).User.ID == user.ID) == null)
     {
         users.Children.Add(new CCheckUserItem(user));
     }
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
0
        public void UpdateRUser(RUser user)
        {
            DbEntityEntry entity = regDB.Entry(user);

            entity.State = System.Data.Entity.EntityState.Modified;
            regDB.SaveChanges();
        }
Ejemplo n.º 4
0
        private void LookForVictim()
        {
            try
            {
                Room MyRoom = GetRoom();
                if (MyRoom == null)
                {
                    return;
                }

                lock (MyRoom.GetRoomUserManager().UserList.Values)
                {
                    foreach (RoomUser RUser in MyRoom.GetRoomUserManager().UserList.Values.ToList())
                    {
                        if (RUser == null || RUser.GetClient() == null || RUser.GetClient().GetRoleplay() == null)
                        {
                            continue;
                        }
                        if (!GetBotData()._Team.Players.ContainsKey(RUser.GetClient()) && RUser.GetClient().GetRoleplay().InMafiaWars&& RUser.Attacker == null)
                        {
                            _Victim          = RUser;
                            _Victim.Attacker = GetRoomUser();
                        }
                    }
                }
            }
            catch { }
        }
Ejemplo n.º 5
0
 private void Login(object obj, EventArgs e)
 {
     Application.Current.Dispatcher.Invoke((Action) delegate {
         RUser usr = (RUser)obj;
         SetPage(new Pages.LoginedPage(this));
     });
 }
Ejemplo n.º 6
0
        public void DeleteRUser(int id)
        {
            RUser item = GetById(id);

            if (item != null)
            {
                regDB.RUsers.Remove(item);
                regDB.SaveChanges();
            }
        }
Ejemplo n.º 7
0
        public GroupMessage(RUser usr, RGroupMessage grpMsg)
        {
            InitializeComponent();

            UserName.Content = usr.Login;
            Teext.Text       = grpMsg.MessageSource;

            baseMsg = grpMsg;
            baseUsr = usr;
        }
Ejemplo n.º 8
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");
        }
 public void OnNewUser(RUser user)
 {
     Application.Current.Dispatcher.Invoke((Action) delegate
     {
         createGroupitem.OnNewUser(user);
         foreach (GroupItem item in ss.Children)
         {
             item.WriteMessages.OnNewOutsider(user);
         }
     });
 }
 public void OnChangeOnline(object obj, EventArgs e)
 {
     Application.Current.Dispatcher.Invoke((Action) delegate
     {
         RUser user = (RUser)obj;
         createGroupitem.OnChangeOnline(user);
         foreach (GroupItem item in ss.Children)
         {
             item.WriteMessages.OnChangeOnline(user);
         }
     });
 }
Ejemplo n.º 11
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);
            }
        }
Ejemplo n.º 12
0
        public static 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);
            }
        }
Ejemplo n.º 13
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");
        }
 /// <summary>
 /// Constructor for specifying a Background Instance of RBrokerWorker
 /// </summary>
 /// <param name="task">BackgroundTask reference</param>
 /// <param name="executorTaskRef">Reserved for future use</param>
 /// <param name="isPriorityTask">Boolean indicating if this ia high priority task</param>
 /// <param name="rUser">RUser reference</param>
 /// <param name="resourceToken">integer referencing the token from the reosurce pool</param>
 /// <param name="rBroker">RBroker reference</param>
 /// <remarks></remarks>
 public BackgroundTaskWorker(BackgroundTask task,
                             long executorTaskRef,
                             Boolean isPriorityTask,
                             RUser rUser,
                             int resourceToken,
                             RBroker rBroker)
 {
     m_task = task;
     m_executorTaskRef = executorTaskRef;
     m_isPriorityTask = isPriorityTask;
     m_rUser = rUser;
     m_resourceToken = resourceToken;
     m_rBroker = (BackgroundTaskBroker) rBroker;
 }
Ejemplo n.º 15
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);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Constructor for specifying a Background Instance of RBrokerWorker
        /// </summary>
        /// <param name="task">BackgroundTask reference</param>
        /// <param name="executorTaskRef">Reserved for future use</param>
        /// <param name="isPriorityTask">Boolean indicating if this ia high priority task</param>
        /// <param name="rUser">RUser reference</param>
        /// <param name="resourceToken">integer referencing the token from the reosurce pool</param>
        /// <param name="rBroker">RBroker reference</param>
        /// <remarks></remarks>
        public BackgroundTaskWorker(BackgroundTask task,
                                    long executorTaskRef,
                                    Boolean isPriorityTask,
                                    RUser rUser,
                                    int resourceToken,
                                    RBroker rBroker) 
        {

            m_task = task;
            m_executorTaskRef = executorTaskRef;
            m_isPriorityTask = isPriorityTask;
            m_rUser = rUser;
            m_resourceToken = resourceToken;
            m_rBroker = (BackgroundTaskBroker) rBroker;

        }
Ejemplo n.º 17
0
        public void OnChangeOnline(RUser user)
        {
            int i = 0; for (; i < users.Children.Count; i++)

            {
                if (((CCheckUserItem)users.Children[i]).User.ID == user.ID)
                {
                    ((CCheckUserItem)users.Children[i]).Online = user.Online;
                    break;
                }
            }

            if (i == users.Children.Count)
            {
                OnNewUser(user);
            }
        }
        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");
        }
Ejemplo n.º 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");
        }
Ejemplo n.º 20
0
        public void MessageRoom(string Msg)
        {
            if (MyRoom == null)
            {
                return;
            }
            lock (MyRoom.GetRoomUserManager().UserList.Values)
            {
                foreach (RoomUser RUser in MyRoom.GetRoomUserManager().UserList.Values.ToList())
                {
                    if (RUser == null)
                    {
                        continue;
                    }
                    GameClient RUSession = RUser.GetClient();
                    if (RUSession == null)
                    {
                        continue;
                    }

                    RUSession.SendWhisper(Msg);
                }
            }
        }
        /*
         * HTTPKeepAliveManager
         *
         * Prevents authenticated HTTP session from timing out
         * due to inactivity to ensure pool of RProject remain
         * live and available to PooledTaskBroker.
         */
        private void HTTPKeepAliveManager(RUser rUser)
        {
            int PING_INTERVAL = 60000;

            try
            {
                while (Interlocked.Read(ref m_taskBrokerIsActive) == 1)
                {
                    try
                    {
                        if (rUser != null)
                        {
                            /* No-Op Ping Authenticated HTTP Session.*/
                            rUser.autosaveProjects(false);
                        }

                        try
                        {
                            Thread.Sleep(PING_INTERVAL);
                        }
                        catch (Exception iex)
                        {
                            throw new Exception("Sleep Exception= " + iex.ToString());
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("PooledTaskBroker: HTTPKeepAliveManager ex=" + ex.ToString());
                    }
                }
            }
            catch (Exception rex)
            {
                throw new Exception("PooledTaskBroker: HTTPKeepAliveManager rex=" + rex.ToString());
            }
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Authenticate with the RevoDeployR server
        /// </summary>
        /// <param name="authentication">A valid RAuthentication object</param>
        /// <param name="autosave">(optional) Flag indicating that autosave should be turned on/off for the user</param>
        /// <returns>RResponse object</returns>
        /// <remarks></remarks>
        public RUser login(RAuthentication authentication, Boolean autosave)
        {
            StringBuilder data = new StringBuilder();

            String uri = Constants.RUSERLOGIN;
            //create the input String
            data.Append(Constants.FORMAT_JSON + "&username="******"&password="******"&save=" + HttpUtility.UrlEncode(autosave.ToString()));
            //call the server
            RClient client = this;
            JSONResponse jresponse = HTTPUtilities.callRESTPost(uri, data.ToString(), ref client);
            RUser returnValue = new RUser(jresponse, this);

            return returnValue;
        }
Ejemplo n.º 23
0
 public void RChangeOnline(RUser usr) => OnChangeOnline?.Invoke(usr, null);
            public void onTaskCompleted(RTask rTask, RTaskResult rTaskResult)
            {
                Console.WriteLine("onTaskCompleted: " + rTask + ", result: " + rTaskResult);

                /*
                 * Retrieve Job identifier from RTaskResult.
                 */
                String jobID = rTaskResult.getID();

                Console.WriteLine("onTaskCompleted: " + rTask + ", background Job ID: " + jobID);

                if (m_rBroker != null)
                {
                    /*
                     * Important:
                     *
                     * To handle the results of a Background RTask you
                     * must transition from using the RBroker Framework
                     * API to using the .NET Client Library API.
                     */
                    RUser rUser = m_rBroker.owner();

                    if (rUser != null)
                    {
                        try
                        {
                            RJob rJob = rUser.queryJob(jobID);

                            Console.WriteLine("onTaskCompleted: " + rTask + ", rJob: " + rJob);

                            /*
                             * Next handle the result of the RJob as appropriate.
                             * In this example, simly cancel and delete the job.
                             */

                            try
                            {
                                rJob.cancel();
                            }
                            catch (Exception cex)
                            {
                                Console.WriteLine("rJob.cancel ex=" + cex.ToString());
                            }
                            try
                            {
                                rJob.delete();
                            }
                            catch (Exception dex)
                            {
                                Console.WriteLine("rJob.delete ex=" + dex.ToString());
                            }
                        }
                        catch (Exception jex)
                        {
                            Console.WriteLine("rUser.queryJob ex=" + jex.ToString());
                        }
                    }

                    m_rBroker.shutdown();
                    Console.WriteLine("BackgroundBasics: rBroker has been shutdown.");
                }
            }
Ejemplo n.º 25
0
 public void RLeaveUserInGroup(RGroup group, RUser usr) => OnLeaveUserInGroup?.Invoke(new KeyValuePair <RGroup, RUser>(group, usr), null);
Ejemplo n.º 26
0
 public void RNewUser(RUser usr) => OnNewUser?.Invoke(usr, null);
Ejemplo n.º 27
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");
        }
Ejemplo n.º 28
0
 public void RNewMessage(RUser usr, RGroupMessage msg) => OnNewMessage?.Invoke(new KeyValuePair <RUser, RGroupMessage>(usr, msg), null);
        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");
        }
        /*
         * HTTPKeepAliveManager
         *
         * Prevents authenticated HTTP session from timing out
         * due to inactivity to ensure pool of RProject remain
         * live and available to PooledTaskBroker.
         */
        private void HTTPKeepAliveManager(RUser rUser)
        {
            int PING_INTERVAL = 60000;

            try
            {
                while (Interlocked.Read(ref m_taskBrokerIsActive) == 1)
                {
                    try
                    {
                        if(rUser != null)
                        {
                            /* No-Op Ping Authenticated HTTP Session.*/
                            rUser.autosaveProjects(false);
                        }

                        try
                        {
                            Thread.Sleep(PING_INTERVAL);
                        }
                        catch(Exception iex)
                        {
                            throw new Exception("Sleep Exception= " + iex.ToString());
                        }
                    }
                    catch(Exception ex)
                    {
                        throw new Exception("PooledTaskBroker: HTTPKeepAliveManager ex=" + ex.ToString());
                    }
                }

            }
            catch(Exception rex)
            {
                throw new Exception("PooledTaskBroker: HTTPKeepAliveManager rex=" + rex.ToString());
            }
        }
        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");
        }
        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");
        }
        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("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");
        }
Ejemplo n.º 35
0
        /// <summary>
        /// Logout from the RevoDeployR server.
        /// </summary>
        /// <param name="user">The RUser object representing the user to logout</param>
        /// <remarks></remarks>
        public void logout(RUser user)
        {
            StringBuilder data = new StringBuilder();

            String uri = Constants.RUSERLOGOUT;
            //create the input String
            data.Append(Constants.FORMAT_JSON);
            //call the server
            RClient client = this;
            JSONResponse jresponse = HTTPUtilities.callRESTPost(uri, data.ToString(), ref client);
        }