public ThrottlingLogger(
            ILogEvents logger,
            TimeSpan mimimumFrequency,
            int maximumNumberOfBufferedItems,
            MessageEvaluationBehaviourOptions messageEvaluationBehaviour,
            ErrorBehaviourOptions individualLogEntryErrorBehaviour)
        {
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }
            if (mimimumFrequency.Ticks <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(mimimumFrequency), "must be a positive duration");
            }
            if (maximumNumberOfBufferedItems <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(maximumNumberOfBufferedItems), "must be a positive value");
            }
            if ((messageEvaluationBehaviour != MessageEvaluationBehaviourOptions.EvaluateWhenLogged) && (messageEvaluationBehaviour != MessageEvaluationBehaviourOptions.EvaluateWhenQueued))
            {
                // Note: Explicitly check for all valid values rather than using Enum.IsDefined since IsDefined uses reflection and logging should be as cheap as possible
                // (so reflection is best avoided)
                throw new ArgumentOutOfRangeException(nameof(messageEvaluationBehaviour));
            }
            if ((individualLogEntryErrorBehaviour != ErrorBehaviourOptions.Ignore) && (individualLogEntryErrorBehaviour != ErrorBehaviourOptions.ThrowException))
            {
                // Note: Explicitly check for all valid values rather than using Enum.IsDefined since IsDefined uses reflection and logging should be as cheap as possible
                // (so reflection is best avoided)
                throw new ArgumentOutOfRangeException(nameof(individualLogEntryErrorBehaviour));
            }

            MaximumNumberOfBufferedItems     = maximumNumberOfBufferedItems;
            MinimumFrequency                 = mimimumFrequency;
            MessageEvaluationBehaviour       = messageEvaluationBehaviour;
            IndividualLogEntryErrorBehaviour = individualLogEntryErrorBehaviour;

            _logger   = logger;
            _messages = new ConcurrentQueue <LogEventDetails>();
            _timer    = new PauseableTimer(
                mimimumFrequency,
                FlushQueueIfNotAlreadyDoingSo
                );
            _lastFlushedAt            = null;
            _flushInProgressIndicator = 0;
        }
Beispiel #2
0
 public MotorModel(short pinNumber1, short pinNumber2,
                   SensorModel frontLim, SensorModel backLim,
                   int fwdTime = Constants.defaultMotorFwdTime, int backTime = Constants.defaultMotorBackTime,
                   bool in1    = false, bool in2 = false)
 {
     this._pinNumber1          = pinNumber1;
     this._pinNumber2          = pinNumber2;
     this._in1                 = in1;
     this._in2                 = in2;
     ForwardTime               = fwdTime;
     _lastForwardTime          = ForwardTime;
     BackwardTime              = backTime;
     _lastBackwardTime         = BackwardTime;
     _forwardTimer             = new PauseableTimer(ForwardTime);
     _forwardTimer.Elapsed    += OnForwardTimerElapsed;
     _backwardTimer            = new PauseableTimer(BackwardTime);
     _backwardTimer.Elapsed   += OnBackwardTimerElapsed;
     frontLim.PropertyChanged += OnFrontLimitHit;
     backLim.PropertyChanged  += OnBackLimitHit;
     LimitMode                 = false;
 }