2025-03-24 14:15:16 +08:00
|
|
|
|
using System.IO;
|
2025-03-24 10:24:36 +08:00
|
|
|
|
using System.Windows.Input;
|
2025-03-24 14:15:16 +08:00
|
|
|
|
using HeBianGu.Base.WpfBase;
|
2025-03-22 15:29:32 +08:00
|
|
|
|
using HeBianGu.Service.Mvc;
|
2025-03-24 14:15:16 +08:00
|
|
|
|
using Hopetry.Services;
|
2025-03-24 10:24:36 +08:00
|
|
|
|
using Microsoft.WindowsAPICodePack.Dialogs;
|
2025-03-24 14:15:16 +08:00
|
|
|
|
using SystemSetting = FileUploader.Models.SystemSetting;
|
2025-03-22 15:29:32 +08:00
|
|
|
|
|
|
|
|
|
|
namespace HeBianGu.App.Disk.ViewModel.Sync;
|
|
|
|
|
|
|
|
|
|
|
|
[ViewModel("Sync")]
|
|
|
|
|
|
public class SyncViewModel : MvcViewModelBase
|
|
|
|
|
|
{
|
2025-03-24 10:24:36 +08:00
|
|
|
|
public ICommand OpenDirCommand { get; set; }
|
2025-03-24 14:15:16 +08:00
|
|
|
|
private readonly ISerializerService _serializerService;
|
|
|
|
|
|
private readonly MinioService _minioService;
|
2025-03-24 16:08:57 +08:00
|
|
|
|
private readonly SystemSetting _setting;
|
2025-03-24 10:24:36 +08:00
|
|
|
|
|
2025-03-22 15:29:32 +08:00
|
|
|
|
protected override void Init()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-24 14:15:16 +08:00
|
|
|
|
public SyncViewModel(ISerializerService serializerService, MinioService minioService)
|
2025-03-24 10:24:36 +08:00
|
|
|
|
{
|
2025-03-24 16:08:57 +08:00
|
|
|
|
Console.WriteLine("SyncViewModel");
|
2025-03-24 14:15:16 +08:00
|
|
|
|
_minioService = minioService;
|
|
|
|
|
|
_serializerService = serializerService;
|
|
|
|
|
|
if (File.Exists("./settings.xml"))
|
|
|
|
|
|
{
|
2025-03-25 11:25:32 +08:00
|
|
|
|
_setting = _serializerService.Load<SystemSetting>("./settings.xml");
|
|
|
|
|
|
// 同步字段
|
2025-03-24 14:44:54 +08:00
|
|
|
|
TaskCount = _setting.TaskCount;
|
2025-03-25 11:25:32 +08:00
|
|
|
|
SyncDir = _setting.SyncDir;
|
2025-03-24 14:44:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
_setting = new SystemSetting();
|
2025-03-24 14:15:16 +08:00
|
|
|
|
}
|
2025-03-25 11:25:32 +08:00
|
|
|
|
ComboBox_SelectionChanged = new RelayCommand( async()=> await ComboBox_SelectionUpdate());
|
2025-03-24 10:24:36 +08:00
|
|
|
|
OpenDirCommand = new RelayCommand(async () => await ButtonBase_OnClick());
|
2025-03-25 11:25:32 +08:00
|
|
|
|
SyncData = new RelayCommand(async () => await SyncDataQuick());
|
|
|
|
|
|
|
2025-03-24 14:15:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-25 11:25:32 +08:00
|
|
|
|
private async Task ComboBox_SelectionUpdate()
|
|
|
|
|
|
{
|
|
|
|
|
|
_setting.TaskCount = TaskCount;
|
|
|
|
|
|
_serializerService.Save("./settings.xml", _setting);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async Task<object> SyncDataQuick()
|
2025-03-24 14:15:16 +08:00
|
|
|
|
{
|
|
|
|
|
|
return _minioService.MirrorAsync1(_minioService._bucketName, SyncDir, _taskCount);
|
2025-03-24 10:24:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-22 15:29:32 +08:00
|
|
|
|
protected override void Loaded(string args)
|
|
|
|
|
|
{
|
2025-03-24 16:08:57 +08:00
|
|
|
|
Console.WriteLine("Loaded");
|
2025-03-22 15:29:32 +08:00
|
|
|
|
}
|
2025-03-24 10:24:36 +08:00
|
|
|
|
|
2025-03-25 11:25:32 +08:00
|
|
|
|
private int _taskCount = 3;
|
2025-03-24 14:15:16 +08:00
|
|
|
|
|
|
|
|
|
|
public int TaskCount
|
|
|
|
|
|
{
|
|
|
|
|
|
get => _taskCount;
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
_taskCount = value;
|
|
|
|
|
|
RaisePropertyChanged();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-22 15:29:32 +08:00
|
|
|
|
public string _syncDir;
|
|
|
|
|
|
|
|
|
|
|
|
public string SyncDir
|
|
|
|
|
|
{
|
|
|
|
|
|
get => _syncDir;
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
_syncDir = value;
|
|
|
|
|
|
RaisePropertyChanged();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-03-25 11:25:32 +08:00
|
|
|
|
|
2025-03-24 14:15:16 +08:00
|
|
|
|
public RelayCommand SyncData { get; set; }
|
2025-03-25 11:25:32 +08:00
|
|
|
|
public RelayCommand ComboBox_SelectionChanged { get; set; }
|
2025-03-24 14:15:16 +08:00
|
|
|
|
|
2025-03-24 10:24:36 +08:00
|
|
|
|
|
|
|
|
|
|
public class RelayCommand : ICommand
|
|
|
|
|
|
{
|
|
|
|
|
|
private readonly Action _execute;
|
|
|
|
|
|
|
|
|
|
|
|
public RelayCommand(Action execute)
|
|
|
|
|
|
{
|
|
|
|
|
|
_execute = execute;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool CanExecute(object parameter)
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public event EventHandler CanExecuteChanged;
|
|
|
|
|
|
|
|
|
|
|
|
public void Execute(object parameter)
|
|
|
|
|
|
{
|
|
|
|
|
|
_execute();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private async Task ButtonBase_OnClick()
|
|
|
|
|
|
{
|
|
|
|
|
|
CommonOpenFileDialog dialog = new CommonOpenFileDialog
|
|
|
|
|
|
{
|
|
|
|
|
|
IsFolderPicker = true
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
if (dialog.ShowDialog() == CommonFileDialogResult.Ok)
|
|
|
|
|
|
{
|
|
|
|
|
|
var folderPath = dialog.FileName; // 获取选中的文件夹路径
|
|
|
|
|
|
//MessageBox.Show("folderPath " + folderPath);
|
|
|
|
|
|
SyncDir = folderPath;
|
2025-03-24 14:15:16 +08:00
|
|
|
|
_setting.SyncDir = folderPath;
|
|
|
|
|
|
_serializerService.Save("./settings.xml", _setting);
|
2025-03-24 10:24:36 +08:00
|
|
|
|
// 处理选中的文件夹路径
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-03-22 15:29:32 +08:00
|
|
|
|
}
|