Skip to content

Commit 776fabd

Browse files
authored
Merge pull request #3 from DevExpress-Examples/fp-update-project
update project files
2 parents c4b401c + 6f96813 commit 776fabd

40 files changed

+275
-14146
lines changed

CS/BlazorAppWordProcessing.sln

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.12.35527.113 d17.12
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlazorAppWordProcessing", "BlazorAppWordProcessing\BlazorAppWordProcessing.csproj", "{3E860A22-CEDF-4FC1-A9D4-52102B917229}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{3E860A22-CEDF-4FC1-A9D4-52102B917229}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{3E860A22-CEDF-4FC1-A9D4-52102B917229}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{3E860A22-CEDF-4FC1-A9D4-52102B917229}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{3E860A22-CEDF-4FC1-A9D4-52102B917229}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal

CS/BlazorApp_WordDocumentAPI/BlazorApp_WordDocumentAPI.csproj renamed to CS/BlazorAppWordProcessing/BlazorAppWordProcessing.csproj

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk.Web">
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
44
<TargetFramework>net8.0</TargetFramework>
@@ -7,9 +7,10 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="DevExpress.Blazor" Version="24.2.*" />
11-
<PackageReference Include="DevExpress.Document.Processor" Version="24.2.*" />
12-
<PackageReference Include="MailKit" Version="4.7.1.1" />
10+
<PackageReference Include="DevExpress.Blazor" Version="24.2.3" />
11+
<PackageReference Include="DevExpress.Document.Processor" Version="24.2.3" />
12+
<PackageReference Include="DevExpress.Drawing.Skia" Version="24.2.3" />
13+
<PackageReference Include="MailKit" Version="4.9.0" />
1314
</ItemGroup>
1415

1516
<ItemGroup>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="utf-8" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<base href="/" />
8+
<link rel="stylesheet" href="bootstrap/bootstrap.min.css" />
9+
<link rel="stylesheet" href="app.css" />
10+
<link rel="stylesheet" href="BlazorAppWordProcessing.styles.css" />
11+
<link rel="icon" type="image/png" href="favicon.png" />
12+
<link href="_content/DevExpress.Blazor.Themes/blazing-berry.bs5.css" rel="stylesheet" />
13+
<script src="js/exportToPdf.js"></script>
14+
<HeadOutlet />
15+
</head>
16+
17+
<body>
18+
<Routes />
19+
<script src="_framework/blazor.web.js"></script>
20+
</body>
21+
22+
</html>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
@inherits LayoutComponentBase
2+
3+
<div class="page">
4+
<div class="sidebar">
5+
<NavMenu />
6+
</div>
7+
8+
<main>
9+
<div class="top-row px-4">
10+
<a href="https://learn.microsoft.com/aspnet/core/" target="_blank">About</a>
11+
</div>
12+
13+
<article class="content px-4">
14+
@Body
15+
</article>
16+
</main>
17+
</div>
18+
19+
<div id="blazor-error-ui">
20+
An unhandled error has occurred.
21+
<a href="" class="reload">Reload</a>
22+
<a class="dismiss">🗙</a>
23+
</div>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
@page "/Error"
2+
@using System.Diagnostics
3+
4+
<PageTitle>Error</PageTitle>
5+
6+
<h1 class="text-danger">Error.</h1>
7+
<h2 class="text-danger">An error occurred while processing your request.</h2>
8+
9+
@if (ShowRequestId)
10+
{
11+
<p>
12+
<strong>Request ID:</strong> <code>@RequestId</code>
13+
</p>
14+
}
15+
16+
<h3>Development Mode</h3>
17+
<p>
18+
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
19+
</p>
20+
<p>
21+
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
22+
It can result in displaying sensitive information from exceptions to end users.
23+
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
24+
and restarting the app.
25+
</p>
26+
27+
@code{
28+
[CascadingParameter]
29+
private HttpContext? HttpContext { get; set; }
30+
31+
private string? RequestId { get; set; }
32+
private bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
33+
34+
protected override void OnInitialized() =>
35+
RequestId = Activity.Current?.Id ?? HttpContext?.TraceIdentifier;
36+
}

CS/BlazorApp_WordDocumentAPI/Pages/Index.razor renamed to CS/BlazorAppWordProcessing/Components/Pages/Home.razor

Lines changed: 56 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
@page "/"
2+
@rendermode InteractiveServer
23
@inject IJSRuntime JS
3-
@using System.IO
4-
@using DevExpress.XtraRichEdit
54
@using MimeKit;
65
@using MailKit.Net.Smtp
76
@using Microsoft.Extensions.Logging
87
@inject ILogger<Index> logger
8+
99
<div class="container">
1010
<div class="card mt-3">
1111
<div class="card-header">
@@ -16,7 +16,7 @@
1616
<DxFormLayoutItem ColSpanMd="12">
1717
<Template>
1818
<p>
19-
This example uses the
19+
This example uses the
2020
<a href="https://www.devexpress.com/products/net/office-file-api/word/">Word Processing Document API</a>
2121
to generate personalized letters based on a template. Select a sender and click <b>Send emails</b> to send
2222
letters to all recipients. Click <b>Download</b> to download a letter in PDF format for a specific recipient.
@@ -38,26 +38,26 @@
3838
</DxFormLayoutItem>
3939
</DxFormLayout>
4040
<div class="col">
41-
<DxGrid Data="@dataSource.RecipientList"
42-
CssClass="mt-3" PagerVisible="false">
43-
<Columns>
44-
<DxGridDataColumn FieldName="@nameof(Recipient.ContactName)" Caption="Recipient" />
45-
<DxGridDataColumn FieldName="@nameof(Recipient.Email)" Caption="Email" />
46-
<DxGridDataColumn Caption="Attachment" Width="150px">
47-
<CellDisplayTemplate>
41+
<DxGrid Data="@dataSource.RecipientList"
42+
CssClass="mt-3" PagerVisible="false">
43+
<Columns>
44+
<DxGridDataColumn FieldName="@nameof(Recipient.ContactName)" Caption="Recipient" />
45+
<DxGridDataColumn FieldName="@nameof(Recipient.Email)" Caption="Email" />
46+
<DxGridDataColumn Caption="Attachment" Width="150px">
47+
<CellDisplayTemplate>
4848
@{
4949
var recipient = context.DataItem as Recipient;
5050
@if (recipient != null)
5151
{
52-
<DxButton Text="Download"
53-
CssClass="btn-block"
54-
Click="@((MouseEventArgs args) => DownloadPdf(recipient))" />
52+
<DxButton Text="Download"
53+
CssClass="btn-block"
54+
Click="@((MouseEventArgs args) => DownloadPdf(recipient))" />
5555
}
5656
}
57-
</CellDisplayTemplate>
58-
</DxGridDataColumn>
59-
</Columns>
60-
</DxGrid>
57+
</CellDisplayTemplate>
58+
</DxGridDataColumn>
59+
</Columns>
60+
</DxGrid>
6161
</div>
6262
</div>
6363
</div>
@@ -68,20 +68,26 @@
6868
SampleData dataSource = new();
6969
Sender? selectedSender;
7070

71-
Sender? SelectedSender {
71+
Sender? SelectedSender
72+
{
7273
get => selectedSender;
73-
set { selectedSender = value;
74-
InvokeAsync(StateHasChanged); }
74+
set
75+
{
76+
selectedSender = value;
77+
InvokeAsync(StateHasChanged);
78+
}
7579
}
7680

77-
protected override Task OnInitializedAsync() {
81+
protected override Task OnInitializedAsync()
82+
{
7883
selectedSender = dataSource.SenderList[0];
7984
documentServer.LoadDocument("Data/MailMerge.rtf", DocumentFormat.Rtf);
8085
return base.OnInitializedAsync();
8186
}
82-
87+
8388
<!--#region CreateAttachment-->
84-
MemoryStream CreateAttachment(Recipient recipient) {
89+
MemoryStream CreateAttachment(Recipient recipient)
90+
{
8591
ArgumentNullException.ThrowIfNull(SelectedSender);
8692

8793
using (var resultDocumentServer = new RichEditDocumentServer())
@@ -100,8 +106,8 @@
100106
}
101107
}
102108
<!--#endregion CreateAttachment-->
103-
104-
void DownloadPdf(Recipient recipient) {
109+
void DownloadPdf(Recipient recipient)
110+
{
105111
// Execute mail merge.
106112
using (MemoryStream stream = CreateAttachment(recipient))
107113
{
@@ -110,15 +116,18 @@
110116
Convert.ToBase64String(stream.ToArray()));
111117
}
112118
}
113-
119+
114120
<!--#region SendMessages-->
115-
void SendEmails(MouseEventArgs mouseEventArgs) {
121+
void SendEmails(MouseEventArgs mouseEventArgs)
122+
{
116123
// Obtain a list of recipients.
117124
List<Recipient> recipientList = dataSource.RecipientList;
118125

119-
for (int i = 0; i < recipientList.Count; i++) {
126+
for (int i = 0; i < recipientList.Count; i++)
127+
{
120128
// Execute mail merge to generate a letter for each recipient.
121-
using (MemoryStream attachmentStream = CreateAttachment(recipientList[i])) {
129+
using (MemoryStream attachmentStream = CreateAttachment(recipientList[i]))
130+
{
122131
// Create e-mail message for each recipient.
123132
// Attach letter to the message as a PDF file.
124133
MimeMessage message = CreateMessage("YOUR_EMAIL_ADDRESS",
@@ -129,7 +138,8 @@
129138
}
130139
}
131140

132-
MimeMessage CreateMessage(string from, Recipient recipient, MemoryStream attachmentStream) {
141+
MimeMessage CreateMessage(string from, Recipient recipient, MemoryStream attachmentStream)
142+
{
133143
var message = new MimeMessage();
134144
// Specify the sender's address.
135145
message.From.Add(new MailboxAddress(SelectedSender?.FullName, from));
@@ -138,17 +148,19 @@
138148
message.Subject = "Your message subject";
139149

140150
// Create the body of your message.
141-
var body = new TextPart() {
151+
var body = new TextPart()
152+
{
142153
Text = "Your message text"
143-
};
154+
};
144155

145156
// Create a PDF attachment to send the generated letter.
146-
var attachment = new MimePart("application", "pdf") {
157+
var attachment = new MimePart("application", "pdf")
158+
{
147159
Content = new MimeContent(attachmentStream, ContentEncoding.Default),
148160
ContentDisposition = new ContentDisposition(ContentDisposition.Attachment),
149161
ContentTransferEncoding = ContentEncoding.Base64,
150162
FileName = "attachment.pdf"
151-
};
163+
};
152164

153165
var multipart = new Multipart("mixed");
154166
multipart.Add(body);
@@ -159,23 +171,28 @@
159171
return message;
160172
}
161173

162-
void SendMessage(MimeMessage message) {
163-
using (var client = new SmtpClient()) {
174+
void SendMessage(MimeMessage message)
175+
{
176+
using (var client = new SmtpClient())
177+
{
164178
// Connect to your SMTP server to send the message.
165179
// Use one of these ports: 25, 465, 587, or 2525.
166180
client.Connect("MAIL_SERVER", 587, false);
167181

168182
// Use the code below if your SMTP server requires authentication.
169183
client.Authenticate("USERNAME", "PASSWORD");
170184

171-
try {
185+
try
186+
{
172187
// Send the message.
173188
client.Send(message);
174189
}
175-
catch(Exception ex) {
190+
catch (Exception ex)
191+
{
176192
logger.LogError(ex.Message);
177193
}
178-
finally {
194+
finally
195+
{
179196
client.Disconnect(true);
180197
}
181198
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<Router AppAssembly="typeof(Program).Assembly">
2+
<Found Context="routeData">
3+
<RouteView RouteData="routeData" DefaultLayout="typeof(Layout.MainLayout)" />
4+
<FocusOnNavigate RouteData="routeData" Selector="h1" />
5+
</Found>
6+
</Router>
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
@using System.Net.Http
2-
@using Microsoft.AspNetCore.Authorization
3-
@using Microsoft.AspNetCore.Components.Authorization
2+
@using System.Net.Http.Json
43
@using Microsoft.AspNetCore.Components.Forms
54
@using Microsoft.AspNetCore.Components.Routing
65
@using Microsoft.AspNetCore.Components.Web
6+
@using static Microsoft.AspNetCore.Components.Web.RenderMode
77
@using Microsoft.AspNetCore.Components.Web.Virtualization
88
@using Microsoft.JSInterop
9-
@using BlazorApp_WordDocumentAPI
10-
@using BlazorApp_WordDocumentAPI.Shared
9+
@using BlazorAppWordProcessing
10+
@using BlazorAppWordProcessing.Components
1111
@using DevExpress.Blazor
12+
@using System.IO
13+
@using DevExpress.XtraRichEdit
14+

0 commit comments

Comments
 (0)