Skip to content

Commit

Permalink
修复验证过滤器bug;升级silky组件版本号
Browse files Browse the repository at this point in the history
  • Loading branch information
liuhll committed Jul 26, 2023
1 parent e56af90 commit a5fe3bd
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 19 deletions.
2 changes: 1 addition & 1 deletion common.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<LicenseUrl>https://raw.githubusercontent.com/liuhll/silky/main/LICENSE</LicenseUrl>

<Version>3.7.9</Version>
<Version>3.7.10</Version>

<PackageIconUrl>https://raw.githubusercontent.com/liuhll/silky/main/docs/.vuepress/public/assets/logo/logo.png</PackageIconUrl>

Expand Down
43 changes: 33 additions & 10 deletions framework/src/Silky.Validation/Filters/ClientValidationFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,39 @@ public ClientValidationFilter(IMethodInvocationValidator methodInvocationValidat
public async Task OnActionExecutionAsync(ClientInvokeExecutingContext context,
ClientInvokeExecutionDelegate next)
{
var remoteInvokeMessage = context.RemoteInvokeMessage;
if (!EngineContext.Current.ApplicationOptions.AutoValidationParameters) return;
if (remoteInvokeMessage.ParameterType != ParameterType.Rpc) return;
var serviceEntry = _serviceEntryLocator.GetServiceEntryById(remoteInvokeMessage.ServiceEntryId);
if (serviceEntry == null) return;
if (serviceEntry.IsLocal) return;
await _methodInvocationValidator.Validate(
new MethodInvocationValidationContext(serviceEntry.MethodInfo, remoteInvokeMessage.Parameters));
RpcContext.Context.SetInvokeAttachment(AttachmentKeys.ValidationParametersInClient, true);
await next();
if (!EngineContext.Current.ApplicationOptions.AutoValidationParameters)
{
await next();
}
else
{
var remoteInvokeMessage = context.RemoteInvokeMessage;

if (remoteInvokeMessage.ParameterType != ParameterType.Rpc)
{
await next();
}
else
{
var serviceEntry = _serviceEntryLocator.GetServiceEntryById(remoteInvokeMessage.ServiceEntryId);
if (serviceEntry == null)
{
await next();
}
else if (serviceEntry.IsLocal)
{
await next();
}
else
{
await _methodInvocationValidator.Validate(
new MethodInvocationValidationContext(serviceEntry.MethodInfo, remoteInvokeMessage.Parameters));
RpcContext.Context.SetInvokeAttachment(AttachmentKeys.ValidationParametersInClient, true);
await next();
}
}
}

}
}
}
25 changes: 18 additions & 7 deletions framework/src/Silky.Validation/Filters/ServerValidationFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,25 @@ public ServerValidationFilter(IMethodInvocationValidator methodInvocationValidat
{
_methodInvocationValidator = methodInvocationValidator;
}

public async Task OnActionExecutionAsync(ServerInvokeExecutingContext context, ServerExecutionDelegate next)
{
if (!EngineContext.Current.ApplicationOptions.AutoValidationParameters) return;
if (RpcContext.Context.GetInvokeAttachment(AttachmentKeys.ValidationParametersInClient)?.ConventTo<bool>() ==
true) return;
await _methodInvocationValidator.Validate(
new MethodInvocationValidationContext(context.ServiceEntry.MethodInfo, context.Parameters));
await next();
if (!EngineContext.Current.ApplicationOptions.AutoValidationParameters)
{
await next();
}

else if (RpcContext.Context.GetInvokeAttachment(AttachmentKeys.ValidationParametersInClient)
?.ConventTo<bool>() ==
true)
{
await next();
}
else
{
await _methodInvocationValidator.Validate(
new MethodInvocationValidationContext(context.ServiceEntry.MethodInfo, context.Parameters));
await next();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public TestInputValidator()
RuleFor(x => x.Name).Length(3, 10).WithMessage("姓名长度为3~10位(Fluent)");
// RuleFor(x => x.Phone).Matches("^1[3-9]\\d{9}$").WithMessage("手机号码格式不正确");
RuleFor(x => x.Address).NotEmpty().WithMessage("地址不允许为空(Fluent)");
RuleFor(x => x.Address).CustomAsync(async (v, context, arg3) => { });
}
}
}
2 changes: 1 addition & 1 deletion templates/app/content/common.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<PropertyGroup>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);1591</NoWarn>
<SilkyVersion>3.7.9</SilkyVersion>
<SilkyVersion>3.7.10</SilkyVersion>
</PropertyGroup>
</Project>

0 comments on commit a5fe3bd

Please sign in to comment.