-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathProgressDelegates.cs
41 lines (36 loc) · 1.44 KB
/
ProgressDelegates.cs
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
using System.Threading;
namespace Hi3Helper.Http
{
/// <summary>
/// The callback to get the download progress of a file.
/// </summary>
/// <param name="size">Current size written to the target stream.</param>
/// <param name="bytesProgress">The struct which consist the amount of data downloaded.</param>
public delegate void DownloadProgressDelegate(int size, DownloadProgress bytesProgress);
/// <summary>
/// The class which consist the amount of data downloaded.
/// </summary>
public class DownloadProgress
{
/// <summary>
/// The amount of data already downloaded.
/// </summary>
public long BytesDownloaded;
/// <summary>
/// The amount of data to be downloaded in total.
/// </summary>
public long BytesTotal;
/// <summary>
/// Increment the current <seealso cref="BytesDownloaded"/> field.
/// </summary>
/// <param name="size">How many bytes to increment the <seealso cref="BytesDownloaded"/> field.</param>
internal void AdvanceBytesDownloaded(long size)
=> Interlocked.Add(ref BytesDownloaded, size);
/// <summary>
/// Set the value of <seealso cref="BytesTotal"/> field.
/// </summary>
/// <param name="size">Value to be set to <seealso cref="BytesTotal"/> field.</param>
internal void SetBytesTotal(long size)
=> BytesTotal = size;
}
}