Redpoint.ProgressMonitor 2023.1176.407

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
dotnet add package Redpoint.ProgressMonitor --version 2023.1176.407
NuGet\Install-Package Redpoint.ProgressMonitor -Version 2023.1176.407
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Redpoint.ProgressMonitor" Version="2023.1176.407" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Redpoint.ProgressMonitor --version 2023.1176.407
#r "nuget: Redpoint.ProgressMonitor, 2023.1176.407"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Redpoint.ProgressMonitor as a Cake Addin
#addin nuget:?package=Redpoint.ProgressMonitor&version=2023.1176.407

// Install Redpoint.ProgressMonitor as a Cake Tool
#tool nuget:?package=Redpoint.ProgressMonitor&version=2023.1176.407

Redpoint.ProgressMonitor

This library provides APIs for monitoring and reporting the progress of arbitrary operations in console applications.

Read on for the following examples:

Example for a generic stream

You can monitor an operation that uses a stream like so:

// Inject these services.
IProgressFactory _progressFactory;
IMonitorFactory _monitorFactory;

using (var stream = new FileStream(...))
{
    // Start monitoring.
    var cts = new CancellationTokenSource();
    var progress = _progressFactory.CreateProgressForStream(stream);
    var monitorTask = Task.Run(async () =>
    {
        var monitor = _monitorFactory.CreateByteBasedMonitor();
        await monitor.MonitorAsync(
            progress,
            SystemConsole.ConsoleInformation,
            SystemConsole.WriteProgressToConsole,
            cts.Token);
    });

    // e.g. hash the stream.
    byte[] hashBytes;
    using (var hasher = SHA256.Create())
    {
        hashBytes = await hasher.ComputeHashAsync(stream);
    }

    // Stop monitoring.
    await SystemConsole.CancelAndWaitForConsoleMonitoringTaskAsync(monitorTask, cts);
}

Example for a HTTP download

If you're reporting progress on a HTTP stream, there's a few extra things to keep in mind:

  • You need to pass HttpCompletionOption.ResponseHeadersRead as the completion option, or HttpClient will buffer the entire response by default.
  • You need to wrap the stream you read from in PositionAwareStream, which is a class provided by this library. Since the underlying HTTP stream does not support Position or Length, this wrapping stream tracks the position as the stream is read from and allows the length to be passed in as a constructor parameter (which you should set based on the Content-Length header).

Below is a concise example of how to show the progress of downloading a file:

using (var client = new HttpClient())
{
    using (var target = new FileStream(targetPath, FileMode.Create, FileAccess.Write, FileShare.None))
    {
        var response = await client.GetAsync(downloadUrl, HttpCompletionOption.ResponseHeadersRead);
        using (var stream = new PositionAwareStream(
            await response.Content.ReadAsStreamAsync(),
            response.Content.Headers.ContentLength!.Value))
        {
            var cts = new CancellationTokenSource();
            var progress = _progressFactory.CreateProgressForStream(stream);
            var monitorTask = Task.Run(async () =>
            {
                var monitor = _monitorFactory.CreateByteBasedMonitor();
                await monitor.MonitorAsync(
                    progress,
                    SystemConsole.ConsoleInformation,
                    SystemConsole.WriteProgressToConsole,
                    cts.Token);
            });

            await stream.CopyToAsync(target);
            
            await SystemConsole.CancelAndWaitForConsoleMonitoringTaskAsync(monitorTask, cts);
        }
    }
}

The SystemConsole static class

The SystemConsole type provides common values for monitoring parameters, such as the current console information and rendering progress information to the console. You should replace the static values in the examples above with your own callbacks and values if you're not rendering progress to the console.

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Framework net48 is compatible.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2023.1176.407 137 6/25/2023
2023.1176.396 115 6/25/2023
2023.1176.363 125 6/25/2023
2023.1176.360 144 6/25/2023
2023.1175.638 121 6/24/2023
2023.1170.907 110 6/19/2023
2023.1170.900 117 6/19/2023
2023.1167.562 115 6/16/2023
2023.1167.556 122 6/16/2023
2023.1167.496 123 6/16/2023
2023.1166.1008 134 6/15/2023
2023.1166.938 108 6/15/2023
2023.1166.713 113 6/15/2023
2023.1166.699 115 6/15/2023
2023.1165.1065 123 6/14/2023
2023.1165.888 120 6/14/2023
2023.1165.878 123 6/14/2023
2023.1165.861 110 6/14/2023
2023.1165.828 118 6/14/2023
2023.1165.686 122 6/14/2023
2023.1165.653 114 6/14/2023
2023.377.1003 199 5/31/2023
2023.377.909 139 5/31/2023
2023.377.558 138 5/31/2023
2023.365.1417 159 5/30/2023
2023.365.1350 114 5/30/2023
2023.365.1327 119 5/30/2023
2023.365.1306 130 5/30/2023
2023.365.1198 147 5/30/2023
2023.365.1046 123 5/30/2023
2023.365.710 122 5/30/2023
2023.365.703 137 5/30/2023
2023.365.336 121 5/30/2023
2023.174.636 124 6/14/2023
2023.174.616 108 6/14/2023
2023.174.442 118 6/14/2023
2023.162.1243 113 6/13/2023
2023.162.1225 121 6/13/2023
2023.162.1023 112 6/13/2023
2023.162.948 106 6/13/2023
2023.162.865 118 6/13/2023
2023.162.770 140 6/13/2023
2023.162.734 130 6/13/2023
2023.162.701 125 6/13/2023
2023.162.470 135 6/13/2023
2023.162.418 120 6/13/2023
2023.150.1142 118 6/12/2023
2023.150.1121 121 6/12/2023
2023.150.1095 118 6/12/2023
2023.150.1081 121 6/12/2023
2023.150.1066 117 6/12/2023
2023.150.999 120 6/12/2023
2023.150.916 132 6/12/2023
2023.150.865 122 6/12/2023
2023.150.831 120 6/12/2023
2023.150.774 116 6/12/2023
2023.150.613 116 6/12/2023
2023.150.558 131 6/12/2023
2023.150.456 141 6/12/2023
2023.150.450 144 6/12/2023
2023.150.220 141 6/12/2023
2023.150.179 147 6/12/2023
2023.150.167 133 6/12/2023
2023.138.864 135 6/11/2023
2023.138.837 128 6/11/2023
2023.138.363 133 6/11/2023
2023.138.224 163 6/11/2023
2023.138.213 116 6/11/2023
2023.126.1167 140 6/11/2023
2023.126.1148 133 6/10/2023
2023.126.838 142 6/10/2023
2023.126.794 138 6/10/2023
2023.126.745 138 6/10/2023
2023.126.714 144 6/10/2023
2023.126.662 147 6/10/2023
2023.114.544 121 6/9/2023
2023.114.351 127 6/9/2023
2023.90.1030 137 6/7/2023
2023.90.1009 125 6/7/2023
2023.54.1152 117 6/4/2023
2023.54.419 133 6/4/2023
2023.54.198 121 6/4/2023
2023.54.60 105 6/4/2023
2023.54.48 132 6/4/2023
2023.42.745 123 6/3/2023
2023.30.1191 118 6/2/2023
2023.30.1172 132 6/2/2023
2023.30.1163 122 6/2/2023
2023.30.1147 133 6/2/2023
2023.30.1136 140 6/2/2023
2023.30.765 140 6/2/2023
2023.30.761 126 6/2/2023
2023.30.747 147 6/2/2023
2023.30.734 117 6/2/2023