You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.4 KiB

using System;
3 years ago
using System.Threading.Tasks;
3 years ago
using System.Threading;
3 years ago
using Newtonsoft.Json;
3 years ago
using Amazon;
3 years ago
using Amazon.S3;
3 years ago
using Amazon.Runtime;
3 years ago
using S3Demo.Helper;
using Ksat.Supplyment.Library.Uploader;
using Ksat.Logging;
namespace S3Demo.Model.Uploader
{
3 years ago
public class S3UploadRequest : IUploaderRequest<S3UploadModel>
{
3 years ago
// 通过固定域名的方式
//private static AmazonS3Config conf = new AmazonS3Config()
//{
// ServiceURL = "https://play.min.io",
// ForcePathStyle = true
//};
//new BasicAWSCredentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
public string bucketName = "minio/test";
public AmazonS3Client client = new AmazonS3Client(new BasicAWSCredentials("admin", "admin123."), new AmazonS3Config()
{
UseHttp = true,
ProxyHost = "http://192.168.60.132",
ProxyPort = 9000,
RegionEndpoint = RegionEndpoint.USEast1
});
private ILogger sLog = LoggerFactory.ForContext<S3UploadOperator>();
3 years ago
public S3UploadModel RequestData { get; set; }
public event UploadFinishHandler UploadFinish;
3 years ago
/// <summary>
/// Scada Api
/// </summary>
private static string url = "http://172.17.204.30:9000/api/tri/imagesupload";
public void Cancel()
{
3 years ago
mTask?.Dispose();
}
public void Start()
{
3 years ago
_ = objSend();
}
private Task<string> mTask;
public async Task objSend()
{
3 years ago
mTask = ObjectHelper.PutObjectsWithTagsAsync(client, bucketName, RequestData.Keyname, RequestData.Path, RequestData.Tags);
3 years ago
string res = await mTask;
UploadFinish(this, res.Equals("OK"), res);
//TODO: 请求接口,上传状态
3 years ago
ScadaRequest req = new ScadaRequest();
ScadaResponse resp = new ScadaResponse();
req.s3Flag = res;
3 years ago
req.dateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff");
3 years ago
resp = JsonConvert.DeserializeObject<ScadaResponse>(Helper.HttpHelper.PostUrl(url, JsonConvert.SerializeObject(req)));
3 years ago
Console.WriteLine($"{DateTime.Now.ToString("HH:mm:ss.fff")} S3Recv {RequestData.Keyname} ==>{res}");
3 years ago
Console.WriteLine($"{DateTime.Now.ToString("HH:mm:ss.fff")} ScadaRecv ==>{resp.code} & {resp.message}");
}
}
}