Recreated plugin with new project template. Started implementing server system daemon
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
using MoonlightServers.Daemon.ServerSystem.Abstractions;
|
||||
|
||||
namespace MoonlightServers.Daemon.ServerSystem.Implementations.Local;
|
||||
|
||||
public static class Extensions
|
||||
{
|
||||
public static void AddLocalServices(this IServiceCollection services)
|
||||
{
|
||||
services.AddSingleton<IRuntimeStorageService, LocalRuntimeStorageService>();
|
||||
services.AddSingleton<IInstallStorageService, LocalInstallStorageService>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using MoonlightServers.Daemon.ServerSystem.Abstractions;
|
||||
|
||||
namespace MoonlightServers.Daemon.ServerSystem.Implementations.Local;
|
||||
|
||||
public class LocalInstallStorage : IInstallStorage
|
||||
{
|
||||
public string HostPath { get; }
|
||||
|
||||
public LocalInstallStorage(string hostPath)
|
||||
{
|
||||
HostPath = hostPath;
|
||||
}
|
||||
|
||||
public Task<string> GetHostPathAsync() => Task.FromResult(HostPath);
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
using MoonlightServers.Daemon.Models;
|
||||
using MoonlightServers.Daemon.ServerSystem.Abstractions;
|
||||
|
||||
namespace MoonlightServers.Daemon.ServerSystem.Implementations.Local;
|
||||
|
||||
public class LocalInstallStorageService : IInstallStorageService
|
||||
{
|
||||
private const string HostPathTemplate = "./mldaemon/install/{0}";
|
||||
|
||||
public Task<IInstallStorage?> FindAsync(string id)
|
||||
{
|
||||
var path = string.Format(HostPathTemplate, id);
|
||||
|
||||
if (!Directory.Exists(path))
|
||||
return Task.FromResult<IInstallStorage?>(null);
|
||||
|
||||
return Task.FromResult<IInstallStorage?>(new LocalInstallStorage(path));
|
||||
}
|
||||
|
||||
public Task<IInstallStorage> CreateAsync(string id, RuntimeConfiguration runtimeConfiguration, InstallConfiguration installConfiguration)
|
||||
{
|
||||
var path = string.Format(HostPathTemplate, id);
|
||||
|
||||
Directory.CreateDirectory(path);
|
||||
|
||||
return Task.FromResult<IInstallStorage>(new LocalInstallStorage(path));
|
||||
}
|
||||
|
||||
public Task DeleteAsync(IInstallStorage installStorage)
|
||||
{
|
||||
if (installStorage is not LocalInstallStorage localInstallStorage)
|
||||
{
|
||||
throw new ArgumentException(
|
||||
$"You cannot delete install storages which haven't been created by {nameof(LocalInstallStorageService)}"
|
||||
);
|
||||
}
|
||||
|
||||
if(Directory.Exists(localInstallStorage.HostPath))
|
||||
Directory.Delete(localInstallStorage.HostPath, true);
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using MoonlightServers.Daemon.ServerSystem.Abstractions;
|
||||
|
||||
namespace MoonlightServers.Daemon.ServerSystem.Implementations.Local;
|
||||
|
||||
public class LocalRuntimeStorage : IRuntimeStorage
|
||||
{
|
||||
public string HostPath { get; }
|
||||
|
||||
public LocalRuntimeStorage(string hostPath)
|
||||
{
|
||||
HostPath = hostPath;
|
||||
}
|
||||
|
||||
public Task<string> GetHostPathAsync() => Task.FromResult(HostPath);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
using MoonlightServers.Daemon.Models;
|
||||
using MoonlightServers.Daemon.ServerSystem.Abstractions;
|
||||
|
||||
namespace MoonlightServers.Daemon.ServerSystem.Implementations.Local;
|
||||
|
||||
public class LocalRuntimeStorageService : IRuntimeStorageService
|
||||
{
|
||||
private const string HostPathTemplate = "./mldaemon/runtime/{0}";
|
||||
|
||||
public Task<IRuntimeStorage?> FindAsync(string id)
|
||||
{
|
||||
var path = string.Format(HostPathTemplate, id);
|
||||
|
||||
if (!Directory.Exists(path))
|
||||
return Task.FromResult<IRuntimeStorage?>(null);
|
||||
|
||||
return Task.FromResult<IRuntimeStorage?>(new LocalRuntimeStorage(path));
|
||||
}
|
||||
|
||||
public Task<IRuntimeStorage> CreateAsync(string id, RuntimeConfiguration configuration)
|
||||
{
|
||||
var path = string.Format(HostPathTemplate, id);
|
||||
|
||||
Directory.CreateDirectory(path);
|
||||
|
||||
return Task.FromResult<IRuntimeStorage>(new LocalRuntimeStorage(path));
|
||||
}
|
||||
|
||||
public Task UpdateAsync(IRuntimeStorage runtimeStorage, RuntimeConfiguration configuration)
|
||||
=> Task.CompletedTask;
|
||||
|
||||
public Task DeleteAsync(IRuntimeStorage runtimeStorage)
|
||||
{
|
||||
if (runtimeStorage is not LocalRuntimeStorage localRuntimeStorage)
|
||||
{
|
||||
throw new ArgumentException(
|
||||
$"You cannot delete runtime storages which haven't been created by {nameof(LocalRuntimeStorageService)}"
|
||||
);
|
||||
}
|
||||
|
||||
if(Directory.Exists(localRuntimeStorage.HostPath))
|
||||
Directory.Delete(localRuntimeStorage.HostPath, true);
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user