Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #3

Merged
merged 4 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions Apps.XtrfCustomerPortal/Actions/ProjectActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,19 @@ public async Task<DownloadProjectFilesResponse> DownloadProjectFiles(
await Client.ExecuteRequestAsync<TaskFilesDto>($"/projects/{projectIdentifier.ProjectId}/files", Method.Get,
null);
var files = taskFilesDto.TasksFiles.SelectMany(x => x.Output?.Files ?? new List<TaskFilesDto.File>()).ToList();

var fileReferences = new List<FileReference>();
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);
}

Expand Down
13 changes: 13 additions & 0 deletions Apps.XtrfCustomerPortal/Api/ApiClient.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Net;
using System.Text.RegularExpressions;
using System.Xml.Serialization;
using Apps.XtrfCustomerPortal.Constants;
using Apps.XtrfCustomerPortal.Models.Dtos;
Expand Down Expand Up @@ -94,6 +96,11 @@ private async Task<LoginDto> 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));
Expand All @@ -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, @"<h1>([^<]+)</h1>");
return match.Success ? match.Groups[1].Value : "Unknown HTML error";
}
}
6 changes: 5 additions & 1 deletion Apps.XtrfCustomerPortal/Apps.XtrfCustomerPortal.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@
<Nullable>enable</Nullable>
<Product>XTRF Customer portal</Product>
<Description>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.</Description>
<Version>1.0.1</Version>
<Version>1.0.3</Version>
<PackageId>Apps.XtrfCustomerPortal</PackageId>
<AssemblyName>Apps.XtrfCustomerPortal</AssemblyName>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Blackbird.Applications.Sdk.Common" Version="2.8.0" />
<PackageReference Include="Blackbird.Applications.Sdk.Utils" Version="1.0.25" />
<PackageReference Include="MimeTypes" Version="2.5.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>? AdditionalPersonIds { get; set; }

[Display("Reference files")]
Expand Down
4 changes: 2 additions & 2 deletions Apps.XtrfCustomerPortal/Models/Requests/QuoteCreateRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>? AdditionalPersonIds { get; set; }

[Display("Reference files")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down