예제 #1
0
        /// <summary>
        ///  Called when the adapter state has changed.
        /// </summary>
        /// <param name="previousState">The previous component state.</param>
        /// <param name="newState">The new component state.</param>
        protected virtual void OnStateChanged(ResonanceComponentState previousState, ResonanceComponentState newState)
        {
            Logger.LogDebug($"State changed '{previousState}' => '{newState}'.");

            StateChanged?.Invoke(this, new ResonanceComponentStateChangedEventArgs(previousState, newState));

            if (newState == ResonanceComponentState.Connected)
            {
                TransferRate = 0;

                if (_transferRateTimer != null)
                {
                    _transferRateTimer.Stop();
                    _transferRateTimer.Dispose();
                }

                _transferRateTimer          = new Timer(1000);
                _transferRateTimer.Elapsed += _transferRateTimer_Elapsed;
                _transferRateTimer.Start();
            }
            else
            {
                if (_transferRateTimer != null)
                {
                    _transferRateTimer.Stop();
                    _transferRateTimer.Dispose();
                }
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ResonanceComponentStateChangedEventArgs"/> class.
 /// </summary>
 /// <param name="previousState">Previous components state.</param>
 /// <param name="newState">New component state.</param>
 public ResonanceComponentStateChangedEventArgs(ResonanceComponentState previousState, ResonanceComponentState newState)
 {
     PreviousState = previousState;
     NewState      = newState;
 }