mirror of
https://github.com/Caraxi/mare.client.git
synced 2025-12-12 22:17:22 +01:00
change downloads to concurrentdictionary
This commit is contained in:
parent
4a0dce0e44
commit
7265dab8a7
4 changed files with 10 additions and 5 deletions
|
|
@ -147,6 +147,7 @@ public class CachedPlayer
|
||||||
{
|
{
|
||||||
Logger.Debug("Downloading missing files for player " + PlayerName + ", kind: " + objectKind);
|
Logger.Debug("Downloading missing files for player " + PlayerName + ", kind: " + objectKind);
|
||||||
await _apiController.DownloadFiles(downloadId, toDownloadReplacements, downloadToken);
|
await _apiController.DownloadFiles(downloadId, toDownloadReplacements, downloadToken);
|
||||||
|
_apiController.CancelDownload(downloadId);
|
||||||
if (downloadToken.IsCancellationRequested)
|
if (downloadToken.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
Logger.Verbose("Detected cancellation");
|
Logger.Verbose("Detected cancellation");
|
||||||
|
|
|
||||||
|
|
@ -378,7 +378,7 @@ namespace MareSynchronos.UI
|
||||||
|
|
||||||
if (currentDownloads.Any())
|
if (currentDownloads.Any())
|
||||||
{
|
{
|
||||||
var totalDownloads = currentDownloads.Count;
|
var totalDownloads = currentDownloads.Count();
|
||||||
var doneDownloads = currentDownloads.Count(c => c.IsTransferred);
|
var doneDownloads = currentDownloads.Count(c => c.IsTransferred);
|
||||||
var totalDownloaded = currentDownloads.Sum(c => c.Transferred);
|
var totalDownloaded = currentDownloads.Sum(c => c.Transferred);
|
||||||
var totalToDownload = currentDownloads.Sum(c => c.Total);
|
var totalToDownload = currentDownloads.Sum(c => c.Total);
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,7 @@ namespace MareSynchronos.WebAPI
|
||||||
{
|
{
|
||||||
File.Delete(tempFile);
|
File.Delete(tempFile);
|
||||||
Logger.Debug("Detected cancellation, removing " + currentDownloadId);
|
Logger.Debug("Detected cancellation, removing " + currentDownloadId);
|
||||||
CurrentDownloads.Remove(currentDownloadId);
|
CancelDownload(currentDownloadId);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -136,7 +136,7 @@ namespace MareSynchronos.WebAPI
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger.Debug("Download complete, removing " + currentDownloadId);
|
Logger.Debug("Download complete, removing " + currentDownloadId);
|
||||||
CurrentDownloads.Remove(currentDownloadId);
|
CancelDownload(currentDownloadId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task PushCharacterData(CharacterCacheDto character, List<string> visibleCharacterIds)
|
public async Task PushCharacterData(CharacterCacheDto character, List<string> visibleCharacterIds)
|
||||||
|
|
@ -292,7 +292,10 @@ namespace MareSynchronos.WebAPI
|
||||||
|
|
||||||
public void CancelDownload(int downloadId)
|
public void CancelDownload(int downloadId)
|
||||||
{
|
{
|
||||||
CurrentDownloads.Remove(downloadId);
|
while (CurrentDownloads.ContainsKey(downloadId))
|
||||||
|
{
|
||||||
|
CurrentDownloads.TryRemove(downloadId, out _);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
|
|
@ -93,7 +94,7 @@ namespace MareSynchronos.WebAPI
|
||||||
|
|
||||||
public event SimpleStringDelegate? UnpairedFromOther;
|
public event SimpleStringDelegate? UnpairedFromOther;
|
||||||
|
|
||||||
public Dictionary<int, List<DownloadFileTransfer>> CurrentDownloads { get; } = new();
|
public ConcurrentDictionary<int, List<DownloadFileTransfer>> CurrentDownloads { get; } = new();
|
||||||
|
|
||||||
public List<FileTransfer> CurrentUploads { get; } = new();
|
public List<FileTransfer> CurrentUploads { get; } = new();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue