From 39d1d09ab094018cc7514b4e523a72039d5b7d51 Mon Sep 17 00:00:00 2001 From: Koen Janssen Date: Mon, 12 Jun 2023 11:41:54 +0200 Subject: [PATCH] Removed PersonaPage type and PersonaPage fetcher. --- .../Component/CompetenceProfile.cs | 1 - Epsilon.Abstractions/Component/Page.cs | 3 +- Epsilon.Abstractions/Component/PersonaPage.cs | 24 ------- .../Service/IFilterService.cs | 1 - Epsilon.Host.WebApi/Program.cs | 2 +- .../Component/PersonaPageComponentFetcher.cs | 66 ------------------- Epsilon/Service/FilterService.cs | 1 - 7 files changed, 2 insertions(+), 96 deletions(-) delete mode 100644 Epsilon.Abstractions/Component/PersonaPage.cs delete mode 100644 Epsilon/Component/PersonaPageComponentFetcher.cs diff --git a/Epsilon.Abstractions/Component/CompetenceProfile.cs b/Epsilon.Abstractions/Component/CompetenceProfile.cs index 75f00fe1..e69ab6eb 100644 --- a/Epsilon.Abstractions/Component/CompetenceProfile.cs +++ b/Epsilon.Abstractions/Component/CompetenceProfile.cs @@ -1,7 +1,6 @@ using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Wordprocessing; using Epsilon.Abstractions.Model; -using Epsilon.Canvas.Abstractions.Model; namespace Epsilon.Abstractions.Component; diff --git a/Epsilon.Abstractions/Component/Page.cs b/Epsilon.Abstractions/Component/Page.cs index 83db4282..14e2b728 100644 --- a/Epsilon.Abstractions/Component/Page.cs +++ b/Epsilon.Abstractions/Component/Page.cs @@ -4,8 +4,7 @@ namespace Epsilon.Abstractions.Component; -[CompetenceComponentName("persona_page")] -public record Page(string Html) : ICompetenceWordComponent +public record Page(string Html) : IWordCompetenceComponent { public void AddToWordDocument(MainDocumentPart mainDocumentPart) { diff --git a/Epsilon.Abstractions/Component/PersonaPage.cs b/Epsilon.Abstractions/Component/PersonaPage.cs deleted file mode 100644 index 8c2d6c2b..00000000 --- a/Epsilon.Abstractions/Component/PersonaPage.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System.Text; -using DocumentFormat.OpenXml.Packaging; -using DocumentFormat.OpenXml.Wordprocessing; - -namespace Epsilon.Abstractions.Component; - -public record PersonaPage(string PersonaHtml) : IWordCompetenceComponent -{ - public void AddToWordDocument(MainDocumentPart mainDocumentPart) - { - var personaHtmlBuffer = Encoding.UTF8.GetPreamble().Concat(Encoding.UTF8.GetBytes($"{PersonaHtml}")).ToArray(); - using var personaHtmlStream = new MemoryStream(personaHtmlBuffer); - - var formatImportPart = mainDocumentPart.AddAlternativeFormatImportPart(AlternativeFormatImportPartType.Html); - formatImportPart.FeedData(personaHtmlStream); - - mainDocumentPart.Document.AppendChild(new Body( - new AltChunk - { - Id = mainDocumentPart.GetIdOfPart(formatImportPart), - } - )); - } -} \ No newline at end of file diff --git a/Epsilon.Abstractions/Service/IFilterService.cs b/Epsilon.Abstractions/Service/IFilterService.cs index 5f11bac0..604629ed 100644 --- a/Epsilon.Abstractions/Service/IFilterService.cs +++ b/Epsilon.Abstractions/Service/IFilterService.cs @@ -1,4 +1,3 @@ -using Epsilon.Abstractions.Component; using Epsilon.Canvas.Abstractions.Model; namespace Epsilon.Abstractions.Service; diff --git a/Epsilon.Host.WebApi/Program.cs b/Epsilon.Host.WebApi/Program.cs index 2f459222..8557f22e 100644 --- a/Epsilon.Host.WebApi/Program.cs +++ b/Epsilon.Host.WebApi/Program.cs @@ -29,7 +29,7 @@ builder.Services.AddScoped(static (services) => new CompetenceComponentService( new Dictionary { - { "persona_page", services.GetRequiredService>() }, + { "persona_page", services.GetRequiredService>() }, { "competence_profile", services.GetRequiredService>() }, { "kpi_matrix", services.GetRequiredService>() }, } diff --git a/Epsilon/Component/PersonaPageComponentFetcher.cs b/Epsilon/Component/PersonaPageComponentFetcher.cs deleted file mode 100644 index 889fddef..00000000 --- a/Epsilon/Component/PersonaPageComponentFetcher.cs +++ /dev/null @@ -1,66 +0,0 @@ -using Epsilon.Abstractions.Component; -using Epsilon.Canvas; -using Epsilon.Canvas.Abstractions.Service; -using HtmlAgilityPack; -using Microsoft.Extensions.Options; - -namespace Epsilon.Component; - -public class PersonaPageComponentFetcher : CompetenceComponentFetcher -{ - private readonly IPageHttpService _pageHttpService; - private readonly IFileHttpService _fileHttpService; - private readonly CanvasSettings _canvasSettings; - - public PersonaPageComponentFetcher( - IPageHttpService pageHttpService, - IFileHttpService fileHttpService, - IOptions canvasSettings - ) - { - _pageHttpService = pageHttpService; - _fileHttpService = fileHttpService; - _canvasSettings = canvasSettings.Value; - } - - public override async Task Fetch(DateTime startDate, DateTime endDate) - { - var courseId = _canvasSettings.CourseId; - var personaHtml = await _pageHttpService.GetPageByName(courseId, "front_page"); - - var updatedPersonaHtml = await GetPersonaHtmlDocument(personaHtml); - - var personaPage = new PersonaPage(updatedPersonaHtml.Text); - - return personaPage; - } - - private async Task GetPersonaHtmlDocument(string htmlString) - { - var htmlDoc = new HtmlDocument(); - htmlDoc.LoadHtml(htmlString); - if (htmlDoc.DocumentNode.SelectNodes("//img") == null) - { - return htmlDoc; - } - - foreach (var node in htmlDoc.DocumentNode.SelectNodes("//img")) - { - var imageSrc = node - .SelectNodes("//img") - .First() - .Attributes["src"].Value; - - if (imageSrc != null) - { - var imageBytes = await _fileHttpService.GetFileByteArray(new Uri(imageSrc)); - var imageBase64 = Convert.ToBase64String(imageBytes.ToArray()); - - node.SetAttributeValue("src", $"data:image/jpeg;base64,{imageBase64}"); - } - } - - return htmlDoc; - } - -} \ No newline at end of file diff --git a/Epsilon/Service/FilterService.cs b/Epsilon/Service/FilterService.cs index 2e6bbc8e..b9b92c8c 100644 --- a/Epsilon/Service/FilterService.cs +++ b/Epsilon/Service/FilterService.cs @@ -1,4 +1,3 @@ -using DocumentFormat.OpenXml; using Epsilon.Abstractions.Service; using Epsilon.Canvas.Abstractions.Model; using Epsilon.Canvas.Abstractions.Model.GraphQl;