Skip to content

Commit

Permalink
升级包版本
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaohua committed Dec 22, 2020
1 parent 693dd99 commit b096630
Show file tree
Hide file tree
Showing 13 changed files with 363 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Facade.Dapper.Oracle" Version="2.2.4" />
<PackageReference Include="Facade.NLogger" Version="2.2.4" />
<PackageReference Include="Facade.Dapper.Oracle" Version="2.2.6" />
<PackageReference Include="Facade.NLogger" Version="2.2.6" />
</ItemGroup>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Facade.AutoMapper" Version="2.2.4" />
<PackageReference Include="Facade.Quartz" Version="2.2.4" />
<PackageReference Include="Facade.AutoMapper" Version="2.2.6" />
<PackageReference Include="Facade.Quartz" Version="2.2.6" />
</ItemGroup>

<ItemGroup>
Expand Down
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; }
}
}
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; }
}
}
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;
}
}
}
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;
}
}
}
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
{
}
}
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);
}
}
}
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() });
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Facade.AspNetCore" Version="2.2.4" />
<PackageReference Include="Facade.AspNetCore.Zero" Version="2.2.4" />
<PackageReference Include="Facade.AspNetCore.SignalR" Version="2.2.4" />
<PackageReference Include="Facade.AspNetCore" Version="2.2.6" />
<PackageReference Include="Facade.AspNetCore.Zero" Version="2.2.6" />
<PackageReference Include="Facade.AspNetCore.SignalR" Version="2.2.6" />

<PackageReference Include="IdentityModel" Version="4.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.6" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.4.1" />
</ItemGroup>

Expand Down
Loading

0 comments on commit b096630

Please sign in to comment.