/// <inheritdoc/>
        public void Perform(CoreAppHost host, ILogger logger)
        {
            var logDirectory       = host.Resolve <IApplicationPaths>().ConfigurationDirectoryPath;
            var existingConfigPath = Path.Combine(logDirectory, "logging.json");

            // If the existing logging.json config file is unmodified, then 'reset' it by moving it to 'logging.old.json'
            // NOTE: This config file has 'reloadOnChange: true', so this change will take effect immediately even though it has already been loaded
            if (File.Exists(existingConfigPath) && ExistingConfigUnmodified(existingConfigPath))
            {
                File.Move(existingConfigPath, Path.Combine(logDirectory, "logging.old.json"));
            }
        }
Beispiel #2
0
        public CoreAppShell(System.Windows.Application application) : base(application)
        {
            var app = new CoreAppHost(() => application.MainWindow);

            context.Provide <IAppHost>(() => app);

            var window = new MainWindow
            {
                DataContext = new MainWindowViewModel(context)
            };

            window.Show();
        }
Beispiel #3
0
        /// <summary>
        /// Run all needed migrations.
        /// </summary>
        /// <param name="host">CoreAppHost that hosts current version.</param>
        /// <param name="loggerFactory">Factory for making the logger.</param>
        public static void Run(CoreAppHost host, ILoggerFactory loggerFactory)
        {
            var logger     = loggerFactory.CreateLogger <MigrationRunner>();
            var migrations = _migrationTypes
                             .Select(m => ActivatorUtilities.CreateInstance(host.ServiceProvider, m))
                             .OfType <IMigrationRoutine>()
                             .ToArray();

            var migrationOptions = host.ConfigurationManager.GetConfiguration <MigrationOptions>(MigrationsListStore.StoreKey);

            HandleStartupWizardCondition(migrations, migrationOptions, host.ConfigurationManager.Configuration.IsStartupWizardCompleted, logger);
            PerformMigrations(migrations, migrationOptions, options => host.ConfigurationManager.SaveConfiguration(MigrationsListStore.StoreKey, options), logger);
        }
Beispiel #4
0
        /// <inheritdoc/>
        public void Perform(CoreAppHost host, ILogger logger)
        {
            // Set EnableThrottling to false since it wasn't used before and may introduce issues
            var encoding = ((IConfigurationManager)host.ServerConfigurationManager).GetConfiguration <EncodingOptions>("encoding");

            if (encoding.EnableThrottling)
            {
                logger.LogInformation("Disabling transcoding throttling during migration");
                encoding.EnableThrottling = false;

                host.ServerConfigurationManager.SaveConfiguration("encoding", encoding);
            }
        }
Beispiel #5
0
        /// <inheritdoc/>
        protected override void ConfigureWebHost(IWebHostBuilder builder)
        {
            // Specify the startup command line options
            var commandLineOpts = new StartupOptions
            {
                NoWebClient     = true,
                NoAutoRunWebApp = true
            };

            // Use a temporary directory for the application paths
            var webHostPathRoot = Path.Combine(_testPathRoot, "test-host-" + Path.GetFileNameWithoutExtension(Path.GetRandomFileName()));

            Directory.CreateDirectory(Path.Combine(webHostPathRoot, "logs"));
            Directory.CreateDirectory(Path.Combine(webHostPathRoot, "config"));
            Directory.CreateDirectory(Path.Combine(webHostPathRoot, "cache"));
            Directory.CreateDirectory(Path.Combine(webHostPathRoot, "jellyfin-web"));
            var appPaths = new ServerApplicationPaths(
                webHostPathRoot,
                Path.Combine(webHostPathRoot, "logs"),
                Path.Combine(webHostPathRoot, "config"),
                Path.Combine(webHostPathRoot, "cache"),
                Path.Combine(webHostPathRoot, "jellyfin-web"));

            // Create the logging config file
            // TODO: We shouldn't need to do this since we are only logging to console
            Program.InitLoggingConfigFile(appPaths).GetAwaiter().GetResult();

            // Create a copy of the application configuration to use for startup
            var startupConfig = Program.CreateAppConfiguration(commandLineOpts, appPaths);

            ILoggerFactory loggerFactory     = new SerilogLoggerFactory();
            var            serviceCollection = new ServiceCollection();

            _disposableComponents.Add(loggerFactory);

            // Create the app host and initialize it
            var appHost = new CoreAppHost(
                appPaths,
                loggerFactory,
                commandLineOpts,
                new ManagedFileSystem(loggerFactory.CreateLogger <ManagedFileSystem>(), appPaths),
                new NetworkManager(loggerFactory.CreateLogger <NetworkManager>()),
                serviceCollection);

            _disposableComponents.Add(appHost);
            appHost.Init();

            // Configure the web host builder
            Program.ConfigureWebHostBuilder(builder, appHost, serviceCollection, commandLineOpts, startupConfig, appPaths);
        }
Beispiel #6
0
        /// <summary>
        /// Run all needed migrations.
        /// </summary>
        /// <param name="host">CoreAppHost that hosts current version.</param>
        /// <param name="loggerFactory">Factory for making the logger.</param>
        public static void Run(CoreAppHost host, ILoggerFactory loggerFactory)
        {
            var logger     = loggerFactory.CreateLogger <MigrationRunner>();
            var migrations = _migrationTypes
                             .Select(m => ActivatorUtilities.CreateInstance(host.ServiceProvider, m))
                             .OfType <IMigrationRoutine>()
                             .ToArray();
            var migrationOptions = ((IConfigurationManager)host.ServerConfigurationManager).GetConfiguration <MigrationOptions>(MigrationsListStore.StoreKey);

            if (!host.ServerConfigurationManager.Configuration.IsStartupWizardCompleted && migrationOptions.Applied.Count == 0)
            {
                // If startup wizard is not finished, this is a fresh install.
                // Don't run any migrations, just mark all of them as applied.
                logger.LogInformation("Marking all known migrations as applied because this is a fresh install");
                migrationOptions.Applied.AddRange(migrations.Select(m => (m.Id, m.Name)));
                host.ServerConfigurationManager.SaveConfiguration(MigrationsListStore.StoreKey, migrationOptions);
                return;
            }

            var appliedMigrationIds = migrationOptions.Applied.Select(m => m.Id).ToHashSet();

            for (var i = 0; i < migrations.Length; i++)
            {
                var migrationRoutine = migrations[i];
                if (appliedMigrationIds.Contains(migrationRoutine.Id))
                {
                    logger.LogDebug("Skipping migration '{Name}' since it is already applied", migrationRoutine.Name);
                    continue;
                }

                logger.LogInformation("Applying migration '{Name}'", migrationRoutine.Name);

                try
                {
                    migrationRoutine.Perform();
                }
                catch (Exception ex)
                {
                    logger.LogError(ex, "Could not apply migration '{Name}'", migrationRoutine.Name);
                    throw;
                }

                // Mark the migration as completed
                logger.LogInformation("Migration '{Name}' applied successfully", migrationRoutine.Name);
                migrationOptions.Applied.Add((migrationRoutine.Id, migrationRoutine.Name));
                host.ServerConfigurationManager.SaveConfiguration(MigrationsListStore.StoreKey, migrationOptions);
                logger.LogDebug("Migration '{Name}' marked as applied in configuration.", migrationRoutine.Name);
            }
        }