Beispiel #1
0
        /// <include file='docs/MySqlConnection.xml' path='docs/Open/*'/>
        public override void Open()
        {
            if (State == ConnectionState.Open)
            {
                Throw(new InvalidOperationException(Resources.ConnectionAlreadyOpen));
            }

#if !CF && !RT
            // start up our interceptors
            exceptionInterceptor = new ExceptionInterceptor(this);
            commandInterceptor   = new CommandInterceptor(this);
#endif

            SetState(ConnectionState.Connecting, true);

            AssertPermissions();

#if !CF && !RT
            // if we are auto enlisting in a current transaction, then we will be
            // treating the connection as pooled
            if (Settings.AutoEnlist && Transaction.Current != null)
            {
                driver = DriverTransactionManager.GetDriverInTransaction(Transaction.Current);
                if (driver != null &&
                    (driver.IsInActiveUse ||
                     !driver.Settings.EquivalentTo(this.Settings)))
                {
                    Throw(new NotSupportedException(Resources.MultipleConnectionsInTransactionNotSupported));
                }
            }
#endif

            try
            {
                MySqlConnectionStringBuilder currentSettings = Settings;
#if !CF
                // Load balancing
                if (ReplicationManager.IsReplicationGroup(Settings.Server))
                {
                    if (driver == null)
                    {
                        ReplicationManager.GetNewConnection(Settings.Server, false, this);
                    }
                    else
                    {
                        currentSettings = driver.Settings;
                    }
                }
#endif

                if (Settings.Pooling)
                {
                    MySqlPool pool = MySqlPoolManager.GetPool(currentSettings);
                    if (driver == null || !driver.IsOpen)
                    {
                        driver = pool.GetConnection();
                    }
                    procedureCache = pool.ProcedureCache;
                }
                else
                {
                    if (driver == null || !driver.IsOpen)
                    {
                        driver = Driver.Create(currentSettings);
                    }
                    procedureCache = new ProcedureCache((int)Settings.ProcedureCacheSize);
                }
            }
            catch (Exception ex)
            {
                SetState(ConnectionState.Closed, true);
                throw;
            }

            // if the user is using old syntax, let them know
            if (driver.Settings.UseOldSyntax)
            {
                MySqlTrace.LogWarning(ServerThread,
                                      "You are using old syntax that will be removed in future versions");
            }

            SetState(ConnectionState.Open, false);
            driver.Configure(this);

            if (!(driver.SupportsPasswordExpiration && driver.IsPasswordExpired))
            {
                if (Settings.Database != null && Settings.Database != String.Empty)
                {
                    ChangeDatabase(Settings.Database);
                }
            }

            // setup our schema provider
            schemaProvider = new ISSchemaProvider(this);

#if !CF
            perfMonitor = new PerformanceMonitor(this);
#endif

            // if we are opening up inside a current transaction, then autoenlist
            // TODO: control this with a connection string option
#if !MONO && !CF && !RT
            if (Transaction.Current != null && Settings.AutoEnlist)
            {
                EnlistTransaction(Transaction.Current);
            }
#endif

            hasBeenOpen = true;
            SetState(ConnectionState.Open, true);
        }
Beispiel #2
0
        public override void UpdateReplication(bool partial = true)
        {
            ReplicationManager.UpdateFloat(Gold, 0, 0);             // gold
            ReplicationManager.UpdateFloat(GoldTotal, 0, 1);        // gold Total

            ReplicationManager.UpdateUInt(uint.MaxValue, 0, 2);     // mReplicatedSpellCanCastBitsLower1
            ReplicationManager.UpdateUInt(uint.MaxValue, 0, 3);     // mReplicatedSpellCanCastBitsUpper1
            ReplicationManager.UpdateUInt(uint.MaxValue, 0, 4);     // mReplicatedSpellCanCastBitsLower2
            ReplicationManager.UpdateUInt(uint.MaxValue, 0, 5);     // mReplicatedSpellCanCastBitsUpper2

            ReplicationManager.UpdateUInt((uint)0, 0, 6);           // evolvePoints kha zix?
            ReplicationManager.UpdateUInt((uint)0, 0, 7);           // ? spells of evolve flags?

            ReplicationManager.UpdateFloat(0f, 0, 8);               // manaCost 0
            ReplicationManager.UpdateFloat(0f, 0, 9);               // manaCost 1
            ReplicationManager.UpdateFloat(0f, 0, 10);              // manaCost 2
            ReplicationManager.UpdateFloat(0f, 0, 11);              // manaCost 3

            ReplicationManager.UpdateInt(0, 0, 12);                 // manaCost  Ex0
            ReplicationManager.UpdateInt(0, 0, 13);                 // manaCost  Ex1
            ReplicationManager.UpdateInt(0, 0, 14);                 // manaCost  Ex2
            ReplicationManager.UpdateInt(0, 0, 15);                 // manaCost  Ex3
            ReplicationManager.UpdateInt(0, 0, 16);                 // manaCost  Ex4
            ReplicationManager.UpdateInt(0, 0, 17);                 // manaCost  Ex5
            ReplicationManager.UpdateInt(0, 0, 18);                 // manaCost  Ex6
            ReplicationManager.UpdateInt(0, 0, 19);                 // manaCost  Ex7
            ReplicationManager.UpdateInt(0, 0, 20);                 // manaCost  Ex8
            ReplicationManager.UpdateInt(0, 0, 21);                 // manaCost  Ex9
            ReplicationManager.UpdateInt(0, 0, 22);                 // manaCost  Ex10
            ReplicationManager.UpdateInt(0, 0, 23);                 // manaCost  Ex11
            ReplicationManager.UpdateInt(0, 0, 24);                 // manaCost  Ex12
            ReplicationManager.UpdateInt(0, 0, 25);                 // manaCost  Ex13
            ReplicationManager.UpdateInt(0, 0, 26);                 // manaCost  Ex14
            ReplicationManager.UpdateInt(0, 0, 27);                 // manaCost  Ex15

            ReplicationManager.UpdateUInt((uint)ActionState, 1, 0); // actionState

            ReplicationManager.UpdateBool(IsMagicImmune, 1, 1);     // magicImmune ? boolean? uint based
            ReplicationManager.UpdateBool(IsInvulnerable, 1, 2);    // IsInvulnerable , uint based
            ReplicationManager.UpdateBool(IsPhysicalImmune, 1, 3);  // Physical Immune
            ReplicationManager.UpdateBool(IsLifeStealImmune, 1, 4); // lifesteal immune


            ReplicationManager.UpdateFloat(AttackDamage.BaseValue, 1, 5);        // baseAttackDamage  non affiché, utilisé pour des items comme sheen
            ReplicationManager.UpdateFloat(AbilityPower.BaseValue, 1, 6);        // baseAbilityDamage

            ReplicationManager.UpdateFloat(Dodge.TotalSafe, 1, 7);               // Dodge
            ReplicationManager.UpdateFloat(CriticalHit.TotalSafe, 1, 8);         // crit

            ReplicationManager.UpdateFloat(Armor.TotalSafe, 1, 9);               // marmor
            ReplicationManager.UpdateFloat(MagicResistance.TotalSafe, 1, 10);    // magicResist

            ReplicationManager.UpdateFloat(HealthRegeneration.TotalSafe, 1, 11); // hpRegenRate
            ReplicationManager.UpdateFloat(ManaRegeneration.TotalSafe, 1, 12);   // mpRegenRate

            ReplicationManager.UpdateFloat(AttackRange.TotalSafe, 1, 13);        // mAttackRange
            ReplicationManager.UpdateFloat(AttackDamage.FlatBonus, 1, 14);       // flat physical damage mod (damagebonus)

            ReplicationManager.UpdateFloat(AttackDamage.PercentBonus, 1, 15);    // mPercentPhysicalDamageMod  (percentage on ad bonus i think, check dat)
            ReplicationManager.UpdateFloat(AbilityPower.FlatBonus, 1, 16);       // mFlatMagicReduction


            ReplicationManager.UpdateFloat(MagicResistance.PercentBonus, 1, 18);          // mPercentMagicReduction

            ReplicationManager.UpdateFloat(AttackSpeed.Ratio, 1, 19);                     // mAttackSpeedMod

            ReplicationManager.UpdateFloat(AttackRange.FlatBonus, 1, 20);                 //mFlatCastRangeMod

            ReplicationManager.UpdateFloat(-(CooldownReduction.TotalSafe / 100f), 1, 21); // mPercentCooldownMod  -0.5f = 50% cd reduction

            ReplicationManager.UpdateFloat(0f, 1, 22);                                    // mPassiveCooldownEndTime

            ReplicationManager.UpdateFloat(0f, 1, 23);                                    // mPassiveCooldownTotalTime

            ReplicationManager.UpdateFloat(ArmorPenetration.FlatBonus, 1, 24);            // mFlatArmorPenetration
            ReplicationManager.UpdateFloat(2f - ArmorPenetration.PercentBonus, 1, 25);    // mPercentArmorPenetration 0.6 is percentage
            ReplicationManager.UpdateFloat(MagicPenetration.TotalSafe, 1, 26);            // mFlatMagicPenetration
            ReplicationManager.UpdateFloat(2f - MagicPenetration.PercentBonus, 1, 27);    //mPercentMagicPenetration

            ReplicationManager.UpdateFloat(LifeSteal.TotalSafe, 1, 28);                   // mPercentLifeStealMod
            ReplicationManager.UpdateFloat(SpellVamp.TotalSafe, 1, 29);                   // mPercentSpellVampMod

            ReplicationManager.UpdateFloat(CCReduction.TotalSafe, 1, 30);                 // mPercentCCReduction

            ReplicationManager.UpdateFloat(ArmorPenetration.PercentBonus, 2, 0);          // mPercentBonusArmorPenetration
            ReplicationManager.UpdateFloat(MagicPenetration.PercentBonus, 2, 1);          // mPercentBonusMagicPenetration
            ReplicationManager.UpdateFloat(HealthRegeneration.BaseValue, 2, 2);           // mBaseHPRegenRate
            ReplicationManager.UpdateFloat(ManaRegeneration.BaseValue, 2, 3);             //  mBasePARRegenRate

            ReplicationManager.UpdateFloat(Health.Current, 3, 0);                         // current hp
            ReplicationManager.UpdateFloat(Mana.Current, 3, 1);                           // current mp

            ReplicationManager.UpdateFloat(Health.TotalSafe, 3, 2);                       // max hp

            ReplicationManager.UpdateFloat(Mana.TotalSafe, 3, 3);                         // max mp

            ReplicationManager.UpdateFloat(Experience, 3, 4);                             // currentExp

            ReplicationManager.UpdateFloat(0f, 3, 5);                                     // lifetime ?
            ReplicationManager.UpdateFloat(0f, 3, 6);                                     // mMaxLifetime ?
            ReplicationManager.UpdateFloat(0f, 3, 7);                                     // mLifetimeTicks?

            ReplicationManager.UpdateFloat(PerceptionBubbleRadius.FlatBonus, 3, 8);       // mFlatBubbleRadiusMod
            ReplicationManager.UpdateFloat(PerceptionBubbleRadius.PercentBonus, 3, 9);    // mPercentBubbleRadiusMod

            ReplicationManager.UpdateFloat(MoveSpeed.TotalSafe, 3, 10);                   // move speed, working
            ReplicationManager.UpdateFloat(ModelSize.TotalSafe, 3, 11);                   // modelSize

            ReplicationManager.UpdateFloat(0f, 3, 12);                                    // mPathfindingRadiusMod
            ReplicationManager.UpdateUInt((uint)Level, 3, 13);                            // mLevel uint

            ReplicationManager.UpdateUInt((uint)NeutralMinionsKilled, 3, 14);             // mNumNeutralMinionsKilled

            ReplicationManager.UpdateBool(IsTargetable, 3, 15);                           // is targetable?

            ReplicationManager.UpdateUInt((uint)TargetableToTeam, 3, 16);                 // targetableToTeam Flags
        }
Beispiel #3
0
        /// <include file='docs/mysqlcommand.xml' path='docs/ExecuteReader1/*'/>
        public new MySqlDataReader ExecuteReader(CommandBehavior behavior)
        {
#if !RT
            // give our interceptors a shot at it first
            MySqlDataReader interceptedReader = null;
            if (connection != null &&
                connection.commandInterceptor != null &&
                connection.commandInterceptor.ExecuteReader(CommandText, behavior, ref interceptedReader))
            {
                return(interceptedReader);
            }
#endif

            // interceptors didn't handle this so we fall through
            bool success = false;
            CheckState();
            Driver driver = connection.driver;

            cmdText = cmdText.Trim();
            if (String.IsNullOrEmpty(cmdText))
            {
                Throw(new InvalidOperationException(Resources.CommandTextNotInitialized));
            }

            string sql = cmdText.Trim(';');

            // Load balancing getting a new connection
            if (connection.hasBeenOpen && !driver.HasStatus(ServerStatusFlags.InTransaction))
            {
                ReplicationManager.GetNewConnection(connection.Settings.Server, !IsReadOnlyCommand(sql), connection);
            }

            lock (driver)
            {
                // We have to recheck that there is no reader, after we got the lock
                if (connection.Reader != null)
                {
                    Throw(new MySqlException(Resources.DataReaderOpen));
                }

#if !RT
                System.Transactions.Transaction curTrans = System.Transactions.Transaction.Current;

                if (curTrans != null)
                {
                    bool inRollback = false;
                    if (driver.CurrentTransaction != null)
                    {
                        inRollback = driver.CurrentTransaction.InRollback;
                    }
                    if (!inRollback)
                    {
                        System.Transactions.TransactionStatus status = System.Transactions.TransactionStatus.InDoubt;
                        try
                        {
                            // in some cases (during state transitions) this throws
                            // an exception. Ignore exceptions, we're only interested
                            // whether transaction was aborted or not.
                            status = curTrans.TransactionInformation.Status;
                        }
                        catch (System.Transactions.TransactionException)
                        {
                        }
                        if (status == System.Transactions.TransactionStatus.Aborted)
                        {
                            Throw(new System.Transactions.TransactionAbortedException());
                        }
                    }
                }
#endif
                commandTimer = new CommandTimer(connection, CommandTimeout);

                lastInsertedId = -1;

                if (CommandType == CommandType.TableDirect)
                {
                    sql = "SELECT * FROM " + sql;
                }
                else if (CommandType == CommandType.Text)
                {
                    // validates single word statetment (maybe is a stored procedure call)
                    if (sql.IndexOf(" ") == -1)
                    {
                        if (AddCallStatement(sql))
                        {
                            sql = "call " + sql;
                        }
                    }
                }

                // if we are on a replicated connection, we are only allow readonly statements
                if (connection.Settings.Replication && !InternallyCreated)
                {
                    EnsureCommandIsReadOnly(sql);
                }

                if (statement == null || !statement.IsPrepared)
                {
                    if (CommandType == CommandType.StoredProcedure)
                    {
                        statement = new StoredProcedure(this, sql);
                    }
                    else
                    {
                        statement = new PreparableStatement(this, sql);
                    }
                }

                // stored procs are the only statement type that need do anything during resolve
                statement.Resolve(false);

                // Now that we have completed our resolve step, we can handle our
                // command behaviors
                HandleCommandBehaviors(behavior);

                updatedRowCount = -1;
                try
                {
                    MySqlDataReader reader = new MySqlDataReader(this, statement, behavior);
                    connection.Reader = reader;
                    canceled          = false;
                    // execute the statement
                    statement.Execute();
                    // wait for data to return
                    reader.NextResult();
                    success = true;
                    return(reader);
                }
                catch (TimeoutException tex)
                {
                    connection.HandleTimeoutOrThreadAbort(tex);
                    throw; //unreached
                }
                catch (ThreadAbortException taex)
                {
                    connection.HandleTimeoutOrThreadAbort(taex);
                    throw;
                }
                catch (IOException ioex)
                {
                    connection.Abort(); // Closes connection without returning it to the pool
                    throw new MySqlException(Resources.FatalErrorDuringExecute, ioex);
                }
                catch (MySqlException ex)
                {
                    if (ex.InnerException is TimeoutException)
                    {
                        throw; // already handled
                    }
                    try
                    {
                        ResetReader();
                        ResetSqlSelectLimit();
                    }
                    catch (Exception)
                    {
                        // Reset SqlLimit did not work, connection is hosed.
                        Connection.Abort();
                        throw new MySqlException(ex.Message, true, ex);
                    }

                    // if we caught an exception because of a cancel, then just return null
                    if (ex.IsQueryAborted)
                    {
                        return(null);
                    }
                    if (ex.IsFatal)
                    {
                        Connection.Close();
                    }
                    if (ex.Number == 0)
                    {
                        throw new MySqlException(Resources.FatalErrorDuringExecute, ex);
                    }
                    throw;
                }
                finally
                {
                    if (connection != null)
                    {
                        if (connection.Reader == null)
                        {
                            // Something went seriously wrong,  and reader would not
                            // be able to clear timeout on closing.
                            // So we clear timeout here.
                            ClearCommandTimer();
                        }
                        if (!success)
                        {
                            // ExecuteReader failed.Close Reader and set to null to
                            // prevent subsequent errors with DataReaderOpen
                            ResetReader();
                        }
                    }
                }
            }
        }
Beispiel #4
0
        /// <include file='docs/MySqlConnection.xml' path='docs/Open/*'/>
        public override void Open()
        {
            if (State == ConnectionState.Open)
            {
                Throw(new InvalidOperationException(Resources.ConnectionAlreadyOpen));
            }

            // start up our interceptors
            _exceptionInterceptor = new ExceptionInterceptor(this);
            commandInterceptor    = new CommandInterceptor(this);

            SetState(ConnectionState.Connecting, true);

#if !NETSTANDARD1_6
            AssertPermissions();

            //TODO: SUPPORT FOR 452 AND 46X
            // if we are auto enlisting in a current transaction, then we will be
            // treating the connection as pooled
            if (Settings.AutoEnlist && Transaction.Current != null)
            {
                driver = DriverTransactionManager.GetDriverInTransaction(Transaction.Current);
                if (driver != null &&
                    (driver.IsInActiveUse ||
                     !driver.Settings.EquivalentTo(this.Settings)))
                {
                    Throw(new NotSupportedException(Resources.MultipleConnectionsInTransactionNotSupported));
                }
            }
#endif
            try
            {
                MySqlConnectionStringBuilder currentSettings = Settings;

                //TODO: SUPPORT FOR 452 AND 46X
                // Load balancing
#if !NETSTANDARD1_6
                if (ReplicationManager.IsReplicationGroup(Settings.Server))
                {
                    if (driver == null)
                    {
                        ReplicationManager.GetNewConnection(Settings.Server, false, this);
                    }
                    else
                    {
                        currentSettings = driver.Settings;
                    }
                }
#endif

                if (Settings.Pooling)
                {
                    MySqlPool pool = MySqlPoolManager.GetPool(currentSettings);
                    if (driver == null || !driver.IsOpen)
                    {
                        driver = pool.GetConnection();
                    }
                    ProcedureCache = pool.ProcedureCache;
                }
                else
                {
                    if (driver == null || !driver.IsOpen)
                    {
                        driver = Driver.Create(currentSettings);
                    }
                    ProcedureCache = new ProcedureCache((int)Settings.ProcedureCacheSize);
                }
            }
            catch (Exception)
            {
                SetState(ConnectionState.Closed, true);
                throw;
            }

            SetState(ConnectionState.Open, false);
            driver.Configure(this);

            if (!(driver.SupportsPasswordExpiration && driver.IsPasswordExpired))
            {
                if (!string.IsNullOrEmpty(Settings.Database))
                {
                    ChangeDatabase(Settings.Database);
                }
            }

            // setup our schema provider
            _schemaProvider = new ISSchemaProvider(this);
            PerfMonitor     = new PerformanceMonitor(this);

            // if we are opening up inside a current transaction, then autoenlist
            // TODO: control this with a connection string option
#if !NETSTANDARD1_6
            if (Transaction.Current != null && Settings.AutoEnlist)
            {
                EnlistTransaction(Transaction.Current);
            }
#endif

            hasBeenOpen = true;
            SetState(ConnectionState.Open, true);
        }
        public new MySqlDataReader ExecuteReader(CommandBehavior behavior)
        {
            MySqlDataReader result = null;

            if (this.connection != null && this.connection.commandInterceptor != null && this.connection.commandInterceptor.ExecuteReader(this.CommandText, behavior, ref result))
            {
                return(result);
            }
            bool flag = false;

            this.CheckState();
            Driver driver = this.connection.driver;

            this.cmdText = this.cmdText.Trim();
            if (string.IsNullOrEmpty(this.cmdText))
            {
                this.Throw(new InvalidOperationException(Resources.CommandTextNotInitialized));
            }
            string text = this.cmdText.Trim(new char[]
            {
                ';'
            });

            if (this.connection.hasBeenOpen && !driver.HasStatus(ServerStatusFlags.InTransaction))
            {
                ReplicationManager.GetNewConnection(this.connection.Settings.Server, !this.IsReadOnlyCommand(text), this.connection);
            }
            Driver          obj = driver;
            MySqlDataReader result2;

            lock (obj)
            {
                if (this.connection.Reader != null)
                {
                    this.Throw(new MySqlException(Resources.DataReaderOpen));
                }
                Transaction current = System.Transactions.Transaction.Current;
                if (current != null)
                {
                    bool flag3 = false;
                    if (driver.CurrentTransaction != null)
                    {
                        flag3 = driver.CurrentTransaction.InRollback;
                    }
                    if (!flag3)
                    {
                        TransactionStatus transactionStatus = TransactionStatus.InDoubt;
                        try
                        {
                            transactionStatus = current.TransactionInformation.Status;
                        }
                        catch (TransactionException)
                        {
                        }
                        if (transactionStatus == TransactionStatus.Aborted)
                        {
                            this.Throw(new TransactionAbortedException());
                        }
                    }
                }
                this.commandTimer   = new CommandTimer(this.connection, this.CommandTimeout);
                this.lastInsertedId = -1L;
                if (this.CommandType == CommandType.TableDirect)
                {
                    text = "SELECT * FROM " + text;
                }
                else if (this.CommandType == CommandType.Text && text.IndexOf(" ") == -1 && this.AddCallStatement(text))
                {
                    text = "call " + text;
                }
                if (this.connection.Settings.Replication && !this.InternallyCreated)
                {
                    this.EnsureCommandIsReadOnly(text);
                }
                if (this.statement == null || !this.statement.IsPrepared)
                {
                    if (this.CommandType == CommandType.StoredProcedure)
                    {
                        this.statement = new StoredProcedure(this, text);
                    }
                    else
                    {
                        this.statement = new PreparableStatement(this, text);
                    }
                }
                this.statement.Resolve(false);
                this.HandleCommandBehaviors(behavior);
                this.updatedRowCount = -1L;
                try
                {
                    MySqlDataReader mySqlDataReader = new MySqlDataReader(this, this.statement, behavior);
                    this.connection.Reader = mySqlDataReader;
                    this.canceled          = false;
                    this.statement.Execute();
                    mySqlDataReader.NextResult();
                    flag    = true;
                    result2 = mySqlDataReader;
                }
                catch (TimeoutException ex)
                {
                    this.connection.HandleTimeoutOrThreadAbort(ex);
                    throw;
                }
                catch (ThreadAbortException ex2)
                {
                    this.connection.HandleTimeoutOrThreadAbort(ex2);
                    throw;
                }
                catch (IOException ex3)
                {
                    this.connection.Abort();
                    throw new MySqlException(Resources.FatalErrorDuringExecute, ex3);
                }
                catch (MySqlException ex4)
                {
                    if (ex4.InnerException is TimeoutException)
                    {
                        throw;
                    }
                    try
                    {
                        this.ResetReader();
                        this.ResetSqlSelectLimit();
                    }
                    catch (Exception)
                    {
                        this.Connection.Abort();
                        throw new MySqlException(ex4.Message, true, ex4);
                    }
                    if (ex4.IsQueryAborted)
                    {
                        result2 = null;
                    }
                    else
                    {
                        if (ex4.IsFatal)
                        {
                            this.Connection.Close();
                        }
                        if (ex4.Number == 0)
                        {
                            throw new MySqlException(Resources.FatalErrorDuringExecute, ex4);
                        }
                        throw;
                    }
                }
                finally
                {
                    if (this.connection != null)
                    {
                        if (this.connection.Reader == null)
                        {
                            this.ClearCommandTimer();
                        }
                        if (!flag)
                        {
                            this.ResetReader();
                        }
                    }
                }
            }
            return(result2);
        }
Beispiel #6
0
 public override void Open()
 {
     if (this.State == ConnectionState.Open)
     {
         this.Throw(new InvalidOperationException(Resources.ConnectionAlreadyOpen));
     }
     this.exceptionInterceptor = new ExceptionInterceptor(this);
     this.commandInterceptor   = new CommandInterceptor(this);
     this.SetState(ConnectionState.Connecting, true);
     this.AssertPermissions();
     if (this.Settings.AutoEnlist && Transaction.Current != null)
     {
         this.driver = DriverTransactionManager.GetDriverInTransaction(Transaction.Current);
         if (this.driver != null && (this.driver.IsInActiveUse || !this.driver.Settings.EquivalentTo(this.Settings)))
         {
             this.Throw(new NotSupportedException(Resources.MultipleConnectionsInTransactionNotSupported));
         }
     }
     try
     {
         MySqlConnectionStringBuilder settings = this.Settings;
         if (ReplicationManager.IsReplicationGroup(this.Settings.Server))
         {
             if (this.driver == null)
             {
                 ReplicationManager.GetNewConnection(this.Settings.Server, false, this);
                 return;
             }
             settings = this.driver.Settings;
         }
         if (this.Settings.Pooling)
         {
             MySqlPool pool = MySqlPoolManager.GetPool(settings);
             if (this.driver == null || !this.driver.IsOpen)
             {
                 this.driver = pool.GetConnection();
             }
             this.procedureCache = pool.ProcedureCache;
         }
         else
         {
             if (this.driver == null || !this.driver.IsOpen)
             {
                 this.driver = Driver.Create(settings);
             }
             this.procedureCache = new ProcedureCache((int)this.Settings.ProcedureCacheSize);
         }
     }
     catch (Exception)
     {
         this.SetState(ConnectionState.Closed, true);
         throw;
     }
     if (this.driver.Settings.UseOldSyntax)
     {
         MySqlTrace.LogWarning(this.ServerThread, "You are using old syntax that will be removed in future versions");
     }
     this.SetState(ConnectionState.Open, false);
     this.driver.Configure(this);
     if ((!this.driver.SupportsPasswordExpiration || !this.driver.IsPasswordExpired) && this.Settings.Database != null && this.Settings.Database != string.Empty)
     {
         this.ChangeDatabase(this.Settings.Database);
     }
     this.schemaProvider = new ISSchemaProvider(this);
     this.perfMonitor    = new PerformanceMonitor(this);
     if (Transaction.Current != null && this.Settings.AutoEnlist)
     {
         this.EnlistTransaction(Transaction.Current);
     }
     this.hasBeenOpen = true;
     this.SetState(ConnectionState.Open, true);
 }
Beispiel #7
0
        /// <include file='docs/MySqlConnection.xml' path='docs/Open/*'/>
        public override void Open()
        {
            if (State == ConnectionState.Open)
            {
                Throw(new InvalidOperationException(Resources.ConnectionAlreadyOpen));
            }

            // start up our interceptors
            _exceptionInterceptor = new ExceptionInterceptor(this);
            commandInterceptor    = new CommandInterceptor(this);

            SetState(ConnectionState.Connecting, true);

            AssertPermissions();

            //TODO: SUPPORT FOR 452 AND 46X
            // if we are auto enlisting in a current transaction, then we will be
            // treating the connection as pooled
            if (Settings.AutoEnlist && Transaction.Current != null)
            {
                driver = DriverTransactionManager.GetDriverInTransaction(Transaction.Current);
                if (driver != null &&
                    (driver.IsInActiveUse ||
                     !driver.Settings.EquivalentTo(this.Settings)))
                {
                    Throw(new NotSupportedException(Resources.MultipleConnectionsInTransactionNotSupported));
                }
            }

            MySqlConnectionStringBuilder currentSettings = Settings;

            try
            {
                if (Settings.ConnectionProtocol == MySqlConnectionProtocol.Tcp && Settings.IsSshEnabled())
                {
                    _sshHandler = new Ssh(
                        Settings.SshHostName,
                        Settings.SshUserName,
                        Settings.SshPassword,
                        Settings.SshKeyFile,
                        Settings.SshPassphrase,
                        Settings.SshPort,
                        Settings.Server,
                        Settings.Port,
                        false
                        );
                    _sshHandler.StartClient();
                }

                if (!Settings.Pooling || MySqlPoolManager.Hosts == null)
                {
                    FailoverManager.Reset();

                    if (Settings.DnsSrv)
                    {
                        var dnsSrvRecords = DnsResolver.GetDnsSrvRecords(Settings.Server);
                        FailoverManager.SetHostList(dnsSrvRecords.ConvertAll(r => new FailoverServer(r.Target, r.Port, null)),
                                                    FailoverMethod.Sequential);
                    }
                    else
                    {
                        FailoverManager.ParseHostList(Settings.Server, false);
                    }
                }

                // Load balancing && Failover
                if (ReplicationManager.IsReplicationGroup(Settings.Server))
                {
                    if (driver == null)
                    {
                        ReplicationManager.GetNewConnection(Settings.Server, false, this);
                    }
                    else
                    {
                        currentSettings = driver.Settings;
                    }
                }
                else if (FailoverManager.FailoverGroup != null && !Settings.Pooling)
                {
                    FailoverManager.AttemptConnection(this, Settings.ConnectionString, out string connectionString);
                    currentSettings.ConnectionString = connectionString;
                }

                if (Settings.Pooling)
                {
                    if (FailoverManager.FailoverGroup != null)
                    {
                        FailoverManager.AttemptConnection(this, Settings.ConnectionString, out string connectionString, true);
                        currentSettings.ConnectionString = connectionString;
                    }

                    MySqlPool pool = MySqlPoolManager.GetPool(currentSettings);
                    if (driver == null || !driver.IsOpen)
                    {
                        driver = pool.GetConnection();
                    }
                    ProcedureCache = pool.ProcedureCache;
                }
                else
                {
                    if (driver == null || !driver.IsOpen)
                    {
                        driver = Driver.Create(currentSettings);
                    }
                    ProcedureCache = new ProcedureCache((int)Settings.ProcedureCacheSize);
                }
            }
            catch (Exception)
            {
                SetState(ConnectionState.Closed, true);
                throw;
            }

            SetState(ConnectionState.Open, false);
            driver.Configure(this);

            if (driver.IsPasswordExpired && Settings.Pooling)
            {
                MySqlPoolManager.ClearPool(currentSettings);
            }

            if (!(driver.SupportsPasswordExpiration && driver.IsPasswordExpired))
            {
                if (!string.IsNullOrEmpty(Settings.Database))
                {
                    ChangeDatabase(Settings.Database);
                }
            }

            // setup our schema provider
            _schemaProvider = new ISSchemaProvider(this);
            PerfMonitor     = new PerformanceMonitor(this);

            // if we are opening up inside a current transaction, then autoenlist
            // TODO: control this with a connection string option
            if (Transaction.Current != null && Settings.AutoEnlist)
            {
                EnlistTransaction(Transaction.Current);
            }

            hasBeenOpen = true;
            SetState(ConnectionState.Open, true);
        }
 public void Setup()
 {
     timer       = new Subject <long>();
     testManager = new ReplicationTestManager();
     manager     = new ReplicationManager(new NullLogger <ReplicationManager>(), testManager.Master.Object, testManager.Slave.Object, timer);
 }