下载目录设置

dev2.0
陈伟 2025-04-12 16:24:15 +08:00
parent d29116d9aa
commit c270561920
3 changed files with 17 additions and 12 deletions

View File

@ -70,14 +70,14 @@ public class MinioDownloadTask : INotifyPropertyChanged
CancelCommand = new CustomCommand(OnCancel);
}
public MinioDownloadTask(MinioService minio, string bucket, string objectKey)
public MinioDownloadTask(MinioService minio, string bucket, string objectKey,string downDir)
{
Status = "等待中";
_minio = minio;
Bucket = bucket;
ObjectKey = objectKey;
FileName = Path.GetFileName(objectKey);
FilePath = "f:\\dest";
FilePath = downDir;
PauseCommand = new CustomCommand(OnPause);
CancelCommand = new CustomCommand(OnCancel);
}
@ -104,7 +104,7 @@ public class MinioDownloadTask : INotifyPropertyChanged
await client.Updateable(updateTask).IgnoreNullColumns().ExecuteCommandAsync();
}
Console.WriteLine($"{ObjectKey}文件下载中...");
Console.WriteLine($"id {TaskId} path: {FilePath} key: {ObjectKey}文件下载中...");
updateTask.Status = "下载中";
await _minio.DownLoadObject(Bucket, ObjectKey, FilePath, "");
Status = "已完成";

View File

@ -158,6 +158,8 @@ namespace HeBianGu.App.Disk
{
// todo 当为文件时,处理
var selectedItems = _selectedItems;
// 清除选中
//SelectedItems = [];
foreach (var item in selectedItems)
{
if (item is MinIOFileModel file)
@ -173,6 +175,7 @@ namespace HeBianGu.App.Disk
//return ((MinIODirectoryInfo)dir.Model).BucketName;
}
}
}
// 添加设置Behavior的方法

View File

@ -2,7 +2,6 @@
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Windows.Data;
using System.Windows.Input;
using HeBianGu.Base.WpfBase;
@ -11,7 +10,6 @@ using Hopetry.Models;
using Hopetry.Provider;
using Hopetry.Services;
using Newtonsoft.Json;
using SqlSugar;
namespace Hopetry.ViewModel.Send;
@ -27,6 +25,7 @@ public class DownViewModel : MvcViewModelBase
private CancellationTokenSource _processingCts = new();
public int count { get; set; }
private readonly ReaderWriterLockSlim _lock = new();
/// <summary>
/// 全部任务动态标题
@ -104,14 +103,15 @@ public class DownViewModel : MvcViewModelBase
// 命令
public ICommand AddTaskCommand { get; set; }
public ICommand ClearFinishedCommand { get; }
private readonly ISerializerService _serializerService;
/// <summary>
/// 构造函数
/// </summary>
/// <param name="minioService"></param>
public DownViewModel(MinioService minioService)
public DownViewModel(MinioService minioService, ISerializerService serializerService)
{
_serializerService = serializerService;
_minioService = minioService;
Console.WriteLine("初始化DownViewModel");
using var client = SqlSugarConfig.GetSqlSugarScope();
@ -178,17 +178,18 @@ public class DownViewModel : MvcViewModelBase
{
Console.WriteLine($"我进入的异常下载{c1++}");
// 启动新线程执行下载任务
// _ = Task.Run(() => ExecuteTaskAsync(task));
_ = ExecuteTaskAsync(task).ContinueWith(_ => _semaphore.Release());
// _ = Task.Run(() => ExecuteTaskAsync(task));
_ = ExecuteTaskAsync(task).ContinueWith(_ => _semaphore.Release());
}
Thread.Sleep(100);
}
}
public void AddTask(string bucketName,string objectKey)
public void AddTask(string bucketName, string objectKey)
{
var task = new MinioDownloadTask(_minioService, bucketName,objectKey);
var downDir = ViewModelLocator.SyncViewModel.SyncDir;
var task = new MinioDownloadTask(_minioService, bucketName, objectKey,downDir);
using var client = SqlSugarConfig.GetSqlSugarScope();
client.Insertable(task).ExecuteCommandIdentityIntoEntity();
AllTasks.Add(task);
@ -202,7 +203,8 @@ public class DownViewModel : MvcViewModelBase
try
{
await task.StartDownload();
// todo 任务完成下载
var x = AllTasks.IndexOf(task);
Console.WriteLine($"完成任务在全部任务中的位置 {x}");
RefreshViewHeader();
Console.WriteLine($"异步下载完成:{task.FileName}");
}