Beispiel #1
0
 private static void Done(ComputerElement element)
 {
     Console.WriteLine("Complete: {0} {1}", (object)element.EndPoint, (object)new {
         ExitCode = element.ExitCode,
         StartTime = element.StartTime,
         TotalProcessorTime = element.TotalProcessorTime
     });
 }
Beispiel #2
0
        public Task<ComputerElement> RunAsync(string filename, string arguments, ComputerElement computer)
        {
            var taskCompletionSource = new TaskCompletionSource<ComputerElement>();
            var processStartInfo = new ProcessStartInfo(filename) {
                UseShellExecute = false,
                RedirectStandardInput = true,
                RedirectStandardOutput = true,
                RedirectStandardError = true,
                CreateNoWindow = true,
                FileName = filename,
                Arguments = string.Format("\\\\{0} {1}", computer.EndPoint, arguments)
            };

            Console.WriteLine("Starting: {0} {1}", computer.EndPoint, arguments);

            var process = new Process() {
                StartInfo = processStartInfo,
                EnableRaisingEvents = true
            };

            process.Exited += (sender, args) => {
                var standardOutput = process.StandardOutput;
                var standardError = process.StandardError;
                computer.Output = standardOutput.ReadToEnd().Replace("\r\n", ";");
                computer.Error = standardError.ReadToEnd().Replace("\r\n", ";");
                computer.ExitCode = process.ExitCode;
                computer.StartTime = process.StartTime;
                computer.TotalProcessorTime = process.TotalProcessorTime;
                taskCompletionSource.SetResult(computer);
                process.Dispose();
            };

            process.Start();

            return taskCompletionSource.Task;
        }