Compare commits
3 Commits
9f07f7edaf
...
68ac9a84a7
| Author | SHA1 | Date |
|---|---|---|
|
|
68ac9a84a7 | |
|
|
e12829bc51 | |
|
|
88b0431837 |
|
|
@ -2,6 +2,7 @@
|
|||
using System.Windows;
|
||||
using System.Windows.Forms.VisualStyles;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Threading;
|
||||
using HeBianGu.Base.WpfBase;
|
||||
using Hopetry.Models;
|
||||
using Hopetry.Provider;
|
||||
|
|
@ -25,7 +26,7 @@ public class MinioDownloadTask : INotifyPropertyChanged
|
|||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
private CancellationTokenSource _cts;
|
||||
public CancellationTokenSource _cts;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
|
|
@ -68,16 +69,16 @@ public class MinioDownloadTask : INotifyPropertyChanged
|
|||
[SugarColumn(ColumnName = "file_etag")]
|
||||
public string FileETag { get; set; }
|
||||
|
||||
private string _progress;
|
||||
private Double _progress;
|
||||
|
||||
[SugarColumn(IsIgnore = true)]
|
||||
public string Progress
|
||||
public Double Progress
|
||||
{
|
||||
get
|
||||
{
|
||||
if (string.IsNullOrEmpty(_progress))
|
||||
if (_progress == 0)
|
||||
{
|
||||
_progress = TotalSize == 0 ? "0%" : $"{(Downloaded * 100 / TotalSize):0.0}%";
|
||||
_progress = Downloaded == 0 ? 0 : (Downloaded * 100 / TotalSize);
|
||||
}
|
||||
|
||||
return _progress;
|
||||
|
|
@ -114,6 +115,12 @@ public class MinioDownloadTask : INotifyPropertyChanged
|
|||
CancelCommand = new CustomCommand(OnCancel);
|
||||
}
|
||||
|
||||
public void RefreshProgress()
|
||||
{
|
||||
OnPropertyChanged(nameof(Progress));
|
||||
OnPropertyChanged("Progress");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 下载
|
||||
/// </summary>
|
||||
|
|
@ -144,20 +151,24 @@ public class MinioDownloadTask : INotifyPropertyChanged
|
|||
|
||||
Console.WriteLine($"id {TaskId} path: {FilePath} key: {ObjectKey}文件下载中...");
|
||||
updateTask.Status = "下载中";
|
||||
|
||||
await _minio.DownLoadObjectWithCallBack(Bucket, ObjectKey, FilePath, FileETag,
|
||||
(downloaded, total) =>
|
||||
{
|
||||
var progress = (double)downloaded / total * 100;
|
||||
Downloaded = downloaded;
|
||||
using (var client = SqlSugarConfig.GetSqlSugarScope())
|
||||
/*using (var client = SqlSugarConfig.GetSqlSugarScope())
|
||||
{
|
||||
updateTask.Downloaded = downloaded;
|
||||
client.Updateable(updateTask).IgnoreNullColumns().ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
Progress = $"{progress:f2}%";
|
||||
Console.WriteLine($"文件 {FileName} 进度 {Progress}");
|
||||
}*/
|
||||
Application.Current.Dispatcher.Invoke(() =>
|
||||
{
|
||||
// 在 UI 线程上更新属性
|
||||
Progress = progress;
|
||||
Console.WriteLine($"文件 {FileName} 进度 {Progress}");
|
||||
RefreshProgress();
|
||||
});
|
||||
//Console.WriteLine($"文件 {FileName} 进度 {Progress}");
|
||||
});
|
||||
//await _minio.DownLoadObject(Bucket, ObjectKey, FilePath, "");
|
||||
Status = "已完成";
|
||||
|
|
@ -211,5 +222,7 @@ public class MinioDownloadTask : INotifyPropertyChanged
|
|||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
protected void OnPropertyChanged(string propertyName)
|
||||
=> PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
using System.Threading.Channels;
|
||||
using System.Windows.Threading;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Minio;
|
||||
using Minio.DataModel.Args;
|
||||
|
|
@ -418,7 +419,6 @@ namespace Hopetry.Services
|
|||
.WithObject(objectKey);
|
||||
var stat = await _minioClient.StatObjectAsync(args);
|
||||
totalBytes = stat.Size;
|
||||
|
||||
var localPath = Path.Combine(filePath, objectKey.Replace('/', Path.DirectorySeparatorChar));
|
||||
GetObjectArgs getObjectArgs = new GetObjectArgs()
|
||||
.WithBucket(string.IsNullOrEmpty(bucketName) ? _bucketName : bucketName)
|
||||
|
|
|
|||
|
|
@ -79,13 +79,26 @@
|
|||
Grid.Column="3"
|
||||
Style="{DynamicResource {x:Static h:TextBlockKeys.Default}}"
|
||||
Text="" />
|
||||
|
||||
|
||||
<h:FProgressBar Grid.Column="3"
|
||||
Height="15"
|
||||
CornerRadius="2"
|
||||
Maximum="100"
|
||||
Value="{Binding Progress}" />
|
||||
|
||||
Value="{Binding Progress,Mode=OneWay,UpdateSourceTrigger=PropertyChanged}">
|
||||
<h:FProgressBar.Triggers>
|
||||
<EventTrigger RoutedEvent="Loaded">
|
||||
<BeginStoryboard>
|
||||
<Storyboard
|
||||
Timeline.DesiredFrameRate="{x:Static h:StoryboardSetting.DesiredFrameRate}">
|
||||
<DoubleAnimation Storyboard.TargetProperty="Value"
|
||||
From="0"
|
||||
To="{Binding RelativeSource={RelativeSource Mode=Self}, Path=Value}"
|
||||
Duration="00:00:01" />
|
||||
</Storyboard>
|
||||
</BeginStoryboard>
|
||||
</EventTrigger>
|
||||
</h:FProgressBar.Triggers>
|
||||
</h:FProgressBar>
|
||||
<TextBlock Grid.Row="1"
|
||||
Grid.Column="3"
|
||||
Margin="-3,0"
|
||||
|
|
@ -99,7 +112,11 @@
|
|||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Orientation="Horizontal">
|
||||
<Button h:Cattach.Icon="" /> <!--暂停-->
|
||||
<Button h:Cattach.Icon=""
|
||||
Command="{Binding RelativeSource={RelativeSource AncestorType=ListBox},
|
||||
Path= DataContext.DownViewModel.StartOrPauseDown }"
|
||||
CommandParameter="{Binding}"
|
||||
/> <!--暂停-->
|
||||
<Button h:Cattach.Icon="" h:Cattach.IconSize="13" /> <!--取消-->
|
||||
<Button h:Cattach.Icon="" h:Cattach.IconSize="15"
|
||||
Command="{Binding RelativeSource={RelativeSource AncestorType=ListBox},
|
||||
|
|
@ -174,6 +191,17 @@
|
|||
Style="{DynamicResource {x:Static h:TextBlockKeys.Default}}"
|
||||
Text="{Binding FinishedTime}" />
|
||||
|
||||
<!--操作-->
|
||||
<StackPanel Grid.RowSpan="2"
|
||||
Grid.Column="4"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Orientation="Horizontal">
|
||||
<Button h:Cattach.Icon="" h:Cattach.IconSize="15"
|
||||
Command="{Binding RelativeSource={RelativeSource AncestorType=ListBox},
|
||||
Path= DataContext.DownViewModel.OpenDownItemFolder }"
|
||||
CommandParameter="{Binding}" /> <!--打开所在文件夹-->
|
||||
</StackPanel>
|
||||
<Border Grid.RowSpan="11"
|
||||
Grid.ColumnSpan="11"
|
||||
Margin="0,0,0,-8"
|
||||
|
|
|
|||
|
|
@ -5,12 +5,15 @@ using System.Diagnostics;
|
|||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Shapes;
|
||||
using System.Windows.Threading;
|
||||
using HeBianGu.Base.WpfBase;
|
||||
using HeBianGu.Service.Mvc;
|
||||
using Hopetry.Models;
|
||||
using Hopetry.Provider;
|
||||
using Hopetry.Services;
|
||||
using Newtonsoft.Json;
|
||||
using Path = System.IO.Path;
|
||||
|
||||
namespace Hopetry.ViewModel.Send;
|
||||
|
||||
|
|
@ -128,6 +131,7 @@ public class DownViewModel : MvcViewModelBase
|
|||
}
|
||||
|
||||
private ObservableCollection<MinioDownloadTask> _finishedTasks;
|
||||
|
||||
public ObservableCollection<MinioDownloadTask> FinishedTasks
|
||||
{
|
||||
get => _finishedTasks;
|
||||
|
|
@ -137,6 +141,7 @@ public class DownViewModel : MvcViewModelBase
|
|||
RaisePropertyChanged(); // 触发INotifyPropertyChanged通知
|
||||
}
|
||||
}
|
||||
|
||||
private int _maxConcurrent = 3;
|
||||
|
||||
public int MaxConcurrent
|
||||
|
|
@ -154,6 +159,7 @@ public class DownViewModel : MvcViewModelBase
|
|||
}
|
||||
|
||||
public ICommand ClearFinishedCommand { get; }
|
||||
public RelayCommand<MinioDownloadTask> StartOrPauseDown { get; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -166,6 +172,7 @@ public class DownViewModel : MvcViewModelBase
|
|||
Console.WriteLine("初始化DownViewModel");
|
||||
using var client = SqlSugarConfig.GetSqlSugarScope();
|
||||
OpenDownItemFolder = new RelayCommand<MinioDownloadTask>(DoOpenDownItemFolder);
|
||||
StartOrPauseDown = new RelayCommand<MinioDownloadTask>(DoStartOrPauseDown);
|
||||
LoadFinishedTasks();
|
||||
LoadRunningTasks();
|
||||
ClearFinishedCommand = new CustomCommand(DoClearFinishedCommand);
|
||||
|
|
@ -174,6 +181,20 @@ public class DownViewModel : MvcViewModelBase
|
|||
new Thread(ProcessTasksLoop) { IsBackground = true }.Start();
|
||||
}
|
||||
|
||||
private void DoStartOrPauseDown(MinioDownloadTask item)
|
||||
{
|
||||
if (item.Status == "下载中")
|
||||
{
|
||||
item.Status = "已暂停";
|
||||
// TODO 暂停下载
|
||||
}
|
||||
else if (item.Status == "已暂停")
|
||||
{
|
||||
item.Status = "下载中";
|
||||
_taskQueue.Enqueue(item);
|
||||
}
|
||||
}
|
||||
|
||||
private void DoClearFinishedCommand()
|
||||
{
|
||||
using var client = SqlSugarConfig.GetSqlSugarScope();
|
||||
|
|
@ -184,6 +205,8 @@ public class DownViewModel : MvcViewModelBase
|
|||
|
||||
public void LoadRunningTasks()
|
||||
{
|
||||
// todo 队列中有几种任务状态 数据库中应该有几种任务状态
|
||||
//
|
||||
using var client = SqlSugarConfig.GetSqlSugarScope();
|
||||
var data = client.Ado
|
||||
.SqlQuery<MinioDownloadTask>(
|
||||
|
|
@ -196,7 +219,8 @@ public class DownViewModel : MvcViewModelBase
|
|||
{
|
||||
using var client = SqlSugarConfig.GetSqlSugarScope();
|
||||
var data = client.Ado
|
||||
.SqlQuery<MinioDownloadTask>($"select * from download_task where status='已完成' order by datetime(finished_time) desc");
|
||||
.SqlQuery<MinioDownloadTask>(
|
||||
$"select * from download_task where status='已完成' order by datetime(finished_time) desc");
|
||||
FinishedTasks = new ObservableCollection<MinioDownloadTask>(data);
|
||||
FinishedTaskHeader = $"已完成({FinishedTasks.Count})";
|
||||
}
|
||||
|
|
@ -268,7 +292,9 @@ public class DownViewModel : MvcViewModelBase
|
|||
public void DoOpenDownItemFolder(MinioDownloadTask para)
|
||||
{
|
||||
Console.WriteLine($"点击item值:{JsonConvert.SerializeObject(para)}");
|
||||
Process.Start("explorer.exe", para.FilePath);
|
||||
//Process.Start("explorer.exe", para.FilePath);
|
||||
var file = Path.Combine(para.FilePath, para.FileName);
|
||||
Process.Start("explorer.exe", $"/select,\"{file}\"");
|
||||
}
|
||||
|
||||
public void DoCancelDownItem(MinioDownloadTask item)
|
||||
|
|
|
|||
Loading…
Reference in New Issue