Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
guru
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DeStream-public
guru
Commits
6453a51a
Commit
6453a51a
authored
Dec 24, 2018
by
Clint.Network
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement Timer
parent
d58f7ebf
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
2 deletions
+15
-2
LotteryService.cs
Stratis.Guru/Services/LotteryService.cs
+15
-2
No files found.
Stratis.Guru/Services/LotteryService.cs
View file @
6453a51a
using
System
;
using
System
;
using
System.Threading
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
System.Timers
;
using
Microsoft.Extensions.Caching.Memory
;
using
Microsoft.Extensions.Caching.Memory
;
using
Microsoft.Extensions.Hosting
;
using
Microsoft.Extensions.Hosting
;
using
Microsoft.Extensions.Options
;
using
Microsoft.Extensions.Options
;
...
@@ -20,6 +21,7 @@ namespace Stratis.Guru.Services
...
@@ -20,6 +21,7 @@ namespace Stratis.Guru.Services
private
readonly
ISettings
_settings
;
private
readonly
ISettings
_settings
;
private
readonly
IDraws
_draws
;
private
readonly
IDraws
_draws
;
private
readonly
DrawSettings
_drawSettings
;
private
readonly
DrawSettings
_drawSettings
;
private
readonly
System
.
Timers
.
Timer
_updateTimer
;
private
DateTime
_nextDraw
;
private
DateTime
_nextDraw
;
public
LotteryService
(
IMemoryCache
memoryCache
,
ISettings
settings
,
IDraws
draws
,
IOptions
<
DrawSettings
>
drawSettings
)
public
LotteryService
(
IMemoryCache
memoryCache
,
ISettings
settings
,
IDraws
draws
,
IOptions
<
DrawSettings
>
drawSettings
)
...
@@ -28,14 +30,23 @@ namespace Stratis.Guru.Services
...
@@ -28,14 +30,23 @@ namespace Stratis.Guru.Services
_settings
=
settings
;
_settings
=
settings
;
_draws
=
draws
;
_draws
=
draws
;
_drawSettings
=
drawSettings
.
Value
;
_drawSettings
=
drawSettings
.
Value
;
_updateTimer
=
new
System
.
Timers
.
Timer
();
}
}
public
async
Task
StartAsync
(
CancellationToken
cancellationToken
)
public
async
Task
StartAsync
(
CancellationToken
cancellationToken
)
{
{
Console
.
WriteLine
(
TimeZone
.
CurrentTimeZone
.
StandardName
.
ToString
());
JackpotCounter
();
JackpotCounter
();
await
InitLotteryAsync
();
await
InitLotteryAsync
();
await
CalculateNextDrawAsync
();
await
CalculateNextDrawAsync
();
_updateTimer
.
Interval
=
10
;
_updateTimer
.
Enabled
=
true
;
_updateTimer
.
Elapsed
+=
async
(
sender
,
args
)
=>
{
JackpotCounter
();
await
CalculateNextDrawAsync
();
};
_updateTimer
.
Start
();
}
}
private
void
JackpotCounter
()
private
void
JackpotCounter
()
...
@@ -64,7 +75,7 @@ namespace Stratis.Guru.Services
...
@@ -64,7 +75,7 @@ namespace Stratis.Guru.Services
DateTime
today
=
DateTime
.
UtcNow
;
DateTime
today
=
DateTime
.
UtcNow
;
int
daysUntilFriday
=
((
int
)
DayOfWeek
.
Friday
-
(
int
)
today
.
DayOfWeek
+
7
)
%
7
;
int
daysUntilFriday
=
((
int
)
DayOfWeek
.
Friday
-
(
int
)
today
.
DayOfWeek
+
7
)
%
7
;
_nextDraw
=
today
.
AddDays
(
daysUntilFriday
);
_nextDraw
=
today
.
AddDays
(
daysUntilFriday
);
_nextDraw
=
DateTime
.
UtcNow
;
//
_nextDraw = DateTime.UtcNow;
var
nextDrawTimestamp
=
((
DateTimeOffset
)
_nextDraw
).
ToUnixTimeSeconds
();
var
nextDrawTimestamp
=
((
DateTimeOffset
)
_nextDraw
).
ToUnixTimeSeconds
();
...
@@ -80,6 +91,8 @@ namespace Stratis.Guru.Services
...
@@ -80,6 +91,8 @@ namespace Stratis.Guru.Services
public
void
Dispose
()
public
void
Dispose
()
{
{
_updateTimer
?.
Stop
();
_updateTimer
?.
Dispose
();
}
}
}
}
}
}
\ 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