From d2d201bd53bda16cedacf675c90d34152328b45d Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Thu, 26 Jul 2018 17:50:54 -0400 Subject: [PATCH] Finishes the instance contruction process --- .../Components/IDmbFactory.cs | 3 +- .../Components/IRepositoryManager.cs | 2 +- .../Components/Instance.cs | 9 ++- .../Components/InstanceFactory.cs | 68 ++++++++++++++----- .../Components/RepositoryManager.cs | 2 +- 5 files changed, 64 insertions(+), 20 deletions(-) diff --git a/src/Tgstation.Server.Host/Components/IDmbFactory.cs b/src/Tgstation.Server.Host/Components/IDmbFactory.cs index 378c9d9860..bcdd48907a 100644 --- a/src/Tgstation.Server.Host/Components/IDmbFactory.cs +++ b/src/Tgstation.Server.Host/Components/IDmbFactory.cs @@ -1,4 +1,5 @@ -using System.Threading; +using System; +using System.Threading; using System.Threading.Tasks; using Tgstation.Server.Host.Models; diff --git a/src/Tgstation.Server.Host/Components/IRepositoryManager.cs b/src/Tgstation.Server.Host/Components/IRepositoryManager.cs index 94fd3a2ac3..ac2823b33a 100644 --- a/src/Tgstation.Server.Host/Components/IRepositoryManager.cs +++ b/src/Tgstation.Server.Host/Components/IRepositoryManager.cs @@ -7,7 +7,7 @@ namespace Tgstation.Server.Host.Components /// /// Factory for creating and loading s /// - public interface IRepositoryManager + public interface IRepositoryManager : IDisposable { /// /// Attempt to load the from the default location diff --git a/src/Tgstation.Server.Host/Components/Instance.cs b/src/Tgstation.Server.Host/Components/Instance.cs index 8c4b30f05c..b886dbee45 100644 --- a/src/Tgstation.Server.Host/Components/Instance.cs +++ b/src/Tgstation.Server.Host/Components/Instance.cs @@ -74,7 +74,14 @@ namespace Tgstation.Server.Host.Components } /// - public void Dispose() => timerCts?.Dispose(); + public void Dispose() + { + timerCts?.Dispose(); + Watchdog.Dispose(); + Chat.Dispose(); + RepositoryManager.Dispose(); + compileJobConsumer.Dispose(); + } /// /// Pull the repository and compile for every set of given diff --git a/src/Tgstation.Server.Host/Components/InstanceFactory.cs b/src/Tgstation.Server.Host/Components/InstanceFactory.cs index ec9021ff1d..6e67f0ff26 100644 --- a/src/Tgstation.Server.Host/Components/InstanceFactory.cs +++ b/src/Tgstation.Server.Host/Components/InstanceFactory.cs @@ -68,6 +68,11 @@ namespace Tgstation.Server.Host.Components /// readonly ISymlinkFactory symlinkFactory; + /// + /// The for the + /// + readonly IByondInstaller byondInstaller; + /// /// Construct an /// @@ -82,7 +87,8 @@ namespace Tgstation.Server.Host.Components /// The value of /// The value of /// The value of - public InstanceFactory(IIOManager ioManager, IDatabaseContextFactory databaseContextFactory, IApplication application, ILoggerFactory loggerFactory, IByondTopicSender byondTopicSender, IServerUpdater serverUpdater, ICryptographySuite cryptographySuite, IExecutor executor, ICommandFactory commandFactory, ISynchronousIOManager synchronousIOManager, ISymlinkFactory symlinkFactory) + /// The value of + public InstanceFactory(IIOManager ioManager, IDatabaseContextFactory databaseContextFactory, IApplication application, ILoggerFactory loggerFactory, IByondTopicSender byondTopicSender, IServerUpdater serverUpdater, ICryptographySuite cryptographySuite, IExecutor executor, ICommandFactory commandFactory, ISynchronousIOManager synchronousIOManager, ISymlinkFactory symlinkFactory, IByondInstaller byondInstaller) { this.ioManager = ioManager ?? throw new ArgumentNullException(nameof(ioManager)); this.databaseContextFactory = databaseContextFactory ?? throw new ArgumentNullException(nameof(databaseContextFactory)); @@ -95,6 +101,7 @@ namespace Tgstation.Server.Host.Components this.commandFactory = commandFactory ?? throw new ArgumentNullException(nameof(commandFactory)); this.synchronousIOManager = synchronousIOManager ?? throw new ArgumentNullException(nameof(synchronousIOManager)); this.symlinkFactory = symlinkFactory ?? throw new ArgumentNullException(nameof(symlinkFactory)); + this.byondInstaller = byondInstaller ?? throw new ArgumentNullException(nameof(byondInstaller)); } /// @@ -110,24 +117,53 @@ namespace Tgstation.Server.Host.Components var configurationIoManager = new ResolvingIOManager(instanceIoManager, "Configuration"); var dmbFactory = new DmbFactory(databaseContextFactory, gameIoManager, metadata); - var commandFactory = new CommandFactory(application); - var chatFactory = new ChatFactory(instanceIoManager, loggerFactory, commandFactory); + try + { + var commandFactory = new CommandFactory(application); + var chatFactory = new ChatFactory(instanceIoManager, loggerFactory, commandFactory); - var repoManager = new RepositoryManager(metadata.RepositorySettings, repoIoManager); + var repoManager = new RepositoryManager(metadata.RepositorySettings, repoIoManager); + try + { + var byond = new ByondManager(byondIOManager, byondInstaller, loggerFactory.CreateLogger()); + var configuration = new Configuration(configurationIoManager, synchronousIOManager, symlinkFactory, loggerFactory.CreateLogger()); - IByondManager byond = null; - var configuration = new Configuration(configurationIoManager, synchronousIOManager, symlinkFactory, loggerFactory.CreateLogger()); - - var chat = chatFactory.CreateChat(); - var sessionControllerFactory = new SessionControllerFactory(executor, byond, byondTopicSender, interopRegistrar, cryptographySuite, application, gameIoManager, chat, loggerFactory, metadata); - var reattachInfoHandler = new ReattachInfoHandler(databaseContextFactory, dmbFactory, metadata); - var watchdogFactory = new WatchdogFactory(chat, sessionControllerFactory, serverUpdater, loggerFactory, reattachInfoHandler, databaseContextFactory, byondTopicSender, metadata); - var watchdog = watchdogFactory.CreateWatchdog(dmbFactory, metadata.DreamDaemonSettings); + var chat = chatFactory.CreateChat(); + try + { + var sessionControllerFactory = new SessionControllerFactory(executor, byond, byondTopicSender, interopRegistrar, cryptographySuite, application, gameIoManager, chat, loggerFactory, metadata); + var reattachInfoHandler = new ReattachInfoHandler(databaseContextFactory, dmbFactory, metadata); + var watchdogFactory = new WatchdogFactory(chat, sessionControllerFactory, serverUpdater, loggerFactory, reattachInfoHandler, databaseContextFactory, byondTopicSender, metadata); + var watchdog = watchdogFactory.CreateWatchdog(dmbFactory, metadata.DreamDaemonSettings); + try + { + var dreamMaker = new DreamMaker(byond, ioManager, configuration, sessionControllerFactory, dmbFactory, application, watchdog, loggerFactory.CreateLogger()); - var dreamMaker = new DreamMaker(byond, ioManager, configuration, sessionControllerFactory, dmbFactory, application, watchdog, loggerFactory.CreateLogger()); - - throw new NotImplementedException(); - //return new Instance(metadata, repoManager, byond, dreamMaker, watchdog, chat, configuration, dmbFactory, databaseContextFactory, dmbFactory); + return new Instance(metadata, repoManager, byond, dreamMaker, watchdog, chat, configuration, dmbFactory, databaseContextFactory, dmbFactory); + } + catch + { + watchdog.Dispose(); + throw; + } + } + catch + { + chat.Dispose(); + throw; + } + } + catch + { + repoManager.Dispose(); + throw; + } + } + catch + { + dmbFactory.Dispose(); + throw; + } } } } diff --git a/src/Tgstation.Server.Host/Components/RepositoryManager.cs b/src/Tgstation.Server.Host/Components/RepositoryManager.cs index e18bd24820..118509530a 100644 --- a/src/Tgstation.Server.Host/Components/RepositoryManager.cs +++ b/src/Tgstation.Server.Host/Components/RepositoryManager.cs @@ -8,7 +8,7 @@ using Tgstation.Server.Host.IO; namespace Tgstation.Server.Host.Components { /// - sealed class RepositoryManager : IRepositoryManager, IDisposable + sealed class RepositoryManager : IRepositoryManager { /// /// The for the