Merge branch 'dev' of http://123.132.248.154:10000/chenwei/FieldWorkClient into dev
commit
a3e87b770b
55
App.xaml.cs
55
App.xaml.cs
|
|
@ -11,6 +11,7 @@ using HeBianGu.Service.Mvp;
|
||||||
using HeBianGu.Systems.Identity;
|
using HeBianGu.Systems.Identity;
|
||||||
using HeBianGu.Systems.Setting;
|
using HeBianGu.Systems.Setting;
|
||||||
using Hopetry.Services;
|
using Hopetry.Services;
|
||||||
|
using SqlSugar;
|
||||||
using SystemSetting = FileUploader.Models.SystemSetting;
|
using SystemSetting = FileUploader.Models.SystemSetting;
|
||||||
|
|
||||||
namespace HeBianGu.App.Disk
|
namespace HeBianGu.App.Disk
|
||||||
|
|
@ -89,6 +90,7 @@ namespace HeBianGu.App.Disk
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
#region - WindowCaption -
|
#region - WindowCaption -
|
||||||
|
|
||||||
//以下各种功能按钮
|
//以下各种功能按钮
|
||||||
|
|
@ -118,15 +120,45 @@ namespace HeBianGu.App.Disk
|
||||||
//services.AddSingleton<IExplorerService, WindowExplorerServiceDemo>();
|
//services.AddSingleton<IExplorerService, WindowExplorerServiceDemo>();
|
||||||
|
|
||||||
|
|
||||||
var minioService = services.GetService<MinioService>();
|
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 bucketName = minioService._bucketName;
|
||||||
var xmlSerializerService = services.GetService<ISerializerService>();
|
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))
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(tempSetting.SyncDir);
|
||||||
|
}
|
||||||
|
xmlSerializerService.Save("./settings.xml", tempSetting);
|
||||||
|
}
|
||||||
|
|
||||||
var setting = xmlSerializerService.Load<SystemSetting>("./settings.xml");
|
var setting = xmlSerializerService.Load<SystemSetting>("./settings.xml");
|
||||||
if (!string.IsNullOrEmpty(setting.SyncDir))
|
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)
|
if (setting.TaskCount == 0)
|
||||||
{
|
{
|
||||||
setting.TaskCount = 3;
|
setting.TaskCount = 3;
|
||||||
|
|
@ -211,9 +243,26 @@ namespace HeBianGu.App.Disk
|
||||||
/*minioService.RealTimeListen(bucketName, setting.SyncDir,
|
/*minioService.RealTimeListen(bucketName, setting.SyncDir,
|
||||||
cancellationToken: cancelToken.Token);*/
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return selectDrive;
|
||||||
|
}
|
||||||
|
|
||||||
protected override void Configure(IApplicationBuilder app)
|
protected override void Configure(IApplicationBuilder app)
|
||||||
{
|
{
|
||||||
base.Configure(app);
|
base.Configure(app);
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,9 @@
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
<PackageReference Include="NLog" Version="5.4.0" />
|
<PackageReference Include="NLog" Version="5.4.0" />
|
||||||
<PackageReference Include="Polly" Version="8.5.2" />
|
<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="WindowsAPICodePack" Version="8.0.6" />
|
||||||
<PackageReference Include="WPF-UI" Version="4.0.2" />
|
<PackageReference Include="WPF-UI" Version="4.0.2" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,40 @@
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,58 @@
|
||||||
|
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,6 +23,7 @@ namespace HeBianGu.App.Disk
|
||||||
internal class LoyoutViewModel : MvcViewModelBase
|
internal class LoyoutViewModel : MvcViewModelBase
|
||||||
{
|
{
|
||||||
private string _path;
|
private string _path;
|
||||||
|
private readonly FileUploadService _uploadService;
|
||||||
/// <summary> 说明 </summary>
|
/// <summary> 说明 </summary>
|
||||||
public string Path
|
public string Path
|
||||||
{
|
{
|
||||||
|
|
@ -368,9 +369,9 @@ namespace HeBianGu.App.Disk
|
||||||
public LoyoutViewModel(SendViewModel sendViewModel)
|
public LoyoutViewModel(SendViewModel sendViewModel)
|
||||||
{
|
{
|
||||||
_sendViewModel = sendViewModel;
|
_sendViewModel = sendViewModel;
|
||||||
|
_uploadService = new FileUploadService();
|
||||||
UploadCommand = new AsyncRelayCommand(async () => await UploadFile());
|
UploadCommand = new AsyncRelayCommand(async () => await UploadFile());
|
||||||
UploadCommand1 = new AsyncRelayCommand(async () => await UploadFile1());
|
UploadCommand1 = new AsyncRelayCommand(async () => await UploadFile1());
|
||||||
|
|
||||||
// 初始化Timer
|
// 初始化Timer
|
||||||
_progressTimer = new System.Timers.Timer(1000);
|
_progressTimer = new System.Timers.Timer(1000);
|
||||||
_progressTimer.Elapsed += UpdateProgress;
|
_progressTimer.Elapsed += UpdateProgress;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue