diff --git a/packages/dotnet/ReadMe/ConfigValues.cs b/packages/dotnet/ReadMe/ConfigValues.cs index ccd2b753de..e11cbd1d52 100644 --- a/packages/dotnet/ReadMe/ConfigValues.cs +++ b/packages/dotnet/ReadMe/ConfigValues.cs @@ -27,5 +27,7 @@ public class Options public int bufferLength { get; set; } = 1; public string baseLogUrl { get; set; } = "https://example.readme.com"; + + public bool fireAndForget { get; set; } = true; } } diff --git a/packages/dotnet/ReadMe/HarJsonTranslationLogics/ReadmeApiCaller.cs b/packages/dotnet/ReadMe/HarJsonTranslationLogics/ReadmeApiCaller.cs index 001e77ee93..c90b4f8f1f 100644 --- a/packages/dotnet/ReadMe/HarJsonTranslationLogics/ReadmeApiCaller.cs +++ b/packages/dotnet/ReadMe/HarJsonTranslationLogics/ReadmeApiCaller.cs @@ -16,7 +16,7 @@ public ReadMeApiCaller(string harJsonObject, string apiKey) this.apiKey = apiKey; } - public void SendHarObjToReadMeApi() + public void SendHarObjToReadMeApi(bool fireAndForget) { try { @@ -26,7 +26,14 @@ public void SendHarObjToReadMeApi() string apiKey = "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(this.apiKey + ":")); request.AddHeader("Authorization", apiKey); request.AddParameter("application/json", this.harJsonObject, ParameterType.RequestBody); - client.ExecuteAsync(request); + if (fireAndForget) + { + client.ExecuteAsync(request); + } + else + { + client.Execute(request); + } } catch (Exception) { diff --git a/packages/dotnet/ReadMe/Metrics.cs b/packages/dotnet/ReadMe/Metrics.cs index 6bf275b585..417a47776d 100644 --- a/packages/dotnet/ReadMe/Metrics.cs +++ b/packages/dotnet/ReadMe/Metrics.cs @@ -46,7 +46,7 @@ public async Task InvokeAsync(HttpContext context) string harJsonObj = await harJsonBuilder.BuildHar(); ReadMeApiCaller readmeApiCaller = new ReadMeApiCaller(harJsonObj, configValues.apiKey); - readmeApiCaller.SendHarObjToReadMeApi(); + readmeApiCaller.SendHarObjToReadMeApi(configValues.options.fireAndForget); } else { @@ -114,6 +114,11 @@ private ConfigValues GetConfigValues() optionsObj.baseLogUrl = options.GetSection("baseLogUrl").Value; } + if (options.GetSection("fireAndForget").Value != null) + { + optionsObj.fireAndForget = bool.Parse(options.GetSection("fireAndForget").Value); + } + configValues.options = optionsObj; return configValues; }