Issue #3:
authoraic.eichhorner.1227328 <e1227328@student.tuwien.ac.at>
Sat, 27 Oct 2018 16:51:19 +0000 (18:51 +0200)
committeraic.eichhorner.1227328 <e1227328@student.tuwien.ac.at>
Sat, 27 Oct 2018 16:51:19 +0000 (18:51 +0200)
Added PDF Generator library
Updated docker file
Updated conroller routes

PdfService/Controllers/PdfController.cs [new file with mode: 0644]
PdfService/Controllers/ValuesController.cs [deleted file]
PdfService/DOCKERFILE
PdfService/Models/Tweet.cs [new file with mode: 0644]
PdfService/PdfService.csproj
PdfService/Startup.cs
PdfService/Utility/TemplateGenerator.cs [new file with mode: 0644]
PdfService/libwkhtmltox.dll [new file with mode: 0644]
PdfService/libwkhtmltox.dylib [new file with mode: 0644]
PdfService/libwkhtmltox.so [new file with mode: 0644]
PdfService/readme.md

diff --git a/PdfService/Controllers/PdfController.cs b/PdfService/Controllers/PdfController.cs
new file mode 100644 (file)
index 0000000..455c324
--- /dev/null
@@ -0,0 +1,53 @@
+using DinkToPdf;
+using DinkToPdf.Contracts;
+using Microsoft.AspNetCore.Mvc;
+using System.IO;
+
+namespace PdfService.Controllers
+{
+
+    
+    [ApiController]
+    public class PdfController : ControllerBase
+    {
+        private IConverter _converter;
+
+        public PdfController(IConverter converter)
+        {
+            _converter = converter;
+        }
+        // GET /generatePDF
+        [Route("generatePDF")]
+        [HttpGet]
+        public ActionResult Get()
+        {
+            var globalSettings = new GlobalSettings
+            {
+                ColorMode = ColorMode.Color,
+                Orientation = Orientation.Portrait,
+                PaperSize = PaperKind.A4,
+                Margins = new MarginSettings { Top = 10 },
+                DocumentTitle = "PDF Report",
+            };
+            var objectSettings = new ObjectSettings
+            {
+                PagesCount = true,
+                HtmlContent = "test",
+                WebSettings = { DefaultEncoding = "utf-8", UserStyleSheet =  Path.Combine(Directory.GetCurrentDirectory(), "assets", "styles.css") },
+                HeaderSettings = { FontName = "Arial", FontSize = 9, Right = "Page [page] of [toPage]", Line = true },
+                FooterSettings = { FontName = "Arial", FontSize = 9, Line = true, Center = "Report Footer" }
+            };
+            var pdf = new HtmlToPdfDocument()
+            {
+                GlobalSettings = globalSettings,
+                Objects = { objectSettings }
+            };
+            var file = _converter.Convert(pdf);
+            return File(file, "application/pdf");
+        }
+
+    }
+}
diff --git a/PdfService/Controllers/ValuesController.cs b/PdfService/Controllers/ValuesController.cs
deleted file mode 100644 (file)
index 22dad6b..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading.Tasks;
-using Microsoft.AspNetCore.Mvc;
-
-namespace PdfService.Controllers
-{
-    [Route("api/[controller]")]
-    [ApiController]
-    public class ValuesController : ControllerBase
-    {
-        // GET api/values
-        [HttpGet]
-        public ActionResult<IEnumerable<string>> Get()
-        {
-            return new string[] { "value1", "value2" };
-        }
-
-        // GET api/values/5
-        [HttpGet("{id}")]
-        public ActionResult<string> Get(int id)
-        {
-            return "value";
-        }
-
-        // POST api/values
-        [HttpPost]
-        public void Post([FromBody] string value)
-        {
-        }
-
-        // PUT api/values/5
-        [HttpPut("{id}")]
-        public void Put(int id, [FromBody] string value)
-        {
-        }
-
-        // DELETE api/values/5
-        [HttpDelete("{id}")]
-        public void Delete(int id)
-        {
-        }
-    }
-}
index 827e85b650b339a8b3b67b4a0e0f7386ab829938..afa6f7571d341776f92e2dfce608309ba4ab68d5 100644 (file)
@@ -10,7 +10,23 @@ COPY . ./
 RUN dotnet publish -c Release -o out
 
 # Build runtime image
-FROM microsoft/dotnet:2.2.0-preview3-aspnetcore-runtime-alpine
+FROM microsoft/dotnet:2.2.0-preview3-aspnetcore-runtime
 WORKDIR /app
 COPY --from=build-env /app/out .
+
+# copy pdf library
+# COPY libwkhtmltox.* ./
+# install additional libaries
+RUN apt-get update \
+    && apt-get install -y --no-install-recommends \
+        zlib1g \
+        fontconfig \
+        libfreetype6 \
+        libx11-6 \
+        libxext6 \
+        libxrender1 \
+    && curl -o /usr/lib/libwkhtmltox.so \
+        --location \
+        https://github.com/rdvojmoc/DinkToPdf/raw/v1.0.8/v0.12.4/64%20bit/libwkhtmltox.so
+
 ENTRYPOINT ["dotnet", "PdfService.dll"]
\ No newline at end of file
diff --git a/PdfService/Models/Tweet.cs b/PdfService/Models/Tweet.cs
new file mode 100644 (file)
index 0000000..624d8d6
--- /dev/null
@@ -0,0 +1,11 @@
+
+namespace PdfService.Models
+{
+    // represents the data got from sentiment analysis.
+    // TODO: adapt to real data from sentiment analysis
+    public class Tweet
+    {
+        public string Name { get; set; }
+        public string Sentiment { get; set; }
+    }
+}
\ No newline at end of file
index 265f5a5ff11d58c6059c1d0e835e24d138ae19f4..2da4a8f2cdb7cf514e186e885119bb83ab61a70e 100644 (file)
@@ -6,6 +6,7 @@
   </PropertyGroup>
 
   <ItemGroup>
+    <PackageReference Include="DinkToPdf" Version="1.0.8" />
     <PackageReference Include="Microsoft.AspNetCore.App" />
     <PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0-preview3-35497" PrivateAssets="All" />
   </ItemGroup>
index 883e4ba7c042f4cce98ab9b1ad61cdde29897d2f..9cb03518cb6d6863d992e5b8ce1f903a3c491fe5 100644 (file)
@@ -1,7 +1,10 @@
 using System;
 using System.Collections.Generic;
+using System.IO;
 using System.Linq;
 using System.Threading.Tasks;
+using DinkToPdf;
+using DinkToPdf.Contracts;
 using Microsoft.AspNetCore.Builder;
 using Microsoft.AspNetCore.Hosting;
 using Microsoft.AspNetCore.HttpsPolicy;
@@ -10,6 +13,7 @@ using Microsoft.Extensions.Configuration;
 using Microsoft.Extensions.DependencyInjection;
 using Microsoft.Extensions.Logging;
 using Microsoft.Extensions.Options;
+using PdfService.Utility;
 
 namespace PdfService
 {
@@ -26,6 +30,8 @@ namespace PdfService
         public void ConfigureServices(IServiceCollection services)
         {
             services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
+
+            services.AddSingleton(typeof(IConverter), new SynchronizedConverter(new PdfTools()));
         }
 
         // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
diff --git a/PdfService/Utility/TemplateGenerator.cs b/PdfService/Utility/TemplateGenerator.cs
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/PdfService/libwkhtmltox.dll b/PdfService/libwkhtmltox.dll
new file mode 100644 (file)
index 0000000..98a007b
Binary files /dev/null and b/PdfService/libwkhtmltox.dll differ
diff --git a/PdfService/libwkhtmltox.dylib b/PdfService/libwkhtmltox.dylib
new file mode 100644 (file)
index 0000000..0263cad
Binary files /dev/null and b/PdfService/libwkhtmltox.dylib differ
diff --git a/PdfService/libwkhtmltox.so b/PdfService/libwkhtmltox.so
new file mode 100644 (file)
index 0000000..eecc883
Binary files /dev/null and b/PdfService/libwkhtmltox.so differ
index d9724c67262023e570bbc427e98e21be1eda2e5c..b8c16ee652c055b24f9a8e942d9a60bba09571ea 100644 (file)
@@ -1,16 +1,16 @@
 # PDF Service
 
-Provides an API interface to generate PDF reports for given inputs
-`POST`: `/generatePdf/` (TODO)
+Provides an API interface to generate PDF reports for given tweets and their sentiment analysis result.
+`POST`: `/generatePDF/` (TODO)
 
-# run with docker
+## run with docker
 
-`docker build -t pdfservice .` if no local image is available
-`docker run -p YOUR_PORT:80 pdfservice:latest`
+- (if no local image is available) `docker build -t pdfservice .`    
+`docker run -p YOUR_PORT:80 pdfservice:latest`
 
-# run local
-## requirements
+## run local
+### requirements
 - .net core 2.2
 
-## commands
+### commands
 - `dotnet run`
\ No newline at end of file