parent
c42497d68b
commit
e86bc4bec8
10
App.xaml.cs
10
App.xaml.cs
|
|
@ -45,12 +45,13 @@ namespace HeBianGu.App.Disk
|
||||||
{
|
{
|
||||||
setting.TaskCount = 3;
|
setting.TaskCount = 3;
|
||||||
}
|
}
|
||||||
|
// 是否启监听
|
||||||
//minioService.MirrorAsync1(bucketName, setting.SyncDir, setting.TaskCount);
|
|
||||||
if (SyncSetting.Instance.IsOn)
|
if (SyncSetting.Instance.IsOn)
|
||||||
{
|
{
|
||||||
|
minioService.MirrorAsync1(bucketName, setting.SyncDir, setting.TaskCount);
|
||||||
minioService.RealTimeListen(bucketName, setting.SyncDir);
|
minioService.RealTimeListen(bucketName, setting.SyncDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -139,6 +140,7 @@ namespace HeBianGu.App.Disk
|
||||||
base.Configure(app);
|
base.Configure(app);
|
||||||
app.UseSetting(x =>
|
app.UseSetting(x =>
|
||||||
{
|
{
|
||||||
|
x.Settings.Clear();
|
||||||
x.Settings.Add(MySetting.Instance);
|
x.Settings.Add(MySetting.Instance);
|
||||||
x.Settings.Add(SyncSetting.Instance);
|
x.Settings.Add(SyncSetting.Instance);
|
||||||
});
|
});
|
||||||
|
|
@ -165,7 +167,7 @@ namespace HeBianGu.App.Disk
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[Displayer(Name = "同步设置", GroupName = "通用设置")]
|
[Displayer(Name = "同步设置", GroupName = "通用设置")]
|
||||||
public class SyncSetting : LazySettingInstance<SyncSetting>
|
public class SyncSetting : LazySettingInstance<SyncSetting>
|
||||||
{
|
{
|
||||||
|
|
@ -183,7 +185,7 @@ namespace HeBianGu.App.Disk
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Displayer(Name = "关机设置", GroupName = "通用设置")]
|
[Displayer(Name = "关机设置", GroupName = "通用设置")]
|
||||||
public class MySetting : LazySettingInstance<MySetting>
|
public class MySetting : LazySettingInstance<MySetting>
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using System.Threading.Channels;
|
using System.Threading.Channels;
|
||||||
|
using HeBianGu.App.Disk;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Minio;
|
using Minio;
|
||||||
using Minio.DataModel.Args;
|
using Minio.DataModel.Args;
|
||||||
|
|
@ -329,15 +330,19 @@ namespace Hopetry.Services
|
||||||
await DownLoadObject(item.bucketName, item.objectKey, item.localDir, item.objectETag);
|
await DownLoadObject(item.bucketName, item.objectKey, item.localDir, item.objectETag);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
#region 监听事件
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var events = new List<EventType> { EventType.ObjectCreatedAll };
|
var events = new List<EventType> { EventType.ObjectCreatedAll };
|
||||||
ListenBucketNotificationsArgs args = new ListenBucketNotificationsArgs()
|
var args = new ListenBucketNotificationsArgs()
|
||||||
.WithBucket(bucketName)
|
.WithBucket(bucketName)
|
||||||
.WithEvents(events);
|
.WithEvents(events);
|
||||||
|
|
||||||
IObservable<MinioNotificationRaw> observable = _minioClient.ListenBucketNotificationsAsync(args);
|
IObservable<MinioNotificationRaw> observable = _minioClient.ListenBucketNotificationsAsync(args);
|
||||||
IDisposable subscription = observable.Subscribe(
|
var subscription = observable.Subscribe(
|
||||||
async notification =>
|
async notification =>
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Received notification: {notification.Json}");
|
Console.WriteLine($"Received notification: {notification.Json}");
|
||||||
|
|
@ -348,6 +353,7 @@ namespace Hopetry.Services
|
||||||
var objectKey = obj["Records"]?[0]?["s3"]?["object"]?["key"]?.Value<string>();
|
var objectKey = obj["Records"]?[0]?["s3"]?["object"]?["key"]?.Value<string>();
|
||||||
var objectETag = obj["Records"]?[0]?["s3"]?["object"]?["eTag"]?.Value<string>();
|
var objectETag = obj["Records"]?[0]?["s3"]?["object"]?["eTag"]?.Value<string>();
|
||||||
Console.WriteLine("将要下载的Key:" + objectKey);
|
Console.WriteLine("将要下载的Key:" + objectKey);
|
||||||
|
// 字段值不会为空
|
||||||
downloadQueue.Writer.TryWrite((bucketName, objectKey, localDir, objectETag));
|
downloadQueue.Writer.TryWrite((bucketName, objectKey, localDir, objectETag));
|
||||||
//await DownLoadObject(bucketName, objectKey, localDir, objectETag);
|
//await DownLoadObject(bucketName, objectKey, localDir, objectETag);
|
||||||
},
|
},
|
||||||
|
|
@ -358,6 +364,8 @@ namespace Hopetry.Services
|
||||||
{
|
{
|
||||||
Console.WriteLine("Error occurred: " + e);
|
Console.WriteLine("Error occurred: " + e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,16 +1,6 @@
|
||||||
using System.Collections.Concurrent;
|
using System.IO;
|
||||||
using System.IO;
|
|
||||||
using System.Security.Cryptography;
|
|
||||||
using System.Threading.Channels;
|
|
||||||
using System.Windows.Threading;
|
|
||||||
using FileUploader.Models;
|
|
||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
using Minio;
|
|
||||||
using Minio.ApiEndpoints;
|
|
||||||
using Minio.DataModel;
|
using Minio.DataModel;
|
||||||
using Minio.DataModel.Args;
|
using Minio.DataModel.Args;
|
||||||
using Minio.DataModel.Notification;
|
|
||||||
using Minio.Exceptions;
|
|
||||||
|
|
||||||
namespace Hopetry.Services
|
namespace Hopetry.Services
|
||||||
{
|
{
|
||||||
|
|
@ -22,7 +12,7 @@ namespace Hopetry.Services
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string bucketName = "test";
|
string bucketName = "test";
|
||||||
string objectName = System.IO.Path.GetFileName(filePath);
|
string objectName = Path.GetFileName(filePath);
|
||||||
|
|
||||||
//判断桶是否存在
|
//判断桶是否存在
|
||||||
var beArgs = new BucketExistsArgs().WithBucket(bucketName);
|
var beArgs = new BucketExistsArgs().WithBucket(bucketName);
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
{
|
{
|
||||||
"Minio": {
|
"Minio": {
|
||||||
"Endpoint": "123.132.248.154:9107",
|
"Endpoint": "192.168.20.239:9000",
|
||||||
"AccessKey": "oZNgo25pNXnKFV9oKGh4",
|
"AccessKey": "cqlatqb0dgqdBRar7KVF",
|
||||||
"SecretKey": "66GYn0x1XAEInSa9wdCutzvUWKfhH1EhqxPJ6a9u",
|
"SecretKey": "FUFzd5VeoBeWhrpql6MBON5tQxNzcIgaK7vkvofX",
|
||||||
"BucketName": "demo"
|
"BucketName": "drone"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*{
|
/*{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue