forked from dotnet/sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIProgressTarget.cs
More file actions
73 lines (59 loc) · 2.21 KB
/
IProgressTarget.cs
File metadata and controls
73 lines (59 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
namespace Microsoft.Dotnet.Installation;
public interface IProgressTarget
{
IProgressReporter CreateProgressReporter();
}
public interface IProgressReporter : IDisposable
{
IProgressTask AddTask(string description, double maxValue);
/// <summary>
/// Adds a task with telemetry activity tracking.
/// </summary>
/// <param name="activityName">The name for the telemetry activity (e.g., "download", "extract").</param>
/// <param name="description">The user-visible description.</param>
/// <param name="maxValue">The maximum progress value.</param>
IProgressTask AddTask(string activityName, string description, double maxValue)
=> AddTask(description, maxValue); // Default: no telemetry
}
public interface IProgressTask
{
string Description { get; set; }
double Value { get; set; }
double MaxValue { get; set; }
/// <summary>
/// Sets a telemetry tag on the underlying activity (if any).
/// </summary>
void SetTag(string key, object? value) { }
/// <summary>
/// Records an error on the underlying activity (if any).
/// </summary>
void RecordError(Exception ex) { }
/// <summary>
/// Marks the task as successfully completed.
/// </summary>
void Complete() { }
}
public class NullProgressTarget : IProgressTarget
{
public IProgressReporter CreateProgressReporter() => new NullProgressReporter();
private sealed class NullProgressReporter : IProgressReporter
{
public void Dispose() { }
public IProgressTask AddTask(string description, double maxValue)
=> new NullProgressTask(description);
public IProgressTask AddTask(string activityName, string description, double maxValue)
=> new NullProgressTask(description);
}
private sealed class NullProgressTask : IProgressTask
{
public NullProgressTask(string description)
{
Description = description;
}
public double Value { get; set; }
public string Description { get; set; }
public double MaxValue { get; set; }
}
}