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
8f108e21
Commit
8f108e21
authored
Oct 20, 2017
by
Savorboard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed json JObject bug
parent
0c831314
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
29 deletions
+24
-29
Helper.cs
src/DotNetCore.CAP/Infrastructure/Helper.cs
+24
-29
No files found.
src/DotNetCore.CAP/Infrastructure/Helper.cs
View file @
8f108e21
using
System
;
using
System.Collections.Generic
;
using
System.ComponentModel
;
using
System.Reflection
;
using
Newtonsoft.Json
;
...
...
@@ -43,13 +42,12 @@ namespace DotNetCore.CAP.Infrastructure
public
static
long
ToTimestamp
(
DateTime
value
)
{
var
elapsedTime
=
value
-
Epoch
;
return
(
long
)
elapsedTime
.
TotalSeconds
;
return
(
long
)
elapsedTime
.
TotalSeconds
;
}
public
static
DateTime
FromTimestamp
(
long
value
)
{
// ReSharper disable once ImpureMethodCallOnReadonlyValueField
return
Epoch
.
AddSeconds
(
value
);
}
...
...
@@ -73,31 +71,6 @@ namespace DotNetCore.CAP.Infrastructure
return
!
CanConvertFromString
(
type
);
}
public
static
JObject
ToJObject
(
Exception
exception
)
{
return
new
JObject
(
new
{
Source
=
exception
.
Source
,
Message
=
exception
.
Message
,
InnerMessage
=
exception
.
InnerException
?.
Message
});
}
public
static
string
AddJsonProperty
(
string
json
,
string
propertyName
,
JObject
propertyValue
)
{
var
jObj
=
JObject
.
Parse
(
json
);
if
(
jObj
.
TryGetValue
(
propertyName
,
out
var
_
))
{
jObj
[
propertyName
]
=
propertyValue
;
}
else
{
jObj
.
Add
(
new
JProperty
(
propertyName
,
propertyValue
));
}
return
jObj
.
ToString
();
}
public
static
string
AddExceptionProperty
(
string
json
,
Exception
exception
)
{
...
...
@@ -136,7 +109,7 @@ namespace DotNetCore.CAP.Infrastructure
var
ipNum
=
a
*
256
*
256
*
256
+
b
*
256
*
256
+
c
*
256
+
d
;
return
ipNum
;
}
private
static
bool
IsInner
(
long
userIp
,
long
begin
,
long
end
)
{
return
userIp
>=
begin
&&
userIp
<=
end
;
...
...
@@ -160,5 +133,27 @@ namespace DotNetCore.CAP.Infrastructure
type
==
typeof
(
TimeSpan
)
||
type
==
typeof
(
Uri
);
}
private
static
JObject
ToJObject
(
Exception
exception
)
{
return
JObject
.
FromObject
(
new
{
exception
.
Source
,
exception
.
Message
,
InnerMessage
=
exception
.
InnerException
?.
Message
});
}
private
static
string
AddJsonProperty
(
string
json
,
string
propertyName
,
JObject
propertyValue
)
{
var
jObj
=
JObject
.
Parse
(
json
);
if
(
jObj
.
TryGetValue
(
propertyName
,
out
var
_
))
jObj
[
propertyName
]
=
propertyValue
;
else
jObj
.
Add
(
new
JProperty
(
propertyName
,
propertyValue
));
return
jObj
.
ToString
(
Formatting
.
None
);
}
}
}
\ 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