1. 添加一次性同步按钮

2. 修复多次调用全量同步报错问题
dev
陈伟 2025-03-24 14:15:16 +08:00
parent 532beae7b6
commit f55764b09c
6 changed files with 75 additions and 14 deletions

View File

@ -31,8 +31,8 @@ namespace HeBianGu.App.Disk
services.AddSingleton<MinioService, MinioService>();
var minioService = services.GetService<MinioService>();
var bucketName = minioService._bucketName;
minioService.MirrorAsync1(bucketName, "d:/test");
minioService.RealTimeListen(bucketName, "d:/test");
//minioService.MirrorAsync1(bucketName, "d:/test");
//minioService.RealTimeListen(bucketName, "d:/test");
services.AddStart(x =>
{
x.ProductFontSize = 90;

View File

@ -62,7 +62,6 @@
</ItemGroup>
<ItemGroup>
<Folder Include="Models\" />
<Folder Include="Assets\" />
</ItemGroup>

7
Models/SystemSetting.cs Normal file
View File

@ -0,0 +1,7 @@
namespace FileUploader.Models;
public class SystemSetting
{
public string SyncDir { get; set; }
public int TaskCount { get; set; }
}

View File

@ -22,7 +22,6 @@ namespace Hopetry.Services
public MinioService()
{
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("global.json", optional: false, reloadOnChange: true);
@ -33,12 +32,12 @@ namespace Hopetry.Services
.WithEndpoint(minioConfig["Endpoint"])
.WithCredentials(minioConfig["AccessKey"], minioConfig["SecretKey"]).Build();
_bucketName = minioConfig["BucketName"]!;
/*_minioClient = new MinioClient()
.WithEndpoint("123.132.248.154:9107")
.WithCredentials("oZNgo25pNXnKFV9oKGh4", "66GYn0x1XAEInSa9wdCutzvUWKfhH1EhqxPJ6a9u")
.Build();*/
EnsureBucketExistsAsync(_bucketName).Wait();
}
@ -53,13 +52,13 @@ namespace Hopetry.Services
});
// 使用 Channel 实现生产者-消费者模式
private static readonly Channel<(string ObjectName, string ETag)> SyncChannel =
/*private Channel<(string ObjectName, string ETag)> SyncChannel =
Channel.CreateBounded<(string, string)>(new BoundedChannelOptions(10000)
{
SingleWriter = false,
SingleReader = false,
FullMode = BoundedChannelFullMode.Wait
});
});*/
public async Task ListObject(string bucketName)
{
@ -99,6 +98,13 @@ namespace Hopetry.Services
/// <param name="maxParallel"></param>
public async Task MirrorAsync1(string bucket, string localDir, int maxParallel = 5)
{
Channel<(string ObjectName, string ETag)> SyncChannel = Channel.CreateBounded<(string, string)>(new BoundedChannelOptions(10000)
{
SingleWriter = false,
SingleReader = false,
FullMode = BoundedChannelFullMode.Wait
});
var count = 0;
var producerTasks = new List<Task>();
var listArgs = new ListObjectsArgs()

View File

@ -91,9 +91,9 @@
<StackPanel Margin="10,6">
<h:Row>
<StackPanel Orientation="Horizontal">
<TextBox h:Cattach.Title="下载目录:" Text="{Binding SyncDir, Mode=TwoWay}"
VerticalAlignment="Center" Width="250"
Grid.Column="0" />
<TextBox h:Cattach.Title="下载目录:" Text="{Binding SyncDir, Mode=TwoWay}"
VerticalAlignment="Center" Width="250"
Grid.Column="0" />
<Button h:Cattach.Icon="&#xeadb;"
VerticalAlignment="Center"
Command="{Binding OpenDirCommand}" Grid.Column="1" />
@ -101,7 +101,8 @@
</h:Row>
<h:Row>
<ComboBox Width="250" h:Cattach.Title="同时下载任务数" SelectedIndex="0">
<ComboBox Width="250" h:Cattach.Title="同时下载任务数"
SelectedValue="{Binding TaskCount, Mode=TwoWay}">
<system:String>1</system:String>
<system:String>2</system:String>
<system:String>3</system:String>
@ -109,6 +110,10 @@
<system:String>5</system:String>
</ComboBox>
</h:Row>
<h:Row>
<Button Margin="0 5 0 5" Content="立即同步一次" HorizontalAlignment="Left" Width="150"
Style="{DynamicResource {x:Static h:ButtonKeys.Accent}}" Command="{Binding SyncData}" />
</h:Row>
</StackPanel>
</GroupBox>
</h:ScrollIntoItems>

View File

@ -1,7 +1,10 @@
using System.Windows.Forms;
using System.IO;
using System.Windows.Input;
using HeBianGu.Base.WpfBase;
using HeBianGu.Service.Mvc;
using Hopetry.Services;
using Microsoft.WindowsAPICodePack.Dialogs;
using SystemSetting = FileUploader.Models.SystemSetting;
namespace HeBianGu.App.Disk.ViewModel.Sync;
@ -9,9 +12,13 @@ namespace HeBianGu.App.Disk.ViewModel.Sync;
public class SyncViewModel : MvcViewModelBase
{
public ICommand OpenDirCommand { get; set; }
private readonly ISerializerService _serializerService;
private readonly MinioService _minioService;
private readonly SystemSetting _setting = new SystemSetting();
protected override void Init()
{
//RaisePropertyChanged();
/*LinkActions.Add(new LinkAction() { Action = "Space", Controller = "Loyout", DisplayName = "会话", Logo = "\xe613" });
Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new Action(() =>
@ -20,15 +27,48 @@ public class SyncViewModel : MvcViewModelBase
}));*/
}
public SyncViewModel()
public SyncViewModel(ISerializerService serializerService, MinioService minioService)
{
_minioService = minioService;
_serializerService = serializerService;
if (File.Exists("./settings.xml"))
{
var setting = _serializerService.Load<SystemSetting>("./settings.xml");
_setting.TaskCount = setting.TaskCount;
_setting.SyncDir = setting.SyncDir;
SyncDir = setting.SyncDir;
_taskCount = setting.TaskCount;
// MessageBox.Show("abc");
}
OpenDirCommand = new RelayCommand(async () => await ButtonBase_OnClick());
SyncData = new RelayCommand(async () => await SyncDataQuck());
}
private async Task<object> SyncDataQuck()
{
return _minioService.MirrorAsync1(_minioService._bucketName, SyncDir, _taskCount);
}
protected override void Loaded(string args)
{
}
public int _taskCount = 3;
public int TaskCount
{
get => _taskCount;
set
{
_taskCount = value;
_setting.TaskCount = value;
_serializerService.Save("./settings.xml", _setting);
//_serializerService.Save("./settings.xml", this);
RaisePropertyChanged();
}
}
public string _syncDir;
public string SyncDir
@ -41,6 +81,8 @@ public class SyncViewModel : MvcViewModelBase
}
}
public RelayCommand SyncData { get; set; }
public class RelayCommand : ICommand
{
@ -77,6 +119,8 @@ public class SyncViewModel : MvcViewModelBase
var folderPath = dialog.FileName; // 获取选中的文件夹路径
//MessageBox.Show("folderPath " + folderPath);
SyncDir = folderPath;
_setting.SyncDir = folderPath;
_serializerService.Save("./settings.xml", _setting);
// 处理选中的文件夹路径
}
}