mirror of
https://github.com/chylex/Minecraft-Phantom-Panel.git
synced 2024-11-22 08:42:44 +01:00
46 lines
1.5 KiB
C#
46 lines
1.5 KiB
C#
using Phantom.Agent.Minecraft.Java;
|
|
using Phantom.Agent.Services.Backups;
|
|
using Phantom.Agent.Services.Instances;
|
|
using Phantom.Common.Data.Agent;
|
|
using Phantom.Common.Logging;
|
|
using Phantom.Utils.Runtime;
|
|
using Serilog;
|
|
|
|
namespace Phantom.Agent.Services;
|
|
|
|
public sealed class AgentServices {
|
|
private static readonly ILogger Logger = PhantomLogger.Create<AgentServices>();
|
|
|
|
private AgentFolders AgentFolders { get; }
|
|
private TaskManager TaskManager { get; }
|
|
private BackupManager BackupManager { get; }
|
|
|
|
internal JavaRuntimeRepository JavaRuntimeRepository { get; }
|
|
internal InstanceSessionManager InstanceSessionManager { get; }
|
|
|
|
public AgentServices(AgentInfo agentInfo, AgentFolders agentFolders) {
|
|
this.AgentFolders = agentFolders;
|
|
this.TaskManager = new TaskManager(PhantomLogger.Create<TaskManager, AgentServices>());
|
|
this.BackupManager = new BackupManager(agentFolders);
|
|
this.JavaRuntimeRepository = new JavaRuntimeRepository();
|
|
this.InstanceSessionManager = new InstanceSessionManager(agentInfo, agentFolders, JavaRuntimeRepository, TaskManager, BackupManager);
|
|
}
|
|
|
|
public async Task Initialize() {
|
|
await foreach (var runtime in JavaRuntimeDiscovery.Scan(AgentFolders.JavaSearchFolderPath)) {
|
|
JavaRuntimeRepository.Include(runtime);
|
|
}
|
|
}
|
|
|
|
public async Task Shutdown() {
|
|
Logger.Information("Stopping services...");
|
|
|
|
await InstanceSessionManager.StopAll();
|
|
InstanceSessionManager.Dispose();
|
|
|
|
await TaskManager.Stop();
|
|
|
|
Logger.Information("Services stopped.");
|
|
}
|
|
}
|