From 2718bebe3870b6711c6e5453a27ca7cb0d661c46 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Mon, 30 Aug 2021 22:30:44 +0000 Subject: [PATCH] --- source/Plugins/AyaNova.Plugin.V8/V8.cs | 11 ++++- source/Plugins/AyaNova.Plugin.V8/util.cs | 53 +++++++++++++----------- 2 files changed, 39 insertions(+), 25 deletions(-) diff --git a/source/Plugins/AyaNova.Plugin.V8/V8.cs b/source/Plugins/AyaNova.Plugin.V8/V8.cs index b1f9e11..b4fe536 100644 --- a/source/Plugins/AyaNova.Plugin.V8/V8.cs +++ b/source/Plugins/AyaNova.Plugin.V8/V8.cs @@ -5731,10 +5731,17 @@ namespace AyaNova.PlugIn.V8 //Upload try { +#if(DEBUG) + progress.Append("Sending file " + fi.Name); +#endif await util.PostFormDataAsync("attachment", formDataContent); + } catch (Exception ex) { +#if(DEBUG) + progress.Append("ERROR Sending file " + fi.Name); +#endif if (ex.Message.Contains("413")) { if (SmallestFileUploadRejectedAsTooBig > fi.Length) @@ -5750,7 +5757,9 @@ namespace AyaNova.PlugIn.V8 } } //No need to map it or save response as long as it works that's all that matters - +#if(DEBUG) + progress.Append("File attached successfully " + fi.Name); +#endif } diff --git a/source/Plugins/AyaNova.Plugin.V8/util.cs b/source/Plugins/AyaNova.Plugin.V8/util.cs index 5bd54aa..cff8be9 100644 --- a/source/Plugins/AyaNova.Plugin.V8/util.cs +++ b/source/Plugins/AyaNova.Plugin.V8/util.cs @@ -23,7 +23,7 @@ namespace AyaNova.PlugIn.V8 public const string API_BASE_ROUTE = "api/v8/"; private const int MAX_TRIES = 3;//max times to retry an api call before giving up private const int API_RETRY_DELAY = 3000;//pause in ms before retrying api call - private const int HTTPCLIENT_TIMEOUT_SECONDS = 300;//default for all ops, normally 100seconds but would kill large file uploads + private const int HTTPCLIENT_TIMEOUT_SECONDS = 1200;//default for all ops, normally 100seconds but would kill large file uploads public static HttpClient client = null; //url once known to be good internal static string ApiBaseUrl { get; set; } @@ -355,33 +355,38 @@ namespace AyaNova.PlugIn.V8 + //public async static Task PostFormDataAsync(string route, MultipartFormDataContent formContent) + //{ + // Exception FirstException = null; + + // for (int x = 0; x < MAX_TRIES; x++) + // { + // try + // { + // return await TryPostFormDataAsync(route, formContent); + // } + // catch (Exception ex) + // { + // if (ex.Message.Contains("413")) throw;//too large, no point in retrying at all let upstream caller handle it immediately + + // if (FirstException == null) + // FirstException = ex; + // } + // await Task.Delay(API_RETRY_DELAY); + // } + + // //no luck re-throw the exception + // throw new Exception("API call failed after " + MAX_TRIES.ToString() + " attempts", FirstException); + //} + + //NO RETRY TEST VERSION OF ABOVE + //UNCOMMENT ABOVE AND COMMENT THIS TO GO BACK public async static Task PostFormDataAsync(string route, MultipartFormDataContent formContent) - { - Exception FirstException = null; - - for (int x = 0; x < MAX_TRIES; x++) - { - try - { - return await TryPostFormDataAsync(route, formContent); - } - catch (Exception ex) - { - if (ex.Message.Contains("413")) throw;//too large, no point in retrying at all let upstream caller handle it immediately - - if (FirstException == null) - FirstException = ex; - } - await Task.Delay(API_RETRY_DELAY); - } - - //no luck re-throw the exception - throw new Exception("API call failed after " + MAX_TRIES.ToString() + " attempts", FirstException); + { + return await TryPostFormDataAsync(route, formContent); } - - private async static Task TryPostFormDataAsync(string route, MultipartFormDataContent formContent) { var requestMessage = new HttpRequestMessage(HttpMethod.Post, ApiBaseUrl + route);