예제 #1
0
        /// <summary>
        /// Adds a database to the server
        /// </summary>
        /// <param name="databaseConfig"></param>
        public void AddDatabase(ServerDatabaseSettings databaseConfig)
        {
            if ((object)databaseConfig == null)
            {
                throw new ArgumentNullException("databaseConfig");
            }

            //Pre check to prevent loading a database with the same name twice.
            lock (m_syncRoot)
            {
                if (m_databases.ContainsKey(databaseConfig.DatabaseName.ToUpper()))
                {
                    Log.Publish(MessageLevel.Error, "Database Already Exists", "Adding a database that already exists in the server: " + databaseConfig.DatabaseName);
                    return;
                }
            }

            SnapServerDatabaseBase database;

            try
            {
                using (Logger.AppendStackMessages(Log.InitialStackMessages))
                {
                    database = SnapServerDatabaseBase.CreateDatabase(databaseConfig);
                }
            }
            catch (Exception ex)
            {
                Log.Publish(MessageLevel.Critical, "Database failed to load.", databaseConfig.DatabaseName, null, ex);
                return;
            }

            string databaseName = database.Info.DatabaseName.ToUpper();

            lock (m_syncRoot)
            {
                if (m_databases.ContainsKey(databaseName))
                {
                    Log.Publish(MessageLevel.Error, "Database Already Exists", "Adding a database that already exists in the server: " + databaseName);
                    database.Dispose();
                }
                else
                {
                    Log.Publish(MessageLevel.Info, "Added Database", "Adding a database to the server: " + databaseName);
                    m_databases.Add(database.Info.DatabaseName.ToUpper(), database);
                }
            }
        }
예제 #2
0
            /// <summary>
            /// Gets the database that matches <see cref="databaseName"/>
            /// </summary>
            /// <param name="databaseName">the case insensitive name of the databse</param>
            /// <returns></returns>
            public override ClientDatabaseBase GetDatabase(string databaseName)
            {
                if (m_disposed)
                {
                    throw new ObjectDisposedException(GetType().FullName);
                }
                databaseName = databaseName.ToUpper();

                ClientDatabaseBase database;

                lock (m_syncRoot)
                {
                    if (!m_connectedDatabases.TryGetValue(databaseName, out database))
                    {
                        SnapServerDatabaseBase serverDb = m_server.GetDatabase(databaseName);
                        database = serverDb.CreateClientDatabase(this, Unregister);
                        m_connectedDatabases.Add(databaseName, database);
                    }
                }
                return(database);
            }