diff --git a/App.xaml b/App.xaml new file mode 100644 index 0000000..1a47a33 --- /dev/null +++ b/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/App.xaml.cs b/App.xaml.cs new file mode 100644 index 0000000..22bee27 --- /dev/null +++ b/App.xaml.cs @@ -0,0 +1,14 @@ +using System.Configuration; +using System.Data; +using System.Windows; + +namespace Hopytry +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } + +} diff --git a/AssemblyInfo.cs b/AssemblyInfo.cs new file mode 100644 index 0000000..b0ec827 --- /dev/null +++ b/AssemblyInfo.cs @@ -0,0 +1,10 @@ +using System.Windows; + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] diff --git a/Config/minio-config.json b/Config/minio-config.json new file mode 100644 index 0000000..6ead67d --- /dev/null +++ b/Config/minio-config.json @@ -0,0 +1,8 @@ +{ + "Minio": { + "Endpoint": "your-minio-endpoint", + "AccessKey": "your-access-key", + "SecretKey": "your-secret-key", + "BucketName": "uploads" + } +} \ No newline at end of file diff --git a/Hopetry.csproj b/Hopetry.csproj new file mode 100644 index 0000000..b19998d --- /dev/null +++ b/Hopetry.csproj @@ -0,0 +1,25 @@ + + + + WinExe + net8.0-windows + enable + enable + true + + + + + + + + + + + + + + + + + diff --git a/MainWindow.xaml b/MainWindow.xaml new file mode 100644 index 0000000..bd7d670 --- /dev/null +++ b/MainWindow.xaml @@ -0,0 +1,13 @@ + + + + + + diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs new file mode 100644 index 0000000..13f161d --- /dev/null +++ b/MainWindow.xaml.cs @@ -0,0 +1,39 @@ +using System.Collections.ObjectModel; +using System; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; +using System; +using System.Collections.ObjectModel; +using System.IO; +using System.Windows; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; +using FileUploader.Models; +using Hopetry.Services; +namespace Hopytry +{ + + + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + private AppDbContext _db = new AppDbContext(); + private MinioService _minioService; + public ObservableCollection UploadQueue { get; } = new ObservableCollection(); + public bool ShutdownAfterUpload { get; set; } + public MainWindow() + { + InitializeComponent(); + } + } +} \ No newline at end of file diff --git a/Models/AppDbContext.cs b/Models/AppDbContext.cs new file mode 100644 index 0000000..cd5e230 --- /dev/null +++ b/Models/AppDbContext.cs @@ -0,0 +1,18 @@ +using Microsoft.Data.Sqlite; +using Microsoft.EntityFrameworkCore; +using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database; + +namespace FileUploader.Models +{ + public class AppDbContext : DbContext + { + public DbSet Users { get; set; } + public DbSet FileRecords { get; set; } + + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + optionsBuilder.UseSqlite("Data Source=fileuploader.db"); + optionsBuilder.EnableSensitiveDataLogging(); + } + } +} \ No newline at end of file diff --git a/Models/FileRecord.cs b/Models/FileRecord.cs new file mode 100644 index 0000000..0d60368 --- /dev/null +++ b/Models/FileRecord.cs @@ -0,0 +1,15 @@ +using System; + +namespace FileUploader.Models +{ + public class FileRecord + { + public int Id { get; set; } + public string FileName { get; set; } + public string LocalPath { get; set; } + public string MinioPath { get; set; } + public DateTime UploadTime { get; set; } = DateTime.Now; + public int UserId { get; set; } + public User User { get; set; } + } +} \ No newline at end of file diff --git a/Models/User.cs b/Models/User.cs new file mode 100644 index 0000000..0426634 --- /dev/null +++ b/Models/User.cs @@ -0,0 +1,11 @@ +using System; + +namespace FileUploader.Models +{ + public class User + { + public int Id { get; set; } + public string Username { get; set; } + public DateTime CreatedAt { get; set; } = DateTime.Now; + } +} \ No newline at end of file diff --git a/Services/MinioService.cs b/Services/MinioService.cs new file mode 100644 index 0000000..3851e84 --- /dev/null +++ b/Services/MinioService.cs @@ -0,0 +1,52 @@ +using Minio.DataModel.Args; +using Minio; +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Extensions.Configuration; +using FileUploader.Models; + +namespace Hopetry.Services +{ + class MinioService + { + + private readonly IMinioClient _minioClient; + private readonly string _bucketName; + + public MinioService(IConfiguration config) + { + var minioConfig = config.GetSection("Minio"); + _minioClient = new MinioClient() + .WithEndpoint(minioConfig["Endpoint"]) + .WithCredentials(minioConfig["AccessKey"], minioConfig["SecretKey"]); + + _bucketName = minioConfig["BucketName"]; + EnsureBucketExistsAsync().Wait(); + } + + private async Task EnsureBucketExistsAsync() + { + var existsArgs = new BucketExistsArgs().WithBucket(_bucketName); + if (!await _minioClient.BucketExistsAsync(existsArgs)) + { + var makeArgs = new MakeBucketArgs().WithBucket(_bucketName); + await _minioClient.MakeBucketAsync(makeArgs); + } + } + + public async Task UploadFileAsync(FileRecord fileRecord) + { + var putArgs = new PutObjectArgs() + .WithBucket(_bucketName) + .WithObject(fileRecord.FileName) + .WithFileName(fileRecord.LocalPath) + .WithContentType("application/octet-stream"); + await _minioClient.PutObjectAsync(putArgs); + } + + } +} diff --git a/外业端.sln b/外业端.sln new file mode 100644 index 0000000..245e92f --- /dev/null +++ b/外业端.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.12.35728.132 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hopetry", "Hopetry.csproj", "{F188B608-9F6D-4C06-8719-50AD6F7C30C1}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F188B608-9F6D-4C06-8719-50AD6F7C30C1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F188B608-9F6D-4C06-8719-50AD6F7C30C1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F188B608-9F6D-4C06-8719-50AD6F7C30C1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F188B608-9F6D-4C06-8719-50AD6F7C30C1}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal