| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System; |
| | 5 | | using System.Diagnostics; |
| | 6 | | using System.IO; |
| | 7 | |
|
| | 8 | | namespace Azure.Identity |
| | 9 | | { |
| | 10 | | internal class ProcessService : IProcessService |
| | 11 | | { |
| 122 | 12 | | public static IProcessService Default { get; } = new ProcessService(); |
| | 13 | |
|
| 4 | 14 | | private ProcessService() { } |
| | 15 | |
|
| 8 | 16 | | public IProcess Create(ProcessStartInfo startInfo) => new ProcessWrapper(startInfo); |
| | 17 | |
|
| | 18 | | private class ProcessWrapper : IProcess |
| | 19 | | { |
| | 20 | | private readonly Process _process; |
| | 21 | |
|
| 8 | 22 | | public ProcessWrapper(ProcessStartInfo processStartInfo) |
| | 23 | | { |
| 8 | 24 | | _process = new Process |
| 8 | 25 | | { |
| 8 | 26 | | StartInfo = processStartInfo, |
| 8 | 27 | | EnableRaisingEvents = true |
| 8 | 28 | | }; |
| 8 | 29 | | } |
| | 30 | |
|
| 0 | 31 | | public bool HasExited => _process.HasExited; |
| 8 | 32 | | public int ExitCode => _process.ExitCode; |
| 4 | 33 | | public StreamReader StandardOutput => _process.StandardOutput; |
| 4 | 34 | | public StreamReader StandardError => _process.StandardError; |
| | 35 | |
|
| | 36 | | public ProcessStartInfo StartInfo |
| | 37 | | { |
| 24 | 38 | | get => _process.StartInfo; |
| 0 | 39 | | set => _process.StartInfo = value; |
| | 40 | | } |
| | 41 | |
|
| | 42 | | public event EventHandler Exited |
| | 43 | | { |
| 8 | 44 | | add => _process.Exited += value; |
| 0 | 45 | | remove => _process.Exited -= value; |
| | 46 | | } |
| | 47 | |
|
| 8 | 48 | | public void Start() => _process.Start(); |
| 0 | 49 | | public void Kill() => _process.Kill(); |
| 8 | 50 | | public void Dispose() => _process.Dispose(); |
| | 51 | | } |
| | 52 | | } |
| | 53 | | } |