示例#1
0
        private IPersistenceContextProvider PrepareRepositoryManager(bool reinit)
        {
            PersistenceContextProvider.InitializeSqlLogging();
            var manager = new PersistenceContextProvider();

            if (reinit || !manager.DatabaseExists())
            {
                Log.Info("The database is getting (re-)ininitialized...");
                manager.ReCreateDatabase();
                var initialization = new DataInitialization(manager);
                initialization.CreateInitialData();
                Log.Info("...initialization finished.");
            }
            else if (!manager.IsDatabaseUpToDate())
            {
                Console.WriteLine("The database needs to be updated before the server can be started. Apply update? (y/n)");
                var key = Console.ReadLine()?.ToLowerInvariant();
                if (key == "y")
                {
                    manager.ApplyAllPendingUpdates();
                    Console.WriteLine("The database has been successfully updated.");
                }
                else
                {
                    Console.WriteLine("Cancelled the update process, can't start the server.");
                    return(null);
                }
            }

            return(manager);
        }
示例#2
0
文件: Program.cs 项目: psydox/OpenMU
        private IPersistenceContextProvider PrepareRepositoryManager(bool reinit, string version, bool autoupdate, ILoggerFactory loggerFactory)
        {
            var contextProvider = new PersistenceContextProvider(loggerFactory);

            if (reinit || !contextProvider.DatabaseExists())
            {
                Log.Info("The database is getting (re-)initialized...");
                contextProvider.ReCreateDatabase();
                this.InitializeData(version, loggerFactory, contextProvider);
                Log.Info("...initialization finished.");
            }
            else if (!contextProvider.IsDatabaseUpToDate())
            {
                if (autoupdate)
                {
                    Console.WriteLine("The database needs to be updated before the server can be started. Updating...");
                    contextProvider.ApplyAllPendingUpdates();
                    Console.WriteLine("The database has been successfully updated.");
                }
                else
                {
                    Console.WriteLine("The database needs to be updated before the server can be started. Apply update? (y/n)");
                    var key = Console.ReadLine()?.ToLowerInvariant();
                    if (key == "y")
                    {
                        contextProvider.ApplyAllPendingUpdates();
                        Console.WriteLine("The database has been successfully updated.");
                    }
                    else
                    {
                        Console.WriteLine("Cancelled the update process, can't start the server.");
                        return(null !);
                    }
                }
            }
            else
            {
                // everything is fine and ready
            }

            return(contextProvider);
        }