| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="ProgressReport.cs" company="Stéphane ANDRE"> |
| | | 3 | | // Copyright (c) Stéphane ANDRE. All rights reserved. |
| | | 4 | | // </copyright> |
| | | 5 | | // ----------------------------------------------------------------------- |
| | | 6 | | |
| | | 7 | | using System; |
| | | 8 | | using System.Collections.Generic; |
| | | 9 | | |
| | | 10 | | namespace MyNet.Utilities.Progress; |
| | | 11 | | |
| | | 12 | | /// <summary> |
| | | 13 | | /// Represents a snapshot of the current progress state reported to subscribers. |
| | | 14 | | /// </summary> |
| | | 15 | | /// <typeparam name="T">The type of progress messages.</typeparam> |
| | | 16 | | public sealed record ProgressReport<T> |
| | | 17 | | { |
| | | 18 | | /// <summary> |
| | | 19 | | /// Initializes a new instance of the <see cref="ProgressReport{T}"/> class. |
| | | 20 | | /// </summary> |
| | | 21 | | /// <param name="progress">Overall progress value between 0.0 and 1.0.</param> |
| | | 22 | | /// <param name="messages">Breadcrumb of active messages from root to innermost step.</param> |
| | | 23 | | /// <param name="cancelAction">Action to invoke in order to cancel the operation, or <see langword="null"/> if none |
| | | 24 | | /// <param name="canCancel">Whether the current operation can be cancelled.</param> |
| | | 25 | | public ProgressReport(double progress, IReadOnlyList<T> messages, Action? cancelAction, bool canCancel) |
| | | 26 | | { |
| | 123 | 27 | | Progress = progress; |
| | 123 | 28 | | Messages = messages; |
| | 123 | 29 | | CancelAction = cancelAction; |
| | 123 | 30 | | CanCancel = canCancel; |
| | 123 | 31 | | } |
| | | 32 | | |
| | | 33 | | /// <summary>Gets the overall progress value, between 0.0 (not started) and 1.0 (complete).</summary> |
| | | 34 | | public double Progress { get; } |
| | | 35 | | |
| | | 36 | | /// <summary>Gets the ordered list of active messages from the root step down to the innermost step.</summary> |
| | | 37 | | public IReadOnlyList<T> Messages { get; } |
| | | 38 | | |
| | | 39 | | /// <summary>Gets the action to invoke to cancel the running operation, or <see langword="null"/> if not provided.</ |
| | | 40 | | public Action? CancelAction { get; } |
| | | 41 | | |
| | | 42 | | /// <summary>Gets a value indicating whether every active step supports cancellation.</summary> |
| | | 43 | | public bool CanCancel { get; } |
| | | 44 | | } |
| | | 45 | | |