Exemple #1
0
        private static async Task ApplyMigration(
            IServiceProvider serviceProvider,
            Type item,
            IMigrationHistoryRepository migrationHistoryRepository,
            ILogger <MigrationHistoryRepository> logger)
        {
            var ctor = item
                       .GetConstructors()
                       .FirstOrDefault();

            var ctorParams = ctor?.GetParameters();

            var fullServices = ctorParams
                               ?.Select(x => serviceProvider.GetRequiredService(x.ParameterType))
                               .ToArray();

            IAnimalRescueMigration instance = (IAnimalRescueMigration)Activator.CreateInstance(item, fullServices);

            try
            {
                await instance.Execute();

                await migrationHistoryRepository.CreateAsync(new MigrationHistory
                {
                    MigrationId = item.GetCustomAttribute <MigrationAttribute>()?.Name
                });
            }
            catch (Exception exception)
            {
                logger.LogCritical(exception.Message);
            }
        }
        public static bool RunTask(HttpConfiguration HttpConfiguration)
        {
            System.Threading.Tasks.Task <bool> MigrationCheckTaskResults = System.Threading.Tasks.Task <bool> .Factory.StartNew(() =>
            {
                try
                {
                    using (HttpConfiguration.DependencyResolver.BeginScope())
                    {
                        IMigrationHistoryRepository IMigrationHistoryRepository = (IMigrationHistoryRepository)HttpConfiguration.DependencyResolver.GetService(typeof(IMigrationHistoryRepository));
                        return(IMigrationHistoryRepository.CheckMigrationsPerformed());
                    }
                }
                catch (Exception Exec)
                {
                    Pyro.Common.Logging.Logger.Log.Error(Exec, "StartupPyroDatabaseMigrationCheck failed.");
                    throw Exec;
                }
                //End of Task Thread.
            });

            try
            {
                //Here we are catching any exceptions that occurred inside the Task thread above.
                MigrationCheckTaskResults.Wait();
                return(MigrationCheckTaskResults.Result);
            }
            catch (Exception Exec)
            {
                string ExecMessage = "Internal Server Error: Start-up Pyro Database Migration Check failed!.";
                Console.WriteLine();
                Console.WriteLine(ExecMessage);
                if (Exec.InnerException != null)
                {
                    Console.WriteLine(Exec.InnerException.Message);
                }
                Console.ReadKey();
                Pyro.Common.Logging.Logger.Log.Fatal(Exec, ExecMessage);
                throw new Exception(ExecMessage, Exec);
            }
        }
Exemple #3
0
 /// <summary>
 /// Sets the migration history repository.
 /// </summary>
 /// <param name="repository">The repository.</param>
 /// <returns>The engine.</returns>
 public virtual Engine SetMigrationHistoryRepository(IMigrationHistoryRepository repository)
 {
     HistoryRepository = repository;
     return this;
 }
Exemple #4
0
 /// <summary>
 /// Sets the migration history repository.
 /// </summary>
 /// <param name="repository">The repository.</param>
 /// <returns>The engine.</returns>
 public virtual Engine SetMigrationHistoryRepository(IMigrationHistoryRepository repository)
 {
     HistoryRepository = repository;
     return(this);
 }