holy! the server app is finished & model is nice now

This commit is contained in:
Schedel Pascal
2024-08-23 11:58:07 +02:00
parent 860c061b98
commit 82429a2f69
22 changed files with 88 additions and 650 deletions

View File

@@ -1,36 +1,42 @@
using OwnChar.Plugins;
using OwnChar.Server.Api.Plugins;
using Pilz.Configuration;
using Castle.Core.Logging;
using OwnChar.Api;
namespace OwnChar.Server;
internal class Program
{
public static string? AppTempFolder { get; private set; }
public static ISettingsManager? SettingsManager { get; private set; }
public static void Main(string[] args)
{
// Load settings
AppTempFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "OwnChar", "Server");
Directory.CreateDirectory(AppTempFolder);
SettingsManager = new SettingsManager(Path.Combine(AppTempFolder, "Settings.json"), true);
// Create server context
var server = new ServerContext(SettingsManager.Instance);
var options = new ServerOptions(args);
var appTempFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "OwnChar", "Server");
// Load log
// ...
Directory.CreateDirectory(appTempFolder);
using var fsLog = File.OpenWrite(Path.Combine(appTempFolder, "Log.log"));
var log = new StreamLogger("OwnChar Server", fsLog);
// Load plugins
server.Log.Debug("Loading plugins");
var pluginPath = Path.Combine(AppTempFolder, "Plugins");
Directory.CreateDirectory(pluginPath);
var pluginPaths = Directory.GetDirectories(pluginPath, "*", SearchOption.TopDirectoryOnly).Select(n => Path.Combine(n, n + ".dll")).ToArray();
var plugins = OwnCharPlugins.Instance.LoadPlugins(pluginPaths, new OwnCharServerPluginInitParams(server));
server.Log.InfoFormat("{0} plugins loaded", plugins.Count());
// Check paramters
if (!options.IsValid())
{
log.Error("Parameters are invalid or not configured. Can not start server app.");
return;
}
// Start server app
server.Start(args);
// Create server context
var server = new OwnCharApiServer(options.ApiUrl, options.DbServer, options.DbDatabase, options.DbUser, options.DbPassword)
{
Log = log
};
// Start server
server.Start();
// Wait for exit
Console.WriteLine("Server started. Press any key to stop.");
Console.ReadKey();
// Stop server
server.Stop();
}
}