Skip to content

Commit c61f49d

Browse files
committed
Add Bootswatch theming and HTTP client utilities
Updated project to include WebSpark.Bootswatch and WebSpark.HttpClientUtility packages. Removed Microsoft.VisualStudio.Web.CodeGeneration.Design reference. Enhanced Program.cs with new services and middleware for Bootswatch. Modified _Layout.cshtml to support dynamic theming and added a theme switcher. Updated _ViewImports.cshtml for Bootswatch integration and added new settings in appsettings.json for CSV output and HTTP request handling options.
1 parent b7a5db4 commit c61f49d

File tree

5 files changed

+37
-13
lines changed

5 files changed

+37
-13
lines changed

Mwh.Sample.Web/Mwh.Sample.Web.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
<PackageReference Include="Swashbuckle.AspNetCore" Version="8.1.2" />
3434
<PackageReference Include="System.Formats.Asn1" Version="9.0.5" />
3535
<PackageReference Include="System.Text.Json" Version="9.0.5" />
36+
<PackageReference Include="WebSpark.Bootswatch" Version="1.10.3" />
37+
<PackageReference Include="WebSpark.HttpClientUtility" Version="1.0.8" />
3638
<PackageReference Include="Westwind.AspNetCore.Markdown" Version="3.23.0" />
3739
</ItemGroup>
3840
<ItemGroup>

Mwh.Sample.Web/Program.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
using Microsoft.OpenApi.Models;
2+
using WebSpark.Bootswatch;
3+
using WebSpark.HttpClientUtility;
4+
using WebSpark.HttpClientUtility.RequestResult;
25
using Westwind.AspNetCore.Markdown;
36

47
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
@@ -42,6 +45,11 @@
4245

4346
builder.Services.AddHttpClient();
4447
builder.Services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();
48+
builder.Services.AddScoped<IHttpRequestResultService, HttpRequestResultService>();
49+
50+
// Add Bootswatch theme switcher services (includes StyleCache)
51+
builder.Services.AddBootswatchThemeSwitcher();
52+
4553
builder.Services.AddMarkdown();
4654
builder.Services.AddSession();
4755
builder.Services.AddRazorPages();
@@ -71,6 +79,10 @@
7179

7280
app.UseMyHttpContext();
7381
app.UseHttpsRedirection();
82+
83+
// Use all Bootswatch features (includes StyleCache and static files)
84+
app.UseBootswatchAll();
85+
7486
app.UseAuthorization();
7587

7688
app.MapHealthChecks("/health");

Mwh.Sample.Web/Views/Shared/_Layout.cshtml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
@{
1+
@inject StyleCache StyleCache
2+
@{
23
var currentYear = DateTime.Now.Year.ToString();
34
var status = new ApplicationStatus(Assembly.GetExecutingAssembly());
5+
var themeName = BootswatchThemeHelper.GetCurrentThemeName(Context);
6+
var themeUrl = BootswatchThemeHelper.GetThemeUrl(StyleCache, themeName);
47
}
58
<!DOCTYPE html>
6-
<html lang="en" class="h-100">
9+
<html lang="en" class="h-100" data-bs-theme="@(BootswatchThemeHelper.GetCurrentColorMode(Context))">
710

8-
<head>
9-
@await Html.PartialAsync("Sections/_metatags")
11+
<head> @await Html.PartialAsync("Sections/_metatags")
1012

1113
<!-- CSS -->
12-
<link rel="stylesheet" href="/lib/bootstrap/dist/css/bootstrap.min.css" />
14+
<link id="bootswatch-theme-stylesheet" rel="stylesheet" href="@themeUrl" />
1315
<link rel="stylesheet" href="/lib/bootstrap-icons/font/bootstrap-icons.css" />
1416
<link rel="stylesheet" href="/lib/datatables.net-bs/css/dataTables.bootstrap5.min.css" />
15-
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
16-
17+
1718
@RenderSection("HeadScripts", required: false)
1819
</head>
1920

@@ -76,6 +77,7 @@
7677
</a>
7778
</li>
7879
</ul>
80+
<bootswatch-theme-switcher />
7981
</div>
8082
</div>
8183
</nav>
@@ -89,14 +91,12 @@
8991

9092
<footer class="footer mt-auto py-3 bg-dark text-white">
9193
@await Html.PartialAsync("_Footer")
92-
</footer>
93-
94-
<!-- JavaScript Bundle -->
94+
</footer> <!-- JavaScript Bundle -->
9595
<script src="~/lib/jquery/jquery.min.js"></script>
9696
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
97+
<script src="/_content/WebSpark.Bootswatch/js/bootswatch-theme-switcher.js"></script>
9798
<script src="~/lib/datatables/dataTables.min.js"></script>
9899
<script src="~/lib/datatables.net-bs/js/dataTables.bootstrap5.min.js"></script>
99-
<script src="~/js/site.js" asp-append-version="true"></script>
100100

101101
@await RenderSectionAsync("Scripts", required: false)
102102
</body>

Mwh.Sample.Web/Views/_ViewImports.cshtml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@
22
@using Mwh.Sample.Web.Models
33
@using Mwh.Sample.Domain.Models;
44
@using System.Reflection;
5-
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
5+
@using WebSpark.Bootswatch.Services
6+
@using WebSpark.Bootswatch.Helpers
7+
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
8+
@addTagHelper *, WebSpark.Bootswatch

Mwh.Sample.Web/appsettings.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
}
77
},
88
"AllowedHosts": "*",
9+
"CsvOutputFolder": "c:\\temp\\WebSpark\\CsvOutput",
10+
"HttpRequestResultPollyOptions": {
11+
"MaxRetryAttempts": 3,
12+
"RetryDelaySeconds": 1,
13+
"CircuitBreakerThreshold": 3,
14+
"CircuitBreakerDurationSeconds": 10
15+
},
916
"profiles": {
1017
"IIS Express": {
1118
"commandName": "IISExpress",
@@ -31,4 +38,4 @@
3138
"ApplicationInsights": {
3239
"ConnectionString": "InstrumentationKey=40203ca4-c795-4fd3-badd-cc009594b571;IngestionEndpoint=https://southcentralus-3.in.applicationinsights.azure.com/;LiveEndpoint=https://southcentralus.livediagnostics.monitor.azure.com/"
3340
}
34-
}
41+
}

0 commit comments

Comments
 (0)