Beispiel #1
0
 /// <summary>
 /// Creates a new <see cref="TagValue"/> object.
 /// </summary>
 /// <param name="utcSampleTime">The UTC sample time.</param>
 /// <param name="numericValue">The numeric value.</param>
 /// <param name="textValue">The text value.</param>
 /// <param name="quality">The quality status for the value.</param>
 /// <param name="units">The unit of measure for the tag value.</param>
 public TagValue(DateTime utcSampleTime, double numericValue, string textValue, TagValueQuality quality, string units)
 {
     UtcSampleTime = utcSampleTime;
     NumericValue  = numericValue;
     IsNumeric     = !Double.IsNaN(numericValue) && !Double.IsInfinity(numericValue);
     TextValue     = String.IsNullOrWhiteSpace(textValue)
                     ? numericValue.ToString(CultureInfo.InvariantCulture)
                     : textValue;
     Quality = quality;
     Units   = String.IsNullOrWhiteSpace(units)
                ? String.Empty
                : units;
 }
Beispiel #2
0
        /// <summary>
        /// Converts a set of Redis <see cref="HashEntry"/> objects back into a <see cref="TagValue"/>.
        /// </summary>
        /// <param name="values">The Redis hash entries containing the tag value details.</param>
        /// <returns>
        /// The equivalent tag value.
        /// </returns>
        private static TagValue GetTagValueFromHashValues(HashEntry[] values)
        {
            DateTime        utcSampleTime = DateTime.MinValue;
            double          numericValue  = Double.NaN;
            string          textValue     = null;
            TagValueQuality quality       = TagValueQuality.Uncertain;
            string          units         = null;

            foreach (var item in values)
            {
                switch (item.Name.ToString())
                {
                case "TS":
                    utcSampleTime = new DateTime((long)item.Value, DateTimeKind.Utc);
                    break;

                case "N":
                    numericValue = (double)item.Value;
                    break;

                case "T":
                    textValue = (string)item.Value;
                    break;

                case "Q":
                    quality = (TagValueQuality)((int)item.Value);
                    break;

                case "U":
                    units = (string)item.Value;
                    break;
                }
            }

            return(new TagValue(utcSampleTime, numericValue, textValue, quality, units));
        }