Exemplo n.º 1
0
        /// <summary>
        /// Constructs a <see cref="StatusPropertyThresholds"/> instance with the specified thresholds.
        /// </summary>
        /// <param name="nature">A <see cref="StatusThresholdNature"/> indicating whether or not low values are good.</param>
        /// <param name="failVsAlertThreshold">The threshold which divides failures from alerts (at this value it counts as a failure).</param>
        /// <param name="alertVsOkayThreshold">The threshold which divides alerts from okays (at this value it counts as an alert).</param>
        /// <param name="okayVsSuperlativeThreshold">The threshold which divides okays from superlatives (at this value it counts as an okay).  Default is <see cref="StatusThresholdNature.LowIsGood"/>.</param>
        public StatusPropertyThresholds(float?failVsAlertThreshold, float?alertVsOkayThreshold, float?okayVsSuperlativeThreshold, StatusThresholdNature nature = StatusThresholdNature.LowIsGood)
        {
            StatusThresholdNature?computedNature = null;

            if (failVsAlertThreshold > alertVsOkayThreshold || alertVsOkayThreshold > okayVsSuperlativeThreshold || failVsAlertThreshold > okayVsSuperlativeThreshold)
            {
                computedNature = StatusThresholdNature.LowIsGood;
            }
            if (failVsAlertThreshold < alertVsOkayThreshold || alertVsOkayThreshold < okayVsSuperlativeThreshold || failVsAlertThreshold < okayVsSuperlativeThreshold)
            {
                if (computedNature != null)
                {
                    throw new ArgumentException("The threshold values must be listed in either ascending or descending order!");
                }
                computedNature = StatusThresholdNature.HighIsGood;
            }
            _nature = computedNature ?? nature;
            _failVsAlertThreshold       = failVsAlertThreshold;
            _alertVsOkayThreshold       = alertVsOkayThreshold;
            _okayVsSuperlativeThreshold = okayVsSuperlativeThreshold;
        }
Exemplo n.º 2
0
 /// <summary>
 /// Constructs a default property thresholds attribute instance using the specified parameters.
 /// Note that attribute parameters cannot take nullable values, so we use <see cref="Single.NaN"/> instead to indicate that there is no such threshold value.
 /// </summary>
 /// <param name="propertyPath">The path to the property with a default threshold.</param>
 /// <param name="failVsAlertThreshold">The first value that is a failure instead of an alert.  <see cref="Single.NaN"/> if there is no such value.</param>
 /// <param name="okayVsSuperlativeThreshold">The first value that is an alert instead of okay.  <see cref="Single.NaN"/> if there is no such value.</param>
 /// <param name="alertVsOkayThreshold">The first value that is okay instead of superlative.  <see cref="Single.NaN"/> if there is no such value.</param>
 /// <param name="thresholdNature">A <see cref="StatusThresholdNature"/> indicating whether low values are good or bad for this threshold.  Only used if less than two threshold values are specified.</param>
 public DefaultPropertyThresholdsAttribute(string propertyPath, float failVsAlertThreshold = float.NaN, float alertVsOkayThreshold = float.NaN, float okayVsSuperlativeThreshold = float.NaN, StatusThresholdNature thresholdNature = StatusThresholdNature.HighIsGood)
 {
     _propertyPath = propertyPath;
     _thresholds   = new StatusPropertyThresholds(float.IsNaN(failVsAlertThreshold) ? null : (float?)failVsAlertThreshold, float.IsNaN(alertVsOkayThreshold) ? null : (float?)alertVsOkayThreshold, float.IsNaN(okayVsSuperlativeThreshold) ? null : (float?)okayVsSuperlativeThreshold, thresholdNature);
     _deferToType  = null;
 }