Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
CAP
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
CAP
Commits
153dc812
Commit
153dc812
authored
Jul 28, 2017
by
yangxiaodong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix issue #18 .
parent
443d140f
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
129 additions
and
44 deletions
+129
-44
ModelBindingResult.cs
...tCore.CAP/Abstractions/ModelBinding/ModelBindingResult.cs
+53
-4
IQueueExecutor.Subscibe.cs
src/DotNetCore.CAP/IQueueExecutor.Subscibe.cs
+0
-1
Helper.cs
src/DotNetCore.CAP/Infrastructure/Helper.cs
+6
-0
IConsumerInvoker.Default.cs
src/DotNetCore.CAP/Internal/IConsumerInvoker.Default.cs
+15
-9
IModelBinder.SimpleType.cs
src/DotNetCore.CAP/Internal/IModelBinder.SimpleType.cs
+39
-24
ModelBinderFactory.cs
src/DotNetCore.CAP/Internal/ModelBinderFactory.cs
+2
-4
LoggerExtensions.cs
src/DotNetCore.CAP/LoggerExtensions.cs
+14
-2
No files found.
src/DotNetCore.CAP/Abstractions/ModelBinding/ModelBindingResult.cs
View file @
153dc812
using
System
;
using
DotNetCore.CAP.Internal
;
using
System.Collections.Generic
;
using
System.Text
;
namespace
DotNetCore.CAP.Abstractions.ModelBinding
namespace
DotNetCore.CAP.Abstractions.ModelBinding
{
{
...
@@ -51,6 +49,57 @@ namespace DotNetCore.CAP.Abstractions.ModelBinding
...
@@ -51,6 +49,57 @@ namespace DotNetCore.CAP.Abstractions.ModelBinding
{
{
return
$"Failed"
;
return
$"Failed"
;
}
}
}
}
public
override
bool
Equals
(
object
obj
)
{
var
other
=
obj
as
ModelBindingResult
?;
if
(
other
==
null
)
{
return
false
;
}
else
{
return
Equals
(
other
.
Value
);
}
}
public
override
int
GetHashCode
()
{
var
hashCodeCombiner
=
HashCodeCombiner
.
Start
();
hashCodeCombiner
.
Add
(
IsSuccess
);
hashCodeCombiner
.
Add
(
Model
);
return
hashCodeCombiner
.
CombinedHash
;
}
public
bool
Equals
(
ModelBindingResult
other
)
{
return
IsSuccess
==
other
.
IsSuccess
&&
object
.
Equals
(
Model
,
other
.
Model
);
}
/// <summary>
/// Compares <see cref="ModelBindingResult"/> objects for equality.
/// </summary>
/// <param name="x">A <see cref="ModelBindingResult"/>.</param>
/// <param name="y">A <see cref="ModelBindingResult"/>.</param>
/// <returns><c>true</c> if the objects are equal, otherwise <c>false</c>.</returns>
public
static
bool
operator
==(
ModelBindingResult
x
,
ModelBindingResult
y
)
{
return
x
.
Equals
(
y
);
}
/// <summary>
/// Compares <see cref="ModelBindingResult"/> objects for inequality.
/// </summary>
/// <param name="x">A <see cref="ModelBindingResult"/>.</param>
/// <param name="y">A <see cref="ModelBindingResult"/>.</param>
/// <returns><c>true</c> if the objects are not equal, otherwise <c>false</c>.</returns>
public
static
bool
operator
!=(
ModelBindingResult
x
,
ModelBindingResult
y
)
{
return
!
x
.
Equals
(
y
);
}
}
}
}
}
src/DotNetCore.CAP/IQueueExecutor.Subscibe.cs
View file @
153dc812
...
@@ -2,7 +2,6 @@
...
@@ -2,7 +2,6 @@
using
System.Diagnostics
;
using
System.Diagnostics
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
DotNetCore.CAP.Abstractions
;
using
DotNetCore.CAP.Abstractions
;
using
DotNetCore.CAP.Infrastructure
;
using
DotNetCore.CAP.Internal
;
using
DotNetCore.CAP.Internal
;
using
DotNetCore.CAP.Models
;
using
DotNetCore.CAP.Models
;
using
DotNetCore.CAP.Processor
;
using
DotNetCore.CAP.Processor
;
...
...
src/DotNetCore.CAP/Infrastructure/Helper.cs
View file @
153dc812
using
System
;
using
System
;
using
System.ComponentModel
;
using
System.Reflection
;
using
System.Reflection
;
using
Newtonsoft.Json
;
using
Newtonsoft.Json
;
...
@@ -68,5 +69,10 @@ namespace DotNetCore.CAP.Infrastructure
...
@@ -68,5 +69,10 @@ namespace DotNetCore.CAP.Infrastructure
return
!
typeInfo
.
ContainsGenericParameters
return
!
typeInfo
.
ContainsGenericParameters
&&
typeInfo
.
Name
.
EndsWith
(
"Controller"
,
StringComparison
.
OrdinalIgnoreCase
);
&&
typeInfo
.
Name
.
EndsWith
(
"Controller"
,
StringComparison
.
OrdinalIgnoreCase
);
}
}
public
static
bool
IsComplexType
(
Type
type
)
{
return
!
TypeDescriptor
.
GetConverter
(
type
).
CanConvertFrom
(
typeof
(
string
));
}
}
}
}
}
\ No newline at end of file
src/DotNetCore.CAP/Internal/IConsumerInvoker.Default.cs
View file @
153dc812
...
@@ -35,23 +35,29 @@ namespace DotNetCore.CAP.Internal
...
@@ -35,23 +35,29 @@ namespace DotNetCore.CAP.Internal
_logger
.
LogDebug
(
"Executing consumer Topic: {0}"
,
_consumerContext
.
ConsumerDescriptor
.
MethodInfo
.
Name
);
_logger
.
LogDebug
(
"Executing consumer Topic: {0}"
,
_consumerContext
.
ConsumerDescriptor
.
MethodInfo
.
Name
);
var
obj
=
ActivatorUtilities
.
GetServiceOrCreateInstance
(
_serviceProvider
,
var
obj
=
ActivatorUtilities
.
GetServiceOrCreateInstance
(
_serviceProvider
,
_consumerContext
.
ConsumerDescriptor
.
ImplTypeInfo
.
AsType
());
_consumerContext
.
ConsumerDescriptor
.
ImplTypeInfo
.
AsType
());
var
value
=
_consumerContext
.
DeliverMessage
.
Content
;
var
value
=
_consumerContext
.
DeliverMessage
.
Content
;
if
(
_executor
.
MethodParameters
.
Length
>
0
)
if
(
_executor
.
MethodParameters
.
Length
>
0
)
{
{
var
firstParameter
=
_executor
.
MethodParameters
[
0
];
var
firstParameter
=
_executor
.
MethodParameters
[
0
];
var
binder
=
_modelBinderFactory
.
CreateBinder
(
firstParameter
);
try
var
result
=
await
binder
.
BindModelAsync
(
value
);
if
(
result
.
IsSuccess
)
{
{
_executor
.
Execute
(
obj
,
result
.
Model
);
var
binder
=
_modelBinderFactory
.
CreateBinder
(
firstParameter
);
var
result
=
await
binder
.
BindModelAsync
(
value
);
if
(
result
.
IsSuccess
)
{
_executor
.
Execute
(
obj
,
result
.
Model
);
}
else
{
_logger
.
LogWarning
(
$"Parameters:
{
firstParameter
.
Name
}
bind failed!"
);
}
}
}
else
catch
(
FormatException
ex
)
{
{
_logger
.
LogWarning
(
$"Parameters:
{
firstParameter
.
Name
}
bind failed!"
);
_logger
.
ModelBinderFormattingException
(
_executor
.
MethodInfo
?.
Name
,
firstParameter
.
Name
,
value
,
ex
);
}
}
}
}
else
else
{
{
...
...
src/DotNetCore.CAP/Internal/IModelBinder.SimpleType.cs
View file @
153dc812
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
using
System.ComponentModel
;
using
System.ComponentModel
;
using
System.Globalization
;
using
System.Globalization
;
using
System.Reflection
;
using
System.Reflection
;
using
System.Runtime.ExceptionServices
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
DotNetCore.CAP.Abstractions.ModelBinding
;
using
DotNetCore.CAP.Abstractions.ModelBinding
;
...
@@ -24,41 +25,55 @@ namespace DotNetCore.CAP.Internal
...
@@ -24,41 +25,55 @@ namespace DotNetCore.CAP.Internal
{
{
throw
new
ArgumentNullException
(
nameof
(
content
));
throw
new
ArgumentNullException
(
nameof
(
content
));
}
}
var
parameterType
=
_parameterInfo
.
ParameterType
;
var
parameterType
=
_parameterInfo
.
ParameterType
;
object
model
;
try
if
(
parameterType
==
typeof
(
string
))
{
{
if
(
string
.
IsNullOrWhiteSpace
(
content
))
object
model
;
if
(
parameterType
==
typeof
(
string
))
{
if
(
string
.
IsNullOrWhiteSpace
(
content
))
{
model
=
null
;
}
else
{
model
=
content
;
}
}
else
if
(
string
.
IsNullOrWhiteSpace
(
content
))
{
{
// Other than the StringConverter, converters Trim() the value then throw if the result is empty.
model
=
null
;
model
=
null
;
}
}
else
else
{
{
model
=
content
;
model
=
_typeConverter
.
ConvertFrom
(
context
:
null
,
culture
:
CultureInfo
.
CurrentCulture
,
value
:
content
);
}
if
(
model
==
null
&&
!
IsReferenceOrNullableType
(
parameterType
))
{
return
Task
.
FromResult
(
ModelBindingResult
.
Failed
());
}
else
{
return
Task
.
FromResult
(
ModelBindingResult
.
Success
(
model
));
}
}
}
}
else
if
(
string
.
IsNullOrWhiteSpace
(
content
))
catch
(
Exception
exception
)
{
// Other than the StringConverter, converters Trim() the value then throw if the result is empty.
model
=
null
;
}
else
{
model
=
_typeConverter
.
ConvertFrom
(
context
:
null
,
culture
:
CultureInfo
.
CurrentCulture
,
value
:
content
);
}
if
(
model
==
null
&&
!
IsReferenceOrNullableType
(
parameterType
))
{
return
Task
.
FromResult
(
ModelBindingResult
.
Failed
());
}
else
{
{
return
Task
.
FromResult
(
ModelBindingResult
.
Success
(
model
));
var
isFormatException
=
exception
is
FormatException
;
if
(!
isFormatException
&&
exception
.
InnerException
!=
null
)
{
// TypeConverter throws System.Exception wrapping the FormatException,
// so we capture the inner exception.
exception
=
ExceptionDispatchInfo
.
Capture
(
exception
.
InnerException
).
SourceException
;
}
throw
exception
;
}
}
}
}
...
...
src/DotNetCore.CAP/Internal/ModelBinderFactory.cs
View file @
153dc812
using
System
;
using
System
;
using
System.Collections.Concurrent
;
using
System.Collections.Concurrent
;
using
System.ComponentModel
;
using
System.Reflection
;
using
System.Reflection
;
using
System.Runtime.CompilerServices
;
using
System.Runtime.CompilerServices
;
using
DotNetCore.CAP.Abstractions.ModelBinding
;
using
DotNetCore.CAP.Abstractions.ModelBinding
;
using
DotNetCore.CAP.Infrastructure
;
namespace
DotNetCore.CAP.Internal
namespace
DotNetCore.CAP.Internal
{
{
...
@@ -40,9 +40,7 @@ namespace DotNetCore.CAP.Internal
...
@@ -40,9 +40,7 @@ namespace DotNetCore.CAP.Internal
{
{
return
binder
;
return
binder
;
}
}
var
type
=
parameterInfo
.
ParameterType
;
if
(!
Helper
.
IsComplexType
(
parameterInfo
.
ParameterType
))
var
isComplexType
=
!
TypeDescriptor
.
GetConverter
(
type
).
CanConvertFrom
(
typeof
(
string
));
if
(!
isComplexType
)
{
{
binder
=
new
SimpleTypeModelBinder
(
parameterInfo
);
binder
=
new
SimpleTypeModelBinder
(
parameterInfo
);
}
}
...
...
src/DotNetCore.CAP/LoggerExtensions.cs
View file @
153dc812
...
@@ -14,6 +14,7 @@ namespace DotNetCore.CAP
...
@@ -14,6 +14,7 @@ namespace DotNetCore.CAP
private
static
readonly
Action
<
ILogger
,
string
,
string
,
Exception
>
_enqueuingReceivdeMessage
;
private
static
readonly
Action
<
ILogger
,
string
,
string
,
Exception
>
_enqueuingReceivdeMessage
;
private
static
readonly
Action
<
ILogger
,
string
,
Exception
>
_executingConsumerMethod
;
private
static
readonly
Action
<
ILogger
,
string
,
Exception
>
_executingConsumerMethod
;
private
static
readonly
Action
<
ILogger
,
string
,
Exception
>
_receivedMessageRetryExecuting
;
private
static
readonly
Action
<
ILogger
,
string
,
Exception
>
_receivedMessageRetryExecuting
;
private
static
readonly
Action
<
ILogger
,
string
,
string
,
string
,
Exception
>
_modelBinderFormattingException
;
private
static
Action
<
ILogger
,
Exception
>
_jobFailed
;
private
static
Action
<
ILogger
,
Exception
>
_jobFailed
;
private
static
Action
<
ILogger
,
Exception
>
_jobFailedWillRetry
;
private
static
Action
<
ILogger
,
Exception
>
_jobFailedWillRetry
;
...
@@ -46,12 +47,12 @@ namespace DotNetCore.CAP
...
@@ -46,12 +47,12 @@ namespace DotNetCore.CAP
_enqueuingSentMessage
=
LoggerMessage
.
Define
<
string
,
string
>(
_enqueuingSentMessage
=
LoggerMessage
.
Define
<
string
,
string
>(
LogLevel
.
Debug
,
LogLevel
.
Debug
,
2
,
2
,
"Enqueuing a topic to the sent message store. NameKey:
{NameKey}. Content: {Content}
"
);
"Enqueuing a topic to the sent message store. NameKey:
'{NameKey}' Content: '{Content}'.
"
);
_enqueuingReceivdeMessage
=
LoggerMessage
.
Define
<
string
,
string
>(
_enqueuingReceivdeMessage
=
LoggerMessage
.
Define
<
string
,
string
>(
LogLevel
.
Debug
,
LogLevel
.
Debug
,
2
,
2
,
"Enqueuing a topic to the received message store. NameKey:
{NameKey}. Content: {Content}
"
);
"Enqueuing a topic to the received message store. NameKey:
'{NameKey}. Content: '{Content}'.
"
);
_executingConsumerMethod
=
LoggerMessage
.
Define
<
string
>(
_executingConsumerMethod
=
LoggerMessage
.
Define
<
string
>(
LogLevel
.
Error
,
LogLevel
.
Error
,
...
@@ -63,6 +64,12 @@ namespace DotNetCore.CAP
...
@@ -63,6 +64,12 @@ namespace DotNetCore.CAP
5
,
5
,
"Received message topic method '{topicName}' failed to execute."
);
"Received message topic method '{topicName}' failed to execute."
);
_modelBinderFormattingException
=
LoggerMessage
.
Define
<
string
,
string
,
string
>(
LogLevel
.
Error
,
5
,
"When call subscribe method, a parameter format conversion exception occurs. MethodName:'{MethodName}' ParameterName:'{ParameterName}' Content:'{Content}'."
);
_jobRetrying
=
LoggerMessage
.
Define
<
int
>(
_jobRetrying
=
LoggerMessage
.
Define
<
int
>(
LogLevel
.
Debug
,
LogLevel
.
Debug
,
3
,
3
,
...
@@ -154,5 +161,10 @@ namespace DotNetCore.CAP
...
@@ -154,5 +161,10 @@ namespace DotNetCore.CAP
{
{
_exceptionOccuredWhileExecutingJob
(
logger
,
jobId
,
ex
);
_exceptionOccuredWhileExecutingJob
(
logger
,
jobId
,
ex
);
}
}
public
static
void
ModelBinderFormattingException
(
this
ILogger
logger
,
string
methodName
,
string
parameterName
,
string
content
,
Exception
ex
)
{
_modelBinderFormattingException
(
logger
,
methodName
,
parameterName
,
content
,
ex
);
}
}
}
}
}
\ 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