Exemplo n.º 1
0
        /// <summary>
        /// Initializes the connections
        /// </summary>
        /// <returns>boolean indicating if the initialization process was succesfull</returns>
        public void init()
        {
            if (isConnected)
            {
                return;
            }
            try
            {
                Out.writeLine("Creating new database connections.. stand by..", Out.logFlags.ImportantLogLevel);
                MySqlConnectionStringBuilder mysqlSb = new MySqlConnectionStringBuilder();

                createNewConnectionString();

                this.dbClientCollection = new Queue();
                this.refreshStack       = new Queue();
                DatabaseClient dbClient;
                if (this.beginClientAmount != 0)
                {
                    for (int i = 0; i < this.beginClientAmount; i++)
                    {
                        Out.writeLine("Opening database connection [" + (i).ToString() + "] out of [" + this.beginClientAmount + "]", Out.logFlags.lowLogLevel);
                        addConnection();
                    }
                }
                else
                {
                    dbClient = new DatabaseClient(this, -1);
                    dbClient.connect();
                    dbClient.disconnect();
                }
                //Out.writePlain(connectionString, Out.logFlags.lowLogLevel);
            }
            catch (MySqlException ex)
            {
                isConnected = false;
                throw new Exception("Could not connect the clients to the database: " + ex.Message);
            }

            isConnected = true;
            checkThread = new Thread(this.healthChecker);
            this.checkThread.Start();
            Out.writeLine("Created new connections: [" + beginClientAmount + "]", Out.logFlags.ImportantLogLevel);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes the connections
        /// </summary>
        /// <returns>boolean indicating if the initialization process was succesfull</returns>
        public void init()
        {
            if (isConnected)
                return;
            try
            {
                Out.writeLine("Creating new database connections.. stand by..", Out.logFlags.ImportantLogLevel);
                MySqlConnectionStringBuilder mysqlSb = new MySqlConnectionStringBuilder();

                createNewConnectionString();

                this.dbClientCollection = new Queue();
                this.refreshStack = new Queue();
                DatabaseClient dbClient;
                if (this.beginClientAmount != 0)
                {
                    for (int i = 0; i < this.beginClientAmount; i++)
                    {
                        Out.writeLine("Opening database connection [" + (i).ToString() + "] out of [" + this.beginClientAmount + "]", Out.logFlags.lowLogLevel);
                        addConnection();
                        
                    }
                }
                else
                {
                    dbClient = new DatabaseClient(this, -1);
                    dbClient.connect();
                    dbClient.disconnect();
                }
                //Out.writePlain(connectionString, Out.logFlags.lowLogLevel);

            }
            catch (MySqlException ex)
            {
                isConnected = false;
                throw new Exception("Could not connect the clients to the database: " + ex.Message);
            }

            isConnected = true;
            checkThread = new Thread(this.healthChecker);
            this.checkThread.Start();
            Out.writeLine("Created new connections: [" + beginClientAmount + "]", Out.logFlags.ImportantLogLevel);
            

        }
Exemplo n.º 3
0
 public void init()
 {
     try
     {
         DatabaseClient client;
         MySqlConnectionStringBuilder builder = new MySqlConnectionStringBuilder();
         this.createNewConnectionString();
         this.databaseClients = new List<DatabaseClient>((int) this.maxPoolSize);
         if (this.beginClientAmount != 0)
         {
             for (int i = 0; i < this.beginClientAmount; i++)
             {
                 client = new DatabaseClient(this, i);
                 if (this.dbEvent != null)
                 {
                     this.dbEvent(client);
                 }
                 client.connect();
                 this.databaseClients.Add(client);
             }
         }
         else
         {
             client = new DatabaseClient(this, -1);
             client.connect();
             client.disconnect();
         }
     }
     catch (MySqlException exception)
     {
         this.isConnected = false;
         throw new Exception("Could not connect the clients to the database: " + exception.Message);
     }
     this.isConnected = true;
 }