Exemplo n.º 1
0
        public AsyncDatabaseInitializeRequest(
            DatabaseManagerConfig config,
            Logger logger)
        {
            m_dbManager = new DatabaseManager(config);
            m_logger    = logger;

            m_thread       = null;
            m_exitedSignal = null;
            m_succeeded    = false;
        }
Exemplo n.º 2
0
        public AsyncDatabaseInitializeRequest(
            DatabaseManagerConfig config,
            Logger logger)
        {
            m_dbManager = new DatabaseManager(config);
            m_logger = logger;

            m_thread = null;
            m_exitedSignal = null;
            m_succeeded = false;
        }
Exemplo n.º 3
0
        public DatabaseManager(
            DatabaseManagerConfig config)
        {
            string[] keyValuePairs = config.CONNECTION_STRING.Split(new char[] { ';' });
            string   vendorType    = "SqlServer";

            foreach (string keyValuePair in keyValuePairs)
            {
                string[] tokens = keyValuePair.Split(new char[] { '=' });

                if (tokens.Length == 2)
                {
                    string key   = tokens[0];
                    string value = tokens[1];

                    if (key == "DbLinqProvider")
                    {
                        vendorType = value;
                        break;
                    }
                }
            }

            if (vendorType == "Sqlite")
            {
                m_builder = new DatabaseBuilderSQLite();
            }
            else
            {
                // Default to SqlServer if no vendor type is given
                m_builder = new DatabaseBuilderMSSQL();
            }

            // Save off the config data
            m_config = config;
        }
Exemplo n.º 4
0
        public DatabaseManager(
            DatabaseManagerConfig config)
        {
            string[] keyValuePairs = config.CONNECTION_STRING.Split(new char[] { ';' });
            string vendorType = "SqlServer";

            foreach (string keyValuePair in keyValuePairs)
            {
                string[] tokens = keyValuePair.Split(new char[] { '=' });

                if (tokens.Length == 2)
                {
                    string key = tokens[0];
                    string value = tokens[1];

                    if (key == "DbLinqProvider")
                    {
                        vendorType = value;
                        break;
                    }
                }
            }

            if (vendorType == "Sqlite")
            {
                m_builder = new DatabaseBuilderSQLite();
            }
            else
            {
                // Default to SqlServer if no vendor type is given
                m_builder = new DatabaseBuilderMSSQL();
            }

            // Save off the config data
            m_config = config;
        }
Exemplo n.º 5
0
    public void StartServer()
    {
        if (m_state == eState.stopped)
        {
            DatabaseManagerConfig dbConfig =
                new DatabaseManagerConfig(DBConnectionString, MobDataDirectory, MapDataDirectory);

            // Start initializing the database
            m_state = eState.starting;
            m_dbInitRequest = new AsyncDatabaseInitializeRequest(dbConfig, m_logger);
            m_dbInitRequest.Execute();
        }
    }
Exemplo n.º 6
0
        private static bool InitializeDatabase(
            Logger logger)
        {
            DatabaseManagerConfig dbConfig =
                new DatabaseManagerConfig(
                    ApplicationConstants.CONNECTION_STRING,
                    ApplicationConstants.MOBS_DIRECTORY,
                    ApplicationConstants.MAPS_DIRECTORY);
            DatabaseManager dbManager = new DatabaseManager(dbConfig);
            bool databaseValid = false;

            if (!dbManager.IsDatabaseValid())
            {
                string constructionResult = "";

                logger.LogInfo("Database invalid. Re-initializing...");

                if (dbManager.ReCreateDatabase(logger, out constructionResult))
                {
                    databaseValid = true;
                }
                else
                {
                    logger.LogError(constructionResult);
                }
            }
            else
            {
                databaseValid = true;
            }

            return databaseValid;
        }
Exemplo n.º 7
0
        public string RecreateDatabase()
        {
            BasicResponse response = new BasicResponse();

            if (RestUtilities.ValidateJSONRequestHasAuthenticatedSession(Session, out response.result) &&
                RestUtilities.ValidateJSONRequestSessionHasAdminOpsLevel(Session, out response.result))
            {
                StringBuilder result = new StringBuilder();
                Logger logger = new Logger((string message) => { result.AppendLine(message); });

                try
                {
                    string constructionResult = "";
                    DatabaseManagerConfig dbConfig =
                        new DatabaseManagerConfig(
                            ApplicationConstants.CONNECTION_STRING,
                            ApplicationConstants.MOBS_DIRECTORY,
                            ApplicationConstants.MAPS_DIRECTORY);
                    DatabaseManager dbManager = new DatabaseManager(dbConfig);

                    if (!dbManager.ReCreateDatabase(logger, out constructionResult))
                    {
                        logger.LogError(constructionResult);
                    }
                }
                catch (System.Exception ex)
                {
                    logger.LogError(string.Format("Failed to recreate database: {0}", ex.Message));
                }

                response.result = result.ToString();
            }

            return JSONUtilities.SerializeJSONResponse<BasicResponse>(response);
        }