public EventManager(IMeterObserver observer, IScaledValue lowerThreshold, IScaledValue upperThreshold, IScaledValue fluctuation, int readInterval) { Observer = observer; LowerThreshold = lowerThreshold; UpperThreshold = upperThreshold; Fluctuation = fluctuation; ReadInterval = readInterval; _isLowerFluctuating = false; _isUpperFluctuating = false; }
public void ValueReadHandle(IScaledValue value) { System.Diagnostics.Debug.WriteLine(String.Format("{0 : yyyy-MM-dd hh:mm} Temperature in {1} is: {2}", value.RecordedDateTime, value.ScaleDisplayName, Math.Round(value.Value, 3))); Values.Add(value); }
public void UpperThresholdReachedHandle(IScaledValue value) { System.Diagnostics.Debug.WriteLine("Upper limit reached!"); UpperThresholdWarnings.Add(value); }
public MeterEventArgs(IScaledValue value, String messsage) { TemperatureReading = value; WarningMessage = messsage; }
public MeterEventArgs(IScaledValue value) { TemperatureReading = value; }
/// <summary> /// check if this value is within the fluctuation range /// and update the flags accordingly. /// </summary> /// <param name="value">a value which were just read from input</param> private void updateFluctuationInfo(IScaledValue value) { if (Math.Round(value.CelsiusValue, 3) < Math.Round(LowerThreshold.CelsiusValue - Fluctuation.CelsiusValue, 3) || value.CelsiusValue > LowerThreshold.CelsiusValue + Fluctuation.CelsiusValue) { _isLowerFluctuating = false; } if (Math.Round(value.CelsiusValue, 3) < Math.Round(UpperThreshold.CelsiusValue - Fluctuation.CelsiusValue, 3) || Math.Round(value.CelsiusValue, 3) > Math.Round(UpperThreshold.CelsiusValue + Fluctuation.CelsiusValue, 3)) { _isUpperFluctuating = false; } }
/// <summary> /// When a new value is read, process the value /// </summary> /// <param name="value">a value which were just read from input</param> public void ReadValue(IScaledValue value) { OnValueRead(value); updateFluctuationInfo(value); //Determine if the value is outside of the thresholds, //as well as whether all the values read since last warning notification //are all within the flunctuation range (determined by _isLowerFluctuating //and _isUpperFluctuating flags). If the above condition meets, fire a new warning if (value.Compare(LowerThreshold) <= 0) { //if less or equal to lower limit, we have a problem. if (!_isLowerFluctuating && (_lastReadValue == null || _lastReadValue.Compare(LowerThreshold) > 0)) { OnLowerThresholdReached(value); _isLowerFluctuating = true; } } else if (value.Compare(UpperThreshold) >= 0) { //if more or equal to upper limit, we have a problem too. if (!_isUpperFluctuating && (_lastReadValue == null || _lastReadValue.Compare(UpperThreshold) < 0)) { OnUpperThresholdReached(value); _isUpperFluctuating = true; } } else { //else we are fine. } _lastReadValue = value; }
/// <summary> /// Fire a value read notification /// Delegate the handler from client. /// </summary> /// <param name="value"></param> public void OnValueRead(IScaledValue value) { if(Observer != null) { MeterEventArgs args = new MeterEventArgs(value); if (ValueUpdated != null) { ValueUpdated(value); } } }
/// <summary> /// Fire a Upper Threshold Reached notification /// Delegate the handler from client. /// </summary> /// <param name="value"></param> public void OnUpperThresholdReached(IScaledValue value) { if (Observer != null) { MeterEventArgs args = new MeterEventArgs(value, "Upper Threshold Reached!"); // UpperThresholdReachedHandler handler = UpperThresholdReached; if (UpperThresholdReached != null) { UpperThresholdReached(value); } } }
/// <summary> /// Fire a Lower Threshold Reached notification /// Delegate the handler from client. /// </summary> /// <param name="value"></param> public void OnLowerThresholdReached(IScaledValue value) { if (Observer != null) { MeterEventArgs args = new MeterEventArgs(value, "Lower Threshold Reached!"); if (LowerThresholdReached != null) { LowerThresholdReached(value); } } }