|
|
|
@ -5,6 +5,7 @@ using Amazon;
|
|
|
|
|
using Amazon.Runtime;
|
|
|
|
|
using Amazon.S3;
|
|
|
|
|
using S3Demo.Model;
|
|
|
|
|
using S3Demo.Model.Uploader;
|
|
|
|
|
using Ksat.Supplyment.Library.Model;
|
|
|
|
|
using Ksat.Supplyment.Library.Uploader;
|
|
|
|
|
using Ksat.Supplyment.Library.Model.Uploader;
|
|
|
|
@ -19,7 +20,7 @@ namespace S3Demo
|
|
|
|
|
private static BasicAWSCredentials credentials = new BasicAWSCredentials("admin", "admin123.");
|
|
|
|
|
//private static BasicAWSCredentials credentials = new BasicAWSCredentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
|
|
|
|
|
private static string bucketName = "minio/test";
|
|
|
|
|
// 受监控的目录,完整目录如:"D:\ClientDir\line01\AOI\20211129\133055851SN001OK.png"
|
|
|
|
|
// 受监控的目录,完整目录如:"D:\ClientDir\line01\AOI\20211129\133055851SN001.png"
|
|
|
|
|
private static string[] paths = { @"D:\ClientDir" };
|
|
|
|
|
private static string suffix = "*.png";
|
|
|
|
|
|
|
|
|
@ -222,38 +223,21 @@ namespace S3Demo
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 创建文件事件
|
|
|
|
|
/// 创建文件
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// 主要逻辑
|
|
|
|
|
/// </remarks>
|
|
|
|
|
private static async void OnCreated(object sender, FileSystemEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
string path = e.FullPath;
|
|
|
|
|
Waiting(path);//等待文件创建完成
|
|
|
|
|
await DisposeFile(path);//处理文件
|
|
|
|
|
Waiting(e.FullPath);
|
|
|
|
|
await DisposeFile(e.FullPath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static async Task DisposeFile(string path)
|
|
|
|
|
{
|
|
|
|
|
// D:\ClientDir\line01\AOI\20211129\085023891P107CN14T00001.png
|
|
|
|
|
string lineName = Path.GetDirectoryName(path).Split('\\')[2];
|
|
|
|
|
string equipmentName = Path.GetDirectoryName(path).Split('\\')[3];
|
|
|
|
|
string date = Path.GetDirectoryName(path).Split('\\')[4];
|
|
|
|
|
string fileName = Path.GetFileName(path);
|
|
|
|
|
string datetime = date + fileName.Substring(0, 9);
|
|
|
|
|
string dt_fomat = DateTime.ParseExact(datetime, "yyyyMMddHHmmssfff", System.Globalization.CultureInfo.CurrentCulture).ToString("yyyy-MM-dd HH:mm:ss:fff");
|
|
|
|
|
string sn = fileName.Substring(9, 14);
|
|
|
|
|
string now = DateTime.Now.ToString("yyyyMMddHHmmssfff");
|
|
|
|
|
String[] tags = new String[] { sn, dt_fomat };
|
|
|
|
|
string S3Path = lineName + "/" + equipmentName + "/" + date + "/" + fileName;
|
|
|
|
|
string recv = await ObjectModel.PutObjectsWithTagsAsync(client, bucketName, S3Path, path, tags);
|
|
|
|
|
Console.WriteLine(recv);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 等待onCreated事件处理完成
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="path">被创建的文件路径</param>
|
|
|
|
|
private static void Waiting(string path)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
@ -273,6 +257,30 @@ namespace S3Demo
|
|
|
|
|
catch { }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 处理文件
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="path">文件路径</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private static async Task DisposeFile(string path)
|
|
|
|
|
{
|
|
|
|
|
// D:\ClientDir\line01\AOI\20211129\085023891P107CN14T00001.png
|
|
|
|
|
string lineName = Path.GetDirectoryName(path).Split('\\')[2];
|
|
|
|
|
string equipmentName = Path.GetDirectoryName(path).Split('\\')[3];
|
|
|
|
|
string date = Path.GetDirectoryName(path).Split('\\')[4];
|
|
|
|
|
string fileName = Path.GetFileName(path);
|
|
|
|
|
string datetime = date + fileName.Substring(0, 9);
|
|
|
|
|
string dt_fomat = DateTime.ParseExact(datetime, "yyyyMMddHHmmssfff", System.Globalization.CultureInfo.CurrentCulture).ToString("yyyy-MM-dd HH:mm:ss:fff");
|
|
|
|
|
string sn = fileName.Substring(9, 14);
|
|
|
|
|
string now = DateTime.Now.ToString("yyyyMMddHHmmssfff");
|
|
|
|
|
String[] tags = new String[] { sn, dt_fomat };
|
|
|
|
|
string S3Path = lineName + "/" + equipmentName + "/" + date + "/" + fileName;
|
|
|
|
|
string recv = await ObjectModel.PutObjectsWithTagsAsync(client, bucketName, S3Path, path, tags);
|
|
|
|
|
Console.WriteLine("recv from S3: " + recv);
|
|
|
|
|
//引入统一上传方式
|
|
|
|
|
//new S3Uploader(lineName).AddUploadTask(S3Path, sn);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 出现错误
|
|
|
|
|
/// </summary>
|
|
|
|
|