|
|
@ -15,10 +15,8 @@ public class TrackedDownloadService : ITrackedDownloadService, IDisposable |
|
|
|
private readonly ISettingsManager settingsManager; |
|
|
|
private readonly ISettingsManager settingsManager; |
|
|
|
private readonly IModelIndexService modelIndexService; |
|
|
|
private readonly IModelIndexService modelIndexService; |
|
|
|
|
|
|
|
|
|
|
|
private readonly ConcurrentDictionary< |
|
|
|
private readonly ConcurrentDictionary<Guid, (TrackedDownload Download, FileStream Stream)> downloads = |
|
|
|
Guid, |
|
|
|
new(); |
|
|
|
(TrackedDownload Download, FileStream Stream) |
|
|
|
|
|
|
|
> downloads = new(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public IEnumerable<TrackedDownload> Downloads => downloads.Values.Select(x => x.Download); |
|
|
|
public IEnumerable<TrackedDownload> Downloads => downloads.Values.Select(x => x.Download); |
|
|
|
|
|
|
|
|
|
|
@ -51,6 +49,7 @@ public class TrackedDownloadService : ITrackedDownloadService, IDisposable |
|
|
|
|
|
|
|
|
|
|
|
private void OnDownloadAdded(TrackedDownload download) |
|
|
|
private void OnDownloadAdded(TrackedDownload download) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
logger.LogInformation("Download added: ({Download}, {State})", download.Id, download.ProgressState); |
|
|
|
DownloadAdded?.Invoke(this, download); |
|
|
|
DownloadAdded?.Invoke(this, download); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -67,11 +66,7 @@ public class TrackedDownloadService : ITrackedDownloadService, IDisposable |
|
|
|
var downloadsDir = new DirectoryPath(settingsManager.DownloadsDirectory); |
|
|
|
var downloadsDir = new DirectoryPath(settingsManager.DownloadsDirectory); |
|
|
|
downloadsDir.Create(); |
|
|
|
downloadsDir.Create(); |
|
|
|
var jsonFile = downloadsDir.JoinFile($"{download.Id}.json"); |
|
|
|
var jsonFile = downloadsDir.JoinFile($"{download.Id}.json"); |
|
|
|
var jsonFileStream = jsonFile.Info.Open( |
|
|
|
var jsonFileStream = jsonFile.Info.Open(FileMode.CreateNew, FileAccess.ReadWrite, FileShare.Read); |
|
|
|
FileMode.CreateNew, |
|
|
|
|
|
|
|
FileAccess.ReadWrite, |
|
|
|
|
|
|
|
FileShare.Read |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Serialize to json |
|
|
|
// Serialize to json |
|
|
|
var json = JsonSerializer.Serialize(download); |
|
|
|
var json = JsonSerializer.Serialize(download); |
|
|
@ -81,11 +76,10 @@ public class TrackedDownloadService : ITrackedDownloadService, IDisposable |
|
|
|
// Add to dictionary |
|
|
|
// Add to dictionary |
|
|
|
downloads.TryAdd(download.Id, (download, jsonFileStream)); |
|
|
|
downloads.TryAdd(download.Id, (download, jsonFileStream)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
OnDownloadAdded(download); |
|
|
|
|
|
|
|
|
|
|
|
// Connect to state changed event to update json file |
|
|
|
// Connect to state changed event to update json file |
|
|
|
AttachHandlers(download); |
|
|
|
AttachHandlers(download); |
|
|
|
|
|
|
|
|
|
|
|
logger.LogDebug("Added download {Download}", download.FileName); |
|
|
|
|
|
|
|
OnDownloadAdded(download); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// <summary> |
|
|
|