private void _connection_StateChange(object sender, StateChangeEventArgs e)
        {
            lock (stateLock)
            {
                ConnectionStateRedundant newState = StateRedundant;
                if (sender == _connectionPrimary)
                {
                    switch (e.CurrentState)
                    {
                    case ConnectionState.Open:
                        newState &= ~ConnectionStateRedundant.BrokenPrimary;
                        newState |= ConnectionStateRedundant.OpenPrimary;
                        break;

                    case ConnectionState.Broken:
                    case ConnectionState.Closed:
                        newState |= ConnectionStateRedundant.BrokenPrimary;
                        newState &= ~ConnectionStateRedundant.OpenPrimary;
                        break;
                    }
                }
                if (sender == _connectionSecondary)
                {
                    switch (e.CurrentState)
                    {
                    case ConnectionState.Open:
                        newState &= ~ConnectionStateRedundant.BrokenSecondary;
                        newState |= ConnectionStateRedundant.OpenSecondary;
                        break;

                    case ConnectionState.Broken:
                    case ConnectionState.Closed:
                        newState |= ConnectionStateRedundant.BrokenSecondary;
                        newState &= ~ConnectionStateRedundant.OpenSecondary;
                        break;
                    }
                }
                if ((newState & (ConnectionStateRedundant.BrokenPrimary | ConnectionStateRedundant.BrokenSecondary)) > 0)
                {
                    newState = (newState & ~ConnectionStateRedundant.Open) | ConnectionStateRedundant.Broken;
                }
                if ((_connectionPrimary != null || _connectionSecondary != null) &&
                    (_connectionPrimary == null || _connectionPrimary.State == ConnectionState.Open) &&
                    (_connectionSecondary == null || _connectionSecondary.State == ConnectionState.Open))
                {
                    newState = (newState & ~ConnectionStateRedundant.Broken) | ConnectionStateRedundant.Open;
                }
                StateRedundant = newState;
            }
        }
Ejemplo n.º 2
0
 public RedundantConnectionStateEventArgs(ConnectionStateRedundant oldState, ConnectionStateRedundant newState)
 {
     OldState = oldState;
     NewState = newState;
 }