|
|
@ -28,6 +28,7 @@ public class TrackedDownload |
|
|
|
[JsonIgnore] |
|
|
|
[JsonIgnore] |
|
|
|
private CancellationTokenSource? downloadPauseTokenSource; |
|
|
|
private CancellationTokenSource? downloadPauseTokenSource; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[JsonIgnore] |
|
|
|
private CancellationTokenSource AggregateCancellationTokenSource => |
|
|
|
private CancellationTokenSource AggregateCancellationTokenSource => |
|
|
|
CancellationTokenSource.CreateLinkedTokenSource( |
|
|
|
CancellationTokenSource.CreateLinkedTokenSource( |
|
|
|
downloadCancellationTokenSource?.Token ?? CancellationToken.None, |
|
|
|
downloadCancellationTokenSource?.Token ?? CancellationToken.None, |
|
|
@ -51,6 +52,7 @@ public class TrackedDownload |
|
|
|
|
|
|
|
|
|
|
|
public ProgressState ProgressState { get; private set; } = ProgressState.Inactive; |
|
|
|
public ProgressState ProgressState { get; private set; } = ProgressState.Inactive; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[JsonIgnore] |
|
|
|
public Exception? Exception { get; private set; } |
|
|
|
public Exception? Exception { get; private set; } |
|
|
|
|
|
|
|
|
|
|
|
#region Events |
|
|
|
#region Events |
|
|
@ -134,6 +136,8 @@ public class TrackedDownload |
|
|
|
|
|
|
|
|
|
|
|
downloadTask = StartDownloadTask(0, AggregateCancellationTokenSource.Token) |
|
|
|
downloadTask = StartDownloadTask(0, AggregateCancellationTokenSource.Token) |
|
|
|
.ContinueWith(OnDownloadTaskCompleted); |
|
|
|
.ContinueWith(OnDownloadTaskCompleted); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ProgressState = ProgressState.Working; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void Resume() |
|
|
|
public void Resume() |
|
|
@ -147,6 +151,8 @@ public class TrackedDownload |
|
|
|
|
|
|
|
|
|
|
|
downloadTask = StartDownloadTask(0, AggregateCancellationTokenSource.Token) |
|
|
|
downloadTask = StartDownloadTask(0, AggregateCancellationTokenSource.Token) |
|
|
|
.ContinueWith(OnDownloadTaskCompleted); |
|
|
|
.ContinueWith(OnDownloadTaskCompleted); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ProgressState = ProgressState.Working; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void Pause() |
|
|
|
public void Pause() |
|
|
@ -232,10 +238,10 @@ public class TrackedDownload |
|
|
|
OnProgressStateChanged(ProgressState); |
|
|
|
OnProgressStateChanged(ProgressState); |
|
|
|
|
|
|
|
|
|
|
|
// Dispose of the task and cancellation token |
|
|
|
// Dispose of the task and cancellation token |
|
|
|
downloadTask?.Dispose(); |
|
|
|
/*downloadTask?.Dispose(); |
|
|
|
downloadTask = null; |
|
|
|
downloadTask = null; |
|
|
|
downloadCancellationTokenSource?.Dispose(); |
|
|
|
downloadCancellationTokenSource?.Dispose(); |
|
|
|
downloadCancellationTokenSource = null; |
|
|
|
downloadCancellationTokenSource = null;*/ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void SetDownloadService(IDownloadService service) |
|
|
|
public void SetDownloadService(IDownloadService service) |
|
|
|