Exemplo n.º 1
0
        /// <summary>
        /// Executes application logic
        /// </summary>
        /// <param name="args">Commandline arguments</param>
        public int ExecuteAsync(string[] args)
        {
            string hostname = (args.Any()) ? args.First() : "localhost";

            _client = new RemoteExecutorClient(hostname);
            _client.ProcessWriteToStdOut += OnOutputDataReceived;
            _client.ProcessWriteToStdErr += OnErrorDataReceived;
            _client.ProcessExited        += delegate(int exitcode)
            {
                _client.ProcessWriteToStdOut -= OnOutputDataReceived;
                _client.ProcessWriteToStdErr -= OnErrorDataReceived;
                _processExitCode              = exitcode;
            };

            _client.Connect();
            _client.AutoReconnectEnabled = true;

            _client.StartProcessAsync(@"cmd", "");

            // Start backgroundworker which reads the STDIN from console
            // In this way the program is not blocked by Console.Read() method
            // and is closed after hosted process has exited
            _inputReader.RunWorkerAsync();

            // Wait for exit of process
            while (!_processExitCode.HasValue)
            {
            }
            _client.Disconnect();

            // ReSharper disable once PossibleInvalidOperationException
            return((_processExitCode.HasValue) ? _processExitCode.Value : -1000);
        }