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);
        }
        public static 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;
        }
        public static void Execute()
        {
            try
            {

                /*
                 * 1. Create RBroker instance using RBrokerFactory.
                 *
                 * This example creates a BackgroundTaskBroker.
                 */

                RAuthentication rAuth = new RBasicAuthentication(Program.AUTH_USER_NAME, Program.AUTH_PASSWORD);

                BackgroundBrokerConfig brokerConfig = new BackgroundBrokerConfig(Program.DEPLOYR_ENDPOINT, rAuth);
                RBroker rBroker = RBrokerFactory.backgroundTaskBroker(brokerConfig);

                /*
                 * 2. Register RTaskListener for asynchronous
                 * notifications on RTask completion.
                 */

                BackgroundTaskListener myTaskListener = new BackgroundTaskListener(rBroker);

                rBroker.addTaskListener(myTaskListener);

                /*
                 * 3. Define RTask
                 *
                 * This example creates a BackgroundTask that will
                 * execute an artibrary block of R code.
                 */

                String rCode = "x <- rnorm(100)";
                RTask rTask = RTaskFactory.backgroundTask("Example Background RTask",
                                                            "Example background RTask.",
                                                            rCode,
                                                            null);

                /*
                 * 4. Submit RTask to RBroker for execution.
                 *
                 * The RTaskToken is returned immediately. You can
                 * use the token to track the progress of RTask
                 * and/or block while waiting for a result.
                 *
                 * However, in this example we are going to allow
                 * the RTaskListener handle the result so
                 * there is nothing further for us to do here after
                 * we submit the RTask.
                 */

                RTaskToken rTaskToken = rBroker.submit(rTask);

                Console.WriteLine("Submitted " + rTask + " for execution on RBroker.");

                /*
                 * 4. Block until all tasks are complete, and shutdown has been called
                 */
                rBroker.waitUntilShutdown();

            }
            catch(Exception tex)
            {
                Console.WriteLine("Runtime exception=" + tex.ToString());
            }
        }
        public static void Execute()
        {
            try
            {
                /*
                 * 1. Prepare PooledBrokerConfig instance.
                 *
                 * This example creates an authenticated PooledTaskBroker
                 * to act as our scoring engine.
                 *
                 * The following steps initialize the pool of
                 * R sessions dedicated to our scoring engine.
                 *
                 * In this example, we pre-initialize the workspace
                 * for each R session in the pool to contain the
                 * R model used when scoring customer requests.
                 *
                 * The R model, insurModel.rData, is loaded from
                 * the DeployR repository into each workspace at
                 * startup time. Preloading the R model at startup
                 * reduces runtime overhead and improves overall
                 * response times in the application.
                 */
                RAuthentication rAuth = new RBasicAuthentication(Program.AUTH_USER_NAME, Program.AUTH_PASSWORD);

                PoolCreationOptions poolOptions = new PoolCreationOptions();

                PoolPreloadOptions preloadOptions = new PoolPreloadOptions();
                preloadOptions.filename = Program.TUTORIAL_INSURANCE_MODEL;
                preloadOptions.directory = Program.TUTORIAL_REPO_DIRECTORY;
                preloadOptions.author = Program.TUTORIAL_REPO_OWNER;

                poolOptions.preloadWorkspace = preloadOptions;

                /*
                 * 2. Create RBroker instance.
                 *
                 * The application designer, in conjunction with the
                 * DeployR administrator who provisions and sets
                 * limits on DeployR grid resources, need to decide how
                 * many R sessions will be reserved for the PooledRBroker
                 * used by our scoring engine application.
                 */

                int TARGET_POOL_SIZE = 10;

                PooledBrokerConfig brokerConfig = new PooledBrokerConfig(Program.DEPLOYR_ENDPOINT,
                                                                           rAuth,
                                                                           TARGET_POOL_SIZE,
                                                                           poolOptions);

                Console.WriteLine("About to create pooledTaskBroker.");

                RBroker rBroker = RBrokerFactory.pooledTaskBroker(brokerConfig);

                Console.WriteLine("R session pool size, requested: " +
                        TARGET_POOL_SIZE + " , actual: " +
                        rBroker.maxConcurrency() + "\n");

                /*
                 * 3. Create an RTaskAppSimulator. It will drive
                 * sample customer data scoring requests through the
                 * RBroker.
                 */

                ScoringEngineSimulation simulation = new ScoringEngineSimulation(rBroker);

                /*
                 * 4. Launch RTaskAppSimulator simulation.
                 */

                rBroker.simulateApp(simulation);

                /*
                 * 5. Block until all tasks are complete, and shutdown has been called
                 */
                rBroker.waitUntilShutdown();

            }
            catch(Exception tex)
            {
                Console.WriteLine("constructor: ex=" + tex.ToString());
            }
        }