-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathVortexContext.cs
More file actions
72 lines (59 loc) · 2.46 KB
/
VortexContext.cs
File metadata and controls
72 lines (59 loc) · 2.46 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using Lagrange.Core;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Vortex.Bot.Command;
using Vortex.Bot.Configuration;
using Vortex.Bot.Core.Service;
using Vortex.Bot.Database;
using Vortex.Bot.Models;
using Vortex.Bot.Utility;
namespace Vortex.Bot;
public partial class VortexContext(
BotContext botContext,
IDatabaseService database,
CommandManager commandManager,
IOptions<CoreConfiguration> configuration,
ILogger<VortexContext> logger) : IHostedService
{
private readonly ILogger<VortexContext> _logger = logger;
public BotContext BotContext { get; } = botContext;
public IDatabaseService Database { get; } = database;
public CommandManager CommandManager { get; } = commandManager;
public ILogger<VortexContext> Logger => _logger;
public CoreConfiguration Configuration { get; } = configuration.Value;
public SystemMonitor SystemMonitor { get; private set; } = null!;
public VortexSocketService? Server { get; set; }
public static string Path => Environment.CurrentDirectory;
public static string SavePath => System.IO.Path.Combine(Path, "Config");
public Task StartAsync(CancellationToken cancellationToken)
{
_logger.LogVortexContextStarted();
DefaultGroup.Initialize();
_logger.LogDefaultGroupInitialized();
SystemMonitor = new SystemMonitor();
_logger.LogSystemMonitorStarted();
return Task.CompletedTask;
}
public Task StopAsync(CancellationToken cancellationToken)
{
_logger.LogVortexContextStopping();
SystemMonitor?.Dispose();
if (Database is IDisposable disposable)
{
disposable.Dispose();
}
return Task.CompletedTask;
}
}
public static partial class VortexContextLoggerExtension
{
[LoggerMessage(LogLevel.Information, "VortexContext started")]
public static partial void LogVortexContextStarted(this ILogger<VortexContext> logger);
[LoggerMessage(LogLevel.Information, "DefaultGroup initialized")]
public static partial void LogDefaultGroupInitialized(this ILogger<VortexContext> logger);
[LoggerMessage(LogLevel.Information, "SystemMonitor started")]
public static partial void LogSystemMonitorStarted(this ILogger<VortexContext> logger);
[LoggerMessage(LogLevel.Information, "VortexContext stopping")]
public static partial void LogVortexContextStopping(this ILogger<VortexContext> logger);
}