示例#1
0
        public static bool InitDB(this IDatabase database)
        {
            try
            {
                DatabaseFixes.InitFixes();
                if (!database.DatabaseAlreadyExists())
                {
                    database.CreateDatabase();
                    Thread.Sleep(3000);
                }
                Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(ServerSettings.Culture);

                JMMService.CloseSessionFactory();
                ServerState.Instance.CurrentSetupStatus = JMMServer.Properties.Resources.Database_Initializing;
                ISessionFactory temp = JMMService.SessionFactory;
                ServerState.Instance.CurrentSetupStatus = JMMServer.Properties.Resources.Database_CreateSchema;
                bool res = database.CreateInitialSchema();
                if (!res)
                {
                    int version = database.GetDatabaseVersion();
                    if (version > database.RequiredVersion)
                    {
                        ServerState.Instance.CurrentSetupStatus = JMMServer.Properties.Resources.Database_NotSupportedVersion;
                        return(false);
                    }
                    if (version < database.RequiredVersion)
                    {
                        ServerState.Instance.CurrentSetupStatus = JMMServer.Properties.Resources.Database_Backup;
                        database.BackupDatabase(GetDatabaseBackupName(version));
                    }
                }
                ServerState.Instance.CurrentSetupStatus = JMMServer.Properties.Resources.Database_ApplySchema;
                database.UpdateSchema();
                RepoFactory.Init();
                DatabaseFixes.ExecuteDatabaseFixes();
                database.PopulateInitialData();

                return(true);
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Could not init database: " + ex.ToString());
                ServerState.Instance.CurrentSetupStatus = JMMServer.Properties.Resources.Server_DatabaseFail;
                return(false);
            }
        }
示例#2
0
        private static void InitCache(this IDatabase db)
        {
            JMMUserRepository.InitCache();
            AniDB_AnimeRepository.InitCache();
            VideoInfoRepository.InitCache();
            VideoLocalRepository.InitCache();
            VideoLocal_UserRepository.InitCache();
            List <GroupFilter> recalc = GroupFilterRepository.InitCache();

            AnimeEpisodeRepository.InitCache();
            AnimeEpisode_UserRepository.InitCache();
            AnimeSeriesRepository.InitCache();
            AnimeSeries_UserRepository.InitCache();
            AnimeGroupRepository.InitCache();
            AnimeGroup_UserRepository.InitCache();
            GroupFilterRepository.InitCacheSecondPart(recalc);
            DatabaseFixes.ExecuteDatabaseFixes();
            db.CleanUpMemory();
        }