From d29116d9aa3ab99dce1f4386e0318766966bc900 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E9=99=88=E4=BC=9F?= <421281095@qq.com>
Date: Sat, 12 Apr 2025 15:50:38 +0800
Subject: [PATCH 1/3] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=8B=E8=BD=BD?=
=?UTF-8?q?=E6=93=8D=E4=BD=9C?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Services/MinioDownloadTask.cs | 1 +
View/Loyout/ExplorerControl.xaml | 4 +-
ViewModel/Loyout/LoyoutViewModel.cs | 140 +++++++++++++++++-----------
ViewModel/Send/DownViewModel.cs | 74 +++++++--------
minio.db | Bin 73728 -> 73728 bytes
5 files changed, 124 insertions(+), 95 deletions(-)
diff --git a/Services/MinioDownloadTask.cs b/Services/MinioDownloadTask.cs
index 5d63252..c8105ea 100644
--- a/Services/MinioDownloadTask.cs
+++ b/Services/MinioDownloadTask.cs
@@ -72,6 +72,7 @@ public class MinioDownloadTask : INotifyPropertyChanged
public MinioDownloadTask(MinioService minio, string bucket, string objectKey)
{
+ Status = "等待中";
_minio = minio;
Bucket = bucket;
ObjectKey = objectKey;
diff --git a/View/Loyout/ExplorerControl.xaml b/View/Loyout/ExplorerControl.xaml
index b5645b5..a5f2415 100644
--- a/View/Loyout/ExplorerControl.xaml
+++ b/View/Loyout/ExplorerControl.xaml
@@ -27,8 +27,8 @@
-
+
+
diff --git a/ViewModel/Loyout/LoyoutViewModel.cs b/ViewModel/Loyout/LoyoutViewModel.cs
index 0890e6d..2f05f2d 100644
--- a/ViewModel/Loyout/LoyoutViewModel.cs
+++ b/ViewModel/Loyout/LoyoutViewModel.cs
@@ -1,4 +1,5 @@
-using System.ComponentModel;
+using System.Collections.ObjectModel;
+using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Timers;
@@ -19,6 +20,7 @@ using Hopetry.ViewModel.Send;
using System.IO;
using System.Security.AccessControl;
using System.Diagnostics;
+using System.Net.Http.Json;
using Microsoft.WindowsAPICodePack.Dialogs;
using Hopetry.Models;
using Yitter.IdGenerator;
@@ -27,9 +29,11 @@ using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window;
using HeBianGu.Control.Explorer;
using Hopetry.Provider.Behaviors;
using System.Text;
+using Hopetry.Provider;
using Minio.ApiEndpoints;
using Minio.DataModel;
using Minio.DataModel.Args;
+using Newtonsoft.Json;
using Timer = System.Timers.Timer;
namespace HeBianGu.App.Disk
@@ -39,6 +43,7 @@ namespace HeBianGu.App.Disk
{
private readonly FileUploadService _uploadService;
private string _path;
+
/// 说明
public string Path
{
@@ -52,6 +57,7 @@ namespace HeBianGu.App.Disk
private string _nearPath;
+
/// 说明
public string NearPath
{
@@ -65,6 +71,7 @@ namespace HeBianGu.App.Disk
private string _sharePath;
+
/// 说明
public string SharePath
{
@@ -77,7 +84,6 @@ namespace HeBianGu.App.Disk
}
-
protected override void Init()
{
Path = Environment.GetFolderPath(Environment.SpecialFolder.MyComputer);
@@ -87,7 +93,8 @@ namespace HeBianGu.App.Disk
SharePath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
// LinkActions.Add(new LinkAction() { Action = "Near", Controller = "Loyout", DisplayName = "最近使用", Logo = "\xe6f3" });
- LinkActions.Add(new LinkAction() { Action = "Explorer", Controller = "Loyout", DisplayName = "全部文件", Logo = "" });
+ LinkActions.Add(new LinkAction()
+ { Action = "Explorer", Controller = "Loyout", DisplayName = "全部文件", Logo = "" });
// LinkActions.Add(new LinkAction() { Action = "Image", Controller = "Loyout", DisplayName = " 图片", Logo = "" });
// LinkActions.Add(new LinkAction() { Action = "Video", Controller = "Loyout", DisplayName = " 视频", Logo = "" });
// LinkActions.Add(new LinkAction() { Action = "Document", Controller = "Loyout", DisplayName = " 文档", Logo = "" });
@@ -98,21 +105,18 @@ namespace HeBianGu.App.Disk
//LinkActions.Add(new LinkAction() { Action = "Share", Controller = "Loyout", DisplayName = "我的分享", Logo = "\xe764" });
// LinkActions.Add(new LinkAction() { Action = "Near", Controller = "Loyout", DisplayName = "回收站", Logo = "\xe618" });
- Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new Action(() =>
- {
- SelectLink = LinkActions[0];
- }));
-
+ Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Loaded,
+ new Action(() => { SelectLink = LinkActions[0]; }));
}
protected override void Loaded(string args)
{
-
}
-
+
#region 文件上传
+
private SendViewModel _sendViewModel;
private IConfiguration config;
private SemaphoreSlim _semaphore = new SemaphoreSlim(5);
@@ -128,8 +132,11 @@ namespace HeBianGu.App.Disk
public ICommand UploadCommand { get; }
public ICommand UploadCommand1 { get; }
- public ICommand CreateFolderCommand { get; }
- public ICommand DeleteFolderCommand { get; }
+ public ICommand CreateFolderCommand { get; }
+ public ICommand DownloadCommand { get; set; }
+
+ public ICommand DeleteFolderCommand { get; }
+
//public ICommand SelectItemsCommand { get; }
public LoyoutViewModel(SendViewModel sendViewModel)
{
@@ -139,20 +146,41 @@ namespace HeBianGu.App.Disk
UploadCommand1 = new AsyncRelayCommand(async () => await UploadFile1());
CreateFolderCommand = new AsyncRelayCommand(async () => await CreateNewFolderAsync());
DeleteFolderCommand = new AsyncRelayCommand(async () => await DeleteSelectedItemsAsync());
+ DownloadCommand = new AsyncRelayCommand(async () => await DoDownloadCommand());
//SelectItemsCommand = new AsyncRelayCommand(async () => await RelayCommand(SelectItem)SelectItem());
// 初始化Timer
_progressTimer = new Timer(1000);
_progressTimer.Elapsed += UpdateProgress;
- _sendViewModel.UpLoadItems.CollectionChanged += (s, e) =>
- {
- _sendViewModel.UpdateUploadingItems();
- };
+ _sendViewModel.UpLoadItems.CollectionChanged += (s, e) => { _sendViewModel.UpdateUploadingItems(); };
}
+
+ private async Task DoDownloadCommand()
+ {
+ // todo 当为文件时,处理
+ var selectedItems = _selectedItems;
+ foreach (var item in selectedItems)
+ {
+ if (item is MinIOFileModel file)
+ {
+ var temp = (MinIOFileInfo)file.Model;
+ var objectKey = temp.FullName.Replace(temp.BucketName + "/", "");
+ ViewModelLocator.DownViewModel.AddTask(temp.BucketName, objectKey);
+ }
+
+ if (item is MinIODirectoryModel dir)
+ {
+ Console.WriteLine("建设中...");
+ //return ((MinIODirectoryInfo)dir.Model).BucketName;
+ }
+ }
+ }
+
// 添加设置Behavior的方法
public void SetExplorerBehavior(ExplorerMinIOBehavior behavior)
{
_explorerBehavior = behavior;
}
+
private void UpdateProgress(object sender, System.Timers.ElapsedEventArgs e)
{
lock (_timerLock)
@@ -163,10 +191,7 @@ namespace HeBianGu.App.Disk
double totalBytes = _sendViewModel.UpLoadItems.Sum(r => r.Double1);
double progress = Math.Round((currentBytes / totalBytes) * 100, 2);
- Application.Current.Dispatcher.Invoke(() =>
- {
- _sendViewModel.Progress = progress;
- });
+ Application.Current.Dispatcher.Invoke(() => { _sendViewModel.Progress = progress; });
}
}
@@ -221,6 +246,7 @@ namespace HeBianGu.App.Disk
var ut = CreateUploadItem(filePath, System.IO.Path.GetFileName(filePath));
_sendViewModel.UpLoadItems.Add(ut);
}
+
_uploadCount = _sendViewModel.UpLoadItems.Count;
//_uploadCount = _sendViewModel.UpLoadItems.Count;
_completeCount = _sendViewModel.UpLoadItems.Where(r => r.Value3 == "已完成").Count();
@@ -259,10 +285,12 @@ namespace HeBianGu.App.Disk
foreach (string filePath in files)
{
- string relativePath = folderName + "/" + filePath.Substring(folderPath.Length + 1).Replace('\\', '/');
+ string relativePath =
+ folderName + "/" + filePath.Substring(folderPath.Length + 1).Replace('\\', '/');
var ut = CreateUploadItem(filePath, relativePath);
_sendViewModel.UpLoadItems.Add(ut);
}
+
_uploadCount = _sendViewModel.UpLoadItems.Count;
_completeCount = _sendViewModel.UpLoadItems.Where(r => r.Value3 == "已完成").Count();
_sendViewModel.FileCount = _completeCount + "/" + _uploadCount;
@@ -279,27 +307,27 @@ namespace HeBianGu.App.Disk
private UpLoadItems CreateUploadItem(string filePath, string objectName)
{
FileInfo fileInfo = new FileInfo(filePath);
- string sizeText = fileInfo.Length < 1024 * 1024 ?
- $"{Math.Ceiling((decimal)fileInfo.Length / 1024)}KB" :
- $"{Math.Ceiling((decimal)fileInfo.Length / (1024 * 1024))}MB";
+ string sizeText = fileInfo.Length < 1024 * 1024
+ ? $"{Math.Ceiling((decimal)fileInfo.Length / 1024)}KB"
+ : $"{Math.Ceiling((decimal)fileInfo.Length / (1024 * 1024))}MB";
//写入数据库
- FUpload fp= new FUpload();
- fp.Id= Guid.NewGuid().ToString();
- fp.FileName= objectName;
+ FUpload fp = new FUpload();
+ fp.Id = Guid.NewGuid().ToString();
+ fp.FileName = objectName;
fp.FileSize = fileInfo.Length;
fp.FilePath = filePath;
fp.FileType = fileInfo.Extension;
- fp.CreateTime=DateTime.Now;
- fp.IsComplete=false;
- fp.FileSizeText=sizeText;
+ fp.CreateTime = DateTime.Now;
+ fp.IsComplete = false;
+ fp.FileSizeText = sizeText;
if (_uploadService.AddFile(fp))
{
return new UpLoadItems
{
Value = System.IO.Path.GetFileName(filePath),
Value3 = "等待上传",
- Value4 = fp.Id, //唯一标识,与数据库一致
+ Value4 = fp.Id, //唯一标识,与数据库一致
Value5 = filePath,
Value6 = objectName,
Double1 = fileInfo.Length,
@@ -369,8 +397,8 @@ namespace HeBianGu.App.Disk
{
ut.Bool1 = true;
var builder = new ConfigurationBuilder()
- .SetBasePath(Directory.GetCurrentDirectory())
- .AddJsonFile("global.json", optional: false, reloadOnChange: true);
+ .SetBasePath(Directory.GetCurrentDirectory())
+ .AddJsonFile("global.json", optional: false, reloadOnChange: true);
// 构建配置
var config = builder.Build();
// 从配置获取MinIO设置更安全
@@ -378,10 +406,9 @@ namespace HeBianGu.App.Disk
.WithEndpoint(config["Minio:Endpoint"])
.WithCredentials(config["Minio:AccessKey"], config["Minio:SecretKey"])
.Build();
-
+
try
{
-
string bucketName = config["Minio:BucketName"];
// 确保桶存在
@@ -403,9 +430,9 @@ namespace HeBianGu.App.Disk
int slashIndex = ut.Value1.IndexOf('/');
string sizePart = ut.Value1.Substring(slashIndex);
- string transferredPart = trans < 1024 * 1024 ?
- $"{Math.Ceiling((decimal)trans / 1024)}KB" :
- $"{Math.Ceiling((decimal)trans / (1024 * 1024))}MB";
+ string transferredPart = trans < 1024 * 1024
+ ? $"{Math.Ceiling((decimal)trans / 1024)}KB"
+ : $"{Math.Ceiling((decimal)trans / (1024 * 1024))}MB";
ut.Value1 = $"{transferredPart}{sizePart}";
if (progressReport.Percentage == 100)
@@ -417,7 +444,7 @@ namespace HeBianGu.App.Disk
ut.Value3 = "已完成";
_sendViewModel.UpdateUploadingItems();
_completeCount++;
- _sendViewModel.FileCount=_completeCount+"/"+_uploadCount;
+ _sendViewModel.FileCount = _completeCount + "/" + _uploadCount;
}
else
{
@@ -432,14 +459,11 @@ namespace HeBianGu.App.Disk
.WithFileName(ut.Value5)
.WithProgress(progress);
- await client.PutObjectAsync(putObjectArgs);
+ await client.PutObjectAsync(putObjectArgs);
}
catch (Exception ex)
{
- Application.Current.Dispatcher.Invoke(() =>
- {
- ut.Value3 = $"上传失败: {ex.Message}";
- });
+ Application.Current.Dispatcher.Invoke(() => { ut.Value3 = $"上传失败: {ex.Message}"; });
}
}
@@ -454,10 +478,13 @@ namespace HeBianGu.App.Disk
MessageBox.Show($"关机失败: {ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
+
#endregion
#region 文件列表
+
private string _currentMinIOPath;
+
/// 说明CurrentMinIOPath
public string CurrentMinIOPath
{
@@ -487,7 +514,6 @@ namespace HeBianGu.App.Disk
}
-
public ObservableCollection Items { get; } = new ObservableCollection();
private async Task CreateNewFolderAsync()
@@ -522,8 +548,8 @@ namespace HeBianGu.App.Disk
public async Task CreateMinIOFolder(string folderName)
{
var builder = new ConfigurationBuilder()
- .SetBasePath(Directory.GetCurrentDirectory())
- .AddJsonFile("global.json", optional: false, reloadOnChange: true);
+ .SetBasePath(Directory.GetCurrentDirectory())
+ .AddJsonFile("global.json", optional: false, reloadOnChange: true);
// 构建配置
var config = builder.Build();
// 从配置获取MinIO设置更安全
@@ -558,7 +584,7 @@ namespace HeBianGu.App.Disk
.WithBucket(bucketName)
.WithObject(prefix + folderName)
.WithStreamData(emptyStream)
- .WithObjectSize(1) // 必须设置为0
+ .WithObjectSize(1) // 必须设置为0
.WithContentType("application/x-directory"));
}
@@ -586,18 +612,27 @@ namespace HeBianGu.App.Disk
return CurrentMinIOPath.Substring(CurrentMinIOPath.IndexOf('/') + 1);
}
+
#endregion
#region 删除文件夹
+
private ObservableCollection _selectedItems = new ObservableCollection();
+
public ObservableCollection SelectedItems
{
get { return _selectedItems; }
- set { _selectedItems = value; RaisePropertyChanged(); }
+ set
+ {
+ _selectedItems = value;
+ RaisePropertyChanged();
+ }
}
private ICommand _selectItemsCommand;
- public ICommand SelectItemsCommand => _selectItemsCommand ?? (_selectItemsCommand = new RelayCommand(SelectItem));
+
+ public ICommand SelectItemsCommand => _selectItemsCommand ??
+ (_selectItemsCommand = new RelayCommand(SelectItem));
private void SelectItem(SystemInfoModel item)
{
@@ -612,6 +647,7 @@ namespace HeBianGu.App.Disk
SelectedItems.Add(item);
}
}
+
private async Task DeleteSelectedItemsAsync()
{
try
@@ -711,7 +747,6 @@ namespace HeBianGu.App.Disk
}
#endregion
-
}
internal class DataFileViewModel : ObservableSourceViewModel
@@ -719,7 +754,6 @@ namespace HeBianGu.App.Disk
protected override void Init()
{
base.Init();
-
}
}
-}
+}
\ No newline at end of file
diff --git a/ViewModel/Send/DownViewModel.cs b/ViewModel/Send/DownViewModel.cs
index b4c5be5..3981632 100644
--- a/ViewModel/Send/DownViewModel.cs
+++ b/ViewModel/Send/DownViewModel.cs
@@ -22,12 +22,10 @@ public class DownViewModel : MvcViewModelBase
public RelayCommand OpenDownItemFolder { get; set; }
private readonly ConcurrentQueue _taskQueue = new();
- private SemaphoreSlim _concurrencySemaphore;
+ private SemaphoreSlim _semaphore;
private CancellationTokenSource _processingCts = new();
public int count { get; set; }
-
- private SemaphoreSlim _semaphore;
private readonly ReaderWriterLockSlim _lock = new();
///
@@ -70,7 +68,7 @@ public class DownViewModel : MvcViewModelBase
}
// 绑定属性
- public ObservableCollection AllTasks { get; set; } = new();
+ public ObservableCollection AllTasks { get; set; }
public ICollectionView RunningTasksView { get; set; }
@@ -112,21 +110,16 @@ public class DownViewModel : MvcViewModelBase
/// 构造函数
///
///
- public DownViewModel(MinioService minioService, SemaphoreSlim semaphore)
+ public DownViewModel(MinioService minioService)
{
_minioService = minioService;
- _semaphore = semaphore;
Console.WriteLine("初始化DownViewModel");
using var client = SqlSugarConfig.GetSqlSugarScope();
var data = client.Ado.SqlQuery($"select * from download_task");
- //DownItems = new ObservableCollection(data);
AllTasks = new ObservableCollection(data);
AllTaskHeader = $"全部({AllTasks.Count})";
//Console.WriteLine(JsonConvert.SerializeObject(data));
OpenDownItemFolder = new RelayCommand(DoOpenDownItemFolder);
- // 命令初始化
- // AddTaskCommand = new RelayCommand(AddTask, CanAddTask);
- // 修正:使用 CollectionViewSource 确保通知
var cvsRunning = new CollectionViewSource { Source = AllTasks };
cvsRunning.Filter += (s, e) =>
{
@@ -142,15 +135,7 @@ public class DownViewModel : MvcViewModelBase
e.Accepted = b;
};
FinishedTasksView = cvsFinished.View;
- if (FinishedTasksView is ListCollectionView finishListView)
- {
- FinishedTaskHeader = $"已完成({finishListView.Count})";
- }
-
- if (RunningTasksView is ListCollectionView runningListView)
- {
- RunningTaskHeader = $"下载中({runningListView.Count})";
- }
+ RefreshViewHeader();
// 关键:订阅数据源变更事件,强制视图刷新
AllTasks.CollectionChanged += (s, e) =>
@@ -166,41 +151,49 @@ public class DownViewModel : MvcViewModelBase
// 启动任务处理线程
_semaphore = new SemaphoreSlim(_maxConcurrent);
- // 启动任务处理线程
- _concurrencySemaphore = new SemaphoreSlim(_maxConcurrent);
new Thread(ProcessTasksLoop) { IsBackground = true }.Start();
-
-
- AddTaskCommand = new ActionCommand(AddTask);
+ //AddTaskCommand = new ActionCommand(AddTask);
}
- private void ProcessTasksLoop()
+ private void RefreshViewHeader()
{
+ if (FinishedTasksView is ListCollectionView finishListView)
+ {
+ FinishedTaskHeader = $"已完成({finishListView.Count})";
+ }
+
+ if (RunningTasksView is ListCollectionView runningListView)
+ {
+ RunningTaskHeader = $"下载中({runningListView.Count})";
+ }
+ }
+
+ private async void ProcessTasksLoop()
+ {
+ int c1 = 1;
while (!_processingCts.IsCancellationRequested)
{
- _semaphore.WaitAsync();
- // 按当前并发数启动任务
- for (int i = 0; i < _maxConcurrent; i++)
+ await _semaphore.WaitAsync();
+ if (_taskQueue.TryDequeue(out var task))
{
- if (_taskQueue.TryDequeue(out var task))
- {
- // 启动新线程执行下载任务
- _ = Task.Run(() => ExecuteTaskAsync(task));
- }
+ Console.WriteLine($"我进入的异常下载{c1++}");
+ // 启动新线程执行下载任务
+ // _ = Task.Run(() => ExecuteTaskAsync(task));
+ _ = ExecuteTaskAsync(task).ContinueWith(_ => _semaphore.Release());
}
Thread.Sleep(100);
}
}
- private void AddTask()
+ public void AddTask(string bucketName,string objectKey)
{
- string[] objectKeys = { "demo/06.mp4", "demo/07.mp4", "demo/08.mp4", "demo/10.mp4" };
- var task = new MinioDownloadTask(_minioService, "demo", objectKeys[count++]);
+ var task = new MinioDownloadTask(_minioService, bucketName,objectKey);
using var client = SqlSugarConfig.GetSqlSugarScope();
client.Insertable(task).ExecuteCommandIdentityIntoEntity();
AllTasks.Add(task);
_taskQueue.Enqueue(task);
+ RefreshViewHeader();
}
@@ -210,24 +203,25 @@ public class DownViewModel : MvcViewModelBase
{
await task.StartDownload();
// todo 任务完成下载
+ RefreshViewHeader();
+ Console.WriteLine($"异步下载完成:{task.FileName}");
}
finally
{
- _semaphore.Release();
}
}
private void AdjustConcurrency()
{
- lock (_concurrencySemaphore)
+ lock (_semaphore)
{
// 调整信号量容量
- var delta = _maxConcurrent - _concurrencySemaphore.CurrentCount;
+ var delta = _maxConcurrent - _semaphore.CurrentCount;
if (delta > 0)
{
for (int i = 0; i < delta; i++)
{
- _concurrencySemaphore.Release();
+ _semaphore.Release();
}
}
}
diff --git a/minio.db b/minio.db
index 7d0493bf3e37a0f2048f4a449df0885a4cbab430..d577e09a3fb4d281a4e0218f0890a2f97c96f1f6 100644
GIT binary patch
delta 84
zcmZoTz|wGlWr8$g{zMsP#{7*53;o3zfIxtOfj5BX3o_g+5zxcS!oa{3Gg-0QfAam@
b6d;Fj>Ew^K!INj@MFTkupEnD}zdrx~kI@}1
delta 58
zcmV-A0LA}+zyyH61dtm6Zjl^A0dBEip-&eIy#NdexBw5c4`B}t4zUhf4fYMB4N$Wf
QP>c<;jBO7Bv$J1Kz$(oXcmMzZ
From c270561920b4b624aeaee55d8a712fafa6f28c8e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E9=99=88=E4=BC=9F?= <421281095@qq.com>
Date: Sat, 12 Apr 2025 16:24:15 +0800
Subject: [PATCH 2/3] =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E7=9B=AE=E5=BD=95?=
=?UTF-8?q?=E8=AE=BE=E7=BD=AE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Services/MinioDownloadTask.cs | 6 +++---
ViewModel/Loyout/LoyoutViewModel.cs | 3 +++
ViewModel/Send/DownViewModel.cs | 20 +++++++++++---------
3 files changed, 17 insertions(+), 12 deletions(-)
diff --git a/Services/MinioDownloadTask.cs b/Services/MinioDownloadTask.cs
index c8105ea..c1584c6 100644
--- a/Services/MinioDownloadTask.cs
+++ b/Services/MinioDownloadTask.cs
@@ -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 = "已完成";
diff --git a/ViewModel/Loyout/LoyoutViewModel.cs b/ViewModel/Loyout/LoyoutViewModel.cs
index 2f05f2d..f97bb47 100644
--- a/ViewModel/Loyout/LoyoutViewModel.cs
+++ b/ViewModel/Loyout/LoyoutViewModel.cs
@@ -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的方法
diff --git a/ViewModel/Send/DownViewModel.cs b/ViewModel/Send/DownViewModel.cs
index 3981632..299ea4e 100644
--- a/ViewModel/Send/DownViewModel.cs
+++ b/ViewModel/Send/DownViewModel.cs
@@ -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();
+
///
/// 全部任务动态标题
@@ -104,14 +103,15 @@ public class DownViewModel : MvcViewModelBase
// 命令
public ICommand AddTaskCommand { get; set; }
public ICommand ClearFinishedCommand { get; }
-
+ private readonly ISerializerService _serializerService;
///
/// 构造函数
///
///
- 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}");
}
From e6e60df9bfd124789673fcce17217d1d4c51b2c4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E9=99=88=E4=BC=9F?= <421281095@qq.com>
Date: Sat, 12 Apr 2025 16:43:28 +0800
Subject: [PATCH 3/3] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=95=8C=E9=9D=A2?=
=?UTF-8?q?=E4=BB=BB=E5=8A=A1=E7=8A=B6=E6=80=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Services/MinioDownloadTask.cs | 4 ++--
ViewModel/Send/DownViewModel.cs | 6 +++++-
2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/Services/MinioDownloadTask.cs b/Services/MinioDownloadTask.cs
index c1584c6..749e99e 100644
--- a/Services/MinioDownloadTask.cs
+++ b/Services/MinioDownloadTask.cs
@@ -53,7 +53,7 @@ public class MinioDownloadTask : INotifyPropertyChanged
[SugarColumn(ColumnName = "file_path")]
public string FilePath { get; set; }
- [SugarColumn(ColumnName = "status")] public string Status { get; private set; } = "等待中";
+ [SugarColumn(ColumnName = "status")] public string Status { get; set; } = "等待中";
[SugarColumn(IsIgnore = true)]
public string Progress
@@ -70,7 +70,7 @@ public class MinioDownloadTask : INotifyPropertyChanged
CancelCommand = new CustomCommand(OnCancel);
}
- public MinioDownloadTask(MinioService minio, string bucket, string objectKey,string downDir)
+ public MinioDownloadTask(MinioService minio, string bucket, string objectKey, string downDir)
{
Status = "等待中";
_minio = minio;
diff --git a/ViewModel/Send/DownViewModel.cs b/ViewModel/Send/DownViewModel.cs
index 299ea4e..127b1ad 100644
--- a/ViewModel/Send/DownViewModel.cs
+++ b/ViewModel/Send/DownViewModel.cs
@@ -174,9 +174,10 @@ public class DownViewModel : MvcViewModelBase
while (!_processingCts.IsCancellationRequested)
{
await _semaphore.WaitAsync();
+ Console.WriteLine("获得下载许可");
if (_taskQueue.TryDequeue(out var task))
{
- Console.WriteLine($"我进入的异常下载{c1++}");
+ Console.WriteLine($"开启下载任务:{c1++}");
// 启动新线程执行下载任务
// _ = Task.Run(() => ExecuteTaskAsync(task));
_ = ExecuteTaskAsync(task).ContinueWith(_ => _semaphore.Release());
@@ -204,6 +205,9 @@ public class DownViewModel : MvcViewModelBase
{
await task.StartDownload();
var x = AllTasks.IndexOf(task);
+ var temp = AllTasks[x];
+ temp.Status = "已完成";
+ Console.WriteLine($"所有任务取出任务id {temp.TaskId} 完成任务id:{task.TaskId}" );
Console.WriteLine($"完成任务在全部任务中的位置 :{x}");
RefreshViewHeader();
Console.WriteLine($"异步下载完成:{task.FileName}");