mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-05-05 18:22:27 +00:00
Split API into its own project
This commit is contained in:
parent
2aa803f69f
commit
47271d1798
16 changed files with 336 additions and 162 deletions
88
ProjectLighthouse/StartupTasks.cs
Normal file
88
ProjectLighthouse/StartupTasks.cs
Normal file
|
@ -0,0 +1,88 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using LBPUnion.ProjectLighthouse.Helpers;
|
||||
using LBPUnion.ProjectLighthouse.Logging;
|
||||
using LBPUnion.ProjectLighthouse.Logging.Loggers;
|
||||
using LBPUnion.ProjectLighthouse.Types;
|
||||
using LBPUnion.ProjectLighthouse.Types.Settings;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse;
|
||||
|
||||
public static class StartupTasks
|
||||
{
|
||||
public static void Run(string[] args, ServerType serverType)
|
||||
{
|
||||
// Log startup time
|
||||
Stopwatch stopwatch = new();
|
||||
stopwatch.Start();
|
||||
|
||||
// Setup logging
|
||||
Logger.AddLogger(new ConsoleLogger());
|
||||
Logger.AddLogger(new LighthouseFileLogger());
|
||||
|
||||
Logger.LogInfo($"Welcome to the Project Lighthouse {serverType.ToString()}!", LogArea.Startup);
|
||||
Logger.LogInfo($"You are running version {VersionHelper.FullVersion}", LogArea.Startup);
|
||||
|
||||
// Referencing ServerSettings.Instance here loads the config, see ServerSettings.cs for more information
|
||||
Logger.LogSuccess("Loaded config file version " + ServerConfiguration.Instance.ConfigVersion, LogArea.Startup);
|
||||
|
||||
Logger.LogInfo("Determining if the database is available...", LogArea.Startup);
|
||||
bool dbConnected = ServerStatics.DbConnected;
|
||||
if (!dbConnected)
|
||||
{
|
||||
Logger.LogError("Database unavailable! Exiting.", LogArea.Startup);
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.LogSuccess("Connected to the database.", LogArea.Startup);
|
||||
}
|
||||
|
||||
if (!dbConnected) Environment.Exit(1);
|
||||
using Database database = new();
|
||||
|
||||
Logger.LogInfo("Migrating database...", LogArea.Database);
|
||||
migrateDatabase(database);
|
||||
|
||||
if (ServerConfiguration.Instance.InfluxDB.InfluxEnabled)
|
||||
{
|
||||
Logger.LogInfo("Influx logging is enabled. Starting influx logging...", LogArea.Startup);
|
||||
InfluxHelper.StartLogging().Wait();
|
||||
if (ServerConfiguration.Instance.InfluxDB.LoggingEnabled) Logger.AddLogger(new InfluxLogger());
|
||||
}
|
||||
|
||||
Logger.LogDebug
|
||||
(
|
||||
"This is a debug build, so performance may suffer! " +
|
||||
"If you are running Lighthouse in a production environment, " +
|
||||
"it is highly recommended to run a release build. ",
|
||||
LogArea.Startup
|
||||
);
|
||||
Logger.LogDebug("You can do so by running any dotnet command with the flag: \"-c Release\". ", LogArea.Startup);
|
||||
|
||||
if (args.Length != 0)
|
||||
{
|
||||
MaintenanceHelper.RunCommand(args).Wait();
|
||||
return;
|
||||
}
|
||||
|
||||
if (ServerConfiguration.Instance.WebsiteConfiguration.ConvertAssetsOnStartup) FileHelper.ConvertAllTexturesToPng();
|
||||
|
||||
Logger.LogInfo("Starting room cleanup thread...", LogArea.Startup);
|
||||
RoomHelper.StartCleanupThread();
|
||||
|
||||
stopwatch.Stop();
|
||||
Logger.LogSuccess($"Ready! Startup took {stopwatch.ElapsedMilliseconds}ms. Passing off control to ASP.NET...", LogArea.Startup);
|
||||
}
|
||||
|
||||
private static void migrateDatabase(Database database)
|
||||
{
|
||||
Stopwatch stopwatch = new();
|
||||
stopwatch.Start();
|
||||
|
||||
database.Database.MigrateAsync().Wait();
|
||||
|
||||
stopwatch.Stop();
|
||||
Logger.LogSuccess($"Migration took {stopwatch.ElapsedMilliseconds}ms.", LogArea.Database);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue