From 4c02b3d3d72fbe33c94d1c51cb7b236bd18d9195 Mon Sep 17 00:00:00 2001 From: peterschubert Date: Sun, 25 Jun 2023 21:46:15 -0400 Subject: [PATCH 01/15] Update MessageFormatter.cs --- Intacct.SDK/Logging/MessageFormatter.cs | 29 ++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/Intacct.SDK/Logging/MessageFormatter.cs b/Intacct.SDK/Logging/MessageFormatter.cs index 4e1ced98..1e9a813f 100644 --- a/Intacct.SDK/Logging/MessageFormatter.cs +++ b/Intacct.SDK/Logging/MessageFormatter.cs @@ -14,10 +14,12 @@ */ using System; +using System.IO; using System.Net; using System.Net.Http; using System.Net.Http.Headers; using System.Text.RegularExpressions; +using System.Threading.Tasks; namespace Intacct.SDK.Logging { @@ -68,7 +70,7 @@ private static string Headers(HttpHeaders headers) public string Format(HttpRequestMessage request, HttpResponseMessage response, Exception error = null) { - string message = Regex.Replace(_template, @"{\s*([A-Za-z_\-\.0-9]+)\s*}", match => { + string message = Regex.Replace(_template, @"{\s*([A-Za-z_\-\.0-9]+)\s*}", async match => { string result = ""; switch (match.Value) { @@ -81,7 +83,10 @@ public string Format(HttpRequestMessage request, HttpResponseMessage response, E { result = result + Environment.NewLine + "{" + header.Key + "}: " + string.Join(", ", header.Value); } - result = result + Environment.NewLine + Environment.NewLine + request.Content.ReadAsStringAsync().Result; + + + + result = result + Environment.NewLine + Environment.NewLine + request.Content.ReadAsStreamAsync().Result; break; case "{response}": result = response != null ? " HTTP/" + response.Version.ToString() @@ -94,7 +99,22 @@ public string Format(HttpRequestMessage request, HttpResponseMessage response, E { result = result + Environment.NewLine + "{" + header.Key + "}: " + string.Join(", ", header.Value); } - result = result + Environment.NewLine + Environment.NewLine + response.Content.ReadAsStringAsync().Result; + + if (response.Content is StringContent stringContent) + { + result = result + Environment.NewLine + Environment.NewLine + stringContent.ReadAsStringAsync(); + } + else + { + using var stream = await response.Content.ReadAsStreamAsync(); + + using var reader = new StreamReader(stream); + + result = await reader.ReadToEndAsync(); + + } + + } break; case "{req_headers}": @@ -197,5 +217,8 @@ public string Format(HttpRequestMessage request, HttpResponseMessage response, E return message; } + + + } } \ No newline at end of file From 47fcbcd1dbd12d874551a5bdc4e067a8d60bd41f Mon Sep 17 00:00:00 2001 From: peterschubert Date: Sun, 25 Jun 2023 21:56:42 -0400 Subject: [PATCH 02/15] Update MessageFormatter.cs --- Intacct.SDK/Logging/MessageFormatter.cs | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/Intacct.SDK/Logging/MessageFormatter.cs b/Intacct.SDK/Logging/MessageFormatter.cs index 1e9a813f..eb0e9ca3 100644 --- a/Intacct.SDK/Logging/MessageFormatter.cs +++ b/Intacct.SDK/Logging/MessageFormatter.cs @@ -20,6 +20,7 @@ using System.Net.Http.Headers; using System.Text.RegularExpressions; using System.Threading.Tasks; +using Intacct.SDK.Xml.Response; namespace Intacct.SDK.Logging { @@ -86,7 +87,7 @@ public string Format(HttpRequestMessage request, HttpResponseMessage response, E - result = result + Environment.NewLine + Environment.NewLine + request.Content.ReadAsStreamAsync().Result; + result = result + Environment.NewLine + Environment.NewLine + GetHttpContentAsString(response.Content).Result; break; case "{response}": result = response != null ? " HTTP/" + response.Version.ToString() @@ -100,21 +101,9 @@ public string Format(HttpRequestMessage request, HttpResponseMessage response, E result = result + Environment.NewLine + "{" + header.Key + "}: " + string.Join(", ", header.Value); } - if (response.Content is StringContent stringContent) - { - result = result + Environment.NewLine + Environment.NewLine + stringContent.ReadAsStringAsync(); - } - else - { - using var stream = await response.Content.ReadAsStreamAsync(); + result = result + Environment.NewLine + Environment.NewLine + GetHttpContentAsString(response.Content).Result; - using var reader = new StreamReader(stream); - result = await reader.ReadToEndAsync(); - - } - - } break; case "{req_headers}": @@ -219,6 +208,13 @@ public string Format(HttpRequestMessage request, HttpResponseMessage response, E + private async Task GetHttpContentAsString(HttpContent httpContent) + { + using var stream = await httpContent.ReadAsStreamAsync(); + + using var reader = new StreamReader(stream); + return await reader.ReadToEndAsync(); + } } } \ No newline at end of file From 071059254e70105c51a83eff46a70099f15809b7 Mon Sep 17 00:00:00 2001 From: peterschubert Date: Sun, 25 Jun 2023 22:00:46 -0400 Subject: [PATCH 03/15] removed async --- Intacct.SDK/Logging/MessageFormatter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Intacct.SDK/Logging/MessageFormatter.cs b/Intacct.SDK/Logging/MessageFormatter.cs index eb0e9ca3..576d2d47 100644 --- a/Intacct.SDK/Logging/MessageFormatter.cs +++ b/Intacct.SDK/Logging/MessageFormatter.cs @@ -71,7 +71,7 @@ private static string Headers(HttpHeaders headers) public string Format(HttpRequestMessage request, HttpResponseMessage response, Exception error = null) { - string message = Regex.Replace(_template, @"{\s*([A-Za-z_\-\.0-9]+)\s*}", async match => { + string message = Regex.Replace(_template, @"{\s*([A-Za-z_\-\.0-9]+)\s*}", match => { string result = ""; switch (match.Value) { From fabe6c273852d0739a05093175f4e24e915c43c3 Mon Sep 17 00:00:00 2001 From: peterschubert Date: Sun, 25 Jun 2023 22:05:03 -0400 Subject: [PATCH 04/15] removed extra whitespace --- Intacct.SDK/Logging/MessageFormatter.cs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Intacct.SDK/Logging/MessageFormatter.cs b/Intacct.SDK/Logging/MessageFormatter.cs index 576d2d47..bda970b1 100644 --- a/Intacct.SDK/Logging/MessageFormatter.cs +++ b/Intacct.SDK/Logging/MessageFormatter.cs @@ -71,7 +71,7 @@ private static string Headers(HttpHeaders headers) public string Format(HttpRequestMessage request, HttpResponseMessage response, Exception error = null) { - string message = Regex.Replace(_template, @"{\s*([A-Za-z_\-\.0-9]+)\s*}", match => { + string message = Regex.Replace(_template, @"{\s*([A-Za-z_\-\.0-9]+)\s*}", match => { string result = ""; switch (match.Value) { @@ -85,8 +85,6 @@ public string Format(HttpRequestMessage request, HttpResponseMessage response, E result = result + Environment.NewLine + "{" + header.Key + "}: " + string.Join(", ", header.Value); } - - result = result + Environment.NewLine + Environment.NewLine + GetHttpContentAsString(response.Content).Result; break; case "{response}": @@ -102,8 +100,6 @@ public string Format(HttpRequestMessage request, HttpResponseMessage response, E } result = result + Environment.NewLine + Environment.NewLine + GetHttpContentAsString(response.Content).Result; - - } break; case "{req_headers}": From f0ca677e75aad0449ae49e2df89b567b3f40d193 Mon Sep 17 00:00:00 2001 From: peterschubert Date: Sun, 25 Jun 2023 22:05:42 -0400 Subject: [PATCH 05/15] remove more whitespace --- Intacct.SDK/Logging/MessageFormatter.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/Intacct.SDK/Logging/MessageFormatter.cs b/Intacct.SDK/Logging/MessageFormatter.cs index bda970b1..959a73e8 100644 --- a/Intacct.SDK/Logging/MessageFormatter.cs +++ b/Intacct.SDK/Logging/MessageFormatter.cs @@ -84,7 +84,6 @@ public string Format(HttpRequestMessage request, HttpResponseMessage response, E { result = result + Environment.NewLine + "{" + header.Key + "}: " + string.Join(", ", header.Value); } - result = result + Environment.NewLine + Environment.NewLine + GetHttpContentAsString(response.Content).Result; break; case "{response}": @@ -98,7 +97,6 @@ public string Format(HttpRequestMessage request, HttpResponseMessage response, E { result = result + Environment.NewLine + "{" + header.Key + "}: " + string.Join(", ", header.Value); } - result = result + Environment.NewLine + Environment.NewLine + GetHttpContentAsString(response.Content).Result; } break; From eae9ca8067b99b9ae986a3481823f8710bdfa558 Mon Sep 17 00:00:00 2001 From: peterschubert Date: Sun, 25 Jun 2023 22:06:27 -0400 Subject: [PATCH 06/15] Update MessageFormatter.cs --- Intacct.SDK/Logging/MessageFormatter.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/Intacct.SDK/Logging/MessageFormatter.cs b/Intacct.SDK/Logging/MessageFormatter.cs index 959a73e8..d3e4f26b 100644 --- a/Intacct.SDK/Logging/MessageFormatter.cs +++ b/Intacct.SDK/Logging/MessageFormatter.cs @@ -200,8 +200,6 @@ public string Format(HttpRequestMessage request, HttpResponseMessage response, E return message; } - - private async Task GetHttpContentAsString(HttpContent httpContent) { using var stream = await httpContent.ReadAsStreamAsync(); From d1b145c75f810e0fe9952a13dc380d82d0ae36ee Mon Sep 17 00:00:00 2001 From: peterschubert Date: Sun, 25 Jun 2023 22:18:15 -0400 Subject: [PATCH 07/15] added utf8 encoding --- Intacct.SDK/Logging/MessageFormatter.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Intacct.SDK/Logging/MessageFormatter.cs b/Intacct.SDK/Logging/MessageFormatter.cs index d3e4f26b..26a5e6d8 100644 --- a/Intacct.SDK/Logging/MessageFormatter.cs +++ b/Intacct.SDK/Logging/MessageFormatter.cs @@ -18,6 +18,7 @@ using System.Net; using System.Net.Http; using System.Net.Http.Headers; +using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using Intacct.SDK.Xml.Response; @@ -204,7 +205,7 @@ private async Task GetHttpContentAsString(HttpContent httpContent) { using var stream = await httpContent.ReadAsStreamAsync(); - using var reader = new StreamReader(stream); + using var reader = new StreamReader(stream, Encoding.UTF8); return await reader.ReadToEndAsync(); } From 7320e745eae924c09a387ce35828953a8f3f995a Mon Sep 17 00:00:00 2001 From: peterschubert Date: Sun, 25 Jun 2023 22:20:25 -0400 Subject: [PATCH 08/15] Update MessageFormatter.cs --- Intacct.SDK/Logging/MessageFormatter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Intacct.SDK/Logging/MessageFormatter.cs b/Intacct.SDK/Logging/MessageFormatter.cs index 26a5e6d8..5f4cf572 100644 --- a/Intacct.SDK/Logging/MessageFormatter.cs +++ b/Intacct.SDK/Logging/MessageFormatter.cs @@ -85,7 +85,7 @@ public string Format(HttpRequestMessage request, HttpResponseMessage response, E { result = result + Environment.NewLine + "{" + header.Key + "}: " + string.Join(", ", header.Value); } - result = result + Environment.NewLine + Environment.NewLine + GetHttpContentAsString(response.Content).Result; + result = result + Environment.NewLine + Environment.NewLine + GetHttpContentAsString(request.Content).Result; break; case "{response}": result = response != null ? " HTTP/" + response.Version.ToString() From 2f3af76997dc727415b7829fef4ff4fc2823382f Mon Sep 17 00:00:00 2001 From: peterschubert Date: Tue, 27 Jun 2023 08:16:20 -0400 Subject: [PATCH 09/15] use readasbyteArray instead --- Intacct.SDK/Logging/MessageFormatter.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Intacct.SDK/Logging/MessageFormatter.cs b/Intacct.SDK/Logging/MessageFormatter.cs index 5f4cf572..99374321 100644 --- a/Intacct.SDK/Logging/MessageFormatter.cs +++ b/Intacct.SDK/Logging/MessageFormatter.cs @@ -203,11 +203,9 @@ public string Format(HttpRequestMessage request, HttpResponseMessage response, E private async Task GetHttpContentAsString(HttpContent httpContent) { - using var stream = await httpContent.ReadAsStreamAsync(); + var bytes = await httpContent.ReadAsByteArrayAsync(); - using var reader = new StreamReader(stream, Encoding.UTF8); - - return await reader.ReadToEndAsync(); + return Encoding.UTF8.GetString(bytes); } } } \ No newline at end of file From f946a19f218931160802bcfb7bef6a2987dd543d Mon Sep 17 00:00:00 2001 From: peterschubert Date: Tue, 27 Jun 2023 08:19:56 -0400 Subject: [PATCH 10/15] remove unused using --- Intacct.SDK/Logging/MessageFormatter.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Intacct.SDK/Logging/MessageFormatter.cs b/Intacct.SDK/Logging/MessageFormatter.cs index 99374321..3bb855d6 100644 --- a/Intacct.SDK/Logging/MessageFormatter.cs +++ b/Intacct.SDK/Logging/MessageFormatter.cs @@ -21,7 +21,6 @@ using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; -using Intacct.SDK.Xml.Response; namespace Intacct.SDK.Logging { From 305bb15f6401e97bf2c735b5f6383e3e51daea63 Mon Sep 17 00:00:00 2001 From: Peter Schubert Date: Thu, 29 Jun 2023 10:54:35 -0400 Subject: [PATCH 11/15] remove gzip/deflate compression --- Intacct.SDK/Logging/MessageFormatter.cs | 4 ++-- Intacct.SDK/Xml/RequestHandler.cs | 23 ++++++++++------------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/Intacct.SDK/Logging/MessageFormatter.cs b/Intacct.SDK/Logging/MessageFormatter.cs index 3bb855d6..c50c33c2 100644 --- a/Intacct.SDK/Logging/MessageFormatter.cs +++ b/Intacct.SDK/Logging/MessageFormatter.cs @@ -84,7 +84,7 @@ public string Format(HttpRequestMessage request, HttpResponseMessage response, E { result = result + Environment.NewLine + "{" + header.Key + "}: " + string.Join(", ", header.Value); } - result = result + Environment.NewLine + Environment.NewLine + GetHttpContentAsString(request.Content).Result; + result = result + Environment.NewLine + Environment.NewLine + request.Content.ReadAsStringAsync().Result; break; case "{response}": result = response != null ? " HTTP/" + response.Version.ToString() @@ -97,7 +97,7 @@ public string Format(HttpRequestMessage request, HttpResponseMessage response, E { result = result + Environment.NewLine + "{" + header.Key + "}: " + string.Join(", ", header.Value); } - result = result + Environment.NewLine + Environment.NewLine + GetHttpContentAsString(response.Content).Result; + result = result + Environment.NewLine + Environment.NewLine + request.Content.ReadAsStringAsync().Result; } break; case "{req_headers}": diff --git a/Intacct.SDK/Xml/RequestHandler.cs b/Intacct.SDK/Xml/RequestHandler.cs index 180584bb..a8439df7 100644 --- a/Intacct.SDK/Xml/RequestHandler.cs +++ b/Intacct.SDK/Xml/RequestHandler.cs @@ -99,10 +99,8 @@ private HttpMessageHandler GetHttpMessageHandler() } else { - HttpClientHandler httpClientHandler = new HttpClientHandler() - { - AutomaticDecompression = System.Net.DecompressionMethods.GZip | System.Net.DecompressionMethods.Deflate - }; + HttpClientHandler httpClientHandler = new HttpClientHandler(); + if (this.ClientConfig.Logger != null) { @@ -122,15 +120,14 @@ private static int ExponentialDelay(int retries) private async Task Execute(Stream requestXml) { - HttpClient client = new HttpClient(GetHttpMessageHandler()); - client.Timeout = this.RequestConfig.MaxTimeout; - client.DefaultRequestHeaders.Add("Accept-Encoding", "gzip,deflate"); - client.DefaultRequestHeaders.UserAgent.ParseAdd("intacct-sdk-net-client/" + RequestHandler.Version); - - requestXml.Position = 0; - StreamContent content = new StreamContent(requestXml); - content.Headers.ContentType = new MediaTypeHeaderValue("application/xml"); - + HttpClient client = new HttpClient(GetHttpMessageHandler()); + client.Timeout = this.RequestConfig.MaxTimeout; + client.DefaultRequestHeaders.UserAgent.ParseAdd("intacct-sdk-net-client/" + RequestHandler.Version); + + requestXml.Position = 0; + StreamContent content = new StreamContent(requestXml); + content.Headers.ContentType = new MediaTypeHeaderValue("application/xml"); + for (int attempt = 0; attempt <= this.RequestConfig.MaxRetries; attempt++) { if (attempt > 0) From b7821dfac9b2226f1632b6f36c605d65a4b1ff3e Mon Sep 17 00:00:00 2001 From: Peter Schubert Date: Thu, 29 Jun 2023 11:02:09 -0400 Subject: [PATCH 12/15] corrected mistake --- Intacct.SDK/Logging/MessageFormatter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Intacct.SDK/Logging/MessageFormatter.cs b/Intacct.SDK/Logging/MessageFormatter.cs index c50c33c2..7bd60b28 100644 --- a/Intacct.SDK/Logging/MessageFormatter.cs +++ b/Intacct.SDK/Logging/MessageFormatter.cs @@ -97,7 +97,7 @@ public string Format(HttpRequestMessage request, HttpResponseMessage response, E { result = result + Environment.NewLine + "{" + header.Key + "}: " + string.Join(", ", header.Value); } - result = result + Environment.NewLine + Environment.NewLine + request.Content.ReadAsStringAsync().Result; + result = result + Environment.NewLine + Environment.NewLine + response.Content.ReadAsStringAsync().Result; } break; case "{req_headers}": From 2b4cab629548320b05dcfc1d140ee6e4ee003df4 Mon Sep 17 00:00:00 2001 From: Peter Schubert Date: Thu, 29 Jun 2023 11:02:36 -0400 Subject: [PATCH 13/15] removed unused methods/usings --- Intacct.SDK/Logging/MessageFormatter.cs | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/Intacct.SDK/Logging/MessageFormatter.cs b/Intacct.SDK/Logging/MessageFormatter.cs index 7bd60b28..687128b4 100644 --- a/Intacct.SDK/Logging/MessageFormatter.cs +++ b/Intacct.SDK/Logging/MessageFormatter.cs @@ -14,13 +14,10 @@ */ using System; -using System.IO; using System.Net; using System.Net.Http; using System.Net.Http.Headers; -using System.Text; using System.Text.RegularExpressions; -using System.Threading.Tasks; namespace Intacct.SDK.Logging { @@ -71,7 +68,8 @@ private static string Headers(HttpHeaders headers) public string Format(HttpRequestMessage request, HttpResponseMessage response, Exception error = null) { - string message = Regex.Replace(_template, @"{\s*([A-Za-z_\-\.0-9]+)\s*}", match => { + string message = Regex.Replace(_template, @"{\s*([A-Za-z_\-\.0-9]+)\s*}", match => + { string result = ""; switch (match.Value) { @@ -199,12 +197,5 @@ public string Format(HttpRequestMessage request, HttpResponseMessage response, E return message; } - - private async Task GetHttpContentAsString(HttpContent httpContent) - { - var bytes = await httpContent.ReadAsByteArrayAsync(); - - return Encoding.UTF8.GetString(bytes); - } } } \ No newline at end of file From 675f09d388d3dc58e5e739a9ad2bb77774e28a54 Mon Sep 17 00:00:00 2001 From: Peter Schubert Date: Thu, 29 Jun 2023 11:03:22 -0400 Subject: [PATCH 14/15] run codemaid --- Intacct.SDK/Xml/RequestHandler.cs | 43 +++++++++++++++---------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/Intacct.SDK/Xml/RequestHandler.cs b/Intacct.SDK/Xml/RequestHandler.cs index a8439df7..40b164e1 100644 --- a/Intacct.SDK/Xml/RequestHandler.cs +++ b/Intacct.SDK/Xml/RequestHandler.cs @@ -1,27 +1,27 @@ /* * Copyright 2022 Sage Intacct, Inc. - * + * * Licensed under the Apache License, Version 2.0 (the "License"). You may not - * use this file except in compliance with the License. You may obtain a copy + * use this file except in compliance with the License. You may obtain a copy * of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "LICENSE" file accompanying this file. This file is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing + * + * or in the "LICENSE" file accompanying this file. This file is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing * permissions and limitations under the License. */ +using Intacct.SDK.Credentials; +using Intacct.SDK.Functions; +using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; using System.IO; using System.Net.Http; using System.Net.Http.Headers; using System.Threading.Tasks; -using Intacct.SDK.Credentials; -using Intacct.SDK.Functions; -using Microsoft.Extensions.Logging; namespace Intacct.SDK.Xml { @@ -43,7 +43,7 @@ public RequestHandler(ClientConfig clientConfig, RequestConfig requestConfig) this.RequestConfig = requestConfig; } - + public async Task ExecuteOnline(List content) { if (!string.IsNullOrEmpty(this.RequestConfig.PolicyId)) @@ -83,7 +83,7 @@ public async Task ExecuteOffline(List content) return response; } - + private HttpMessageHandler GetHttpMessageHandler() { if (this.ClientConfig.MockHandler != null) @@ -101,7 +101,6 @@ private HttpMessageHandler GetHttpMessageHandler() { HttpClientHandler httpClientHandler = new HttpClientHandler(); - if (this.ClientConfig.Logger != null) { return new LoggingHandler(httpClientHandler, this.ClientConfig.Logger, this.ClientConfig.LogMessageFormatter, this.ClientConfig.LogLevel); @@ -120,13 +119,13 @@ private static int ExponentialDelay(int retries) private async Task Execute(Stream requestXml) { - HttpClient client = new HttpClient(GetHttpMessageHandler()); - client.Timeout = this.RequestConfig.MaxTimeout; - client.DefaultRequestHeaders.UserAgent.ParseAdd("intacct-sdk-net-client/" + RequestHandler.Version); + HttpClient client = new HttpClient(GetHttpMessageHandler()); + client.Timeout = this.RequestConfig.MaxTimeout; + client.DefaultRequestHeaders.UserAgent.ParseAdd("intacct-sdk-net-client/" + RequestHandler.Version); - requestXml.Position = 0; - StreamContent content = new StreamContent(requestXml); - content.Headers.ContentType = new MediaTypeHeaderValue("application/xml"); + requestXml.Position = 0; + StreamContent content = new StreamContent(requestXml); + content.Headers.ContentType = new MediaTypeHeaderValue("application/xml"); for (int attempt = 0; attempt <= this.RequestConfig.MaxRetries; attempt++) { @@ -140,7 +139,7 @@ private async Task Execute(Stream requestXml) int httpCode = (int)response.StatusCode; if (response.IsSuccessStatusCode) { - Stream stream= await response.Content.ReadAsStreamAsync().ConfigureAwait(false); + Stream stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false); return stream; } else if (Array.Exists(this.RequestConfig.NoRetryServerErrorCodes, element => element == httpCode)) @@ -161,7 +160,7 @@ private async Task Execute(Stream requestXml) Stream stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false); return stream; } - + // Throw exception for non-500 level errors response.EnsureSuccessStatusCode(); } @@ -170,4 +169,4 @@ private async Task Execute(Stream requestXml) throw new HttpRequestException("Request retry count exceeded max retry count: " + this.RequestConfig.MaxRetries.ToString()); } } -} +} \ No newline at end of file From 0da1583ac4238a871f6c5cc9becab799b8dbecf1 Mon Sep 17 00:00:00 2001 From: Peter Schubert Date: Thu, 29 Jun 2023 11:04:00 -0400 Subject: [PATCH 15/15] reformat again --- Intacct.SDK/Xml/RequestHandler.cs | 33 ++++++++++++++++--------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/Intacct.SDK/Xml/RequestHandler.cs b/Intacct.SDK/Xml/RequestHandler.cs index 40b164e1..93ac5348 100644 --- a/Intacct.SDK/Xml/RequestHandler.cs +++ b/Intacct.SDK/Xml/RequestHandler.cs @@ -1,27 +1,27 @@ /* * Copyright 2022 Sage Intacct, Inc. - * + * * Licensed under the Apache License, Version 2.0 (the "License"). You may not - * use this file except in compliance with the License. You may obtain a copy + * use this file except in compliance with the License. You may obtain a copy * of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "LICENSE" file accompanying this file. This file is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing + * + * or in the "LICENSE" file accompanying this file. This file is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing * permissions and limitations under the License. */ -using Intacct.SDK.Credentials; -using Intacct.SDK.Functions; -using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; using System.IO; using System.Net.Http; using System.Net.Http.Headers; using System.Threading.Tasks; +using Intacct.SDK.Credentials; +using Intacct.SDK.Functions; +using Microsoft.Extensions.Logging; namespace Intacct.SDK.Xml { @@ -43,7 +43,7 @@ public RequestHandler(ClientConfig clientConfig, RequestConfig requestConfig) this.RequestConfig = requestConfig; } - + public async Task ExecuteOnline(List content) { if (!string.IsNullOrEmpty(this.RequestConfig.PolicyId)) @@ -83,7 +83,7 @@ public async Task ExecuteOffline(List content) return response; } - + private HttpMessageHandler GetHttpMessageHandler() { if (this.ClientConfig.MockHandler != null) @@ -101,6 +101,7 @@ private HttpMessageHandler GetHttpMessageHandler() { HttpClientHandler httpClientHandler = new HttpClientHandler(); + if (this.ClientConfig.Logger != null) { return new LoggingHandler(httpClientHandler, this.ClientConfig.Logger, this.ClientConfig.LogMessageFormatter, this.ClientConfig.LogLevel); @@ -122,7 +123,7 @@ private async Task Execute(Stream requestXml) HttpClient client = new HttpClient(GetHttpMessageHandler()); client.Timeout = this.RequestConfig.MaxTimeout; client.DefaultRequestHeaders.UserAgent.ParseAdd("intacct-sdk-net-client/" + RequestHandler.Version); - + requestXml.Position = 0; StreamContent content = new StreamContent(requestXml); content.Headers.ContentType = new MediaTypeHeaderValue("application/xml"); @@ -139,7 +140,7 @@ private async Task Execute(Stream requestXml) int httpCode = (int)response.StatusCode; if (response.IsSuccessStatusCode) { - Stream stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false); + Stream stream= await response.Content.ReadAsStreamAsync().ConfigureAwait(false); return stream; } else if (Array.Exists(this.RequestConfig.NoRetryServerErrorCodes, element => element == httpCode)) @@ -160,7 +161,7 @@ private async Task Execute(Stream requestXml) Stream stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false); return stream; } - + // Throw exception for non-500 level errors response.EnsureSuccessStatusCode(); } @@ -169,4 +170,4 @@ private async Task Execute(Stream requestXml) throw new HttpRequestException("Request retry count exceeded max retry count: " + this.RequestConfig.MaxRetries.ToString()); } } -} \ No newline at end of file +}