Skip to content

Commit

Permalink
merge hotfix
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm360 committed Nov 29, 2022
2 parents 7aaf90c + f5994e7 commit 667855e
Show file tree
Hide file tree
Showing 8 changed files with 192 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/EthernaACR/EthernaACR.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="GitVersion.MsBuild" Version="5.10.3">
<PackageReference Include="GitVersion.MsBuild" Version="5.11.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="6.0.9" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="6.0.11" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Options;
using System;

namespace Etherna.ACR.Middlewares.PrintConfigurationPage
{
public static class ApplicationBuilderExtensions
{
public static IApplicationBuilder UsePrintConfigurationPage(this IApplicationBuilder app)
{
if (app == null)
throw new ArgumentNullException(nameof(app));

return app.UseMiddleware<PrintConfigurationPageMiddleware>();
}

public static IApplicationBuilder UsePrintConfigurationPage(
this IApplicationBuilder app,
PrintConfigurationPageOptions options)
{
if (app == null)
throw new ArgumentNullException(nameof(app));
if (options == null)
throw new ArgumentNullException(nameof(options));

return app.UseMiddleware<PrintConfigurationPageMiddleware>(Options.Create(options));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using Etherna.ACR.Middlewares.PrintConfigurationPage.Views;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using System;
using System.Threading.Tasks;

namespace Etherna.ACR.Middlewares.PrintConfigurationPage
{
public class PrintConfigurationPageMiddleware
{
private readonly RequestDelegate next;
private readonly PrintConfigurationPageOptions options;

public PrintConfigurationPageMiddleware(
RequestDelegate next,
IOptions<PrintConfigurationPageOptions> options)
{
if (options is null)
throw new ArgumentNullException(nameof(options));

this.next = next;
this.options = options.Value;
}

public async Task InvokeAsync(HttpContext context)
{
if (context is null)
throw new ArgumentNullException(nameof(context));

if (context.Request.Path == options.PagePath)
{
var viewResult = new ViewResult()
{
ViewName = "~/Middlewares/PrintConfigurationPage/Views/PrintConfigurationPage.cshtml"
};

var viewDataDictionary = new ViewDataDictionary(
new EmptyModelMetadataProvider(),
new ModelStateDictionary())
{
Model = new PrintConfigurationPageModel(
context.RequestServices.GetRequiredService<IConfiguration>(), options)
};
viewResult.ViewData = viewDataDictionary;

var executor = context.RequestServices.GetRequiredService<IActionResultExecutor<ViewResult>>();
var actionContext = new ActionContext(
context,
context.GetRouteData() ?? new RouteData(),
new Microsoft.AspNetCore.Mvc.Abstractions.ActionDescriptor());

await executor.ExecuteAsync(actionContext, viewResult);
}
else
{
// Call the next delegate/middleware in the pipeline.
await next(context);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace Etherna.ACR.Middlewares.PrintConfigurationPage
{
public class PrintConfigurationPageOptions
{
public PrintConfigurationPageOptions()
{
PagePath = "/debug/config";
PageTitle = "Configuration print";
}

public string PagePath { get; set; }
public string PageTitle { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@using System
@using System.Globalization
@using System.Linq
@using System.Net
@using System.Reflection
@using Microsoft.AspNetCore.Diagnostics.RazorViews
@using Microsoft.AspNetCore.Diagnostics
@model PrintConfigurationPageModel

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>@Model.Title</title>
</head>
<body>

<partial name="_PrintConfigurationSectionPartial" model="Model.Configuration" />

</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Etherna.ACR.Middlewares.PrintConfigurationPage.Views
{
public class PrintConfigurationPageModel
{
public PrintConfigurationPageModel(
IConfiguration configuration,
PrintConfigurationPageOptions options)
{
if (options is null)
throw new ArgumentNullException(nameof(options));

Configuration = configuration;
Title = options.PageTitle;
}

public IConfiguration Configuration { get; }
public string Title { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@using Microsoft.Extensions.Configuration;
@model IConfiguration

@if (Model.GetChildren().Any())
{
<ul>
@foreach (var configSection in Model.GetChildren())
{
<li>
@configSection.Key|@configSection.Value
</li>
<partial name="_PrintConfigurationPartial" model="configSection" />
}
</ul>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@* * Copyright 2021-present Etherna Sagl
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*@

@namespace Etherna.ACR.Middlewares.PrintConfigurationPage.Views
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

0 comments on commit 667855e

Please sign in to comment.