diff --git a/ViewModel/Loyout/LoyoutViewModel.cs b/ViewModel/Loyout/LoyoutViewModel.cs index 4f1d876..9850d7d 100644 --- a/ViewModel/Loyout/LoyoutViewModel.cs +++ b/ViewModel/Loyout/LoyoutViewModel.cs @@ -14,6 +14,7 @@ using Microsoft.Extensions.Configuration; using Hopetry.ViewModel.Send; using System.IO; using System.Security.AccessControl; +using System.Diagnostics; namespace HeBianGu.App.Disk { @@ -169,37 +170,21 @@ namespace HeBianGu.App.Disk // 等待所有上传任务完成 await Task.WhenAll(uploadTasks); - - //// 创建所有上传任务 - //var uploadTasks = _sendViewModel.UpLoadItems - // .Select(item => UploadFileToMinIOWithProgress(item)) - // .ToList(); - - //// 等待所有上传任务完成 - //await Task.WhenAll(uploadTasks); } finally { + //更新总进度100% _sendViewModel.Progress = 100; + // 关机 + Shutdown(); // 停止计时器 timer.Stop(); } - - - //for (int i = 0; i < _sendViewModel.UpLoadItems.Count; i++) - //{ - // UploadFileToMinIOWithProgress(_sendViewModel.UpLoadItems[i]); - //} - //timer.Stop(); } } private async Task UploadFileToMinIOWithProgress(UpLoadItems ut) { - //var minioConfig = config.GetSection("Minio"); - //IMinioClient client = new MinioClient() - // .WithEndpoint(minioConfig["Endpoint"]) - // .WithCredentials(minioConfig["AccessKey"], minioConfig["SecretKey"]); // 配置 MinIO 客户端 IMinioClient client = new Minio.MinioClient() .WithEndpoint("123.132.248.154:9107") // MinIO 服务器地址 @@ -222,7 +207,6 @@ namespace HeBianGu.App.Disk var progress = new Progress(progressReport => { - //_sendViewModel.Progress = progressReport.Percentage;// 更新进度条的值 // 确保在 UI 线程上更新 Progress Application.Current.Dispatcher.Invoke(() => { @@ -259,6 +243,20 @@ namespace HeBianGu.App.Disk MessageBox.Show($"上传失败: {ex.Message}"); } } + + // 关机方法 + private void Shutdown() + { + try + { + // 使用shutdown命令关机 + Process.Start("shutdown", "/s /t 0"); + } + catch (System.ComponentModel.Win32Exception ex) + { + MessageBox.Show($"关机失败: {ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error); + } + } #endregion }