FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
ServiceStack/src/ServiceStack/HotReloadFeature.cs at master · csharpbuilder/ServiceStack · GitHub
csharpbuilder
/
ServiceStack
Public
forked from
ServiceStack/ServiceStack
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
ServiceStack
/
src
/
ServiceStack
/
HotReloadFeature.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
80 lines (68 loc) · 2.72 KB
Breadcrumbs
ServiceStack
/
src
/
ServiceStack
/
HotReloadFeature.cs
Copy path
File metadata and controls
80 lines (68 loc) · 2.72 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
using
System
;
using
System
.
Collections
.
Generic
;
using
System
.
Linq
;
using
System
.
Threading
.
Tasks
;
using
ServiceStack
.
DataAnnotations
;
namespace
ServiceStack
{
/// <summary>
/// Back-end Service used by /js/hot-fileloader.js to detect file changes in /wwwroot and auto reload page.
/// </summary>
public
class
HotReloadFeature
:
IPlugin
{
public
void
Register
(
IAppHost
appHost
)
{
appHost
.
RegisterService
(
typeof
(
HotReloadFilesService
)
)
;
}
}
[
ExcludeMetadata
]
[
Route
(
"/hotreload/files"
)
]
public
class
HotReloadFiles
:
IReturn
<
HotReloadPageResponse
>
{
public
string
Pattern
{
get
;
set
;
}
public
string
ETag
{
get
;
set
;
}
}
[
DefaultRequest
(
typeof
(
HotReloadFiles
)
)
]
[
Restrict
(
VisibilityTo
=
RequestAttributes
.
None
)
]
public
class
HotReloadFilesService
:
Service
{
public
static
List
<
string
>
ExcludePatterns
{
get
;
}
=
new
List
<
string
>
{
"*.sqlite"
,
"*.db"
,
}
;
public
static
TimeSpan
LongPollDuration
=
TimeSpan
.
FromSeconds
(
60
)
;
public
static
TimeSpan
CheckDelay
=
TimeSpan
.
FromMilliseconds
(
50
)
;
// No delay sometimes causes repetitive loop
public
static
TimeSpan
ModifiedDelay
=
TimeSpan
.
FromMilliseconds
(
50
)
;
public
async
Task
<
HotReloadPageResponse
>
Any
(
HotReloadFiles
request
)
{
var
pattern
=
request
.
Pattern
??
"*"
;
var
startedAt
=
DateTime
.
UtcNow
;
var
maxLastModified
=
DateTime
.
MinValue
;
var
shouldReload
=
false
;
while
(
DateTime
.
UtcNow
-
startedAt
<
LongPollDuration
)
{
maxLastModified
=
DateTime
.
MinValue
;
var
files
=
VirtualFileSources
.
GetAllMatchingFiles
(
pattern
)
;
foreach
(
var
file
in
files
)
{
if
(
ExcludePatterns
.
Any
(
exclude
=>
file
.
Name
.
Glob
(
exclude
)
)
==
true
)
continue
;
file
.
Refresh
(
)
;
if
(
file
.
LastModified
>
maxLastModified
)
maxLastModified
=
file
.
LastModified
;
}
if
(
string
.
IsNullOrEmpty
(
request
.
ETag
)
)
return
new
HotReloadPageResponse
{
ETag
=
maxLastModified
.
Ticks
.
ToString
(
)
}
;
shouldReload
=
maxLastModified
!=
DateTime
.
MinValue
&&
maxLastModified
.
Ticks
>
long
.
Parse
(
request
.
ETag
)
;
if
(
shouldReload
)
{
await
Task
.
Delay
(
ModifiedDelay
)
;
break
;
}
await
Task
.
Delay
(
CheckDelay
)
;
}
return
new
HotReloadPageResponse
{
Reload
=
shouldReload
,
ETag
=
maxLastModified
.
Ticks
.
ToString
(
)
}
;
}
}
}
Back
|
FazBrowse Home
|
New Git URL