Skip to content

Commit bf2782c

Browse files
committed
add Telerik document features
1 parent 22b4c66 commit bf2782c

24 files changed

+1212
-13
lines changed

API/Controllers/DocumentProcessingController.cs

Lines changed: 595 additions & 0 deletions
Large diffs are not rendered by default.

API/P1.API.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,17 @@
3939
</PackageReference>
4040
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
4141
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
42+
<PackageReference Include="Telerik.Documents.Core" Version="2022.1.217" />
43+
<PackageReference Include="Telerik.Documents.Fixed" Version="2022.1.217" />
44+
<PackageReference Include="Telerik.Documents.Flow" Version="2022.1.217" />
45+
<PackageReference Include="Telerik.Documents.Spreadsheet" Version="2022.1.217" />
4246
<PackageReference Include="Telerik.Reporting.Services.AspNetCore" Version="16.0.22.225" />
4347
</ItemGroup>
4448

4549
<ItemGroup>
4650
<ProjectReference Include="..\Client\Client.csproj" />
4751
<ProjectReference Include="..\Data\P3.Data.csproj" />
52+
<ProjectReference Include="..\DocumentProcessing\P8.DocumentProcessing.csproj" />
4853
<ProjectReference Include="..\Migrator\P7.Migrator.csproj" />
4954
<ProjectReference Include="..\Service\P2.Service.csproj" />
5055
</ItemGroup>

API/RegisterModule.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Service;
55
using MediatR;
66
using Microsoft.AspNetCore.Authorization;
7+
using DocumentProcessing;
78

89
namespace API {
910
public class RegisterModule : Module {
@@ -50,6 +51,10 @@ protected override void Load(ContainerBuilder builder) {
5051
builder.RegisterType<AuthorizationResultTransformer>().As<IAuthorizationMiddlewareResultHandler>()
5152
.SingleInstance();
5253
//builder.RegisterType<JWTUtil>().As<IJWTUtil>().SingleInstance();
54+
builder.RegisterType<PdfProcessing>().As<IPdfProcessing>();
55+
builder.RegisterType<WordProcessing>().As<IWordProcessing>();
56+
builder.RegisterType<SpreadProcessing>().As<ISpreadProcessing>();
57+
builder.RegisterType<ZipProcessing>().As<IZipProcessing>();
5358
}
5459
}
5560

Client/Client.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<PackageReference Include="Blazored.LocalStorage" Version="4.2.0" />
2222
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.3" />
2323
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.3" PrivateAssets="all" />
24+
<PackageReference Include="Microsoft.Authentication.WebAssembly.Msal" Version="6.0.5" />
2425
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0" />
2526
<PackageReference Include="Telerik.ReportViewer.Blazor" Version="16.0.22.225" />
2627
<PackageReference Include="Telerik.UI.for.Blazor" Version="3.1.0" />
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
@page "/documentprocessing"
2+
@using System.Diagnostics
3+
@inject HttpUtil _httpUtil
4+
@inject IJSRuntime JsRuntime
5+
6+
<h3>Document Processing</h3>
7+
8+
<TelerikButton OnClick="@ExportPDF" Icon="file-pdf" Title="Export PDF"></TelerikButton>
9+
<TelerikButton OnClick="@MergePDF" Icon="file-ascx" Title="Merge PDF"></TelerikButton>
10+
<TelerikButton OnClick="@ExportDocx" Icon="file-word" Title="Export Docx"></TelerikButton>
11+
<TelerikButton OnClick="@ExportXlsx" Icon="file-excel" Title="Export Xlsx"></TelerikButton>
12+
<div class="k-form k-form-horizontal div-container">
13+
<label>Zip Files Demo</label>
14+
<div class="k-form-field-wrap">
15+
<TelerikUpload SaveUrl="@SaveUrl"
16+
AllowedExtensions="@AllowedExtensions"
17+
AutoUpload="false"
18+
MinFileSize="@MinFileSize"
19+
MaxFileSize="@MaxFileSize"
20+
Multiple="true"
21+
OnUpload="@UploadHandler">
22+
</TelerikUpload>
23+
<div class="k-form-hint">Accepted files: <strong>DOCX, PDF, JPG and PNG</strong></div>
24+
<div calss="div-container">
25+
<TelerikTextBox Width="200px" Value="@Password" Title="Password" ValueChanged="@PasswordChanged" PlaceHolder="Password for protect."></TelerikTextBox>
26+
<TelerikButton OnClick="@ZipFiles" Icon="file-zip" Title="Zip all uploaded files."></TelerikButton>
27+
</div>
28+
29+
</div>
30+
</div>
31+
<div class="loader-container">
32+
<TelerikLoader Class="loader-indicator" Type="@LoaderType.InfiniteSpinner" Size="@(ThemeConstants.Loader.Size.Large)" Visible="@IsLoad"></TelerikLoader>
33+
</div>
34+
35+
@code {
36+
public bool IsLoad { get; set; } = false;
37+
public string Password { get; set; }
38+
public async Task PasswordChanged(string value) {
39+
Password = value;
40+
}
41+
public async Task ExportPDF() {
42+
IsLoad = true;
43+
var response = await _httpUtil.GetAsync("documentprocessing/exporttopdf");
44+
var fileData = await response.Content.ReadAsByteArrayAsync();
45+
Save(fileData, "application/pdf", "Sample Document.pdf");
46+
}
47+
48+
public async Task MergePDF() {
49+
IsLoad = true;
50+
var response = await _httpUtil.GetAsync("documentprocessing/mergepdf");
51+
var fileData = await response.Content.ReadAsByteArrayAsync();
52+
Save(fileData, "application/pdf", "Merge Sample Document.pdf");
53+
}
54+
public async Task ExportDocx() {
55+
IsLoad = true;
56+
var response = await _httpUtil.GetAsync("documentprocessing/exporttodocx");
57+
var fileData = await response.Content.ReadAsByteArrayAsync();
58+
Save(fileData, "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "Sample Document.docx");
59+
}
60+
public async Task ExportXlsx() {
61+
IsLoad = true;
62+
var response = await _httpUtil.GetAsync("documentprocessing/exporttoxlsx");
63+
var fileData = await response.Content.ReadAsByteArrayAsync();
64+
Save(fileData, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "Sample Document.xlsx");
65+
66+
}
67+
public string SaveUrl => "documentprocessing/uploadfiles";
68+
public List<string> AllowedExtensions { get; set; } = new List<string>() { ".docx", ".pdf", ".jpg", ".png" };
69+
public int MinFileSize { get; set; } = 1024;
70+
public int MaxFileSize { get; set; } = 4 * 1024 * 1024;
71+
public async Task UploadHandler(UploadEventArgs e) {
72+
e.RequestHeaders = new Dictionary<string, object>();
73+
await _httpUtil.RefreshToken(e.RequestHeaders);
74+
}
75+
public async Task ZipFiles() {
76+
IsLoad = true;
77+
var response = await _httpUtil.GetAsync($"documentprocessing/zipfiles?password={Password}");
78+
var fileData = await response.Content.ReadAsByteArrayAsync();
79+
Save(fileData, "application/x-zip-compressed", "ZipDemo.zip");
80+
}
81+
public void Save(byte[] byteData, string mimeType, string fileName) {
82+
if (byteData == null) {
83+
return;
84+
}
85+
var fileBase64=Convert.ToBase64String(byteData);
86+
JsRuntime.InvokeVoidAsync("saveFile", fileBase64, mimeType, fileName);
87+
IsLoad = false;
88+
}
89+
}

Client/Shared/NavMenu/DrawerMenu.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public static class DrawerMenu {
1818
new DrawerItem{ Text = "Search User", Icon = "dollar", Url="/dotnet6EAA/searchuser", Group = "app"},
1919
new DrawerItem{ Text = "Report", Icon = "dollar", Url="/dotnet6EAA/Report", Group = "app"},
2020
new DrawerItem{ Text = "System Parameters", Icon = "tell-a-friend", Url="/dotnet6EAA/systemparameters/searchdatas", Group = "app"},
21+
new DrawerItem{ Text = "Document Processing", Icon = "tell-a-friend", Url="/dotnet6EAA/documentprocessing", Group = "app"},
2122
new DrawerItem{ Text = "Swagger UI", Icon="gear", Url="/dotnet6EAA/swagger/index.html",Group="settings",Target= MenuTarget.Blank.Code},
2223
};
2324
}

Client/Util/GeneralSearchUtil.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ private async Task PostData(HttpContent jsonContent, string apiUrl) {
6565
Notspinning = true;
6666
if (response == null) {
6767
Message = "Response data is null";
68+
return;
6869
}
6970
var content = await response.Content.ReadAsStringAsync();
7071
if (response.IsSuccessStatusCode) {
@@ -85,6 +86,7 @@ public async Task DeleteAsync(string apiUrl) {
8586
Notspinning = true;
8687
if (response == null) {
8788
Message = "Response data is null";
89+
return;
8890
}
8991
var content = await response.Content.ReadAsStringAsync();
9092
if (response.IsSuccessStatusCode) {

Client/Util/HttpUtil.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
using Common;
22
using System.Net.Http.Json;
33
using Microsoft.JSInterop;
4+
using Microsoft.AspNetCore.Components.WebAssembly.Authentication;
45

56
namespace Client {
67
public class HttpUtil {
78
private readonly HttpClient _http;
8-
private IJSRuntime _jSRuntime;
9-
public HttpUtil(HttpClient http, IJSRuntime jsRuntime) {
9+
private readonly IJSRuntime _jSRuntime;
10+
public HttpUtil(HttpClient http, IJSRuntime jsRuntime, IServiceProvider serviceProvider) {
1011
_http = http;
1112
_jSRuntime = jsRuntime;
1213
}
1314
public async Task<HttpResponseMessage> PostAsync(string? requestUri, HttpContent? content) {
1415
await RefreshToken();
15-
return await _http.PostAsync($"{requestUri}", content);
16+
return await _http.PostAsync($"{requestUri}", content);
1617
}
1718
public async Task<HttpResponseMessage> GetAsync(string? requestUri) {
19+
await RefreshToken();
1820
return await _http.GetAsync($"{requestUri}");
1921
}
2022
public async Task<HttpResponseMessage> PostAsJsonAsync(string? requestUri, object? content) {
@@ -25,9 +27,9 @@ public async Task<T> GetFromJsonAsync<T>(string? requestUri) {
2527
await RefreshToken();
2628
return await _http.GetFromJsonAsync<T>($"{requestUri}");
2729
}
28-
private async Task RefreshToken() {
30+
public async Task RefreshToken() {
2931
AuthResult authResult;
30-
authResult = await _http.GetFromJsonAsync<AuthResult>("Login");
32+
authResult = await _http.GetFromJsonAsync<AuthResult>("Login") ?? new AuthResult();
3133

3234
_http.DefaultRequestHeaders.Remove("X-UserRoles");
3335
_http.DefaultRequestHeaders.Add("X-UserRoles", authResult.Token);
@@ -36,6 +38,12 @@ private async Task RefreshToken() {
3638
_http.DefaultRequestHeaders.Remove("X-CSRF-TOKEN-HEADER");
3739
_http.DefaultRequestHeaders.Add("X-CSRF-TOKEN-HEADER", token);
3840
}
39-
41+
public async Task RefreshToken(Dictionary<string, object> requestHeaders) {
42+
AuthResult authResult;
43+
authResult = await _http.GetFromJsonAsync<AuthResult>("Login") ?? new AuthResult();
44+
requestHeaders.Add("X-UserRoles", authResult.Token);
45+
var token = await _jSRuntime.InvokeAsync<string>("getCookie", "XSRF-TOKEN");
46+
requestHeaders.Add("X-CSRF-TOKEN-HEADER", token);
47+
}
4048
}
4149
}

Client/wwwroot/css/app.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,3 +455,14 @@ a {
455455
.k-notification-group {
456456
width: fit-content;
457457
}
458+
.loader-size-title {
459+
display: block;
460+
margin-bottom: 10px;
461+
}
462+
463+
.loader-container {
464+
text-align: center;
465+
width: 100%;
466+
display: inline-table;
467+
padding-top: 10px;
468+
}

Client/wwwroot/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<link href="Client.styles.css" rel="stylesheet" />
1414
<link rel="stylesheet" href="_content/Telerik.UI.for.Blazor/css/kendo-theme-default/all.css" />
1515
<script src="_content/Telerik.UI.for.Blazor/js/telerik-blazor.js" defer></script>
16+
<script src="js/download-upload-files.js"></script>
1617
</head>
1718

1819
<body>

0 commit comments

Comments
 (0)