123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
-
- 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
- {
-
-
-
- public class UploadService
- {
- public static BResult UploadExportFile(string result)
- {
- return DelayRetryPolicy(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";
- 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}");
- }
- }
- }
|