core plugin, both signalR and service override works, theme added

This commit is contained in:
Adam 2025-09-02 11:51:01 +02:00
parent 34455c0de5
commit e266fbf289
10 changed files with 298 additions and 15 deletions

View File

@ -24,15 +24,15 @@ public class PluginNopStartup : INopStartup
options.ViewLocationExpanders.Add(new ViewLocationExpander());
});
services.AddCors(feature =>
feature.AddPolicy(
"AllowBlazorClient",
apiPolicy => apiPolicy
.WithOrigins("https://localhost:7144")
.AllowAnyHeader()
.AllowAnyMethod()
.AllowCredentials()
));
//services.AddCors(feature =>
// feature.AddPolicy(
// "AllowBlazorClient",
// apiPolicy => apiPolicy
// .WithOrigins("https://localhost:7144")
// .AllowAnyHeader()
// .AllowAnyMethod()
// .AllowCredentials()
// ));
services.AddSignalR();
@ -55,23 +55,20 @@ public class PluginNopStartup : INopStartup
public void Configure(IApplicationBuilder application)
{
application.UseWhen(context => context.Request.Path.StartsWithSegments("/fbhub"), app =>
{
app.UseCors("AllowBlazorClient");
app.UseRouting();
//app.UseCors("AllowBlazorClient");
//app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapHub<FruitBankHub>("/fbhub");
});
});
}
/// <summary>
/// Gets order of this startup configuration implementation
/// </summary>
public int Order => 100;
public int Order => 4000;
}

View File

@ -0,0 +1,10 @@
@inherits Nop.Web.Framework.Mvc.Razor.NopRazorPage<TModel>
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, Nop.Web.Framework
@using Microsoft.AspNetCore.Mvc.ViewFeatures
@using Nop.Web.Framework.UI
@using Nop.Web.Framework.Extensions
@using System.Text.Encodings.Web
@using Nop.Services.Events
@using Nop.Web.Framework.Events

View File

@ -0,0 +1,60 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Mvc.Razor;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Nop.Core.Infrastructure;
namespace Nop.Plugin.Misc.MangoCore.Infrastructure;
public class PluginNopStartup : INopStartup
{
/// <summary>
/// Add and configure any of the middleware
/// </summary>
/// <param name="services">Collection of service descriptors</param>
/// <param name="configuration">Configuration of the application</param>
public void ConfigureServices(IServiceCollection services, IConfiguration configuration)
{
services.Configure<RazorViewEngineOptions>(options =>
{
options.ViewLocationExpanders.Add(new ViewLocationExpander());
});
services.AddCors(feature =>
feature.AddPolicy(
"AllowBlazorClient",
apiPolicy => apiPolicy
.WithOrigins("https://localhost:7144")
.AllowAnyHeader()
.AllowAnyMethod()
.AllowCredentials()
));
//register services and interfaces
//services.AddScoped<CustomModelFactory, ICustomerModelFactory>();
}
/// <summary>
/// Configure the using of added middleware
/// </summary>
/// <param name="application">Builder for configuring an application's request pipeline</param>
public void Configure(IApplicationBuilder application)
{
application.UseWhen(context => context.Request.Path.StartsWithSegments("/fbhub"), app =>
{
app.UseCors("AllowBlazorClient");
app.UseRouting();
//app.UseEndpoints(endpoints =>
//{
// endpoints.MapHub<FruitBankHub>("/fbhub");
//});
});
}
/// <summary>
/// Gets order of this startup configuration implementation
/// </summary>
public int Order => 100;
}

View File

@ -0,0 +1,24 @@
using Microsoft.AspNetCore.Routing;
using Nop.Web.Framework.Mvc.Routing;
namespace Nop.Plugin.Misc.MangoCore.Infrastructure;
/// <summary>
/// Represents plugin route provider
/// </summary>
public class RouteProvider : IRouteProvider
{
/// <summary>
/// Register routes
/// </summary>
/// <param name="endpointRouteBuilder">Route builder</param>
public void RegisterRoutes(IEndpointRouteBuilder endpointRouteBuilder)
{
}
/// <summary>
/// Gets a priority of route provider
/// </summary>
public int Priority => 0;
}

View File

@ -0,0 +1,38 @@
using Microsoft.AspNetCore.Mvc.Razor;
namespace Nop.Plugin.Misc.MangoCore.Infrastructure;
public class ViewLocationExpander : IViewLocationExpander
{
/// <summary>
/// Invoked by a <see cref="T:Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine" /> to determine the values that would be consumed by this instance
/// of <see cref="T:Microsoft.AspNetCore.Mvc.Razor.IViewLocationExpander" />. The calculated values are used to determine if the view location
/// has changed since the last time it was located.
/// </summary>
/// <param name="context">The <see cref="T:Microsoft.AspNetCore.Mvc.Razor.ViewLocationExpanderContext" /> for the current view location
/// expansion operation.</param>
public void PopulateValues(ViewLocationExpanderContext context)
{
}
/// <summary>
/// Invoked by a <see cref="T:Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine" /> to determine potential locations for a view.
/// </summary>
/// <param name="context">The <see cref="T:Microsoft.AspNetCore.Mvc.Razor.ViewLocationExpanderContext" /> for the current view location
/// expansion operation.</param>
/// <param name="viewLocations">The sequence of view locations to expand.</param>
/// <returns>A list of expanded view locations.</returns>
public IEnumerable<string> ExpandViewLocations(ViewLocationExpanderContext context, IEnumerable<string> viewLocations)
{
if (context.AreaName == "Admin")
{
viewLocations = new[] { $"/Plugins/Nop.Plugin.Misc.MangoCore/Areas/Admin/Views/{context.ControllerName}/{context.ViewName}.cshtml" }.Concat(viewLocations);
}
else
{
viewLocations = new[] { $"/Plugins/Nop.Plugin.Misc.MangoCore/Views/{context.ControllerName}/{context.ViewName}.cshtml" }.Concat(viewLocations);
}
return viewLocations;
}
}

View File

@ -0,0 +1,60 @@
using DocumentFormat.OpenXml.Packaging;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.AspNetCore.Mvc.Routing;
using Nop.Services.Cms;
using Nop.Services.Configuration;
using Nop.Services.Localization;
using Nop.Services.Plugins;
using Nop.Services.Security;
using Nop.Web.Framework.Infrastructure;
using Nop.Web.Framework.Menu;
namespace Nop.Plugin.Misc.MangoCore;
/// <summary>
/// Rename this file and change to the correct type
/// </summary>
public class MangoCorePlugin : BasePlugin
{
protected readonly IActionContextAccessor _actionContextAccessor;
private readonly ISettingService _settingService;
//private readonly IWebHelper _webHelper;
protected readonly IPermissionService _permissionService;
protected readonly ILocalizationService _localizationService;
protected readonly IUrlHelperFactory _urlHelperFactory;
private readonly IAdminMenu _adminMenu;
//handle AdminMenuCreatedEvent
public MangoCorePlugin(IActionContextAccessor actionContextAccessor,
ISettingService settingService,
//IWebHelper webHelper,
ILocalizationService localizationService,
IPermissionService permissionService,
IUrlHelperFactory urlHelperFactory,
IAdminMenu adminMenu)
{
_actionContextAccessor = actionContextAccessor;
_settingService = settingService;
//_webHelper = webHelper;
_localizationService = localizationService;
_urlHelperFactory = urlHelperFactory;
_adminMenu = adminMenu;
_permissionService = permissionService;
}
// --- INSTALL ---
public override async Task InstallAsync()
{
await base.InstallAsync();
}
// --- UNINSTALL ---
public override async Task UninstallAsync()
{
await base.UninstallAsync();
}
}

View File

@ -0,0 +1,70 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<OutputPath>$(SolutionDir)\Presentation\Nop.Web\Plugins\Nop.Plugin.Misc.MangoCore</OutputPath>
<OutDir>$(OutputPath)</OutDir>
<!--Set this parameter to true to get the dlls copied from the NuGet cache to the output of your project.
You need to set this parameter to true if your plugin has a nuget package
to ensure that the dlls copied from the NuGet cache to the output of your project-->
<CopyLocalLockFileAssemblies>false</CopyLocalLockFileAssemblies>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<None Remove="logo.jpg" />
<None Remove="plugin.json" />
<None Remove="Views\_ViewImports.cshtml" />
<None Remove="Areas\Admin\Views\_ViewImports.cshtml" />
</ItemGroup>
<ItemGroup>
<Content Include="logo.jpg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="plugin.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Views\_ViewImports.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Areas\Admin\Views\_ViewImports.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Areas\Admin\Views\_ViewImports.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Views\_ViewImports.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="$(SolutionDir)\Presentation\Nop.Web\Nop.Web.csproj" />
<ClearPluginAssemblies Include="$(SolutionDir)\Build\ClearPluginAssemblies.proj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Areas\Admin\Components\" />
<Folder Include="Areas\Admin\Controllers\" />
<Folder Include="Areas\Admin\Extensions\" />
<Folder Include="Areas\Admin\Factories\" />
<Folder Include="Areas\Admin\Models\" />
<Folder Include="Areas\Admin\Validators\" />
<Folder Include="Components\" />
<Folder Include="Controllers\" />
<Folder Include="Domains\" />
<Folder Include="Extensions\" />
<Folder Include="Factories\" />
<Folder Include="Mapping\Builders\" />
<Folder Include="Models\" />
<Folder Include="Services\" />
<Folder Include="Validators\" />
</ItemGroup>
<!-- This target execute after "Build" target -->
<Target Name="NopTarget" AfterTargets="Build">
<MSBuild Projects="@(ClearPluginAssemblies)" Properties="PluginPath=$(OutDir)" Targets="NopClear" />
</Target>
</Project>

View File

@ -0,0 +1,11 @@
@inherits Nop.Web.Framework.Mvc.Razor.NopRazorPage<TModel>
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, Nop.Web.Framework
@using Microsoft.AspNetCore.Mvc.ViewFeatures
@using Nop.Web.Framework.UI
@using Nop.Web.Framework.Extensions
@using System.Text.Encodings.Web
@using Nop.Services.Events
@using Nop.Web.Framework.Events
@using Nop.Web.Framework.Infrastructure

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

View File

@ -0,0 +1,13 @@
{
"Group": "Misc",
"FriendlyName": "MangoCorePlugin",
"SystemName": "Misc.MangoCorePlugin",
"Version": "1.00",
"SupportedVersions": [
"4.80"
],
"Author": "Adam Gelencser",
"DisplayOrder": 1,
"FileName": "Nop.Plugin.Misc.MangoCore.dll",
"Description": ""
}