Esempio n. 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);
        }
        public void SetupDatabaseAndTestLoadingData()
        {
            var manager = new PersistenceContextProvider(new NullLoggerFactory());

            manager.ReCreateDatabase();
            this.TestDataInitialization(new PersistenceContextProvider(new NullLoggerFactory()));
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        public void SetupDatabaseAndTestLoadingData()
        {
            var manager = new PersistenceContextProvider();

            manager.ReCreateDatabase();
            var initialization = new DataInitialization(manager);

            initialization.CreateInitialData();

            // Loading game configuration
            using (var context = manager.CreateNewConfigurationContext())
            {
                var gameConfiguraton = context.Get <GameConfiguration>().FirstOrDefault();
                Assert.That(gameConfiguraton, Is.Not.Null);

                // Testing loading of an account
                using (var accountContext = manager.CreateNewPlayerContext(gameConfiguraton))
                {
                    var account1 = accountContext.GetAccountByLoginName("test1", "test1");
                    Assert.That(account1, Is.Not.Null);
                    Assert.That(account1.LoginName, Is.EqualTo("test1"));
                }
            }
        }