89 lines
2.9 KiB
C#
89 lines
2.9 KiB
C#
using Castle.DynamicProxy;
|
|
using EasyCaching.Core;
|
|
using IRaCIS.Application.Contracts;
|
|
using IRaCIS.Core.Domain.Share;
|
|
|
|
namespace IRaCIS.Core.Application.AOP
|
|
{
|
|
public class TrialStatusAutofacAOP : IAsyncInterceptor
|
|
{
|
|
private readonly IEasyCachingProvider _provider;
|
|
|
|
public TrialStatusAutofacAOP(IEasyCachingProvider provider)
|
|
{
|
|
_provider = provider;
|
|
}
|
|
|
|
|
|
|
|
public void InterceptAsynchronous(IInvocation invocation)
|
|
{
|
|
invocation.Proceed();
|
|
}
|
|
|
|
//这里AOP 处理两个方法 分别是 项目的添加和更新、项目状态的变更
|
|
|
|
public void InterceptAsynchronous<TResult>(IInvocation invocation)
|
|
{
|
|
|
|
|
|
//处理拦截的方法
|
|
invocation.Proceed();
|
|
|
|
|
|
|
|
dynamic result = invocation.ReturnValue;
|
|
|
|
//接口成功了,才修改缓存
|
|
if (!result.IsSuccess)
|
|
{
|
|
return;
|
|
}
|
|
|
|
#region 处理项目列表的查询 在前端界面已经在某个界面,但是服务器重置了,此时没有缓存项目信息,接口不能正确返回,因故采用,启动时查询,每天查询一次,缓存一天,然后项目添加、更改状态时,及时更新
|
|
|
|
//if (invocation.Method.Name == "GetTrialList")
|
|
//{
|
|
// //在此 将当前查询的项目Id 和对应的项目状态进行缓存
|
|
// dynamic result = invocation.ReturnValue;
|
|
// foreach (var item in result.CurrentPageData)
|
|
// {
|
|
// _provider.Remove(item.Id.ToString());
|
|
// _provider.Set(item.Id.ToString(), item.TrialStatusStr.ToString(), TimeSpan.FromDays(1));
|
|
// }
|
|
//}
|
|
|
|
#endregion
|
|
|
|
if (invocation.Method.Name == "AddOrUpdateTrial")
|
|
{
|
|
//如果是添加 那么将对应的初始状态加进去 更新状态是单独操作的
|
|
|
|
var trialModel = (invocation.Arguments[0] as TrialCommand).IfNullThrowConvertException();
|
|
if (trialModel.Id == null || trialModel.Id == Guid.Empty)
|
|
{
|
|
_provider.Set(result.Data.Id.ToString(), StaticData.TrialOngoing, TimeSpan.FromDays(1));
|
|
}
|
|
|
|
|
|
}
|
|
// 更新缓存
|
|
else if (invocation.Method.Name == "UpdateTrialStatus")
|
|
{
|
|
//项目状态更新,也需要及时更新
|
|
_provider.Set(invocation.Arguments[0].ToString(), invocation.Arguments[1].ToString(), TimeSpan.FromDays(1));
|
|
|
|
////Test参数是否符合要求
|
|
//var tt = invocation.Arguments[0].ToString();
|
|
//var cc = _provider.Get<string>(invocation.Arguments[0].ToString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public void InterceptSynchronous(IInvocation invocation)
|
|
{
|
|
invocation.Proceed();
|
|
}
|
|
}
|
|
} |