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
dc9250ca
Commit
dc9250ca
authored
Sep 07, 2017
by
yangxiaodong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add json dispatcher.
parent
8d5b1ffc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
0 deletions
+37
-0
JsonDispatcher.cs
src/DotNetCore.CAP/Dashboard/JsonDispatcher.cs
+37
-0
No files found.
src/DotNetCore.CAP/Dashboard/JsonDispatcher.cs
0 → 100644
View file @
dc9250ca
using
System
;
using
System.Net
;
using
System.Threading.Tasks
;
using
Newtonsoft.Json
;
using
Newtonsoft.Json.Converters
;
using
Newtonsoft.Json.Serialization
;
namespace
DotNetCore.CAP.Dashboard
{
internal
class
JsonDispatcher
:
IDashboardDispatcher
{
private
readonly
Func
<
DashboardContext
,
object
>
_command
;
public
JsonDispatcher
(
Func
<
DashboardContext
,
object
>
command
)
{
_command
=
command
;
}
public
async
Task
Dispatch
(
DashboardContext
context
)
{
var
request
=
context
.
Request
;
var
response
=
context
.
Response
;
object
result
=
_command
(
context
);
var
settings
=
new
JsonSerializerSettings
{
ContractResolver
=
new
CamelCasePropertyNamesContractResolver
(),
Converters
=
new
JsonConverter
[]
{
new
StringEnumConverter
{
CamelCaseText
=
true
}
}
};
var
serialized
=
JsonConvert
.
SerializeObject
(
result
,
settings
);
context
.
Response
.
ContentType
=
"application/json"
;
await
context
.
Response
.
WriteAsync
(
serialized
);
}
}
}
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