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
82e71439
Commit
82e71439
authored
Nov 08, 2018
by
Clint.Network
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding Fixer API Service
parent
2872c941
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
75 additions
and
18 deletions
+75
-18
FixerService.cs
Stratis.Guru/Services/FixerService.cs
+51
-0
UpdateInfosService.cs
Stratis.Guru/Services/UpdateInfosService.cs
+9
-9
FixerApiSettings.cs
Stratis.Guru/Settings/FixerApiSettings.cs
+8
-0
Startup.cs
Stratis.Guru/Startup.cs
+7
-9
No files found.
Stratis.Guru/Services/FixerService.cs
0 → 100644
View file @
82e71439
using
System
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
Microsoft.Extensions.Caching.Distributed
;
using
Microsoft.Extensions.Hosting
;
using
Microsoft.Extensions.Options
;
using
Newtonsoft.Json
;
using
RestSharp
;
using
Stratis.Guru.Settings
;
namespace
Stratis.Guru.Services
{
public
class
FixerService
:
IHostedService
,
IDisposable
{
private
FixerApiSettings
_options
;
private
IDistributedCache
_distributedCache
;
private
Timer
_timer
;
public
FixerService
(
IOptions
<
FixerApiSettings
>
options
,
IDistributedCache
distributedCache
)
{
_options
=
options
.
Value
;
_distributedCache
=
distributedCache
;
}
public
Task
StartAsync
(
CancellationToken
cancellationToken
)
{
_timer
=
new
Timer
(
DoWork
,
null
,
TimeSpan
.
Zero
,
TimeSpan
.
FromHours
(
1
));
return
Task
.
CompletedTask
;
}
private
void
DoWork
(
object
state
)
{
var
rs
=
new
RestClient
(
$"
{
_options
.
Endpoint
}
?access_key=
{
_options
.
ApiKey
}
&format=1"
);
var
rq
=
new
RestRequest
(
Method
.
GET
);
rs
.
ExecuteAsync
(
rq
,
delegate
(
IRestResponse
response
)
{
_distributedCache
.
SetString
(
"Fixer"
,
response
.
Content
);
});
}
public
Task
StopAsync
(
CancellationToken
cancellationToken
)
{
return
Task
.
CompletedTask
;
}
public
void
Dispose
()
{
_timer
?.
Dispose
();
}
}
}
\ No newline at end of file
Stratis.Guru/Services/UpdateInfosService.cs
View file @
82e71439
...
@@ -16,7 +16,7 @@ namespace Stratis.Guru.Services
...
@@ -16,7 +16,7 @@ namespace Stratis.Guru.Services
private
readonly
IMemoryCache
_memoryCache
;
private
readonly
IMemoryCache
_memoryCache
;
private
readonly
IHubContext
<
UpdateHub
>
_hubContext
;
private
readonly
IHubContext
<
UpdateHub
>
_hubContext
;
private
readonly
UpdateHub
_hub
;
private
readonly
UpdateHub
_hub
;
private
readonly
System
.
Timers
.
Timer
updateTimer
;
private
readonly
System
.
Timers
.
Timer
_
updateTimer
;
private
readonly
NakoApiSettings
_nakoApiSettings
;
private
readonly
NakoApiSettings
_nakoApiSettings
;
public
UpdateInfosService
(
IMemoryCache
memoryCache
,
UpdateHub
hub
,
IHubContext
<
UpdateHub
>
hubContext
,
IOptions
<
NakoApiSettings
>
nakoApiSettings
)
public
UpdateInfosService
(
IMemoryCache
memoryCache
,
UpdateHub
hub
,
IHubContext
<
UpdateHub
>
hubContext
,
IOptions
<
NakoApiSettings
>
nakoApiSettings
)
...
@@ -24,17 +24,17 @@ namespace Stratis.Guru.Services
...
@@ -24,17 +24,17 @@ namespace Stratis.Guru.Services
_memoryCache
=
memoryCache
;
_memoryCache
=
memoryCache
;
_hub
=
hub
;
_hub
=
hub
;
_hubContext
=
hubContext
;
_hubContext
=
hubContext
;
updateTimer
=
new
System
.
Timers
.
Timer
();
_
updateTimer
=
new
System
.
Timers
.
Timer
();
_nakoApiSettings
=
nakoApiSettings
.
Value
;
_nakoApiSettings
=
nakoApiSettings
.
Value
;
}
}
public
Task
StartAsync
(
CancellationToken
cancellationToken
)
public
Task
StartAsync
(
CancellationToken
cancellationToken
)
{
{
updateTimer
.
Interval
=
10
;
_
updateTimer
.
Interval
=
10
;
updateTimer
.
Enabled
=
true
;
_
updateTimer
.
Enabled
=
true
;
updateTimer
.
Elapsed
+=
async
(
sender
,
args
)
=>
_
updateTimer
.
Elapsed
+=
async
(
sender
,
args
)
=>
{
{
updateTimer
.
Interval
=
TimeSpan
.
FromMinutes
(
10
).
TotalMilliseconds
;
_
updateTimer
.
Interval
=
TimeSpan
.
FromMinutes
(
10
).
TotalMilliseconds
;
var
coinmarketCapApiClient
=
new
RestClient
(
"https://api.coinmarketcap.com/v2/ticker/1343/"
);
var
coinmarketCapApiClient
=
new
RestClient
(
"https://api.coinmarketcap.com/v2/ticker/1343/"
);
var
coinmarketCapApiRequest
=
new
RestRequest
(
Method
.
GET
);
var
coinmarketCapApiRequest
=
new
RestRequest
(
Method
.
GET
);
var
coinmarketcapApi
=
coinmarketCapApiClient
.
Execute
(
coinmarketCapApiRequest
);
var
coinmarketcapApi
=
coinmarketCapApiClient
.
Execute
(
coinmarketCapApiRequest
);
...
@@ -46,7 +46,7 @@ namespace Stratis.Guru.Services
...
@@ -46,7 +46,7 @@ namespace Stratis.Guru.Services
var
blockchainStatsRequest
=
new
RestRequest
(
Method
.
GET
);
var
blockchainStatsRequest
=
new
RestRequest
(
Method
.
GET
);
_memoryCache
.
Set
(
"BlockchainStats"
,
blockchainStatsClient
.
Execute
(
blockchainStatsRequest
).
Content
);
_memoryCache
.
Set
(
"BlockchainStats"
,
blockchainStatsClient
.
Execute
(
blockchainStatsRequest
).
Content
);
};
};
updateTimer
.
Start
();
_
updateTimer
.
Start
();
return
Task
.
CompletedTask
;
return
Task
.
CompletedTask
;
}
}
...
@@ -57,8 +57,8 @@ namespace Stratis.Guru.Services
...
@@ -57,8 +57,8 @@ namespace Stratis.Guru.Services
public
void
Dispose
()
public
void
Dispose
()
{
{
updateTimer
?.
Stop
();
_
updateTimer
?.
Stop
();
updateTimer
?.
Dispose
();
;
_updateTimer
?.
Dispose
()
;
}
}
}
}
}
}
\ No newline at end of file
Stratis.Guru/Settings/FixerApiSettings.cs
0 → 100644
View file @
82e71439
namespace
Stratis.Guru.Settings
{
public
class
FixerApiSettings
{
public
string
ApiKey
{
get
;
set
;
}
public
string
Endpoint
{
get
;
set
;
}
}
}
\ No newline at end of file
Stratis.Guru/Startup.cs
View file @
82e71439
...
@@ -14,6 +14,7 @@ using Microsoft.Extensions.Configuration;
...
@@ -14,6 +14,7 @@ using Microsoft.Extensions.Configuration;
using
Microsoft.Extensions.DependencyInjection
;
using
Microsoft.Extensions.DependencyInjection
;
using
Microsoft.Extensions.FileProviders
;
using
Microsoft.Extensions.FileProviders
;
using
Stratis.Guru.Hubs
;
using
Stratis.Guru.Hubs
;
using
Stratis.Guru.Models
;
using
Stratis.Guru.Modules
;
using
Stratis.Guru.Modules
;
using
Stratis.Guru.Services
;
using
Stratis.Guru.Services
;
using
Stratis.Guru.Settings
;
using
Stratis.Guru.Settings
;
...
@@ -39,22 +40,19 @@ namespace Stratis.Guru
...
@@ -39,22 +40,19 @@ namespace Stratis.Guru
options
.
MinimumSameSitePolicy
=
SameSiteMode
.
None
;
options
.
MinimumSameSitePolicy
=
SameSiteMode
.
None
;
});
});
services
.
Configure
<
NakoApiSettings
>(
Configuration
.
GetSection
(
"NakoApi"
));
services
.
Configure
<
NakoApiSettings
>(
Configuration
.
GetSection
(
"NakoApi"
));
services
.
Configure
<
FixerApiSettings
>(
Configuration
.
GetSection
(
"FixerApi"
));
Thread
.
CurrentThread
.
CurrentCulture
=
new
CultureInfo
(
"en-US"
);
Thread
.
CurrentThread
.
CurrentCulture
=
new
CultureInfo
(
"en-US"
);
Thread
.
CurrentThread
.
CurrentUICulture
=
new
CultureInfo
(
"en-US"
);
Thread
.
CurrentThread
.
CurrentUICulture
=
new
CultureInfo
(
"en-US"
);
services
.
AddMemoryCache
();
services
.
AddMemoryCache
();
services
.
AddHostedService
<
UpdateInfosService
>();
//services.AddHostedService<VanityService>();
services
.
AddTransient
<
UpdateHub
>();
services
.
AddTransient
<
UpdateHub
>();
services
.
AddSingleton
<
IAsk
,
Ask
>();
services
.
AddSingleton
<
IAsk
,
Ask
>();
/*services.AddResponseCaching(options =>
services
.
AddHostedService
<
UpdateInfosService
>();
{
services
.
AddHostedService
<
FixerService
>();
options.UseCaseSensitivePaths = true;
services
.
AddHostedService
<
VanityService
>();
options.MaximumBodySize = 1024;
});*/
services
.
AddMvc
().
SetCompatibilityVersion
(
CompatibilityVersion
.
Version_2_1
);
services
.
AddMvc
().
SetCompatibilityVersion
(
CompatibilityVersion
.
Version_2_1
);
...
...
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