Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
netcoreplus
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
tsai
netcoreplus
Commits
40acf97e
Commit
40acf97e
authored
May 17, 2019
by
阿星Plus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
工作单元 over.
parent
bba639d0
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
267 additions
and
73 deletions
+267
-73
ConnectionStringResolveArgs.cs
src/Plus/Domain/Uow/ConnectionStringResolveArgs.cs
+12
-0
IConnectionStringResolver.cs
src/Plus/Domain/Uow/IConnectionStringResolver.cs
+14
-0
IUnitOfWork.cs
src/Plus/Domain/Uow/IUnitOfWork.cs
+1
-13
NullUnitOfWork.cs
src/Plus/Domain/Uow/NullUnitOfWork.cs
+38
-3
NullUnitOfWorkFilterExecuter.cs
src/Plus/Domain/Uow/NullUnitOfWorkFilterExecuter.cs
+23
-0
PlusDataFilters.cs
src/Plus/Domain/Uow/PlusDataFilters.cs
+46
-0
UnitOfWorkBase.cs
src/Plus/Domain/Uow/UnitOfWorkBase.cs
+58
-57
PlusLeadershipModule.cs
src/Plus/PlusLeadershipModule.cs
+1
-0
DataAnnotationsValidator.cs
...ntime/Validation/Interception/DataAnnotationsValidator.cs
+51
-0
ValidatableObjectValidator.cs
...ime/Validation/Interception/ValidatableObjectValidator.cs
+23
-0
No files found.
src/Plus/Domain/Uow/ConnectionStringResolveArgs.cs
0 → 100644
View file @
40acf97e
using
System.Collections.Generic
;
namespace
Plus.Domain.Uow
{
/// <summary>
/// ConnectionStringResolveArgs
/// </summary>
public
class
ConnectionStringResolveArgs
:
Dictionary
<
string
,
object
>
{
}
}
\ No newline at end of file
src/Plus/Domain/Uow/IConnectionStringResolver.cs
0 → 100644
View file @
40acf97e
namespace
Plus.Domain.Uow
{
/// <summary>
/// Used to get connection string when a database connection is needed.
/// </summary>
public
interface
IConnectionStringResolver
{
/// <summary>
/// Gets a connection string name (in config file) or a valid connection string.
/// </summary>
/// <param name="args">Arguments that can be used while resolving connection string.</param>
string
GetNameOrConnectionString
(
ConnectionStringResolveArgs
args
);
}
}
\ No newline at end of file
src/Plus/Domain/Uow/IUnitOfWork.cs
View file @
40acf97e
namespace
Plus.Domain.Uow
namespace
Plus.Domain.Uow
{
{
/// <summary>
/// <summary>
/// Defines a unit of work.
/// 工作单元接口
/// This interface is internally used by ABP.
/// Use <see cref="IUnitOfWorkManager.Begin()"/> to start a new unit of work.
/// </summary>
/// </summary>
public
interface
IUnitOfWork
:
IActiveUnitOfWork
,
IUnitOfWorkCompleteHandle
public
interface
IUnitOfWork
:
IActiveUnitOfWork
,
IUnitOfWorkCompleteHandle
{
{
/// <summary>
/// Unique id of this UOW.
/// </summary>
string
Id
{
get
;
}
string
Id
{
get
;
}
/// <summary>
/// Reference to the outer UOW if exists.
/// </summary>
IUnitOfWork
Outer
{
get
;
set
;
}
IUnitOfWork
Outer
{
get
;
set
;
}
/// <summary>
/// Begins the unit of work with given options.
/// </summary>
/// <param name="options">Unit of work options</param>
void
Begin
(
UnitOfWorkOptions
options
);
void
Begin
(
UnitOfWorkOptions
options
);
}
}
}
}
\ No newline at end of file
src/Plus/Domain/Uow/NullUnitOfWork.cs
View file @
40acf97e
using
System
;
using
System.Threading.Tasks
;
using
System.Collections.Generic
;
using
System.Text
;
namespace
Plus.Domain.Uow
namespace
Plus.Domain.Uow
{
{
/// <summary>
/// 工作单元的空实现
/// </summary>
public
sealed
class
NullUnitOfWork
:
UnitOfWorkBase
public
sealed
class
NullUnitOfWork
:
UnitOfWorkBase
{
{
public
override
void
SaveChanges
()
{
}
public
override
Task
SaveChangesAsync
()
{
return
Task
.
FromResult
(
0
);
}
protected
override
void
BeginUow
()
{
}
protected
override
void
CompleteUow
()
{
}
protected
override
Task
CompleteUowAsync
()
{
return
Task
.
FromResult
(
0
);
}
protected
override
void
DisposeUow
()
{
}
public
NullUnitOfWork
(
IConnectionStringResolver
connectionStringResolver
,
IUnitOfWorkDefaultOptions
defaultOptions
,
IUnitOfWorkFilterExecuter
filterExecuter
)
:
base
(
connectionStringResolver
,
defaultOptions
,
filterExecuter
)
{
}
}
}
}
}
\ No newline at end of file
src/Plus/Domain/Uow/NullUnitOfWorkFilterExecuter.cs
0 → 100644
View file @
40acf97e
namespace
Plus.Domain.Uow
{
/// <summary>
/// NullUnitOfWorkFilterExecuter
/// </summary>
public
class
NullUnitOfWorkFilterExecuter
:
IUnitOfWorkFilterExecuter
{
public
void
ApplyDisableFilter
(
IUnitOfWork
unitOfWork
,
string
filterName
)
{
}
public
void
ApplyEnableFilter
(
IUnitOfWork
unitOfWork
,
string
filterName
)
{
}
public
void
ApplyFilterParameterValue
(
IUnitOfWork
unitOfWork
,
string
filterName
,
string
parameterName
,
object
value
)
{
}
}
}
\ No newline at end of file
src/Plus/Domain/Uow/PlusDataFilters.cs
0 → 100644
View file @
40acf97e
namespace
Plus.Domain.Uow
{
/// <summary>
/// Standard filters of ABP.
/// </summary>
public
static
class
PlusDataFilters
{
/// <summary>
/// "SoftDelete".
/// Soft delete filter.
/// Prevents getting deleted data from database.
/// See <see cref="ISoftDelete"/> interface.
/// </summary>
public
const
string
SoftDelete
=
"SoftDelete"
;
/// <summary>
/// "MustHaveTenant".
/// Tenant filter to prevent getting data that is
/// not belong to current tenant.
/// </summary>
public
const
string
MustHaveTenant
=
"MustHaveTenant"
;
/// <summary>
/// "MayHaveTenant".
/// Tenant filter to prevent getting data that is
/// not belong to current tenant.
/// </summary>
public
const
string
MayHaveTenant
=
"MayHaveTenant"
;
/// <summary>
/// Standard parameters of ABP.
/// </summary>
public
static
class
Parameters
{
/// <summary>
/// "tenantId".
/// </summary>
public
const
string
TenantId
=
"tenantId"
;
/// <summary>
/// "isDeleted".
/// </summary>
public
const
string
IsDeleted
=
"isDeleted"
;
}
}
}
\ No newline at end of file
src/Plus/Domain/Uow/UnitOfWorkBase.cs
View file @
40acf97e
...
@@ -22,52 +22,26 @@ namespace Plus.Domain.Uow
...
@@ -22,52 +22,26 @@ namespace Plus.Domain.Uow
private
Exception
_exception
;
private
Exception
_exception
;
public
string
Id
private
int
?
_tenantId
;
{
get
;
public
string
Id
{
get
;
}
}
[
DoNotWire
]
[
DoNotWire
]
public
IUnitOfWork
Outer
public
IUnitOfWork
Outer
{
get
;
set
;
}
{
get
;
set
;
}
public
UnitOfWorkOptions
Options
public
UnitOfWorkOptions
Options
{
get
;
private
set
;
}
{
get
;
private
set
;
}
public
IReadOnlyList
<
DataFilterConfiguration
>
Filters
=>
_filters
.
ToImmutableList
();
public
IReadOnlyList
<
DataFilterConfiguration
>
Filters
=>
_filters
.
ToImmutableList
();
public
Dictionary
<
string
,
object
>
Items
public
Dictionary
<
string
,
object
>
Items
{
get
;
set
;
}
{
get
;
set
;
}
protected
IUnitOfWorkDefaultOptions
DefaultOptions
protected
IUnitOfWorkDefaultOptions
DefaultOptions
{
get
;
}
{
get
;
}
protected
IConnectionStringResolver
ConnectionStringResolver
protected
IConnectionStringResolver
ConnectionStringResolver
{
get
;
}
{
get
;
}
public
bool
IsDisposed
public
bool
IsDisposed
{
get
;
private
set
;
}
{
get
;
private
set
;
}
protected
IUnitOfWorkFilterExecuter
FilterExecuter
protected
IUnitOfWorkFilterExecuter
FilterExecuter
{
get
;
}
{
get
;
}
public
event
EventHandler
Completed
;
public
event
EventHandler
Completed
;
...
@@ -210,6 +184,7 @@ namespace Plus.Domain.Uow
...
@@ -210,6 +184,7 @@ namespace Plus.Domain.Uow
protected
virtual
void
BeginUow
()
protected
virtual
void
BeginUow
()
{
{
}
}
protected
abstract
void
CompleteUow
();
protected
abstract
void
CompleteUow
();
...
@@ -257,7 +232,7 @@ namespace Plus.Domain.Uow
...
@@ -257,7 +232,7 @@ namespace Plus.Domain.Uow
{
{
if
(
_isBeginCalledBefore
)
if
(
_isBeginCalledBefore
)
{
{
throw
new
UPrime
Exception
(
"This unit of work has started before. Can not call Start method more than once."
);
throw
new
Plus
Exception
(
"This unit of work has started before. Can not call Start method more than once."
);
}
}
_isBeginCalledBefore
=
true
;
_isBeginCalledBefore
=
true
;
}
}
...
@@ -266,32 +241,19 @@ namespace Plus.Domain.Uow
...
@@ -266,32 +241,19 @@ namespace Plus.Domain.Uow
{
{
if
(
_isCompleteCalledBefore
)
if
(
_isCompleteCalledBefore
)
{
{
throw
new
UPrime
Exception
(
"Complete is called before!"
);
throw
new
Plus
Exception
(
"Complete is called before!"
);
}
}
_isCompleteCalledBefore
=
true
;
_isCompleteCalledBefore
=
true
;
}
}
private
void
SetFilters
(
List
<
DataFilterConfiguration
>
filterOverrides
)
private
void
SetFilters
(
List
<
DataFilterConfiguration
>
filterOverrides
)
{
{
int
i
;
for
(
var
i
=
0
;
i
<
_filters
.
Count
;
i
++)
for
(
i
=
0
;
i
<
_filters
.
Count
;
i
++)
{
{
DataFilterConfiguration
dataFilterConfiguration
=
filterOverrides
.
FirstOrDefault
((
DataFilterConfiguration
f
)
=>
f
.
FilterName
==
_filters
[
i
].
FilterName
);
var
filterOverride
=
filterOverrides
.
FirstOrDefault
(
f
=>
f
.
FilterName
==
_filters
[
i
].
FilterName
);
if
(
dataFilterConfiguration
!=
null
)
if
(
filterOverride
!=
null
)
{
{
_filters
[
i
]
=
dataFilterConfiguration
;
_filters
[
i
]
=
filterOverride
;
}
}
}
private
void
ChangeFilterIsEnabledIfNotOverrided
(
List
<
DataFilterConfiguration
>
filterOverrides
,
string
filterName
,
bool
isEnabled
)
{
if
(!
filterOverrides
.
Any
((
DataFilterConfiguration
f
)
=>
f
.
FilterName
==
filterName
))
{
int
num
=
_filters
.
FindIndex
((
DataFilterConfiguration
f
)
=>
f
.
FilterName
==
filterName
);
if
(
num
>=
0
&&
_filters
[
num
].
IsEnabled
!=
isEnabled
)
{
_filters
[
num
]
=
new
DataFilterConfiguration
(
filterName
,
isEnabled
);
}
}
}
}
}
}
...
@@ -301,7 +263,7 @@ namespace Plus.Domain.Uow
...
@@ -301,7 +263,7 @@ namespace Plus.Domain.Uow
DataFilterConfiguration
dataFilterConfiguration
=
_filters
.
FirstOrDefault
((
DataFilterConfiguration
f
)
=>
f
.
FilterName
==
filterName
);
DataFilterConfiguration
dataFilterConfiguration
=
_filters
.
FirstOrDefault
((
DataFilterConfiguration
f
)
=>
f
.
FilterName
==
filterName
);
if
(
dataFilterConfiguration
==
null
)
if
(
dataFilterConfiguration
==
null
)
{
{
throw
new
UPrime
Exception
(
"Unknown filter name: "
+
filterName
+
". Be sure this filter is registered before."
);
throw
new
Plus
Exception
(
"Unknown filter name: "
+
filterName
+
". Be sure this filter is registered before."
);
}
}
return
dataFilterConfiguration
;
return
dataFilterConfiguration
;
}
}
...
@@ -311,7 +273,7 @@ namespace Plus.Domain.Uow
...
@@ -311,7 +273,7 @@ namespace Plus.Domain.Uow
int
num
=
_filters
.
FindIndex
((
DataFilterConfiguration
f
)
=>
f
.
FilterName
==
filterName
);
int
num
=
_filters
.
FindIndex
((
DataFilterConfiguration
f
)
=>
f
.
FilterName
==
filterName
);
if
(
num
<
0
)
if
(
num
<
0
)
{
{
throw
new
UPrime
Exception
(
"Unknown filter name: "
+
filterName
+
". Be sure this filter is registered before."
);
throw
new
Plus
Exception
(
"Unknown filter name: "
+
filterName
+
". Be sure this filter is registered before."
);
}
}
return
num
;
return
num
;
}
}
...
@@ -320,5 +282,44 @@ namespace Plus.Domain.Uow
...
@@ -320,5 +282,44 @@ namespace Plus.Domain.Uow
{
{
return
"[UnitOfWork "
+
Id
+
"]"
;
return
"[UnitOfWork "
+
Id
+
"]"
;
}
}
public
virtual
IDisposable
SetTenantId
(
int
?
tenantId
)
{
return
SetTenantId
(
tenantId
,
true
);
}
public
virtual
IDisposable
SetTenantId
(
int
?
tenantId
,
bool
switchMustHaveTenantEnableDisable
)
{
var
oldTenantId
=
_tenantId
;
_tenantId
=
tenantId
;
IDisposable
mustHaveTenantEnableChange
;
if
(
switchMustHaveTenantEnableDisable
)
{
mustHaveTenantEnableChange
=
tenantId
==
null
?
DisableFilter
(
PlusDataFilters
.
MustHaveTenant
)
:
EnableFilter
(
PlusDataFilters
.
MustHaveTenant
);
}
else
{
mustHaveTenantEnableChange
=
NullDisposable
.
Instance
;
}
var
mayHaveTenantChange
=
SetFilterParameter
(
PlusDataFilters
.
MayHaveTenant
,
PlusDataFilters
.
Parameters
.
TenantId
,
tenantId
);
var
mustHaveTenantChange
=
SetFilterParameter
(
PlusDataFilters
.
MustHaveTenant
,
PlusDataFilters
.
Parameters
.
TenantId
,
tenantId
??
0
);
return
new
DisposeAction
(()
=>
{
mayHaveTenantChange
.
Dispose
();
mustHaveTenantChange
.
Dispose
();
mustHaveTenantEnableChange
.
Dispose
();
_tenantId
=
oldTenantId
;
});
}
public
int
?
GetTenantId
()
{
return
_tenantId
;
}
}
}
}
}
\ No newline at end of file
src/Plus/PlusLeadershipModule.cs
View file @
40acf97e
...
@@ -4,6 +4,7 @@ using Plus.Dependency;
...
@@ -4,6 +4,7 @@ using Plus.Dependency;
using
Plus.Domain.Uow
;
using
Plus.Domain.Uow
;
using
Plus.Event.Bus
;
using
Plus.Event.Bus
;
using
Plus.Modules
;
using
Plus.Modules
;
using
Plus.Runtime.Validation.Interception
;
using
System
;
using
System
;
using
System.IO
;
using
System.IO
;
using
System.Linq.Expressions
;
using
System.Linq.Expressions
;
...
...
src/Plus/Runtime/Validation/Interception/DataAnnotationsValidator.cs
0 → 100644
View file @
40acf97e
using
Plus.Dependency
;
using
System.Collections.Generic
;
using
System.ComponentModel
;
using
System.ComponentModel.DataAnnotations
;
using
System.Linq
;
namespace
Plus.Runtime.Validation.Interception
{
/// <summary>
/// DataAnnotationsValidator
/// </summary>
public
class
DataAnnotationsValidator
:
IMethodParameterValidator
,
ITransientDependency
{
public
virtual
IReadOnlyList
<
ValidationResult
>
Validate
(
object
validatingObject
)
{
return
GetDataAnnotationAttributeErrors
(
validatingObject
);
}
protected
virtual
List
<
ValidationResult
>
GetDataAnnotationAttributeErrors
(
object
validatingObject
)
{
var
validationErrors
=
new
List
<
ValidationResult
>();
var
properties
=
TypeDescriptor
.
GetProperties
(
validatingObject
).
Cast
<
PropertyDescriptor
>();
foreach
(
var
property
in
properties
)
{
var
validationAttributes
=
property
.
Attributes
.
OfType
<
ValidationAttribute
>().
ToArray
();
if
(
validationAttributes
.
IsNullOrEmpty
())
{
continue
;
}
var
validationContext
=
new
ValidationContext
(
validatingObject
)
{
DisplayName
=
property
.
DisplayName
,
MemberName
=
property
.
Name
};
foreach
(
var
attribute
in
validationAttributes
)
{
var
result
=
attribute
.
GetValidationResult
(
property
.
GetValue
(
validatingObject
),
validationContext
);
if
(
result
!=
null
)
{
validationErrors
.
Add
(
result
);
}
}
}
return
validationErrors
;
}
}
}
\ No newline at end of file
src/Plus/Runtime/Validation/Interception/ValidatableObjectValidator.cs
0 → 100644
View file @
40acf97e
using
Plus.Dependency
;
using
System.Collections.Generic
;
using
System.ComponentModel.DataAnnotations
;
namespace
Plus.Runtime.Validation.Interception
{
/// <summary>
/// ValidatableObjectValidator
/// </summary>
public
class
ValidatableObjectValidator
:
IMethodParameterValidator
,
ITransientDependency
{
public
virtual
IReadOnlyList
<
ValidationResult
>
Validate
(
object
validatingObject
)
{
List
<
ValidationResult
>
list
=
new
List
<
ValidationResult
>();
IValidatableObject
validatableObject
;
if
((
validatableObject
=
(
validatingObject
as
IValidatableObject
))
!=
null
)
{
list
.
AddRange
(
validatableObject
.
Validate
(
new
ValidationContext
(
validatableObject
)));
}
return
list
;
}
}
}
\ No newline at end of file
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