private static bool CheckRunningJob(BitsManager bitsManager) {
if (Settings.Instance.BitsJobId.HasValue) {
BitsJob runningJob;
if (bitsManager.EnumJobs().TryGetValue(Settings.Instance.BitsJobId.Value, out runningJob)) {
if (runningJob.State == JobState.Transferred) {
_logger.Debug("Download completed");
Settings.Instance.BitsJobId = null;
Settings.Instance.Save();
runningJob.Complete();
} else if (runningJob.State == JobState.Error) {
var error = runningJob.Error;
_logger.Error($"Download of {error.File.RemoteName} failed: {error.Description}\n{error.ContextDescription}");
Settings.Instance.BitsJobId = null;
Settings.Instance.Save();
runningJob.Cancel();
} else if (runningJob.State == JobState.TransientError) {
var error = runningJob.Error;
_logger.Warn("Download of {0} is failing: {1}\n{2}", error.File.RemoteName, error.Description,
error.ContextDescription);
} else if (runningJob.State == JobState.Transferring) {
var progress = runningJob.Progress;
_logger.Debug(
$"Download is in progress (files {progress.FilesTransferred} of {progress.FilesTotal}, bytes {progress.BytesTransferred} of {progress.BytesTotal})");
}
return true;
} else {
Settings.Instance.BitsJobId = null;
Settings.Instance.Save();
}
}
return false;
}