From 2bbbe2d0351f13b531c18941dd9e1e834658f656 Mon Sep 17 00:00:00 2001 From: vitalii-bezuhlyi Date: Wed, 31 Jul 2024 10:45:15 +0300 Subject: [PATCH 1/4] Added handling for too many request error --- Apps.XtrfCustomerPortal/Api/ApiClient.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Apps.XtrfCustomerPortal/Api/ApiClient.cs b/Apps.XtrfCustomerPortal/Api/ApiClient.cs index 18bb946..343fb88 100644 --- a/Apps.XtrfCustomerPortal/Api/ApiClient.cs +++ b/Apps.XtrfCustomerPortal/Api/ApiClient.cs @@ -1,3 +1,5 @@ +using System.Net; +using System.Text.RegularExpressions; using System.Xml.Serialization; using Apps.XtrfCustomerPortal.Constants; using Apps.XtrfCustomerPortal.Models.Dtos; @@ -94,6 +96,11 @@ private async Task GetTokenAsync() protected override Exception ConfigureErrorException(RestResponse response) { + if (response.StatusCode == HttpStatusCode.TooManyRequests) + { + return new Exception(ParseHtmlErrorMessage(response.Content!)); + } + try { var xmlSerializer = new XmlSerializer(typeof(XmlErrorDto)); @@ -119,4 +126,10 @@ protected override Exception ConfigureErrorException(RestResponse response) return new Exception($"Unexpected error during error deserialization: {ex.Message}; Error body: {response.Content!} ; Status code: {response.StatusCode}"); } } + + private string ParseHtmlErrorMessage(string htmlContent) + { + var match = Regex.Match(htmlContent, @"

([^<]+)

"); + return match.Success ? match.Groups[1].Value : "Unknown HTML error"; + } } \ No newline at end of file From 4905477f617672893b05880baddaaa30666816a5 Mon Sep 17 00:00:00 2001 From: vitalii-bezuhlyi Date: Wed, 31 Jul 2024 11:21:33 +0300 Subject: [PATCH 2/4] Minor improvements --- .../Models/Requests/CreateProjectRequest.cs | 4 ++-- Apps.XtrfCustomerPortal/Models/Requests/QuoteCreateRequest.cs | 4 ++-- .../Utilities/Extensions/DateTimeExtensions.cs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Apps.XtrfCustomerPortal/Models/Requests/CreateProjectRequest.cs b/Apps.XtrfCustomerPortal/Models/Requests/CreateProjectRequest.cs index 92c95d8..e6281c0 100644 --- a/Apps.XtrfCustomerPortal/Models/Requests/CreateProjectRequest.cs +++ b/Apps.XtrfCustomerPortal/Models/Requests/CreateProjectRequest.cs @@ -38,10 +38,10 @@ public class CreateProjectRequest [Display("Contact person ID"), DataSource(typeof(PersonDataSource))] public string PersonId { get; set; } - [Display("Send back to ID"), DataSource(typeof(PersonDataSource))] + [Display("Send back to contact person ID"), DataSource(typeof(PersonDataSource))] public string? SendBackToId { get; set; } - [Display("Additional person IDs"), DataSource(typeof(PersonDataSource))] + [Display("Additional contact IDs"), DataSource(typeof(PersonDataSource))] public IEnumerable? AdditionalPersonIds { get; set; } [Display("Reference files")] diff --git a/Apps.XtrfCustomerPortal/Models/Requests/QuoteCreateRequest.cs b/Apps.XtrfCustomerPortal/Models/Requests/QuoteCreateRequest.cs index e55e7f7..f6192ce 100644 --- a/Apps.XtrfCustomerPortal/Models/Requests/QuoteCreateRequest.cs +++ b/Apps.XtrfCustomerPortal/Models/Requests/QuoteCreateRequest.cs @@ -38,10 +38,10 @@ public class QuoteCreateRequest [Display("Contact person ID"), DataSource(typeof(PersonDataSource))] public string PersonId { get; set; } - [Display("Send back to ID"), DataSource(typeof(PersonDataSource))] + [Display("Send back to contact person ID"), DataSource(typeof(PersonDataSource))] public string? SendBackToId { get; set; } - [Display("Additional person IDs"), DataSource(typeof(PersonDataSource))] + [Display("Additional contact IDs"), DataSource(typeof(PersonDataSource))] public IEnumerable? AdditionalPersonIds { get; set; } [Display("Reference files")] diff --git a/Apps.XtrfCustomerPortal/Utilities/Extensions/DateTimeExtensions.cs b/Apps.XtrfCustomerPortal/Utilities/Extensions/DateTimeExtensions.cs index 44f03f9..6855e96 100644 --- a/Apps.XtrfCustomerPortal/Utilities/Extensions/DateTimeExtensions.cs +++ b/Apps.XtrfCustomerPortal/Utilities/Extensions/DateTimeExtensions.cs @@ -21,7 +21,7 @@ public static DateTime ParseDate(this string? dateString) if (DateTimeOffset.TryParseExact(dateString, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTimeOffset parsedDate)) { - return parsedDate.DateTime; + return parsedDate.DateTime.ToUniversalTime(); } return DateTime.MinValue; From 9934cfc0444fcc48e0c00d4ca70ca43ee4f4fdf6 Mon Sep 17 00:00:00 2001 From: vitalii-bezuhlyi Date: Wed, 31 Jul 2024 11:26:22 +0300 Subject: [PATCH 3/4] Updated csproj --- Apps.XtrfCustomerPortal/Apps.XtrfCustomerPortal.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Apps.XtrfCustomerPortal/Apps.XtrfCustomerPortal.csproj b/Apps.XtrfCustomerPortal/Apps.XtrfCustomerPortal.csproj index 46fb7a7..11c87f4 100644 --- a/Apps.XtrfCustomerPortal/Apps.XtrfCustomerPortal.csproj +++ b/Apps.XtrfCustomerPortal/Apps.XtrfCustomerPortal.csproj @@ -6,7 +6,7 @@ enable XTRF Customer portal The XTRF Customer Portal is a private website restricted to authorized use for business purposes. It allows clients to access and manage translation project details. Within the portal, clients can view and edit information such as contact details, account manager, pricing, language combinations, and CAT tools used. - 1.0.1 + 1.0.2 Apps.XtrfCustomerPortal Apps.XtrfCustomerPortal From 502115eec3dfb022de1387c4895b824b3b284b33 Mon Sep 17 00:00:00 2001 From: vitalii-bezuhlyi Date: Tue, 13 Aug 2024 10:44:57 +0300 Subject: [PATCH 4/4] Download project translated files improvements --- Apps.XtrfCustomerPortal/Actions/ProjectActions.cs | 9 +++++---- Apps.XtrfCustomerPortal/Apps.XtrfCustomerPortal.csproj | 6 +++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Apps.XtrfCustomerPortal/Actions/ProjectActions.cs b/Apps.XtrfCustomerPortal/Actions/ProjectActions.cs index 20f143e..cebe61c 100644 --- a/Apps.XtrfCustomerPortal/Actions/ProjectActions.cs +++ b/Apps.XtrfCustomerPortal/Actions/ProjectActions.cs @@ -113,18 +113,19 @@ public async Task DownloadProjectFiles( await Client.ExecuteRequestAsync($"/projects/{projectIdentifier.ProjectId}/files", Method.Get, null); var files = taskFilesDto.TasksFiles.SelectMany(x => x.Output?.Files ?? new List()).ToList(); - + var fileReferences = new List(); foreach (var file in files) { - var invoicePdf = await Client.ExecuteRequestAsync($"/projects/files/{file.Id}", Method.Get, null, + var filesResponse = await Client.ExecuteRequestAsync($"/projects/files/{file.Id}", Method.Get, null, "application/octet-stream"); - var rawBytes = invoicePdf.RawBytes!; + var rawBytes = filesResponse.RawBytes!; var stream = new MemoryStream(rawBytes); stream.Position = 0; - var fileReference = await fileManagementClient.UploadAsync(stream, "application/octet-stream", file.Name); + var mimeType = MimeTypes.GetMimeType(file.Name); + var fileReference = await fileManagementClient.UploadAsync(stream, mimeType, file.Name); fileReferences.Add(fileReference); } diff --git a/Apps.XtrfCustomerPortal/Apps.XtrfCustomerPortal.csproj b/Apps.XtrfCustomerPortal/Apps.XtrfCustomerPortal.csproj index 11c87f4..f341abf 100644 --- a/Apps.XtrfCustomerPortal/Apps.XtrfCustomerPortal.csproj +++ b/Apps.XtrfCustomerPortal/Apps.XtrfCustomerPortal.csproj @@ -6,7 +6,7 @@ enable XTRF Customer portal The XTRF Customer Portal is a private website restricted to authorized use for business purposes. It allows clients to access and manage translation project details. Within the portal, clients can view and edit information such as contact details, account manager, pricing, language combinations, and CAT tools used. - 1.0.2 + 1.0.3 Apps.XtrfCustomerPortal Apps.XtrfCustomerPortal @@ -14,6 +14,10 @@ + + all + runtime; build; native; contentfiles; analyzers; buildtransitive +