예제 #1
0
        public static bool InitDB()
        {
            try
            {
                if (ServerSettings.DatabaseType.Trim().ToUpper() == "SQLSERVER")
                {
                    if (!SQLServer.DatabaseAlreadyExists())
                    {
                        logger.Error("Database: {0} does not exist", ServerSettings.DatabaseName);
                        SQLServer.CreateDatabase();
                        Thread.Sleep(3000);
                    }

                    JMMService.CloseSessionFactory();
                    ServerState.Instance.CurrentSetupStatus = JMMServer.Properties.Resources.Database_Initializing;
                    ISessionFactory temp = JMMService.SessionFactory;

                    ServerState.Instance.CurrentSetupStatus = JMMServer.Properties.Resources.Database_CreateSchema;
                    SQLServer.CreateInitialSchema();

                    ServerState.Instance.CurrentSetupStatus = JMMServer.Properties.Resources.Database_ApplySchema;
                    SQLServer.UpdateSchema();

                    PopulateInitialData();
                    DatabaseHelper.CreateInitialCustomTags();

                    return(true);
                }
                else if (ServerSettings.DatabaseType.Trim().ToUpper() == "SQLITE")
                {
                    ServerState.Instance.CurrentSetupStatus = JMMServer.Properties.Resources.Database_CreateDatabase;
                    SQLite.CreateDatabase();

                    JMMService.CloseSessionFactory();
                    ServerState.Instance.CurrentSetupStatus = JMMServer.Properties.Resources.Database_Initializing;
                    ISessionFactory temp = JMMService.SessionFactory;

                    ServerState.Instance.CurrentSetupStatus = JMMServer.Properties.Resources.Database_CreateSchema;
                    SQLite.CreateInitialSchema();

                    ServerState.Instance.CurrentSetupStatus = JMMServer.Properties.Resources.Database_ApplySchema;
                    SQLite.UpdateSchema();

                    PopulateInitialData();
                    DatabaseHelper.CreateInitialCustomTags();

                    return(true);
                }
                else if (ServerSettings.DatabaseType.Trim().ToUpper() == "MYSQL")
                {
                    logger.Trace("Database - Creating Database...");
                    ServerState.Instance.CurrentSetupStatus = JMMServer.Properties.Resources.Database_CreateDatabase;
                    MySQL.CreateDatabase();

                    logger.Trace("Initializing Session Factory...");
                    JMMService.CloseSessionFactory();
                    ServerState.Instance.CurrentSetupStatus = JMMServer.Properties.Resources.Database_Initializing;
                    ISessionFactory temp = JMMService.SessionFactory;

                    logger.Trace("Database - Creating Initial Schema...");
                    ServerState.Instance.CurrentSetupStatus = JMMServer.Properties.Resources.Database_CreateSchema;
                    MySQL.CreateInitialSchema();

                    logger.Trace("Database - Applying Schema Patches...");
                    ServerState.Instance.CurrentSetupStatus = JMMServer.Properties.Resources.Database_ApplySchema;
                    MySQL.UpdateSchema();
                    //MySQL.UpdateSchema_Fix();

                    PopulateInitialData();
                    DatabaseHelper.CreateInitialCustomTags();

                    return(true);
                }

                return(false);
            }
            catch (Exception ex)
            {
                logger.ErrorException("Could not init database: " + ex.ToString(), ex);
                return(false);
            }
        }