/// <summary> /// Adds a new observer to this event /// </summary> /// <param name="observation">Contains all the information needed</param> /// <returns></returns> internal IDisposable Add(ThresholdObservation observation) { // Only add a new observation if not already exists if (!_observations.Contains(observation)) { _observations.Add(observation); } return(new Unsubscriber <ThresholdInfo>(_observations, observation)); }
protected bool IsSensitivityVarianceMet(ThresholdObservation observation, NewReadingReceivedEventArgs e) => Math.Abs(e.Reading - observation.Threshold.LastNotificationTemperature.Value) >= observation.Threshold.Sensitivity;
protected bool IsReadingDifferentThanLastOne(ThresholdObservation observation, NewReadingReceivedEventArgs e) => e.Reading != observation.Threshold.LastNotificationTemperature;
// Common business logic snippets to all protected bool IsFirstReading(ThresholdObservation observation, NewReadingReceivedEventArgs e) => !observation.Threshold.LastNotificationTemperature.HasValue;
/// <summary> /// Template method to ask the subclass if the threshold was reached /// </summary> /// <param name="observation">The observation with all the necessary info</param> /// <param name="e">The current reading received</param> /// <returns></returns> protected abstract bool IsThresholdReached(ThresholdObservation observation, NewReadingReceivedEventArgs e);
// Check if we've hit the threshold protected override bool IsThresholdReached(ThresholdObservation observation, NewReadingReceivedEventArgs e) => e.Reading >= observation.Threshold.Temperature;
internal Unsubscriber(List <ThresholdObservation> observations, ThresholdObservation observation) { _observations = observations; _observation = observation; }