|
@@ -8,10 +8,12 @@
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
+using System.Security.Cryptography.X509Certificates;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
using MBIRevitBase.Config;
|
|
|
using MBIRevitBase.Tools;
|
|
|
+using Polly;
|
|
|
|
|
|
namespace MBIRevitBase.Services
|
|
|
{
|
|
@@ -20,16 +22,45 @@ namespace MBIRevitBase.Services
|
|
|
/// </summary>
|
|
|
public class UploadService
|
|
|
{
|
|
|
+ public static BResult UploadExportFile(string result)
|
|
|
+ {
|
|
|
+ return DelayRetryPolicy(result);
|
|
|
+ }
|
|
|
/// <summary>
|
|
|
/// 上传导出文件
|
|
|
/// </summary>
|
|
|
/// <param name="result"></param>
|
|
|
/// <returns></returns>
|
|
|
- public static BResult UploadExportFile(string result)
|
|
|
+ public static T UploadExportFileRetry<T>(string result)where T:BResult
|
|
|
{
|
|
|
var stream = ZipUtils.ZipString(result, "export.json");
|
|
|
var url = ApiConfig.AlgorithmUrl() + @"/upload-json-zip/upload";
|
|
|
- return HttpUtils.PostFormDataFile(url, stream);
|
|
|
+ Console.WriteLine("BeginUploadData");
|
|
|
+ return HttpUtils.PostFormDataFileThrowException(url, stream) as T;
|
|
|
+ }
|
|
|
+
|
|
|
+ static BResult DelayRetryPolicy(string result)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var waitAndRetryPolicy = Policy.Handle<Exception>().WaitAndRetry(new[]
|
|
|
+ {
|
|
|
+ TimeSpan.FromSeconds(5),
|
|
|
+ TimeSpan.FromSeconds(5),
|
|
|
+ TimeSpan.FromSeconds(5),
|
|
|
+ TimeSpan.FromSeconds(5)
|
|
|
+ }, ReportError);
|
|
|
+ return waitAndRetryPolicy.Execute<BResult>(()=> UploadExportFileRetry<BResult>(result));
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ Console.WriteLine($"Execute failed,Message:{e.Message}");
|
|
|
+ return e.Message;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ static void ReportError(Exception e, TimeSpan timeSpan, int intento, Context context)
|
|
|
+ {
|
|
|
+ Console.WriteLine($"异常{intento:00} <调用秒数:{timeSpan.Seconds} 秒>\t 执行时间:{DateTime.Now}");
|
|
|
}
|
|
|
}
|
|
|
}
|