-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathGameDatabaseProvider.cs
More file actions
51 lines (43 loc) · 1.33 KB
/
GameDatabaseProvider.cs
File metadata and controls
51 lines (43 loc) · 1.33 KB
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
using System.Diagnostics.CodeAnalysis;
using NotEnoughLogs;
using Refresh.Common.Time;
using Refresh.Database.Configuration;
namespace Refresh.Database;
public class GameDatabaseProvider :
IDatabaseProvider<GameDatabaseContext>
{
private readonly IDateTimeProvider _time;
private readonly IDatabaseConfig _dbConfig;
protected readonly Logger Logger;
public GameDatabaseProvider(Logger logger, IDatabaseConfig dbConfig)
{
this.Logger = logger;
this._time = new SystemDateTimeProvider();
this._dbConfig = dbConfig;
}
protected GameDatabaseProvider(Logger logger, IDateTimeProvider time)
{
this.Logger = logger;
this._time = time;
this._dbConfig = new EmptyDatabaseConfig();
}
[SuppressMessage("ReSharper.DPA", "DPA0005: Database issues")]
public virtual void Initialize()
{
using GameDatabaseContext context = this.GetContext();
context.Database.Migrate();
}
public virtual void Dispose()
{
GC.SuppressFinalize(this);
}
public void Warmup()
{
using GameDatabaseContext context = this.GetContext();
_ = context.GetTotalLevelCount();
}
public virtual GameDatabaseContext GetContext()
{
return new GameDatabaseContext(this.Logger, this._time, this._dbConfig);
}
}