Exemple #1
0
        /// <summary>
        /// Checks for migratable data
        /// </summary>
        /// <param name="cancellationToken">Cancellation Token</param>
        /// <returns>Task for the async task</returns>
        public async Task StartAsync(CancellationToken cancellationToken)
        {
            using (IServiceScope serviceScope = _serviceScopeFactory.CreateScope())
            {
                IUserDbAccess userDbAccess = (IUserDbAccess)serviceScope.ServiceProvider.GetService(typeof(IUserDbAccess));
                IDbSetup      dbSetup      = (IDbSetup)serviceScope.ServiceProvider.GetService(typeof(IDbSetup));
                ILogger       logger       = (ILogger)serviceScope.ServiceProvider.GetService(typeof(ILogger <AutoDataMigrator>));

                try
                {
                    await RemoveUnusedRolesForUsers(userDbAccess);
                }
                catch (Exception ex)
                {
                    logger.LogError(ex, "Could not remove old user roles");
                }

                try
                {
                    await dbSetup.CheckForNeededMigrations();
                }
                catch (Exception ex)
                {
                    logger.LogError(ex, "Could not migrate database");
                }
            }
        }
        /// <summary>
        /// Checks for migratable data
        /// </summary>
        /// <returns>Task for the async task</returns>
        public async Task UpdateMigratableData()
        {
            try
            {
                await RemoveUnusedRolesForUsers();
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Could not remove old user roles");
            }

            try
            {
                await _dbSetup.CheckForNeededMigrations();
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Could not migrate database");
            }
        }