Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Blazor Sample #45

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions OCBlazor/BlazorCms/BlazorCms.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<Folder Include="wwwroot\" />
<Folder Include="Localization\" />
</ItemGroup>

<!-- Watcher include and excludes -->
<ItemGroup>
<Watch Include="**\*.cs" Exclude="Recipes\**;Assets\**;node_modules\**\*;**\*.js.map;obj\**\*;bin\**\*" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="OrchardCore.Logging.NLog" Version="1.8.2" />
<PackageReference Include="OrchardCore.Application.Cms.Targets" Version="1.8.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\OCBlazorLib\OCBlazorLib.csproj" />
</ItemGroup>

</Project>
1 change: 1 addition & 0 deletions OCBlazor/BlazorCms/Localization/.placeholder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
��
32 changes: 32 additions & 0 deletions OCBlazor/BlazorCms/NLog.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true"
internalLogLevel="Warn"
internalLogFile="App_Data/logs/internal-nlog.txt">

<extensions>
<add assembly="NLog.Web.AspNetCore"/>
<add assembly="OrchardCore.Logging.NLog"/>
</extensions>

<targets>
<!-- file target -->
<target xsi:type="File" name="file"
fileName="${var:configDir}/App_Data/logs/orchard-log-${shortdate}.log"
layout="${longdate}|${orchard-tenant-name}|${aspnet-traceidentifier}|${event-properties:item=EventId}|${logger}|${uppercase:${level}}|${message} ${exception:format=ToString,StackTrace}"
/>

<!-- console target -->
<target xsi:type="Console" name="console" />

</targets>

<rules>
<!-- all warnings and above go to the file target -->
<logger name="*" minlevel="Warn" writeTo="file" />

<!-- the hosting lifetime events go to the console and file targets -->
<logger name="Microsoft.Hosting.Lifetime" minlevel="Info" writeTo="file, console" />
</rules>
</nlog>
39 changes: 39 additions & 0 deletions OCBlazor/BlazorCms/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using OCBlazorLib;
using OrchardCore.Logging;

var builder = WebApplication.CreateBuilder(args);

builder.Host.UseNLogHost();

builder.Services
.AddOrchardCms()
.ConfigureServices(services => {
services.AddRazorComponents()
.AddInteractiveServerComponents()
;

})
.Configure((app, routes, services) => {
app.UseStaticFiles();
app.UseAntiforgery();
routes.MapRazorComponents<App>()
.AddInteractiveServerRenderMode()
;
})
;

var app = builder.Build();

if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}

app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseOrchardCore();

app.Run();
27 changes: 27 additions & 0 deletions OCBlazor/BlazorCms/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:8080",
"sslPort": 44300
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"BlazorCms": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
9 changes: 9 additions & 0 deletions OCBlazor/BlazorCms/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
}
1 change: 1 addition & 0 deletions OCBlazor/BlazorCms/wwwroot/.placeholder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
��
31 changes: 31 additions & 0 deletions OCBlazor/OCBlazor.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorCms", "BlazorCms\BlazorCms.csproj", "{32905CF1-43EB-47FC-860A-FB7D85AF2B76}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OCBlazorLib", "OCBlazorLib\OCBlazorLib.csproj", "{BA22F3E8-8A2E-4CDD-BF58-D2F0EABC4BD5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{32905CF1-43EB-47FC-860A-FB7D85AF2B76}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{32905CF1-43EB-47FC-860A-FB7D85AF2B76}.Debug|Any CPU.Build.0 = Debug|Any CPU
{32905CF1-43EB-47FC-860A-FB7D85AF2B76}.Release|Any CPU.ActiveCfg = Release|Any CPU
{32905CF1-43EB-47FC-860A-FB7D85AF2B76}.Release|Any CPU.Build.0 = Release|Any CPU
{BA22F3E8-8A2E-4CDD-BF58-D2F0EABC4BD5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BA22F3E8-8A2E-4CDD-BF58-D2F0EABC4BD5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BA22F3E8-8A2E-4CDD-BF58-D2F0EABC4BD5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BA22F3E8-8A2E-4CDD-BF58-D2F0EABC4BD5}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {F08411E7-8491-4657-BF73-55E32435DAB7}
EndGlobalSection
EndGlobal
17 changes: 17 additions & 0 deletions OCBlazor/OCBlazorLib/App.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<base href="/" />
<link rel="stylesheet" href="OrchardCore.Resources/Styles/bootstrap.min.css" />
<link rel="stylesheet" href="_content/OCBlazorLib/OCBlazorLib.bundle.scp.css" />
<HeadOutlet />
</head>

<body>
<Routes />
<script src="_framework/blazor.web.js"></script>
</body>
</html>
51 changes: 51 additions & 0 deletions OCBlazor/OCBlazorLib/App.razor.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
html, body {
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
}

a, .btn-link {
color: #006bb7;
}

.btn-primary {
color: #fff;
background-color: #1b6ec2;
border-color: #1861ac;
}

.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus {
box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem #258cfb;
}

.content {
padding-top: 1.1rem;
}

h1:focus {
outline: none;
}

.valid.modified:not([type=checkbox]) {
outline: 1px solid #26b050;
}

.invalid {
outline: 1px solid #e50000;
}

.validation-message {
color: #e50000;
}

.blazor-error-boundary {
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5LjYxMDIgMjU5LjMzMiA2OS44NjA4IDI1OS4zNzEgNzAuMDg4N0wyNjEuNzk1IDg0LjAxNjEgMjY1LjM4IDg0LjAxNjEgMjY3LjgyMSA2OS43NDc1QzI2Ny44NiA2OS43MzA5IDI2Ny44NzkgNjkuNTg3NyAyNjcuODc5IDY5LjMxNzkgMjY3Ljg3OSA2Ny4xMTgyIDI2Ni40NDggNjYuMDE4MyAyNjMuNTg2IDY2LjAxODNaTTI2My41NzYgODYuMDU0N0MyNjEuMDQ5IDg2LjA1NDcgMjU5Ljc4NiA4Ny4zMDA1IDI1OS43ODYgODkuNzkyMSAyNTkuNzg2IDkyLjI4MzcgMjYxLjA0OSA5My41Mjk1IDI2My41NzYgOTMuNTI5NSAyNjYuMTE2IDkzLjUyOTUgMjY3LjM4NyA5Mi4yODM3IDI2Ny4zODcgODkuNzkyMSAyNjcuMzg3IDg3LjMwMDUgMjY2LjExNiA4Ni4wNTQ3IDI2My41NzYgODYuMDU0N1oiIGZpbGw9IiNGRkU1MDAiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjwvZz48L3N2Zz4=) no-repeat 1rem/1.8rem, #b32121;
padding: 1rem 1rem 1rem 3.7rem;
color: white;
}

.blazor-error-boundary::after {
content: "An error has occurred."
}

.darker-border-checkbox.form-check-input {
border-color: #929292;
}
3 changes: 3 additions & 0 deletions OCBlazor/OCBlazorLib/Component1.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="my-component">
This component is defined in the <strong>OCBlazorLib</strong> library.
</div>
6 changes: 6 additions & 0 deletions OCBlazor/OCBlazorLib/Component1.razor.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.my-component {
border: 2px dashed red;
padding: 1em;
margin: 1em 0;
background-image: url('background.png');
}
36 changes: 36 additions & 0 deletions OCBlazor/OCBlazorLib/ExampleJsInterop.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Microsoft.JSInterop;

namespace OCBlazorLib;

// This class provides an example of how JavaScript functionality can be wrapped
// in a .NET class for easy consumption. The associated JavaScript module is
// loaded on demand when first needed.
//
// This class can be registered as scoped DI service and then injected into Blazor
// components for use.

public class ExampleJsInterop : IAsyncDisposable
{
private readonly Lazy<Task<IJSObjectReference>> moduleTask;

public ExampleJsInterop(IJSRuntime jsRuntime)
{
moduleTask = new (() => jsRuntime.InvokeAsync<IJSObjectReference>(
"import", "./_content/OCBlazorLib/exampleJsInterop.js").AsTask());
}

public async ValueTask<string> Prompt(string message)
{
var module = await moduleTask.Value;
return await module.InvokeAsync<string>("showPrompt", message);
}

public async ValueTask DisposeAsync()
{
if (moduleTask.IsValueCreated)
{
var module = await moduleTask.Value;
await module.DisposeAsync();
}
}
}
23 changes: 23 additions & 0 deletions OCBlazor/OCBlazorLib/Layout/MainLayout.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@inherits LayoutComponentBase

<div class="page">
<div class="sidebar">
<NavMenu />
</div>

<main>
<div class="top-row px-4">
<a href="https://docs.orchardcore.net/" target="_blank">Learn Orchard</a>
</div>

<article class="content px-4">
@Body
</article>
</main>
</div>

<div id="blazor-error-ui">
An unhandled error has occurred.
<a href="" class="reload">Reload</a>
<a class="dismiss">🗙</a>
</div>
Loading