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