Compare commits
No commits in common. "068494a6f97e6c6b3848529c367903680a0222b1" and "9c1bf77cefe5efe27af46bf84203cd73fb6db8bb" have entirely different histories.
068494a6f9
...
9c1bf77cef
189
App.xaml.cs
189
App.xaml.cs
|
|
@ -11,7 +11,6 @@ using HeBianGu.Service.Mvp;
|
|||
using HeBianGu.Systems.Identity;
|
||||
using HeBianGu.Systems.Setting;
|
||||
using Hopetry.Services;
|
||||
using SqlSugar;
|
||||
using SystemSetting = FileUploader.Models.SystemSetting;
|
||||
|
||||
namespace HeBianGu.App.Disk
|
||||
|
|
@ -90,7 +89,6 @@ namespace HeBianGu.App.Disk
|
|||
|
||||
#endregion
|
||||
|
||||
|
||||
#region - WindowCaption -
|
||||
|
||||
//以下各种功能按钮
|
||||
|
|
@ -120,147 +118,100 @@ namespace HeBianGu.App.Disk
|
|||
//services.AddSingleton<IExplorerService, WindowExplorerServiceDemo>();
|
||||
|
||||
|
||||
foreach (DriveInfo drive in DriveInfo.GetDrives())
|
||||
{
|
||||
if (drive.DriveType != DriveType.Fixed) continue; // 只获取固定硬盘
|
||||
|
||||
Console.WriteLine(
|
||||
// D:\ (Fixed) 软件 NTFS 329113399296
|
||||
$"{drive.Name} ({drive.DriveType}) {drive.VolumeLabel} {drive.DriveFormat} {drive.TotalSize} {drive.AvailableFreeSpace}");
|
||||
}
|
||||
|
||||
var minioService = services.GetService<MinioService>();
|
||||
|
||||
var bucketName = minioService._bucketName;
|
||||
var xmlSerializerService = services.GetService<ISerializerService>();
|
||||
if (!File.Exists("./settings.xml"))
|
||||
if (File.Exists("./settings.xml"))
|
||||
{
|
||||
var tempSetting = new SystemSetting();
|
||||
tempSetting.TaskCount = 3;
|
||||
tempSetting.SyncDir = Path.Combine(SelectDrive(),"HopetryBoxData");
|
||||
if (!Directory.Exists(tempSetting.SyncDir))
|
||||
var setting = xmlSerializerService.Load<SystemSetting>("./settings.xml");
|
||||
if (!string.IsNullOrEmpty(setting.SyncDir))
|
||||
{
|
||||
Directory.CreateDirectory(tempSetting.SyncDir);
|
||||
}
|
||||
xmlSerializerService.Save("./settings.xml", tempSetting);
|
||||
}
|
||||
|
||||
var setting = xmlSerializerService.Load<SystemSetting>("./settings.xml");
|
||||
if (string.IsNullOrEmpty(setting.SyncDir))
|
||||
{
|
||||
var selectDrive = SelectDrive();
|
||||
|
||||
setting.SyncDir = Path.Combine(selectDrive, "HopetryBoxData");
|
||||
if (!Directory.Exists(setting.SyncDir))
|
||||
{
|
||||
Directory.CreateDirectory(setting.SyncDir);
|
||||
}
|
||||
|
||||
// 保存配置
|
||||
xmlSerializerService.Save("./settings.xml", setting);
|
||||
}
|
||||
|
||||
if (setting.TaskCount == 0)
|
||||
{
|
||||
setting.TaskCount = 3;
|
||||
}
|
||||
|
||||
// 创建统一的取消令牌源
|
||||
var cancelToken = new CancellationTokenSource();
|
||||
var temp = SyncSetting.Instance;
|
||||
var notRun = true;
|
||||
// 注册设置变更监听
|
||||
temp.PropertyChanged += (s, e) =>
|
||||
{
|
||||
if (temp.IsOn && notRun)
|
||||
{
|
||||
// 异步启动服务
|
||||
Console.WriteLine("启动同步:");
|
||||
try
|
||||
if (setting.TaskCount == 0)
|
||||
{
|
||||
minioService.MirrorAsync(bucketName, setting.SyncDir, setting.TaskCount);
|
||||
minioService.RealTimeListen(bucketName, setting.SyncDir,
|
||||
cancellationToken: cancelToken.Token);
|
||||
notRun = false;
|
||||
setting.TaskCount = 3;
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
Console.WriteLine("同步监听已取消");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"同步失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
// 运行中 且 temp.IsOn 变成 false
|
||||
else if (!notRun && !temp.IsOn)
|
||||
{
|
||||
notRun = true;
|
||||
// 当设置关闭时取消所有任务
|
||||
cancelToken.Cancel(); // 取消任务
|
||||
cancelToken.Dispose();
|
||||
cancelToken = new CancellationTokenSource();
|
||||
}
|
||||
};
|
||||
/*var delayTimer = new DispatcherTimer();
|
||||
delayTimer.Interval = TimeSpan.FromSeconds(5);
|
||||
delayTimer.Tick += async (s, e) =>
|
||||
{
|
||||
delayTimer.Stop(); // 确保只执行一次
|
||||
// 异步操作不会阻塞UI
|
||||
await Current.Dispatcher.InvokeAsync(() =>
|
||||
{
|
||||
|
||||
// 创建统一的取消令牌源
|
||||
var cancelToken = new CancellationTokenSource();
|
||||
var temp = SyncSetting.Instance;
|
||||
var notRun = true;
|
||||
// 注册设置变更监听
|
||||
SyncSetting.Instance.PropertyChanged += (s1, e1) =>
|
||||
temp.PropertyChanged += (s, e) =>
|
||||
{
|
||||
if (SyncSetting.Instance.IsOn)
|
||||
if (temp.IsOn && notRun)
|
||||
{
|
||||
// 异步启动服务
|
||||
_ = StartSyncServicesAsync();
|
||||
Console.WriteLine("启动同步:");
|
||||
try
|
||||
{
|
||||
minioService.MirrorAsync(bucketName, setting.SyncDir, setting.TaskCount);
|
||||
minioService.RealTimeListen(bucketName, setting.SyncDir,
|
||||
cancellationToken: cancelToken.Token);
|
||||
notRun = false;
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
Console.WriteLine("同步监听已取消");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"同步失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
else
|
||||
// 运行中 且 temp.IsOn 变成 false
|
||||
else if (!notRun && !temp.IsOn)
|
||||
{
|
||||
notRun = true;
|
||||
// 当设置关闭时取消所有任务
|
||||
cancelToken.Cancel();
|
||||
cancelToken.Cancel(); // 取消任务
|
||||
cancelToken.Dispose();
|
||||
cancelToken = new CancellationTokenSource();
|
||||
}
|
||||
};
|
||||
});
|
||||
};
|
||||
/*var delayTimer = new DispatcherTimer();
|
||||
delayTimer.Interval = TimeSpan.FromSeconds(5);
|
||||
delayTimer.Tick += async (s, e) =>
|
||||
{
|
||||
delayTimer.Stop(); // 确保只执行一次
|
||||
// 异步操作不会阻塞UI
|
||||
await Current.Dispatcher.InvokeAsync(() =>
|
||||
{
|
||||
// 注册设置变更监听
|
||||
SyncSetting.Instance.PropertyChanged += (s1, e1) =>
|
||||
{
|
||||
if (SyncSetting.Instance.IsOn)
|
||||
{
|
||||
// 异步启动服务
|
||||
_ = StartSyncServicesAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
// 当设置关闭时取消所有任务
|
||||
cancelToken.Cancel();
|
||||
cancelToken.Dispose();
|
||||
cancelToken = new CancellationTokenSource();
|
||||
}
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
delayTimer.Start();*/
|
||||
delayTimer.Start();*/
|
||||
|
||||
|
||||
/*var syncSettingPath = SyncSetting.Instance.GetPath();
|
||||
var syncSetting = xmlSerializerService.Load<SyncSetting>(syncSettingPath);
|
||||
SyncSetting.Instance.IsOn = syncSetting.IsOn;
|
||||
if (syncSetting.IsOn)
|
||||
{
|
||||
// 是否启监听
|
||||
minioService.MirrorAsync1(bucketName, setting.SyncDir, setting.TaskCount);
|
||||
}*/
|
||||
/*var syncSettingPath = SyncSetting.Instance.GetPath();
|
||||
var syncSetting = xmlSerializerService.Load<SyncSetting>(syncSettingPath);
|
||||
SyncSetting.Instance.IsOn = syncSetting.IsOn;
|
||||
if (syncSetting.IsOn)
|
||||
{
|
||||
// 是否启监听
|
||||
minioService.MirrorAsync1(bucketName, setting.SyncDir, setting.TaskCount);
|
||||
}*/
|
||||
|
||||
/*minioService.RealTimeListen(bucketName, setting.SyncDir,
|
||||
cancellationToken: cancelToken.Token);*/
|
||||
}
|
||||
|
||||
private static string SelectDrive()
|
||||
{
|
||||
var maxFreeSpace = 0L;
|
||||
var selectDrive = "";
|
||||
// 如果同步目录为空,则选择一个本地空闲空间比较大的分区
|
||||
foreach (DriveInfo drive in DriveInfo.GetDrives())
|
||||
{
|
||||
if (drive.DriveType != DriveType.Fixed) continue; // 只获取固定硬盘
|
||||
|
||||
if (drive.AvailableFreeSpace > maxFreeSpace)
|
||||
{
|
||||
maxFreeSpace = drive.AvailableFreeSpace;
|
||||
selectDrive = drive.Name;
|
||||
/*minioService.RealTimeListen(bucketName, setting.SyncDir,
|
||||
cancellationToken: cancelToken.Token);*/
|
||||
}
|
||||
}
|
||||
|
||||
return selectDrive;
|
||||
}
|
||||
|
||||
protected override void Configure(IApplicationBuilder app)
|
||||
|
|
|
|||
|
|
@ -57,9 +57,6 @@
|
|||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="NLog" Version="5.4.0" />
|
||||
<PackageReference Include="Polly" Version="8.5.2" />
|
||||
<PackageReference Include="SqlSugar" Version="5.1.4.187" />
|
||||
<PackageReference Include="SqlSugarCore" Version="5.1.4.187" />
|
||||
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.119" />
|
||||
<PackageReference Include="WindowsAPICodePack" Version="8.0.6" />
|
||||
<PackageReference Include="WPF-UI" Version="4.0.2" />
|
||||
</ItemGroup>
|
||||
|
|
|
|||
|
|
@ -1,28 +0,0 @@
|
|||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Hopetry.Models
|
||||
{
|
||||
[SugarTable("f_upload")]
|
||||
public class FUpload
|
||||
{
|
||||
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
|
||||
public int Id { get; set; }
|
||||
|
||||
public string FilePath { get; set; }
|
||||
|
||||
public string FileName { get; set; }
|
||||
|
||||
public long FileSize { get; set; }
|
||||
|
||||
public string FileType { get; set; }
|
||||
|
||||
public DateTime CreateTime { get; set; }
|
||||
public DateTime CompleteTime { get; set; }
|
||||
public bool IsComplete { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Hopetry.Provider
|
||||
{
|
||||
public class SqlSugarConfig
|
||||
{
|
||||
public static SqlSugarScope GetSqlSugarScope()
|
||||
{
|
||||
return new SqlSugarScope(new ConnectionConfig()
|
||||
{
|
||||
ConnectionString = $"Data Source={GetDbPath()};Version=3;", // 数据库路径
|
||||
DbType = DbType.Sqlite, // 数据库类型
|
||||
IsAutoCloseConnection = true, // 自动释放
|
||||
InitKeyType = InitKeyType.Attribute // 从实体特性中读取主键信息
|
||||
},
|
||||
db =>
|
||||
{
|
||||
// 配置AOP
|
||||
db.Aop.OnLogExecuting = (sql, pars) =>
|
||||
{
|
||||
Console.WriteLine(sql); // 输出SQL
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
private static string GetDbPath()
|
||||
{
|
||||
// 这里假设数据库放在应用程序根目录下
|
||||
// 对于WPF项目,可以使用AppDomain.CurrentDomain.BaseDirectory获取基目录
|
||||
var basePath = AppDomain.CurrentDomain.BaseDirectory;
|
||||
return Path.Combine(basePath, "minio.db");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,58 +0,0 @@
|
|||
using Hopetry.Models;
|
||||
using Hopetry.Provider;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Hopetry.Services
|
||||
{
|
||||
public class FileUploadService
|
||||
{
|
||||
private readonly SqlSugarScope _db;
|
||||
|
||||
public FileUploadService()
|
||||
{
|
||||
_db = SqlSugarConfig.GetSqlSugarScope();
|
||||
}
|
||||
|
||||
// 示例:查询所有文件信息
|
||||
public List<FUpload> GetAllFiles()
|
||||
{
|
||||
return _db.Queryable<FUpload>().ToList();
|
||||
}
|
||||
|
||||
// 示例:添加文件信息
|
||||
public bool AddFile(FUpload file)
|
||||
{
|
||||
return _db.Insertable(file).ExecuteCommand() > 0;
|
||||
}
|
||||
|
||||
// 示例:更新文件信息
|
||||
public bool UpdateFile(FUpload file)
|
||||
{
|
||||
return _db.Updateable(file).ExecuteCommand() > 0;
|
||||
}
|
||||
|
||||
// 示例:删除文件信息
|
||||
public bool DeleteFile(int id)
|
||||
{
|
||||
return _db.Deleteable<FUpload>().Where(f => f.Id == id).ExecuteCommand() > 0;
|
||||
}
|
||||
|
||||
// 检查数据库是否存在,不存在则创建
|
||||
public void InitDatabase()
|
||||
{
|
||||
_db.DbMaintenance.CreateDatabase(); // SQLite不需要创建数据库,但可以用于检查
|
||||
|
||||
// 如果表不存在则创建
|
||||
if (!_db.DbMaintenance.IsAnyTable("f_upload", false))
|
||||
{
|
||||
_db.CodeFirst.InitTables(typeof(FUpload));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -23,7 +23,6 @@ namespace HeBianGu.App.Disk
|
|||
internal class LoyoutViewModel : MvcViewModelBase
|
||||
{
|
||||
private string _path;
|
||||
private readonly FileUploadService _uploadService;
|
||||
/// <summary> 说明 </summary>
|
||||
public string Path
|
||||
{
|
||||
|
|
@ -369,9 +368,9 @@ namespace HeBianGu.App.Disk
|
|||
public LoyoutViewModel(SendViewModel sendViewModel)
|
||||
{
|
||||
_sendViewModel = sendViewModel;
|
||||
_uploadService = new FileUploadService();
|
||||
UploadCommand = new AsyncRelayCommand(async () => await UploadFile());
|
||||
UploadCommand1 = new AsyncRelayCommand(async () => await UploadFile1());
|
||||
|
||||
// 初始化Timer
|
||||
_progressTimer = new System.Timers.Timer(1000);
|
||||
_progressTimer.Elapsed += UpdateProgress;
|
||||
|
|
|
|||
Loading…
Reference in New Issue