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
5b5fafcc
Commit
5b5fafcc
authored
Oct 12, 2017
by
Savorboard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add helper method.
parent
8e107693
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
117 additions
and
102 deletions
+117
-102
Helper.cs
src/DotNetCore.CAP/Infrastructure/Helper.cs
+117
-102
No files found.
src/DotNetCore.CAP/Infrastructure/Helper.cs
View file @
5b5fafcc
...
@@ -46,6 +46,7 @@ namespace DotNetCore.CAP.Infrastructure
...
@@ -46,6 +46,7 @@ namespace DotNetCore.CAP.Infrastructure
return
(
long
)
elapsedTime
.
TotalSeconds
;
return
(
long
)
elapsedTime
.
TotalSeconds
;
}
}
public
static
DateTime
FromTimestamp
(
long
value
)
public
static
DateTime
FromTimestamp
(
long
value
)
{
{
// ReSharper disable once ImpureMethodCallOnReadonlyValueField
// ReSharper disable once ImpureMethodCallOnReadonlyValueField
...
@@ -72,24 +73,38 @@ namespace DotNetCore.CAP.Infrastructure
...
@@ -72,24 +73,38 @@ namespace DotNetCore.CAP.Infrastructure
return
!
CanConvertFromString
(
type
);
return
!
CanConvertFromString
(
type
);
}
}
public
static
string
AddJsonProperty
(
string
json
,
IList
<
KeyValuePair
<
string
,
string
>>
properties
)
public
static
JObject
ToJObject
(
Exception
exception
)
{
{
var
jObj
=
JObject
.
Parse
(
json
);
return
new
JObject
(
new
foreach
(
var
property
in
properties
)
{
{
if
(
jObj
.
TryGetValue
(
property
.
Key
,
out
var
_
))
Source
=
exception
.
Source
,
Message
=
exception
.
Message
,
InnerMessage
=
exception
.
InnerException
?.
Message
});
}
public
static
string
AddJsonProperty
(
string
json
,
string
propertyName
,
JObject
propertyValue
)
{
{
jObj
[
property
.
Key
]
=
property
.
Value
;
var
jObj
=
JObject
.
Parse
(
json
);
if
(
jObj
.
TryGetValue
(
propertyName
,
out
var
_
))
{
jObj
[
propertyName
]
=
propertyValue
;
}
}
else
else
{
{
jObj
.
Add
(
new
JProperty
(
property
.
Key
,
property
.
Value
));
jObj
.
Add
(
new
JProperty
(
propertyName
,
propertyValue
));
}
}
}
return
jObj
.
ToString
();
return
jObj
.
ToString
();
}
}
public
static
string
AddExceptionProperty
(
string
json
,
Exception
exception
)
{
var
jObject
=
ToJObject
(
exception
);
return
AddJsonProperty
(
json
,
"ExceptionMessage"
,
jObject
);
}
private
static
bool
CanConvertFromString
(
Type
destinationType
)
private
static
bool
CanConvertFromString
(
Type
destinationType
)
{
{
destinationType
=
Nullable
.
GetUnderlyingType
(
destinationType
)
??
destinationType
;
destinationType
=
Nullable
.
GetUnderlyingType
(
destinationType
)
??
destinationType
;
...
...
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