添加项目文件。
parent
dffc03a785
commit
74fa884eda
|
|
@ -0,0 +1,9 @@
|
||||||
|
<Application x:Class="Hopytry.App"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:local="clr-namespace:Hopytry"
|
||||||
|
StartupUri="MainWindow.xaml">
|
||||||
|
<Application.Resources>
|
||||||
|
|
||||||
|
</Application.Resources>
|
||||||
|
</Application>
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
using System.Configuration;
|
||||||
|
using System.Data;
|
||||||
|
using System.Windows;
|
||||||
|
|
||||||
|
namespace Hopytry
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Interaction logic for App.xaml
|
||||||
|
/// </summary>
|
||||||
|
public partial class App : Application
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -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)
|
||||||
|
)]
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
{
|
||||||
|
"Minio": {
|
||||||
|
"Endpoint": "your-minio-endpoint",
|
||||||
|
"AccessKey": "your-access-key",
|
||||||
|
"SecretKey": "your-secret-key",
|
||||||
|
"BucketName": "uploads"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>WinExe</OutputType>
|
||||||
|
<TargetFramework>net8.0-windows</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<UseWPF>true</UseWPF>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Data.Sqlite" Version="9.0.3" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.3" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.3" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="9.0.3" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.3" />
|
||||||
|
<PackageReference Include="Minio" Version="6.0.4" />
|
||||||
|
<PackageReference Include="WPF-UI" Version="4.0.2" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Models\" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
<Window x:Class="Hopytry.MainWindow"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:local="clr-namespace:Hopytry"
|
||||||
|
mc:Ignorable="d"
|
||||||
|
Title="MainWindow" Height="450" Width="800">
|
||||||
|
|
||||||
|
<Grid>
|
||||||
|
|
||||||
|
</Grid>
|
||||||
|
</Window>
|
||||||
|
|
@ -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
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Interaction logic for MainWindow.xaml
|
||||||
|
/// </summary>
|
||||||
|
public partial class MainWindow : Window
|
||||||
|
{
|
||||||
|
private AppDbContext _db = new AppDbContext();
|
||||||
|
private MinioService _minioService;
|
||||||
|
public ObservableCollection<FileRecord> UploadQueue { get; } = new ObservableCollection<FileRecord>();
|
||||||
|
public bool ShutdownAfterUpload { get; set; }
|
||||||
|
public MainWindow()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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<User> Users { get; set; }
|
||||||
|
public DbSet<FileRecord> FileRecords { get; set; }
|
||||||
|
|
||||||
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||||
|
{
|
||||||
|
optionsBuilder.UseSqlite("Data Source=fileuploader.db");
|
||||||
|
optionsBuilder.EnableSensitiveDataLogging();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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
|
||||||
Loading…
Reference in New Issue