Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mall.oytour.com
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
黄奎
mall.oytour.com
Commits
84fdcc16
Commit
84fdcc16
authored
Aug 05, 2020
by
黄奎
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增页面
parent
9ecc86f5
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
1582 additions
and
0 deletions
+1582
-0
AOPHelper.cs
Mall.AOP/AOPHelper.cs
+26
-0
BaseInterceptorAttribute.cs
Mall.AOP/BaseInterceptorAttribute.cs
+23
-0
LogAttribute.cs
Mall.AOP/CustomerAttribute/LogAttribute.cs
+23
-0
TransactionCallHandlerAttribute.cs
....AOP/CustomerAttribute/TransactionCallHandlerAttribute.cs
+80
-0
IOCInterceptor.cs
Mall.AOP/IOCInterceptor.cs
+51
-0
Mall.AOP.csproj
Mall.AOP/Mall.AOP.csproj
+11
-0
RedisConnectionHelp.cs
Mall.CacheManager/Base/RedisConnectionHelp.cs
+167
-0
RedisHelper.cs
Mall.CacheManager/Base/RedisHelper.cs
+1142
-0
BaseRepository.cs
Mall.Repository/Core/BaseRepository.cs
+59
-0
No files found.
Mall.AOP/AOPHelper.cs
0 → 100644
View file @
84fdcc16
using
Castle.DynamicProxy
;
using
System
;
using
System.Collections.Generic
;
using
System.Text
;
namespace
Mall.AOP
{
/// <summary>
/// AOP帮助类
/// </summary>
public
class
AOPHelper
{
/// <summary>
/// 生成代理类对象
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public
static
T
CreateAOPObject
<
T
>()
where
T
:
class
{
ProxyGenerator
generator
=
new
ProxyGenerator
();
IOCInterceptor
interceptor
=
new
IOCInterceptor
();
T
t
=
generator
.
CreateClassProxy
<
T
>(
interceptor
);
return
t
;
}
}
}
Mall.AOP/BaseInterceptorAttribute.cs
0 → 100644
View file @
84fdcc16
using
Castle.DynamicProxy
;
using
Mall.AOP.CustomerAttribute
;
using
System
;
using
System.Collections.Generic
;
using
System.Reflection
;
using
System.Text
;
using
System.Transactions
;
using
System.Linq
;
namespace
Mall.AOP
{
/// <summary>
/// AOP属性基类
/// </summary>
public
abstract
class
BaseInterceptorAttribute
:
Attribute
{
/// <summary>
/// 具体执行的方法
/// </summary>
public
abstract
Action
Do
(
IInvocation
invocation
,
Action
action
);
}
}
Mall.AOP/CustomerAttribute/LogAttribute.cs
0 → 100644
View file @
84fdcc16
using
Castle.DynamicProxy
;
using
System
;
using
System.Collections.Generic
;
using
System.Text
;
namespace
Mall.AOP.CustomerAttribute
{
/// <summary>
/// 日志属性
/// </summary>
public
class
LogAttribute
:
BaseInterceptorAttribute
{
public
override
Action
Do
(
IInvocation
invocation
,
Action
action
)
{
return
()
=>
{
Console
.
WriteLine
(
"LogAttribute1"
);
action
.
Invoke
();
Console
.
WriteLine
(
"LogAttribute2"
);
};
}
}
}
Mall.AOP/CustomerAttribute/TransactionCallHandlerAttribute.cs
0 → 100644
View file @
84fdcc16
using
Castle.DynamicProxy
;
using
System
;
using
System.Collections.Generic
;
using
System.Text
;
using
System.Transactions
;
namespace
Mall.AOP.CustomerAttribute
{
/// <summary>
/// 事务属性
/// </summary>
[
AttributeUsage
(
AttributeTargets
.
Method
,
Inherited
=
true
)]
public
class
TransactionCallHandlerAttribute
:
BaseInterceptorAttribute
{
/// <summary>
/// 超时时间
/// </summary>
public
int
Timeout
{
get
;
set
;
}
/// <summary>
/// 事务范围
/// </summary>
public
TransactionScopeOption
ScopeOption
{
get
;
set
;
}
/// <summary>
/// 事务隔离级别
/// </summary>
public
IsolationLevel
IsolationLevel
{
get
;
set
;
}
/// <summary>
/// 构造函数
/// </summary>
public
TransactionCallHandlerAttribute
()
{
Timeout
=
60
;
ScopeOption
=
TransactionScopeOption
.
Required
;
IsolationLevel
=
IsolationLevel
.
ReadCommitted
;
}
/// <summary>
/// 执行方法
/// </summary>
/// <param name="invocation"></param>
/// <param name="action"></param>
/// <returns></returns>
public
override
Action
Do
(
IInvocation
invocation
,
Action
action
)
{
return
()
=>
{
Console
.
WriteLine
(
"TransactionCallHandlerAttribute1"
);
TransactionOptions
transactionOptions
=
new
TransactionOptions
();
//设置事务隔离级别
transactionOptions
.
IsolationLevel
=
this
.
IsolationLevel
;
//设置事务超时时间为60秒
transactionOptions
.
Timeout
=
new
TimeSpan
(
0
,
0
,
this
.
Timeout
);
using
(
TransactionScope
scope
=
new
TransactionScope
(
this
.
ScopeOption
,
transactionOptions
))
{
try
{
//实现事务性工作
action
.
Invoke
();
var
result
=
invocation
.
ReturnValue
;
bool
.
TryParse
((
result
!=
null
?
result
.
ToString
()
:
""
),
out
bool
IsSuccess
);
if
(
IsSuccess
)
{
scope
.
Complete
();
}
}
catch
(
Exception
ex
)
{
// 记录异常
throw
ex
;
}
}
Console
.
WriteLine
(
"TransactionCallHandlerAttribute2"
);
};
}
}
}
Mall.AOP/IOCInterceptor.cs
0 → 100644
View file @
84fdcc16
using
System
;
using
System.Collections.Generic
;
namespace
Mall.AOP
{
/// <summary>
/// 拦截器基类
/// </summary>
public
class
IOCInterceptor
:
Castle
.
DynamicProxy
.
StandardInterceptor
{
/// <summary>
/// 方法调用前执行
/// </summary>
/// <param name="invocation"></param>
protected
override
void
PreProceed
(
Castle
.
DynamicProxy
.
IInvocation
invocation
)
{
Console
.
WriteLine
(
"调用前的拦截器, 方法名是: {0}"
,
invocation
.
Method
.
Name
);
}
/// <summary>
/// 方法执行时调用
/// </summary>
/// <param name="invocation"></param>
protected
override
void
PerformProceed
(
Castle
.
DynamicProxy
.
IInvocation
invocation
)
{
var
method
=
invocation
.
Method
;
Action
action
=
()
=>
base
.
PerformProceed
(
invocation
);
if
(
method
.
IsDefined
(
typeof
(
BaseInterceptorAttribute
),
true
))
{
foreach
(
var
attribute
in
method
.
GetCustomAttributes
(
typeof
(
BaseInterceptorAttribute
),
true
))
{
var
attr
=
(
BaseInterceptorAttribute
)
attribute
;
action
=
attr
.
Do
(
invocation
,
action
);
}
}
action
.
Invoke
();
Console
.
WriteLine
(
"拦截的方法返回时调用的拦截, 方法名是: {0}"
,
invocation
.
Method
.
Name
);
}
/// <summary>
/// 方法执行后调用
/// </summary>
/// <param name="invocation"></param>
protected
override
void
PostProceed
(
Castle
.
DynamicProxy
.
IInvocation
invocation
)
{
Console
.
WriteLine
(
"调用后的拦截器, 方法名是: {0}"
,
invocation
.
Method
.
Name
);
}
}
}
Mall.AOP/Mall.AOP.csproj
0 → 100644
View file @
84fdcc16
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Castle.Core" Version="4.4.1" />
</ItemGroup>
</Project>
Mall.CacheManager/Base/RedisConnectionHelp.cs
0 → 100644
View file @
84fdcc16
using
Microsoft.Extensions.Configuration
;
using
Microsoft.Extensions.Configuration.Json
;
using
StackExchange.Redis
;
using
System
;
using
System.Collections.Concurrent
;
using
System.Collections.Generic
;
using
System.Configuration
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
namespace
Mall.CacheManager.Base
{
/// <summary>
/// ConnectionMultiplexer对象管理帮助类
/// </summary>
public
static
class
RedisConnectionHelp
{
/// <summary>
/// 系统自定义Key前缀
/// </summary>
public
static
readonly
string
SysCustomKey
=
""
;
/// <summary>
/// 连接字符串
/// </summary>
private
static
readonly
string
RedisConnectionString
=
$@"
{
new
ConfigurationBuilder
().
Add
(
new
JsonConfigurationSource
{
Path
=
"appsettings.json"
}).
Build
().
GetSection
(
"RedisSetting"
)[
"RedisServer"
]}
:
{
new
ConfigurationBuilder
().
Add
(
new
JsonConfigurationSource
{
Path
=
"appsettings.json"
}).
Build
().
GetSection
(
"RedisSetting"
)[
"RedisPort"
]}
,allowadmin=true,password=
{
new
ConfigurationBuilder
().
Add
(
new
JsonConfigurationSource
{
Path
=
"appsettings.json"
}).
Build
().
GetSection
(
"RedisSetting"
)[
"RedisPwd"
]}
"
;
private
static
readonly
object
Locker
=
new
object
();
private
static
ConnectionMultiplexer
_instance
;
/// <summary>
/// 线程安全的字典
/// </summary>
private
static
readonly
ConcurrentDictionary
<
string
,
ConnectionMultiplexer
>
ConnectionCache
=
new
ConcurrentDictionary
<
string
,
ConnectionMultiplexer
>();
/// <summary>
/// 单例获取
/// </summary>
public
static
ConnectionMultiplexer
Instance
{
get
{
if
(
_instance
==
null
)
{
lock
(
Locker
)
{
if
(
_instance
==
null
||
!
_instance
.
IsConnected
)
{
_instance
=
GetManager
();
}
}
}
return
_instance
;
}
}
/// <summary>
/// 缓存获取
/// </summary>
/// <param name="connectionString"></param>
/// <returns></returns>
public
static
ConnectionMultiplexer
GetConnectionMultiplexer
(
string
connectionString
)
{
if
(!
ConnectionCache
.
ContainsKey
(
connectionString
))
{
ConnectionCache
[
connectionString
]
=
GetManager
(
connectionString
);
}
return
ConnectionCache
[
connectionString
];
}
/// <summary>
/// 获取连接
/// </summary>
/// <param name="connectionString"></param>
/// <returns></returns>
private
static
ConnectionMultiplexer
GetManager
(
string
connectionString
=
null
)
{
connectionString
=
connectionString
??
RedisConnectionString
;
var
connect
=
ConnectionMultiplexer
.
Connect
(
connectionString
);
//注册如下事件
connect
.
ConnectionFailed
+=
MuxerConnectionFailed
;
connect
.
ConnectionRestored
+=
MuxerConnectionRestored
;
connect
.
ErrorMessage
+=
MuxerErrorMessage
;
connect
.
ConfigurationChanged
+=
MuxerConfigurationChanged
;
connect
.
HashSlotMoved
+=
MuxerHashSlotMoved
;
connect
.
InternalError
+=
MuxerInternalError
;
connect
.
ConfigurationChangedBroadcast
+=
MuxerConfigurationChangedBroadcast
;
return
connect
;
}
#
region
事件
/// <summary>
/// 重新配置广播时(通常意味着主从同步更改)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private
static
void
MuxerConfigurationChangedBroadcast
(
object
sender
,
EndPointEventArgs
e
)
{
Console
.
WriteLine
(
$"
{
nameof
(
MuxerConfigurationChangedBroadcast
)}
:
{
e
.
EndPoint
}
"
);
}
/// <summary>
/// 配置更改时
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private
static
void
MuxerConfigurationChanged
(
object
sender
,
EndPointEventArgs
e
)
{
Console
.
WriteLine
(
"Configuration changed: "
+
e
.
EndPoint
);
}
/// <summary>
/// 发生内部错误时(主要用于调试)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private
static
void
MuxerErrorMessage
(
object
sender
,
RedisErrorEventArgs
e
)
{
Console
.
WriteLine
(
"ErrorMessage: "
+
e
.
Message
);
}
/// <summary>
/// 重新建立连接之前的错误
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private
static
void
MuxerConnectionRestored
(
object
sender
,
ConnectionFailedEventArgs
e
)
{
Console
.
WriteLine
(
"ConnectionRestored: "
+
e
.
EndPoint
);
}
/// <summary>
/// 连接失败 , 如果重新连接成功你将不会收到这个通知
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private
static
void
MuxerConnectionFailed
(
object
sender
,
ConnectionFailedEventArgs
e
)
{
Console
.
WriteLine
(
"重新连接:Endpoint failed: "
+
e
.
EndPoint
+
", "
+
e
.
FailureType
+
(
e
.
Exception
==
null
?
""
:
(
", "
+
e
.
Exception
.
Message
)));
}
/// <summary>
/// 更改集群时
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private
static
void
MuxerHashSlotMoved
(
object
sender
,
HashSlotMovedEventArgs
e
)
{
Console
.
WriteLine
(
"HashSlotMoved:NewEndPoint"
+
e
.
NewEndPoint
+
", OldEndPoint"
+
e
.
OldEndPoint
);
}
/// <summary>
/// redis类库错误
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private
static
void
MuxerInternalError
(
object
sender
,
InternalErrorEventArgs
e
)
{
Console
.
WriteLine
(
"InternalError:Message"
+
e
.
Exception
.
Message
);
}
#
endregion
}
}
Mall.CacheManager/Base/RedisHelper.cs
0 → 100644
View file @
84fdcc16
This diff is collapsed.
Click to expand it.
Mall.Repository/Core/BaseRepository.cs
0 → 100644
View file @
84fdcc16
using
System
;
using
System.Collections.Generic
;
using
System.Text
;
using
VT.FW.DB
;
namespace
Mall.Repository
{
public
class
BaseRepository
<
T
>
:
RepositoryBase
<
T
>
where
T
:
class
{
/// <summary>
/// 数据库连接Key
/// </summary>
public
string
ConnKey
{
get
;
set
;
}
public
BaseRepository
(
string
connKey
=
"DefaultConnection"
)
{
try
{
var
classAttribute
=
(
DBAttribute
)
Attribute
.
GetCustomAttribute
(
typeof
(
T
),
typeof
(
DBAttribute
));
connKey
=
classAttribute
.
ConnectionName
??
"DefaultConnection"
;
}
catch
(
Exception
ex
)
{
throw
ex
;
}
ConnKey
=
connKey
;
}
public
string
_ConnectionStr
;
public
string
_ProviderName
;
public
override
string
ConnectionStr
{
get
{
_ConnectionStr
=
Common
.
Config
.
GetConnectionString
(
ConnKey
);
return
_ConnectionStr
;
}
set
{
_ConnectionStr
=
value
;
}
}
public
override
string
ProviderName
{
get
{
_ProviderName
=
"MySql.Data.MySqlClient"
;
return
_ProviderName
;
}
set
{
_ProviderName
=
value
;
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment