diff --git a/source/Plugins/AyaNova.Plugin.V8/util.cs b/source/Plugins/AyaNova.Plugin.V8/util.cs index f1059bc..d489e06 100644 --- a/source/Plugins/AyaNova.Plugin.V8/util.cs +++ b/source/Plugins/AyaNova.Plugin.V8/util.cs @@ -250,12 +250,57 @@ namespace AyaNova.PlugIn.V8 } + + + + + + + + public async static Task PutAsync(string route, dynamic d) { - return await PutAsync(route, d.ToString(Newtonsoft.Json.Formatting.None)); + Exception FirstException = null; + + for (int x = 0; x < MAX_TRIES; x++) + { + try + { + return await TryPutAsync(route, d.ToString(Newtonsoft.Json.Formatting.None)); + } + catch (Exception ex) + { + if (FirstException == null) + FirstException = ex; + } + } + + //no luck re-throw the exception + throw FirstException; } - public async static Task PutAsync(string route, string putJson = null) + public async static Task PutAsync(string route) + { + Exception FirstException = null; + + for (int x = 0; x < MAX_TRIES; x++) + { + try + { + return await TryPutAsync(route); + } + catch (Exception ex) + { + if (FirstException == null) + FirstException = ex; + } + } + + //no luck re-throw the exception + throw FirstException; + } + + public async static Task TryPutAsync(string route, string putJson = null) { var requestMessage = new HttpRequestMessage(HttpMethod.Put, ApiBaseUrl + route); requestMessage.Headers.Add("X-AY-Import-Mode", "1"); @@ -289,7 +334,36 @@ 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 (FirstException == null) + FirstException = ex; + } + } + + //no luck re-throw the exception + throw FirstException; + } + + + private async static Task TryPostFormDataAsync(string route, MultipartFormDataContent formContent) { var requestMessage = new HttpRequestMessage(HttpMethod.Post, ApiBaseUrl + route); requestMessage.Headers.Add("X-AY-Import-Mode", "1");