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;
namespace S3Demo.Model.Uploader
{
public class S3UploadOperator : IUploaderOperator<S3UploadModel>
{
//Log
private ILogger sLog = LoggerFactory.ForContext<S3UploadOperator>();
public S3UploadModel ConvertCacheToRequest(string cache)
{
return Newtonsoft.Json.JsonConvert.DeserializeObject<S3UploadModel>(cache);
}
public string ConvertRequestToCachel(S3UploadModel requestData)
{
return Newtonsoft.Json.JsonConvert.SerializeObject(requestData);
}
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;
}
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;
}
public IUploaderRequest<S3UploadModel> UploadData(S3UploadModel data)
{
return new S3UploadRequest() { RequestData = data };
}
}
}