1. 从数据库加载下载任务
parent
b475c7009c
commit
452b0e0b8a
|
|
@ -37,7 +37,7 @@ public class MinioDownloadTask : NotifyPropertyChangedBase
|
||||||
public string ObjectKey { get; set; }
|
public string ObjectKey { get; set; }
|
||||||
|
|
||||||
[SugarColumn(ColumnName = "total_size")]
|
[SugarColumn(ColumnName = "total_size")]
|
||||||
public long TotalSize { get; private set; }
|
public long TotalSize { get; set; }
|
||||||
|
|
||||||
[SugarColumn(ColumnName = "downloaded")]
|
[SugarColumn(ColumnName = "downloaded")]
|
||||||
public long Downloaded { get; set; }
|
public long Downloaded { get; set; }
|
||||||
|
|
@ -122,6 +122,8 @@ public class MinioDownloadTask : NotifyPropertyChangedBase
|
||||||
|
|
||||||
public MinioDownloadTask()
|
public MinioDownloadTask()
|
||||||
{
|
{
|
||||||
|
StartOrPauseIcon = "\xe76e";
|
||||||
|
Status = "等待中";
|
||||||
}
|
}
|
||||||
|
|
||||||
public MinioDownloadTask(MinioService minio, string bucket, string objectKey, string downDir, string fileSize)
|
public MinioDownloadTask(MinioService minio, string bucket, string objectKey, string downDir, string fileSize)
|
||||||
|
|
@ -134,8 +136,8 @@ public class MinioDownloadTask : NotifyPropertyChangedBase
|
||||||
FileName = Path.GetFileName(objectKey);
|
FileName = Path.GetFileName(objectKey);
|
||||||
FilePath = downDir;
|
FilePath = downDir;
|
||||||
CreateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
CreateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||||||
//var x = _minio.GetObjectMetadata(bucket, objectKey);
|
var x = minio.GetObjectMetadata(bucket, objectKey);
|
||||||
//TotalSize = x.Result.Size;
|
TotalSize = x.Result.Size;
|
||||||
FileSize = fileSize;
|
FileSize = fileSize;
|
||||||
Speed = Status;
|
Speed = Status;
|
||||||
DownloadInfo = $"0MB/{FileSize}";
|
DownloadInfo = $"0MB/{FileSize}";
|
||||||
|
|
@ -181,11 +183,13 @@ public class MinioDownloadTask : NotifyPropertyChangedBase
|
||||||
{
|
{
|
||||||
var progress = (double)(downloaded + offset) / total * 100;
|
var progress = (double)(downloaded + offset) / total * 100;
|
||||||
Downloaded = downloaded + offset;
|
Downloaded = downloaded + offset;
|
||||||
/*using (var client = SqlSugarConfig.GetSqlSugarScope())
|
/* todo 这部分会导致锁库
|
||||||
|
using (var client = SqlSugarConfig.GetSqlSugarScope())
|
||||||
{
|
{
|
||||||
updateTask.Downloaded = downloaded;
|
updateTask.Downloaded = downloaded;
|
||||||
client.Updateable(updateTask).IgnoreNullColumns().ExecuteCommandAsync();
|
client.Updateable(updateTask).IgnoreNullColumns().ExecuteCommandAsync();
|
||||||
}*/
|
}
|
||||||
|
*/
|
||||||
Application.Current.Dispatcher.Invoke(() =>
|
Application.Current.Dispatcher.Invoke(() =>
|
||||||
{
|
{
|
||||||
var remaining = total - downloaded;
|
var remaining = total - downloaded;
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,7 @@
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using System.Threading.Channels;
|
using System.Threading.Channels;
|
||||||
using FileUploader.Models;
|
|
||||||
using Hopetry.Provider;
|
using Hopetry.Provider;
|
||||||
using Hopetry.Util;
|
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Minio;
|
using Minio;
|
||||||
using Minio.DataModel.Args;
|
using Minio.DataModel.Args;
|
||||||
|
|
@ -467,6 +465,7 @@ namespace Hopetry.Services
|
||||||
Downloaded = bytesRead + offset
|
Downloaded = bytesRead + offset
|
||||||
};
|
};
|
||||||
client.Updateable(temp).IgnoreNullColumns().ExecuteCommand();
|
client.Updateable(temp).IgnoreNullColumns().ExecuteCommand();
|
||||||
|
// todo 这里有bug,有可能变成0
|
||||||
downTask.Downloaded = temp.Downloaded;
|
downTask.Downloaded = temp.Downloaded;
|
||||||
fileStream.Close();
|
fileStream.Close();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@ using HeBianGu.Service.Mvc;
|
||||||
using Hopetry.Models;
|
using Hopetry.Models;
|
||||||
using Hopetry.Provider;
|
using Hopetry.Provider;
|
||||||
using Hopetry.Services;
|
using Hopetry.Services;
|
||||||
using Newtonsoft.Json;
|
|
||||||
using Path = System.IO.Path;
|
using Path = System.IO.Path;
|
||||||
|
|
||||||
namespace Hopetry.ViewModel.Send;
|
namespace Hopetry.ViewModel.Send;
|
||||||
|
|
@ -217,9 +216,11 @@ public class DownViewModel : MvcViewModelBase
|
||||||
{
|
{
|
||||||
minioDownloadTask.StopDownTs.Cancel();
|
minioDownloadTask.StopDownTs.Cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
using var client = SqlSugarConfig.GetSqlSugarScope();
|
using var client = SqlSugarConfig.GetSqlSugarScope();
|
||||||
client.Deleteable<MinioDownloadTask>().Where(x => x.TaskId == minioDownloadTask.TaskId).ExecuteCommand();
|
client.Deleteable<MinioDownloadTask>().Where(x => x.TaskId == minioDownloadTask.TaskId).ExecuteCommand();
|
||||||
}
|
}
|
||||||
|
|
||||||
RunningTasks.Clear();
|
RunningTasks.Clear();
|
||||||
RefreshHeader();
|
RefreshHeader();
|
||||||
MessageProxy.Snacker.Show("取消下载成功");
|
MessageProxy.Snacker.Show("取消下载成功");
|
||||||
|
|
@ -252,8 +253,12 @@ public class DownViewModel : MvcViewModelBase
|
||||||
item.StartOrPauseIcon = "\xe748";
|
item.StartOrPauseIcon = "\xe748";
|
||||||
// 速度及剩余时间(视图显示信息)
|
// 速度及剩余时间(视图显示信息)
|
||||||
item.Speed = "已暂停";
|
item.Speed = "已暂停";
|
||||||
//暂停下载
|
// 避免结构函数加载的任务报错
|
||||||
item.StopDownTs.Cancel();
|
if (item.StopDownTs != null)
|
||||||
|
{
|
||||||
|
//暂停下载
|
||||||
|
item.StopDownTs.Cancel();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (item.Status == "已暂停")
|
else if (item.Status == "已暂停")
|
||||||
{
|
{
|
||||||
|
|
@ -285,9 +290,30 @@ public class DownViewModel : MvcViewModelBase
|
||||||
// todo 队列中有几种任务状态 数据库中应该有几种任务状态
|
// todo 队列中有几种任务状态 数据库中应该有几种任务状态
|
||||||
//
|
//
|
||||||
using var client = SqlSugarConfig.GetSqlSugarScope();
|
using var client = SqlSugarConfig.GetSqlSugarScope();
|
||||||
|
// todo
|
||||||
var data = client.Ado
|
var data = client.Ado
|
||||||
.SqlQuery<MinioDownloadTask>(
|
.SqlQuery<MinioDownloadTask>(
|
||||||
$"select * from download_task where status='下载中' or status='等待中' or status='已暂停' order by task_id desc");
|
$"select * from download_task where status='下载中' or status='等待中' or status='已暂停' order by task_id desc")
|
||||||
|
.Select(x => new MinioDownloadTask
|
||||||
|
{
|
||||||
|
Status = "已暂停",
|
||||||
|
TaskId = x.TaskId,
|
||||||
|
FileName = x.FileName,
|
||||||
|
Bucket = x.Bucket,
|
||||||
|
ObjectKey = x.ObjectKey,
|
||||||
|
TotalSize = x.TotalSize,
|
||||||
|
Downloaded = x.Downloaded,
|
||||||
|
FilePath = x.FilePath,
|
||||||
|
CreateTime = x.CreateTime,
|
||||||
|
FinishedTime = x.FinishedTime,
|
||||||
|
FileSize = x.FileSize,
|
||||||
|
FileETag = x.FileETag,
|
||||||
|
DownloadInfo =
|
||||||
|
(x.Downloaded > 1048576 ? $"{x.Downloaded / 1048576:f2}MB" : $"{x.Downloaded / 1024:f2}KB") +
|
||||||
|
$"/{x.FileSize}",
|
||||||
|
Speed = "已暂停",
|
||||||
|
StartOrPauseIcon = "\xe748"
|
||||||
|
}).ToList();
|
||||||
RunningTasks = new ObservableCollection<MinioDownloadTask>(data);
|
RunningTasks = new ObservableCollection<MinioDownloadTask>(data);
|
||||||
RunningTaskHeader = $"下载中({RunningTasks.Count})";
|
RunningTaskHeader = $"下载中({RunningTasks.Count})";
|
||||||
}
|
}
|
||||||
|
|
@ -332,6 +358,7 @@ public class DownViewModel : MvcViewModelBase
|
||||||
{
|
{
|
||||||
var task = new MinioDownloadTask(_minioService, bucketName, objectKey, downDir, size);
|
var task = new MinioDownloadTask(_minioService, bucketName, objectKey, downDir, size);
|
||||||
using var client = SqlSugarConfig.GetSqlSugarScope();
|
using var client = SqlSugarConfig.GetSqlSugarScope();
|
||||||
|
//todo 文件总字节数
|
||||||
client.Insertable(task).ExecuteCommandIdentityIntoEntity();
|
client.Insertable(task).ExecuteCommandIdentityIntoEntity();
|
||||||
Application.Current.Dispatcher.Invoke(() =>
|
Application.Current.Dispatcher.Invoke(() =>
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue