FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
NetCoreServer/source/NetCoreServer/Utilities.cs at master · WarfareCode/NetCoreServer · GitHub
WarfareCode
NetCoreServer
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
NetCoreServer
/
source
/
NetCoreServer
/
Utilities.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
164 lines (156 loc) · 6.11 KB
Breadcrumbs
NetCoreServer
/
source
/
NetCoreServer
/
Utilities.cs
Copy path
File metadata and controls
164 lines (156 loc) · 6.11 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
using
System
;
using
System
.
Text
;
namespace
NetCoreServer
{
/// <summary>
/// Conversion metrics utilities
/// </summary>
public
class
Utilities
{
/// <summary>
/// Generate data size string. Will return a pretty string of bytes, KiB, MiB, GiB, TiB based on the given bytes.
/// </summary>
/// <param name="b">Data size in bytes</param>
/// <returns>String with data size representation</returns>
public
static
string
GenerateDataSize
(
double
b
)
{
var
sb
=
new
StringBuilder
(
)
;
long
bytes
=
(
long
)
b
;
long
absBytes
=
Math
.
Abs
(
bytes
)
;
if
(
absBytes
>=
(
1024L
*
1024L
*
1024L
*
1024L
)
)
{
long
tb
=
bytes
/
(
1024L
*
1024L
*
1024L
*
1024L
)
;
long
gb
=
(
bytes
%
(
1024L
*
1024L
*
1024L
*
1024L
)
)
/
(
1024
*
1024
*
1024
)
;
sb
.
Append
(
tb
)
;
sb
.
Append
(
'.'
)
;
sb
.
Append
(
(
gb
<
100
)
?
"0"
:
""
)
;
sb
.
Append
(
(
gb
<
10
)
?
"0"
:
""
)
;
sb
.
Append
(
gb
)
;
sb
.
Append
(
" TiB"
)
;
}
else
if
(
absBytes
>=
(
1024
*
1024
*
1024
)
)
{
long
gb
=
bytes
/
(
1024
*
1024
*
1024
)
;
long
mb
=
(
bytes
%
(
1024
*
1024
*
1024
)
)
/
(
1024
*
1024
)
;
sb
.
Append
(
gb
)
;
sb
.
Append
(
'.'
)
;
sb
.
Append
(
(
mb
<
100
)
?
"0"
:
""
)
;
sb
.
Append
(
(
mb
<
10
)
?
"0"
:
""
)
;
sb
.
Append
(
mb
)
;
sb
.
Append
(
" GiB"
)
;
}
else
if
(
absBytes
>=
(
1024
*
1024
)
)
{
long
mb
=
bytes
/
(
1024
*
1024
)
;
long
kb
=
(
bytes
%
(
1024
*
1024
)
)
/
1024
;
sb
.
Append
(
mb
)
;
sb
.
Append
(
'.'
)
;
sb
.
Append
(
(
kb
<
100
)
?
"0"
:
""
)
;
sb
.
Append
(
(
kb
<
10
)
?
"0"
:
""
)
;
sb
.
Append
(
kb
)
;
sb
.
Append
(
" MiB"
)
;
}
else
if
(
absBytes
>=
1024
)
{
long
kb
=
bytes
/
1024
;
bytes
=
bytes
%
1024
;
sb
.
Append
(
kb
)
;
sb
.
Append
(
'.'
)
;
sb
.
Append
(
(
bytes
<
100
)
?
"0"
:
""
)
;
sb
.
Append
(
(
bytes
<
10
)
?
"0"
:
""
)
;
sb
.
Append
(
bytes
)
;
sb
.
Append
(
" KiB"
)
;
}
else
{
sb
.
Append
(
bytes
)
;
sb
.
Append
(
" bytes"
)
;
}
return
sb
.
ToString
(
)
;
}
/// <summary>
/// Generate time period string. Will return a pretty string of ns, mcs, ms, s, m, h based on the given nanoseconds.
/// </summary>
/// <param name="ms">Milliseconds</param>
/// <returns>String with time period representation</returns>
public
static
string
GenerateTimePeriod
(
double
ms
)
{
var
sb
=
new
StringBuilder
(
)
;
long
nanoseconds
=
(
long
)
(
ms
*
1000.0
*
1000.0
)
;
long
absNanoseconds
=
Math
.
Abs
(
nanoseconds
)
;
if
(
absNanoseconds
>=
(
60
*
60
*
1000000000L
)
)
{
long
hours
=
nanoseconds
/
(
60
*
60
*
1000000000L
)
;
long
minutes
=
(
(
nanoseconds
%
(
60
*
60
*
1000000000L
)
)
/
1000000000
)
/
60
;
long
seconds
=
(
(
nanoseconds
%
(
60
*
60
*
1000000000L
)
)
/
1000000000
)
%
60
;
long
milliseconds
=
(
(
nanoseconds
%
(
60
*
60
*
1000000000L
)
)
%
1000000000
)
/
1000000
;
sb
.
Append
(
hours
)
;
sb
.
Append
(
':'
)
;
sb
.
Append
(
(
minutes
<
10
)
?
"0"
:
""
)
;
sb
.
Append
(
minutes
)
;
sb
.
Append
(
':'
)
;
sb
.
Append
(
(
seconds
<
10
)
?
"0"
:
""
)
;
sb
.
Append
(
seconds
)
;
sb
.
Append
(
'.'
)
;
sb
.
Append
(
(
milliseconds
<
100
)
?
"0"
:
""
)
;
sb
.
Append
(
(
milliseconds
<
10
)
?
"0"
:
""
)
;
sb
.
Append
(
milliseconds
)
;
sb
.
Append
(
" h"
)
;
}
else
if
(
absNanoseconds
>=
(
60
*
1000000000L
)
)
{
long
minutes
=
nanoseconds
/
(
60
*
1000000000L
)
;
long
seconds
=
(
nanoseconds
%
(
60
*
1000000000L
)
)
/
1000000000
;
long
milliseconds
=
(
(
nanoseconds
%
(
60
*
1000000000L
)
)
%
1000000000
)
/
1000000
;
sb
.
Append
(
minutes
)
;
sb
.
Append
(
':'
)
;
sb
.
Append
(
(
seconds
<
10
)
?
"0"
:
""
)
;
sb
.
Append
(
seconds
)
;
sb
.
Append
(
'.'
)
;
sb
.
Append
(
(
milliseconds
<
100
)
?
"0"
:
""
)
;
sb
.
Append
(
(
milliseconds
<
10
)
?
"0"
:
""
)
;
sb
.
Append
(
milliseconds
)
;
sb
.
Append
(
" m"
)
;
}
else
if
(
absNanoseconds
>=
1000000000
)
{
long
seconds
=
nanoseconds
/
1000000000
;
long
milliseconds
=
(
nanoseconds
%
1000000000
)
/
1000000
;
sb
.
Append
(
seconds
)
;
sb
.
Append
(
'.'
)
;
sb
.
Append
(
(
milliseconds
<
100
)
?
"0"
:
""
)
;
sb
.
Append
(
(
milliseconds
<
10
)
?
"0"
:
""
)
;
sb
.
Append
(
milliseconds
)
;
sb
.
Append
(
" s"
)
;
}
else
if
(
absNanoseconds
>=
1000000
)
{
long
milliseconds
=
nanoseconds
/
1000000
;
long
microseconds
=
(
nanoseconds
%
1000000
)
/
1000
;
sb
.
Append
(
milliseconds
)
;
sb
.
Append
(
'.'
)
;
sb
.
Append
(
(
microseconds
<
100
)
?
"0"
:
""
)
;
sb
.
Append
(
(
microseconds
<
10
)
?
"0"
:
""
)
;
sb
.
Append
(
microseconds
)
;
sb
.
Append
(
" ms"
)
;
}
else
if
(
absNanoseconds
>=
1000
)
{
long
microseconds
=
nanoseconds
/
1000
;
nanoseconds
=
nanoseconds
%
1000
;
sb
.
Append
(
microseconds
)
;
sb
.
Append
(
'.'
)
;
sb
.
Append
(
(
nanoseconds
<
100
)
?
"0"
:
""
)
;
sb
.
Append
(
(
nanoseconds
<
10
)
?
"0"
:
""
)
;
sb
.
Append
(
nanoseconds
)
;
sb
.
Append
(
" mcs"
)
;
}
else
{
sb
.
Append
(
nanoseconds
)
;
sb
.
Append
(
" ns"
)
;
}
return
sb
.
ToString
(
)
;
}
}
}
Back
|
FazBrowse Home
|
New Git URL