Exemple #1
0
        /// <inheritdoc />
#pragma warning disable CA1506 // TODO: Decomplexify
        public async Task <IInstance> CreateInstance(IBridgeRegistrar bridgeRegistrar, Models.Instance metadata)
        {
            // Create the ioManager for the instance
            var instanceIoManager = new ResolvingIOManager(ioManager, metadata.Path);

            // various other ioManagers
            var repoIoManager          = new ResolvingIOManager(instanceIoManager, "Repository");
            var byondIOManager         = new ResolvingIOManager(instanceIoManager, "Byond");
            var gameIoManager          = new ResolvingIOManager(instanceIoManager, "Game");
            var diagnosticsIOManager   = new ResolvingIOManager(instanceIoManager, "Diagnostics");
            var configurationIoManager = new ResolvingIOManager(instanceIoManager, "Configuration");

            var configuration = new StaticFiles.Configuration(
                configurationIoManager,
                synchronousIOManager,
                symlinkFactory,
                processExecutor,
                postWriteHandler,
                platformIdentifier,
                fileTransferService,
                loggerFactory.CreateLogger <StaticFiles.Configuration>());
            var eventConsumer = new EventConsumer(configuration);
            var repoManager   = new RepositoryManager(
                repositoryFactory,
                repositoryCommands,
                repoIoManager,
                eventConsumer,
                gitRemoteFeaturesFactory,
                loggerFactory.CreateLogger <Repository.Repository>(),
                loggerFactory.CreateLogger <RepositoryManager>());

            try
            {
                var byond = new ByondManager(byondIOManager, byondInstaller, eventConsumer, loggerFactory.CreateLogger <ByondManager>());

                var commandFactory = new CommandFactory(assemblyInformationProvider, byond, repoManager, databaseContextFactory, metadata);

                var chatManager = chatFactory.CreateChatManager(instanceIoManager, commandFactory, metadata.ChatSettings);
                try
                {
                    var sessionControllerFactory = new SessionControllerFactory(
                        processExecutor,
                        byond,
                        topicClientFactory,
                        cryptographySuite,
                        assemblyInformationProvider,
                        gameIoManager,
                        chatManager,
                        networkPromptReaper,
                        platformIdentifier,
                        bridgeRegistrar,
                        serverPortProvider,
                        eventConsumer,
                        loggerFactory,
                        loggerFactory.CreateLogger <SessionControllerFactory>(),
                        metadata);

                    var dmbFactory = new DmbFactory(
                        databaseContextFactory,
                        gameIoManager,
                        remoteDeploymentManagerFactory,
                        loggerFactory.CreateLogger <DmbFactory>(),
                        metadata);
                    try
                    {
                        var reattachInfoHandler = new SessionPersistor(
                            databaseContextFactory,
                            dmbFactory,
                            processExecutor,
                            loggerFactory.CreateLogger <SessionPersistor>(),
                            metadata);
                        var watchdog = watchdogFactory.CreateWatchdog(
                            chatManager,
                            dmbFactory,
                            reattachInfoHandler,
                            sessionControllerFactory,
                            gameIoManager,
                            diagnosticsIOManager,
                            eventConsumer,
                            remoteDeploymentManagerFactory,
                            metadata,
                            metadata.DreamDaemonSettings);
                        eventConsumer.SetWatchdog(watchdog);
                        commandFactory.SetWatchdog(watchdog);
                        try
                        {
                            Instance instance   = null;
                            var      dreamMaker = new DreamMaker(
                                byond,
                                gameIoManager,
                                configuration,
                                sessionControllerFactory,
                                eventConsumer,
                                chatManager,
                                processExecutor,
                                dmbFactory,
                                repoManager,
                                remoteDeploymentManagerFactory,
                                loggerFactory.CreateLogger <DreamMaker>(),
                                metadata);

                            instance = new Instance(
                                metadata,
                                repoManager,
                                byond,
                                dreamMaker,
                                watchdog,
                                chatManager,
                                configuration,
                                dmbFactory,
                                jobManager,
                                eventConsumer,
                                remoteDeploymentManagerFactory,
                                loggerFactory.CreateLogger <Instance>());

                            return(instance);
                        }
                        catch
                        {
                            await watchdog.DisposeAsync().ConfigureAwait(false);

                            throw;
                        }
                    }
                    catch
                    {
                        dmbFactory.Dispose();
                        throw;
                    }
                }
                catch
                {
                    await chatManager.DisposeAsync().ConfigureAwait(false);

                    throw;
                }
            }
            catch
            {
                repoManager.Dispose();
                throw;
            }
        }
        /// <inheritdoc />
        public IInstance CreateInstance(Models.Instance metadata)
        {
            //Create the ioManager for the instance
            var instanceIoManager = new ResolvingIOManager(ioManager, metadata.Path);

            //various other ioManagers
            var repoIoManager          = new ResolvingIOManager(instanceIoManager, "Repository");
            var byondIOManager         = new ResolvingIOManager(instanceIoManager, "Byond");
            var gameIoManager          = new ResolvingIOManager(instanceIoManager, "Game");
            var configurationIoManager = new ResolvingIOManager(instanceIoManager, "Configuration");

            var configuration = new StaticFiles.Configuration(configurationIoManager, synchronousIOManager, symlinkFactory, processExecutor, postWriteHandler, loggerFactory.CreateLogger <StaticFiles.Configuration>());
            var eventConsumer = new EventConsumer(configuration);

            var dmbFactory = new DmbFactory(databaseContextFactory, gameIoManager, loggerFactory.CreateLogger <DmbFactory>(), metadata.CloneMetadata());

            try
            {
                var repoManager = new RepositoryManager(metadata.RepositorySettings, repoIoManager, eventConsumer, credentialsProvider, loggerFactory.CreateLogger <Repository.Repository>(), loggerFactory.CreateLogger <RepositoryManager>());
                try
                {
                    var byond = new ByondManager(byondIOManager, byondInstaller, eventConsumer, loggerFactory.CreateLogger <ByondManager>());

                    var commandFactory = new CommandFactory(application, byond, repoManager, databaseContextFactory, metadata);

                    var chat = chatFactory.CreateChat(instanceIoManager, commandFactory, metadata.ChatSettings);
                    try
                    {
                        var sessionControllerFactory = new SessionControllerFactory(processExecutor, byond, byondTopicSender, cryptographySuite, application, gameIoManager, chat, networkPromptReaper, loggerFactory, metadata.CloneMetadata());
                        var reattachInfoHandler      = new ReattachInfoHandler(databaseContextFactory, dmbFactory, loggerFactory.CreateLogger <ReattachInfoHandler>(), metadata.CloneMetadata());
                        var watchdog = watchdogFactory.CreateWatchdog(chat, dmbFactory, reattachInfoHandler, configuration, sessionControllerFactory, metadata.CloneMetadata(), metadata.DreamDaemonSettings);
                        eventConsumer.SetWatchdog(watchdog);
                        commandFactory.SetWatchdog(watchdog);
                        try
                        {
                            var dreamMaker = new DreamMaker(byond, gameIoManager, configuration, sessionControllerFactory, dmbFactory, application, eventConsumer, chat, processExecutor, watchdog, loggerFactory.CreateLogger <DreamMaker>());

                            return(new Instance(metadata.CloneMetadata(), repoManager, byond, dreamMaker, watchdog, chat, configuration, dmbFactory, databaseContextFactory, dmbFactory, jobManager, eventConsumer, gitHubClientFactory, loggerFactory.CreateLogger <Instance>()));
                        }
                        catch
                        {
                            watchdog.Dispose();
                            throw;
                        }
                    }
                    catch
                    {
                        chat.Dispose();
                        throw;
                    }
                }
                catch
                {
                    repoManager.Dispose();
                    throw;
                }
            }
            catch
            {
                dmbFactory.Dispose();
                throw;
            }
        }