-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
xiaohua
committed
Dec 22, 2020
1 parent
693dd99
commit b096630
Showing
13 changed files
with
363 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/FacadeCompanyName.FacadeProjectName.DomainService/Folders/AppFolders.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using Abp.Dependency; | ||
|
||
namespace FacadeCompanyName.FacadeProjectName.DomainService.Folders | ||
{ | ||
public class AppFolders : IAppFolders, ISingletonDependency | ||
{ | ||
public string TempFileUploadFolder { get; set; } | ||
public string TempFileDownloadFolder { get; set; } | ||
public string FileUploadFolder { get; set; } | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/FacadeCompanyName.FacadeProjectName.DomainService/Folders/IAppFolders.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
namespace FacadeCompanyName.FacadeProjectName.DomainService.Folders | ||
{ | ||
public interface IAppFolders | ||
{ | ||
/// <summary> | ||
/// 临时文件下载文件夹 /downloads/temps | ||
/// </summary> | ||
string TempFileDownloadFolder { get; } | ||
/// <summary> | ||
/// 临时文件上传文件夹 /uploads/temps | ||
/// </summary> | ||
string TempFileUploadFolder { get; } | ||
|
||
/// <summary> | ||
/// 文件上传后保存的路径 /uploads/ | ||
/// </summary> | ||
string FileUploadFolder { get; } | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...anyName.FacadeProjectName.Oracle/EntityFrameworkCore/Interceptors/InterceptorRegistrar.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using Castle.Core; | ||
using Castle.MicroKernel; | ||
using System; | ||
using System.Linq; | ||
|
||
namespace FacadeCompanyName.FacadeProjectName.Oracle.EntityFrameworkCore.Interceptors | ||
{ | ||
public class InterceptorRegistrar | ||
{ | ||
public static void Initialize(IKernel kernel) | ||
{ | ||
kernel.ComponentRegistered += Kernel_ComponentRegistered; | ||
} | ||
|
||
private static void Kernel_ComponentRegistered(string key, IHandler handler) | ||
{ | ||
if (JobShouldIntercept(handler.ComponentModel.Implementation)) | ||
{ | ||
handler.ComponentModel.Interceptors.Add(new InterceptorReference(typeof(RepositoryInterceptor))); | ||
} | ||
|
||
|
||
} | ||
private static bool JobShouldIntercept(Type type) | ||
{ | ||
|
||
//if (type.GetTypeInfo().IsDefined(typeof(JobInterceptorAttribute), true)) | ||
//{ | ||
// return true; | ||
//} | ||
|
||
if (type.GetMethods().Any(m => m.IsDefined(typeof(RepositoryInterceptorAttribute), true))) | ||
{ | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
} | ||
} |
118 changes: 118 additions & 0 deletions
118
...nyName.FacadeProjectName.Oracle/EntityFrameworkCore/Interceptors/RepositoryInterceptor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
using Abp.Dependency; | ||
using Abp.Json; | ||
using Abp.Threading; | ||
using Castle.Core.Logging; | ||
using Castle.DynamicProxy; | ||
using FacadeCompanyName.FacadeProjectName.DomainService.Share; | ||
using System; | ||
using System.Reflection; | ||
using System.Threading.Tasks; | ||
|
||
namespace FacadeCompanyName.FacadeProjectName.Oracle.EntityFrameworkCore.Interceptors | ||
{ | ||
public class RepositoryInterceptor : IInterceptor | ||
{ | ||
private readonly ILogger _logger; | ||
|
||
public RepositoryInterceptor() | ||
{ | ||
_logger = IocManager.Instance.Resolve<ILogger>(); | ||
} | ||
|
||
public void Intercept(IInvocation invocation) | ||
{ | ||
if (!ShouldIntercept(invocation.MethodInvocationTarget)) | ||
{ | ||
invocation.Proceed(); | ||
return; | ||
} | ||
|
||
if (invocation.Method.IsAsync()) | ||
{ | ||
PerformAsync(invocation); | ||
} | ||
else | ||
{ | ||
PerformSync(invocation); | ||
} | ||
} | ||
|
||
private void PerformSync(IInvocation invocation) | ||
{ | ||
var fullName = invocation.Method.DeclaringType.FullName + "." + invocation.Method.Name; | ||
try | ||
{ | ||
invocation.Proceed(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
ExceptionHanding(ex, fullName, invocation.Arguments); | ||
} | ||
} | ||
|
||
private void PerformAsync(IInvocation invocation) | ||
{ | ||
var fullName = invocation.Method.DeclaringType.FullName + "." + invocation.Method.Name; | ||
PerformSync(invocation); | ||
|
||
if (invocation.Method.ReturnType == typeof(Task)) | ||
{ | ||
invocation.ReturnValue = InternalAsyncHelper.AwaitTaskWithFinally( | ||
(Task)invocation.ReturnValue, | ||
ex => | ||
{ | ||
ExceptionHanding(ex, fullName, invocation.Arguments); | ||
}); | ||
} | ||
else //Task<TResult> | ||
{ | ||
invocation.ReturnValue = InternalAsyncHelper.CallAwaitTaskWithFinallyAndGetResult( | ||
invocation.Method.ReturnType.GenericTypeArguments[0], | ||
invocation.ReturnValue, | ||
ex => | ||
{ | ||
ExceptionHanding(ex, fullName, invocation.Arguments); | ||
}); | ||
} | ||
} | ||
|
||
private void ExceptionHanding(Exception ex, string fullName, object args) | ||
{ | ||
if (ex != null) | ||
{ | ||
_logger.Error(ex.Message + $"\r\n{fullName}:\r\n" + args.ToJsonString().Replace("\r\n", " "), ex); | ||
throw ex; | ||
} | ||
} | ||
|
||
|
||
private bool ShouldIntercept(MethodInfo methodInfo) | ||
{ | ||
if (methodInfo == null) | ||
{ | ||
return false; | ||
} | ||
|
||
if (!methodInfo.IsPublic) | ||
{ | ||
return false; | ||
} | ||
|
||
if (methodInfo.IsDefined(typeof(RepositoryInterceptorAttribute), true)) | ||
{ | ||
return true; | ||
} | ||
|
||
//var classType = methodInfo.DeclaringType; | ||
//if (classType != null) | ||
//{ | ||
// if (classType.GetTypeInfo().IsDefined(typeof(JobInterceptorAttribute), true)) | ||
// { | ||
// return true; | ||
// } | ||
//} | ||
|
||
return false; | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...cadeProjectName.Oracle/EntityFrameworkCore/Interceptors/RepositoryInterceptorAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System; | ||
|
||
namespace FacadeCompanyName.FacadeProjectName.Oracle.EntityFrameworkCore.Interceptors | ||
{ | ||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)] | ||
public class RepositoryInterceptorAttribute : Attribute | ||
{ | ||
} | ||
} |
78 changes: 64 additions & 14 deletions
78
...mpanyName.FacadeProjectName.Oracle/EntityFrameworkCore/Repositories/AppQueryRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,64 @@ | ||
using Facade.Dapper; | ||
using Facade.Dapper.Oracle; | ||
using FacadeCompanyName.FacadeProjectName.DomainService.Share; | ||
|
||
namespace FacadeCompanyName.FacadeProjectName.Oracle.EntityFrameworkCore.Repositories | ||
{ | ||
public class AppQueryRepository : OracleQueryRepository, IAppQueryRepository | ||
{ | ||
public AppQueryRepository(IFacadeConnectionProvider facadeConnectionProvider) | ||
: base(facadeConnectionProvider) | ||
{ | ||
} | ||
} | ||
} | ||
using Dapper; | ||
using Facade.Dapper; | ||
using Facade.Dapper.Oracle; | ||
using FacadeCompanyName.FacadeProjectName.DomainService.Share; | ||
using FacadeCompanyName.FacadeProjectName.Oracle.EntityFrameworkCore.Interceptors; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
|
||
namespace FacadeCompanyName.FacadeProjectName.Oracle.EntityFrameworkCore.Repositories | ||
{ | ||
public class AppQueryRepository : OracleQueryRepository, IAppQueryRepository | ||
{ | ||
public AppQueryRepository(IFacadeConnectionProvider facadeConnectionProvider) | ||
: base(facadeConnectionProvider) | ||
{ | ||
} | ||
[RepositoryInterceptor] | ||
public override Task<int> ExecuteAsync(string query, object param = null) | ||
{ | ||
return base.ExecuteAsync(query, param); | ||
} | ||
[RepositoryInterceptor] | ||
public override Task<T> ExecuteScalarAsync<T>(string query, object param = null) | ||
{ | ||
return base.ExecuteScalarAsync<T>(query, param); | ||
} | ||
[RepositoryInterceptor] | ||
public override Task<IEnumerable<T>> QueryAsync<T>(string query, object param = null) | ||
{ | ||
return base.QueryAsync<T>(query, param); | ||
} | ||
[RepositoryInterceptor] | ||
public override Task<IEnumerable<TReturn>> QueryAsync<TFirst, TSecond, TReturn>(string query, Func<TFirst, TSecond, TReturn> map, object param = null) | ||
{ | ||
return base.QueryAsync<TFirst, TSecond, TReturn>(query, map, param); | ||
} | ||
[RepositoryInterceptor] | ||
public override Task<IEnumerable<TReturn>> QueryAsync<TFirst, TSecond, TThird, TReturn>(string query, Func<TFirst, TSecond, TThird, TReturn> map, object param = null) | ||
{ | ||
return base.QueryAsync<TFirst, TSecond, TThird, TReturn>(query, map, param); | ||
} | ||
[RepositoryInterceptor] | ||
public override Task<IEnumerable<TReturn>> QueryAsync<TFirst, TSecond, TThird, TFourth, TReturn>(string query, Func<TFirst, TSecond, TThird, TFourth, TReturn> map, object param = null) | ||
{ | ||
return base.QueryAsync<TFirst, TSecond, TThird, TFourth, TReturn>(query, map, param); | ||
} | ||
[RepositoryInterceptor] | ||
public override Task<T> QueryFirstOrDefaultAsync<T>(string query, object param = null) | ||
{ | ||
return base.QueryFirstOrDefaultAsync<T>(query, param); | ||
} | ||
[RepositoryInterceptor] | ||
public override Task<SqlMapper.GridReader> QueryMultipleAsync(string query, object param = null) | ||
{ | ||
return base.QueryMultipleAsync(query, param); | ||
} | ||
[RepositoryInterceptor] | ||
public override Task<(IEnumerable<T> list, int totalCount)> PagedAsync<T>(string query, int currentPage = 1, int pageCount = 10, object param = null) | ||
{ | ||
return base.PagedAsync<T>(query, currentPage, pageCount, param); | ||
} | ||
} | ||
} |
61 changes: 32 additions & 29 deletions
61
src/FacadeCompanyName.FacadeProjectName.Oracle/FacadeProjectNameOracleModule.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,32 @@ | ||
using Abp.Modules; | ||
using Abp.Reflection.Extensions; | ||
using FacadeCompanyName.FacadeProjectName.DomainService.Share; | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
|
||
namespace FacadeCompanyName.FacadeProjectName.Oracle | ||
{ | ||
[DependsOn( | ||
typeof(FacadeProjectNameDomainServiceShareModule) | ||
)] | ||
public class FacadeProjectNameOracleModule : AbpModule | ||
{ | ||
|
||
public FacadeProjectNameOracleModule() | ||
{ | ||
} | ||
public override void PreInitialize() | ||
{ | ||
} | ||
|
||
public override void Initialize() | ||
{ | ||
IocManager.RegisterAssemblyByConvention(typeof(FacadeProjectNameOracleModule).GetAssembly()); | ||
DapperExtensions.DapperExtensions.SetMappingAssemblies(new List<Assembly> { typeof(FacadeProjectNameOracleModule).GetAssembly() }); | ||
} | ||
|
||
} | ||
} | ||
using Abp.Modules; | ||
using Abp.Reflection.Extensions; | ||
using FacadeCompanyName.FacadeProjectName.DomainService.Share; | ||
using FacadeCompanyName.FacadeProjectName.Oracle.EntityFrameworkCore.Interceptors; | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
|
||
namespace FacadeCompanyName.FacadeProjectName.Oracle | ||
{ | ||
[DependsOn( | ||
typeof(FacadeProjectNameDomainServiceShareModule) | ||
)] | ||
public class FacadeProjectNameOracleModule : AbpModule | ||
{ | ||
|
||
public FacadeProjectNameOracleModule() | ||
{ | ||
} | ||
public override void PreInitialize() | ||
{ | ||
//注册拦截器 | ||
InterceptorRegistrar.Initialize(IocManager.IocContainer.Kernel); | ||
} | ||
|
||
public override void Initialize() | ||
{ | ||
IocManager.RegisterAssemblyByConvention(typeof(FacadeProjectNameOracleModule).GetAssembly()); | ||
DapperExtensions.DapperExtensions.SetMappingAssemblies(new List<Assembly> { typeof(FacadeProjectNameOracleModule).GetAssembly() }); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.