-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBackgroundCopyJobExtensions.cs
68 lines (56 loc) · 2.25 KB
/
BackgroundCopyJobExtensions.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
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
//
// @(#) BackgroundCopyJobExtensions.cs
//
// Project: usis.Net.Bits
// System: Microsoft Visual Studio 2022
// Author: Udo Schäfer
//
// Copyright (c) 2017-2023 usis GmbH. All rights reserved.
using System;
namespace usis.Net.Bits
{
// ---------------------------------
// BackgroundCopyJobExtensions class
// ---------------------------------
/// <summary>
/// Provides extension methods to the <see cref="BackgroundCopyJob"/> class.
/// </summary>
public static class BackgroundCopyJobExtensions
{
// ---------------------------------
// GetPercentBytesTransferred method
// ---------------------------------
/// <summary>
/// Gets the percentage of bytes transferred.
/// </summary>
/// <param name="job">The job.</param>
/// <returns>
/// The percentage of bytes transferred.
/// </returns>
/// <exception cref="ArgumentNullException"><paramref name="job" /> is a <c>null</c> reference.</exception>
public static float GetPercentBytesTransferred(this BackgroundCopyJob job)
{
if (job == null) throw new ArgumentNullException(nameof(job));
var progress = job.RetrieveProgress();
return progress.BytesTotal == 0 ? 0.0f : 100.0f * progress.BytesTransferred / progress.BytesTotal;
}
// -------------------
// GetErrorInfo method
// -------------------
/// <summary>
/// Gets error informations after an error occurs.
/// </summary>
/// <param name="job">The job.</param>
/// <returns>
/// Informations about the last error that occured.
/// </returns>
/// <exception cref="ArgumentNullException"><paramref name="job"/> is a <c>null</c> reference.</exception>
public static BackgroundCopyErrorInfo? GetErrorInfo(this BackgroundCopyJob job)
{
if (job == null) throw new ArgumentNullException(nameof(job));
using var error = job.RetrieveError(false);
return error == null ? null : new BackgroundCopyErrorInfo(error);
}
}
}
// eof "BackgroundCopyJobExtensions.cs"