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.

59 lines
1.8 KiB

using System;
using Ksat.Logging;
using Ksat.Supplyment.Library.Uploader;
using Ksat.Supplyment.Library.Model.Uploader;
3 years ago
namespace S3Demo.Model.Uploader
{
3 years ago
public class S3UploadOperator : IUploaderOperator<S3UploadModel>
{
//Log
private ILogger sLog = LoggerFactory.ForContext<S3UploadOperator>();
3 years ago
public S3UploadModel ConvertCacheToRequest(string cache)
{
3 years ago
return Newtonsoft.Json.JsonConvert.DeserializeObject<S3UploadModel>(cache);
}
3 years ago
public string ConvertRequestToCachel(S3UploadModel requestData)
{
3 years ago
return Newtonsoft.Json.JsonConvert.SerializeObject(requestData);
}
3 years ago
public bool ShouldRetryRequest(UploadModel<S3UploadModel> requestModel, out string cancelReason)
{
if (DateTime.Now.Subtract(requestModel.CreateAt).TotalSeconds > 600)
{
cancelReason = "exceed 600s";
return false;
}
if (requestModel.RetryCount > 5)
{
cancelReason = "exceed 5";
return false;
}
cancelReason = null;
return true;
}
3 years ago
public bool ShouldStartRequest(UploadModel<S3UploadModel> requestModel, out string cancelReason)
{
if (DateTime.Now.Subtract(requestModel.CreateAt).TotalSeconds > 600)
{
cancelReason = "exceed 600s";
return false;
}
if (requestModel.RetryCount > 5)
{
cancelReason = "exceed 5";
return false;
}
cancelReason = null;
return true;
}
3 years ago
public IUploaderRequest<S3UploadModel> UploadData(S3UploadModel data)
{
return new S3UploadRequest() { RequestData = data };
}
}
}