Skip to content

Commit

Permalink
✨ feat: 增加通知模板解析模块.
Browse files Browse the repository at this point in the history
  • Loading branch information
colinin committed Jan 14, 2025
1 parent a0d0959 commit c702f5d
Show file tree
Hide file tree
Showing 38 changed files with 538 additions and 95 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: "Publish"

on:
push:
branches: [ rel-8.3.4 ]
branches: [ main ]
env:
DOTNET_VERSION: "8.0.200"

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: "Tagged Release"

on:
push:
branches: [ rel-8.3.4 ]
branches: [ main ]

jobs:
tagged-release:
Expand Down
14 changes: 14 additions & 0 deletions aspnet-core/LINGYUN.MicroService.All.sln
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.OssManagement.I
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINGYUN.Abp.Notifications.HttpApi.Client", "modules\realtime-notifications\LINGYUN.Abp.Notifications.HttpApi.Client\LINGYUN.Abp.Notifications.HttpApi.Client.csproj", "{3CBD1342-C021-49FB-933F-FAC1DAFC7B48}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINGYUN.Abp.Notifications.Templating", "modules\realtime-notifications\LINGYUN.Abp.Notifications.Templating\LINGYUN.Abp.Notifications.Templating.csproj", "{E2AC3DB8-D579-49A3-845B-528C77A1EC75}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINGYUN.Abp.Notifications.Templating.Tests", "tests\LINGYUN.Abp.Notifications.Templating.Tests\LINGYUN.Abp.Notifications.Templating.Tests.csproj", "{F47EDB4F-1F92-4887-8F33-BFCEB61BB51A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -1969,6 +1973,14 @@ Global
{3CBD1342-C021-49FB-933F-FAC1DAFC7B48}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3CBD1342-C021-49FB-933F-FAC1DAFC7B48}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3CBD1342-C021-49FB-933F-FAC1DAFC7B48}.Release|Any CPU.Build.0 = Release|Any CPU
{E2AC3DB8-D579-49A3-845B-528C77A1EC75}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E2AC3DB8-D579-49A3-845B-528C77A1EC75}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E2AC3DB8-D579-49A3-845B-528C77A1EC75}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E2AC3DB8-D579-49A3-845B-528C77A1EC75}.Release|Any CPU.Build.0 = Release|Any CPU
{F47EDB4F-1F92-4887-8F33-BFCEB61BB51A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F47EDB4F-1F92-4887-8F33-BFCEB61BB51A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F47EDB4F-1F92-4887-8F33-BFCEB61BB51A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F47EDB4F-1F92-4887-8F33-BFCEB61BB51A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -2340,6 +2352,8 @@ Global
{76DDE71D-00BD-4BC8-AEA2-31209E2B7E05} = {B05CB08F-C088-4D6D-97EE-A94A5D1AE4A6}
{267933BD-BFB8-4906-BA39-DF193B2FD558} = {B05CB08F-C088-4D6D-97EE-A94A5D1AE4A6}
{3CBD1342-C021-49FB-933F-FAC1DAFC7B48} = {1A23BB7F-1839-4204-88C5-7E9A6C9FBF1E}
{E2AC3DB8-D579-49A3-845B-528C77A1EC75} = {1A23BB7F-1839-4204-88C5-7E9A6C9FBF1E}
{F47EDB4F-1F92-4887-8F33-BFCEB61BB51A} = {370D7CD5-1E17-4F3D-BBFA-03429F6D4F2F}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C95FDF91-16F2-4A8B-A4BE-0E62D1B66718}
Expand Down
7 changes: 7 additions & 0 deletions aspnet-core/LINGYUN.MicroService.SingleProject.sln
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINGYUN.Abp.AuditLogging.IP
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LY.MicroService.Applications.Single.EntityFrameworkCore.MySql", "migrations\LY.MicroService.Applications.Single.EntityFrameworkCore.MySql\LY.MicroService.Applications.Single.EntityFrameworkCore.MySql.csproj", "{746813A9-4221-42D8-AAB5-66CB69EC844F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINGYUN.Abp.Notifications.Templating", "modules\realtime-notifications\LINGYUN.Abp.Notifications.Templating\LINGYUN.Abp.Notifications.Templating.csproj", "{8CFA17AA-568C-4B40-A48E-1212123ABDD6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -1622,6 +1624,10 @@ Global
{746813A9-4221-42D8-AAB5-66CB69EC844F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{746813A9-4221-42D8-AAB5-66CB69EC844F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{746813A9-4221-42D8-AAB5-66CB69EC844F}.Release|Any CPU.Build.0 = Release|Any CPU
{8CFA17AA-568C-4B40-A48E-1212123ABDD6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8CFA17AA-568C-4B40-A48E-1212123ABDD6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8CFA17AA-568C-4B40-A48E-1212123ABDD6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8CFA17AA-568C-4B40-A48E-1212123ABDD6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -1921,6 +1927,7 @@ Global
{5BE31786-EAAB-4C86-8FFF-C07F27FBFD1C} = {99B7CBDE-A251-4738-97F0-DB1DB484BEE1}
{77B3C7A4-15C7-4EFF-8451-4F13B4CCA4AE} = {C22741F9-FC56-4AE3-B543-9F15C779D345}
{746813A9-4221-42D8-AAB5-66CB69EC844F} = {0D69B63D-F082-4D57-9FF0-355642C56993}
{8CFA17AA-568C-4B40-A48E-1212123ABDD6} = {42F31C68-B8B2-4BE0-9AD0-A7DFA6092629}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {711A43C0-A2F8-4E5C-9B9F-F2551E4B3FF1}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<ConfigureAwait ContinueOnCapturedContext="false" />
</Weavers>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. -->
<xs:element name="Weavers">
<xs:complexType>
<xs:all>
<xs:element name="ConfigureAwait" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:attribute name="ContinueOnCapturedContext" type="xs:boolean" />
</xs:complexType>
</xs:element>
</xs:all>
<xs:attribute name="VerifyAssembly" type="xs:boolean">
<xs:annotation>
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="VerifyIgnoreCodes" type="xs:string">
<xs:annotation>
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="GenerateXsd" type="xs:boolean">
<xs:annotation>
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="..\..\..\..\configureawait.props" />
<Import Project="..\..\..\..\common.props" />

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;net8.0</TargetFrameworks>
<AssemblyName>LINGYUN.Abp.Notifications.Templating</AssemblyName>
<PackageId>LINGYUN.Abp.Notifications.Templating</PackageId>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<RootNamespace />
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\LINGYUN.Abp.Notifications.Core\LINGYUN.Abp.Notifications.Core.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using JetBrains.Annotations;
using System.Collections.Generic;

namespace LINGYUN.Abp.Notifications.Templating;
public class AbpNotificationsResolveOptions
{
/// <summary>
/// 模板解析提供者列表
/// </summary>
[NotNull]
public List<INotificationTemplateResolveContributor> TemplateResolvers { get; }

public AbpNotificationsResolveOptions()
{
TemplateResolvers = new List<INotificationTemplateResolveContributor>();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Volo.Abp.Modularity;

namespace LINGYUN.Abp.Notifications.Templating;

[DependsOn(typeof(AbpNotificationsCoreModule))]
public class AbpNotificationsTemplatingModule : AbpModule
{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Volo.Abp.DependencyInjection;

namespace LINGYUN.Abp.Notifications.Templating;
public interface INotificationTemplateResolveContext : IServiceProviderAccessor
{
NotificationTemplate Template { get; }

object Model { get; set; }

bool Handled { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Threading.Tasks;

namespace LINGYUN.Abp.Notifications.Templating;
public interface INotificationTemplateResolveContributor
{
string Name { get; }

Task ResolveAsync(INotificationTemplateResolveContext context);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using JetBrains.Annotations;
using System.Threading.Tasks;

namespace LINGYUN.Abp.Notifications.Templating;
/// <summary>
/// 通知模板模型解析接口
/// </summary>
public interface INotificationTemplateResolver
{
/// <summary>
/// 解析模板数据
/// </summary>
/// <param name="template"></param>
/// <returns></returns>
[NotNull]
Task<NotificationTemplateResolveResult> ResolveAsync(NotificationTemplate template);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;

namespace LINGYUN.Abp.Notifications.Templating;
public class NotificationTemplateResolveContext : INotificationTemplateResolveContext
{
public IServiceProvider ServiceProvider { get; }

public NotificationTemplate Template { get; }

public object Model { get; set; }

public bool Handled { get; set; }

public bool HasResolvedModel()
{
return Handled || Model != null;
}

public NotificationTemplateResolveContext(
NotificationTemplate template,
IServiceProvider serviceProvider)
{
Template = template;
ServiceProvider = serviceProvider;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Threading.Tasks;

namespace LINGYUN.Abp.Notifications.Templating;
public abstract class NotificationTemplateResolveContributorBase : INotificationTemplateResolveContributor
{
public abstract string Name { get; }
/// <summary>
/// 实现此接口处理模板数据
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public abstract Task ResolveAsync(INotificationTemplateResolveContext context);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Collections.Generic;

namespace LINGYUN.Abp.Notifications.Templating;
public class NotificationTemplateResolveResult
{
/// <summary>
/// 模板数据
/// </summary>
public object Model { get; set; }

public List<string> AppliedResolvers { get; }
public NotificationTemplateResolveResult()
{
AppliedResolvers = new List<string>();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using System;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;

namespace LINGYUN.Abp.Notifications.Templating;
public class NotificationTemplateResolver : INotificationTemplateResolver, ITransientDependency
{
private readonly IServiceProvider _serviceProvider;
private readonly AbpNotificationsResolveOptions _options;

public NotificationTemplateResolver(
IOptions<AbpNotificationsResolveOptions> options,
IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
_options = options.Value;
}
public async virtual Task<NotificationTemplateResolveResult> ResolveAsync(NotificationTemplate template)
{
var result = new NotificationTemplateResolveResult();

using (var serviceScope = _serviceProvider.CreateScope())
{
var context = new NotificationTemplateResolveContext(template, serviceScope.ServiceProvider);

foreach (var resolveContributor in _options.TemplateResolvers)
{
// TODO: 设定为每一个通知都配置自己的解析提供者?
/**
if (resolveContributor.Name.Equals(template.Name))
{
await resolveContributor.ResolveAsync(context);
}
if (context.HasResolvedModel())
{
result.Model = context.Model;
break;
}
**/

await resolveContributor.ResolveAsync(context);

result.AppliedResolvers.Add(resolveContributor.Name);

if (context.HasResolvedModel())
{
result.Model = context.Model;
break;
}
}
}

return result;
}
}
47 changes: 0 additions & 47 deletions aspnet-core/services/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,53 +3,6 @@
<PropertyGroup>
<LYAbpPackageVersion>8.3.4</LYAbpPackageVersion>
</PropertyGroup>

<ItemGroup>
<PackageVersion Include="DistributedLock.Redis" Version="$(LYAbpPackageVersion)" />
<PackageVersion Include="Elsa.Activities.Email" Version="$(LYAbpPackageVersion)" />
<PackageVersion Include="Elsa.Activities.Http" Version="$(LYAbpPackageVersion)" />
<PackageVersion Include="Elsa.Activities.UserTask" Version="$(LYAbpPackageVersion)" />
<PackageVersion Include="Elsa.Activities.Temporal.Quartz" Version="$(LYAbpPackageVersion)" />
<!--<PackageVersion Include="Elsa.Designer.Components.Web" Version="$(LYAbpPackageVersion)" />-->
<PackageVersion Include="Elsa.Webhooks.Api" Version="$(LYAbpPackageVersion)" />
<PackageVersion Include="Microsoft.AspNetCore.DataProtection.StackExchangeRedis" Version="$(LYAbpPackageVersion)" />
<PackageVersion Include="OpenIddict.Validation.DataProtection" Version="$(LYAbpPackageVersion)" />
<PackageVersion Include="OpenIddict.Server.DataProtection" Version="$(LYAbpPackageVersion)" />
<PackageVersion Include="Serilog.AspNetCore" Version="$(LYAbpPackageVersion)" />
<PackageVersion Include="Serilog.Enrichers.Environment" Version="$(LYAbpPackageVersion)" />
<PackageVersion Include="Serilog.Enrichers.Assembly" Version="$(LYAbpPackageVersion)" />
<PackageVersion Include="Serilog.Enrichers.Process" Version="$(LYAbpPackageVersion)" />
<PackageVersion Include="Serilog.Enrichers.Thread" Version="$(LYAbpPackageVersion)" />
<PackageVersion Include="Serilog.Settings.Configuration" Version="$(LYAbpPackageVersion)" />
<PackageVersion Include="Serilog.Sinks.Elasticsearch" Version="$(LYAbpPackageVersion)" />
<PackageVersion Include="Serilog.Sinks.File" Version="$(LYAbpPackageVersion)" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="$(LYAbpPackageVersion)" />
<PackageVersion Include="Quartz.Serialization.Json" Version="$(LYAbpPackageVersion)" />
<PackageVersion Include="Volo.Abp.Account.Web.OpenIddict" Version="$(LYAbpPackageVersion)" />
<!--<PackageVersion Include="Volo.Abp.Account.Web.IdentityServer" Version="$(LYAbpPackageVersion)" />-->
<PackageVersion Include="Volo.Abp.AspNetCore.Serilog" Version="$(LYAbpPackageVersion)" />
<PackageVersion Include="Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy" Version="$(LYAbpPackageVersion)" />
<PackageVersion Include="Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic" Version="$(LYAbpPackageVersion)" />
<PackageVersion Include="Volo.Abp.AspNetCore.Authentication.JwtBearer" Version="$(LYAbpPackageVersion)" />
<PackageVersion Include="Volo.Abp.Autofac" Version="$(LYAbpPackageVersion)" />
<PackageVersion Include="Volo.Abp.Caching.StackExchangeRedis" Version="$(LYAbpPackageVersion)" />
<!-- <PackageVersion Include="Volo.Abp.EntityFrameworkCore.MySQL" Version="$(LYAbpPackageVersion)" />-->
<PackageVersion Include="Volo.Abp.EntityFrameworkCore.PostgreSql" Version="$(LYAbpPackageVersion)" />
<PackageVersion Include="Volo.Abp.FeatureManagement.Application" Version="$(LYAbpPackageVersion)" />
<PackageVersion Include="Volo.Abp.FeatureManagement.EntityFrameworkCore" Version="$(LYAbpPackageVersion)" />
<PackageVersion Include="Volo.Abp.FeatureManagement.HttpApi" Version="$(LYAbpPackageVersion)" />
<PackageVersion Include="Volo.Abp.PermissionManagement.Application" Version="$(LYAbpPackageVersion)" />
<PackageVersion Include="Volo.Abp.PermissionManagement.Domain.Identity" Version="$(LYAbpPackageVersion)" />
<PackageVersion Include="Volo.Abp.PermissionManagement.Domain.IdentityServer" Version="$(LYAbpPackageVersion)" />
<PackageVersion Include="Volo.Abp.PermissionManagement.Domain.OpenIddict" Version="$(LYAbpPackageVersion)" />
<PackageVersion Include="Volo.Abp.PermissionManagement.HttpApi" Version="$(LYAbpPackageVersion)" />
<PackageVersion Include="Volo.Abp.Identity.AspNetCore" Version="$(LYAbpPackageVersion)" />
<PackageVersion Include="Volo.Abp.Imaging.ImageSharp" Version="$(LYAbpPackageVersion)" />
<!--<PackageVersion Include="Volo.Abp.IdentityServer.EntityFrameworkCore" Version="$(LYAbpPackageVersion)" />-->
<PackageVersion Include="Volo.Abp.SettingManagement.EntityFrameworkCore" Version="$(LYAbpPackageVersion)" />
<PackageVersion Include="Volo.Abp.PermissionManagement.EntityFrameworkCore" Version="$(LYAbpPackageVersion)" />
<PackageVersion Include="Volo.Abp.OpenIddict.EntityFrameworkCore" Version="$(LYAbpPackageVersion)" />
</ItemGroup>

<ItemGroup>
<PackageVersion Include="LINGYUN.Abp.AuditLogging.EntityFrameworkCore" Version="$(LYAbpPackageVersion)" />
Expand Down
Loading

0 comments on commit c702f5d

Please sign in to comment.