完善打印

master
ZGGSONG 3 years ago
parent 8c1af0634d
commit d86ab95cc1

@ -152,7 +152,7 @@ namespace Ksat.Supplyment.Library.Uploader
private void Req_OnRequestFinished(object sender, bool success, string reason) private void Req_OnRequestFinished(object sender, bool success, string reason)
{ {
var request = sender as IUploaderRequest<T>; var request = sender as IUploaderRequest<T>;
var x = (request.RequestData); var x = request.RequestData;
var reqModel = dequeRequest(request); var reqModel = dequeRequest(request);
if (reqModel == null) if (reqModel == null)

@ -27,12 +27,26 @@ namespace S3Demo.Helper
/// object to be tagged.</param> /// object to be tagged.</param>
/// <param name="filePath">The directory location and file name of the /// <param name="filePath">The directory location and file name of the
/// object to be uploaded to the S3 bucket.</param> /// object to be uploaded to the S3 bucket.</param>
public static async Task<string> PutObjectsWithTagsAsync(IAmazonS3 client, string bucketName, string keyName, string filePath, string[] tags) public static async Task<string> PutObjectsWithTagsAsync(IAmazonS3 client, string bucketName, string keyName, string filePath, List<string> tags)
{ {
try try
{ {
// Create an object with tags. // Create an object with tags.
var putRequest = new PutObjectRequest //List<string> keys = new List<string> { "sn", "date", "code" };
//var putRequest = new PutObjectRequest()
//{
// BucketName = bucketName,
// Key = keyName,
// FilePath = filePath
//};
//for (int i = 0; i < tags.Count; i++)
//{
// //TODO: 优化添加标签参数细节
// putRequest.TagSet = new List<Tag> {
// new Tag { Key = keys[i], Value = tags[i] }
// };
//}
var putRequest = new PutObjectRequest()
{ {
BucketName = bucketName, BucketName = bucketName,
Key = keyName, Key = keyName,
@ -45,7 +59,6 @@ namespace S3Demo.Helper
//new Tag { Key = "code", Value = tags[2] } //new Tag { Key = "code", Value = tags[2] }
}, },
}; };
PutObjectResponse response = await client.PutObjectAsync(putRequest); PutObjectResponse response = await client.PutObjectAsync(putRequest);
//Console.WriteLine(putRequest.Key + "," + putRequest.BucketName + "," + putRequest.FilePath + "," + response.HttpStatusCode); //Console.WriteLine(putRequest.Key + "," + putRequest.BucketName + "," + putRequest.FilePath + "," + response.HttpStatusCode);
return response.HttpStatusCode.ToString(); return response.HttpStatusCode.ToString();
@ -97,7 +110,7 @@ namespace S3Demo.Helper
} }
catch (Exception ex) catch (Exception ex)
{ {
Console.WriteLine($"Error: {ex.Message}"); //Console.WriteLine($"Error: {ex.Message}");
return ex.Message.ToString(); return ex.Message.ToString();
} }
} }

@ -37,8 +37,8 @@ namespace S3Demo.Model.Uploader
public void Cancel() public void Cancel()
{ {
mTask?.Dispose();
//TODO: //TODO:
mTask?.Dispose();
} }
public void Start() public void Start()
@ -50,11 +50,10 @@ namespace S3Demo.Model.Uploader
private Task<string> mTask; private Task<string> mTask;
public async Task objSend() public async Task objSend()
{ {
Console.WriteLine("==开始上传=="); mTask = ObjectHelper.PutObjectsWithTagsAsync(client, bucketName, RequestData.Keyname, RequestData.Path, RequestData.Tags);
mTask = ObjectHelper.PutObjectsWithTagsAsync(client, bucketName, RequestData.Keyname, RequestData.Path, RequestData.Tags.ToArray());
string res = await mTask; string res = await mTask;
UploadFinish(this, res.Equals("OK"), res); UploadFinish(this, res.Equals("OK"), res);
Console.WriteLine($"S3 Upload recv: {res}"); Console.WriteLine($"{DateTime.Now.ToString("HH:mm:ss.fff")} s3Recv {RequestData.Keyname}==>{res}");
} }
} }
} }

@ -3,6 +3,7 @@ using System.IO;
using S3Demo.Model.Uploader; using S3Demo.Model.Uploader;
using System.Threading; using System.Threading;
using System.Linq; using System.Linq;
using System.Collections.Generic;
namespace S3Demo namespace S3Demo
{ {
@ -179,10 +180,12 @@ namespace S3Demo
string dt_fomat = DateTime.ParseExact(datetime, "yyyyMMddHHmmssfff", System.Globalization.CultureInfo.CurrentCulture).ToString("yyyy-MM-dd HH:mm:ss:fff"); 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 sn = fileName.Substring(9, 14);
string now = DateTime.Now.ToString("yyyyMMddHHmmssfff"); string now = DateTime.Now.ToString("yyyyMMddHHmmssfff");
String[] tags = new String[] { sn, dt_fomat }; List<string> tags = new List<string>();
tags.Add(sn);
tags.Add(dt_fomat);
string S3Path = lineName + "/" + equipmentName + "/" + date + "/" + fileName; string S3Path = lineName + "/" + equipmentName + "/" + date + "/" + fileName;
var uploadModel = new S3UploadModel { Keyname = S3Path, Path = path, Tags = tags.ToList() }; var uploadModel = new S3UploadModel { Keyname = S3Path, Path = path, Tags = tags };
S3Uploader.Instance().AddUploadTask(uploadModel, sn); S3Uploader.Instance().AddUploadTask(uploadModel, sn);
} }

Loading…
Cancel
Save