|
| 1 | +using SIL.Progress; |
| 2 | + |
| 3 | +namespace FwHeadless.Services; |
| 4 | + |
| 5 | +public class CombiningProgress(params ICollection<IProgress?> progresses) : IProgress |
| 6 | +{ |
| 7 | + |
| 8 | + public bool ShowVerbose |
| 9 | + { |
| 10 | + set { foreach (var p in progresses) { if (p is not null) p.ShowVerbose = value; } } |
| 11 | + } |
| 12 | + |
| 13 | + public bool CancelRequested |
| 14 | + { |
| 15 | + get => progresses.Any(p => p?.CancelRequested ?? false); |
| 16 | + set { foreach (var p in progresses) { if (p is not null) p.CancelRequested = value; } } |
| 17 | + } |
| 18 | + |
| 19 | + public bool ErrorEncountered |
| 20 | + { |
| 21 | + get => progresses.Any(p => p?.ErrorEncountered ?? false); |
| 22 | + set { foreach (var p in progresses) { if (p is not null) p.ErrorEncountered = value; } } |
| 23 | + } |
| 24 | + |
| 25 | + public IProgressIndicator ProgressIndicator |
| 26 | + { |
| 27 | + get => progresses.FirstOrDefault(p => p?.ProgressIndicator is not null)?.ProgressIndicator ?? null!; |
| 28 | + set { foreach (var p in progresses) { if (p is not null) p.ProgressIndicator = value; } } |
| 29 | + } |
| 30 | + |
| 31 | + public SynchronizationContext SyncContext |
| 32 | + { |
| 33 | + get => progresses.FirstOrDefault(p => p?.SyncContext is not null)?.SyncContext ?? null!; |
| 34 | + set { foreach (var p in progresses) { if (p is not null) p.SyncContext = value; } } |
| 35 | + } |
| 36 | + |
| 37 | + public void WriteError(string message, params object[] args) |
| 38 | + { |
| 39 | + foreach (var p in progresses) { p?.WriteError(message, args); } |
| 40 | + } |
| 41 | + |
| 42 | + public void WriteException(Exception error) |
| 43 | + { |
| 44 | + foreach (var p in progresses) { p?.WriteException(error); } |
| 45 | + } |
| 46 | + |
| 47 | + public void WriteMessage(string message, params object[] args) |
| 48 | + { |
| 49 | + foreach (var p in progresses) { p?.WriteMessage(message, args); } |
| 50 | + } |
| 51 | + |
| 52 | + public void WriteMessageWithColor(string colorName, string message, params object[] args) |
| 53 | + { |
| 54 | + foreach (var p in progresses) { p?.WriteMessageWithColor(colorName, message, args); } |
| 55 | + } |
| 56 | + |
| 57 | + public void WriteStatus(string message, params object[] args) |
| 58 | + { |
| 59 | + foreach (var p in progresses) { p?.WriteStatus(message, args); } |
| 60 | + } |
| 61 | + |
| 62 | + public void WriteVerbose(string message, params object[] args) |
| 63 | + { |
| 64 | + foreach (var p in progresses) { p?.WriteVerbose(message, args); } |
| 65 | + } |
| 66 | + |
| 67 | + public void WriteWarning(string message, params object[] args) |
| 68 | + { |
| 69 | + foreach (var p in progresses) { p?.WriteWarning(message, args); } |
| 70 | + } |
| 71 | +} |
0 commit comments