/// <summary> /// Converts an Elasticsearch <see cref="TagValueDocument"/> into an Aika <see cref="TagValue"/>, /// optionally overriding one or more of the tag value document's fields. /// </summary> /// <param name="value">The value document.</param> /// <param name="utcSampleTime">Overrides the UTC sample time from the <paramref name="value"/>.</param> /// <param name="numericValue">Overrides the numeric value from the <paramref name="value"/>.</param> /// <param name="textValue">Overrides the text value from the <paramref name="value"/>.</param> /// <param name="quality">Overrides the quality status from the <paramref name="value"/>.</param> /// <param name="units">Specifies the tag units for the <see cref="TagValue"/>.</param> /// <returns> /// An equivalent <see cref="TagValue"/>. /// </returns> /// <exception cref="ArgumentNullException"><paramref name="value"/> is <see langword="null"/>.</exception> public static TagValue ToTagValue(this TagValueDocument value, DateTime?utcSampleTime = null, double?numericValue = null, string textValue = null, TagValueQuality?quality = null, string units = null) { if (value == null) { throw new ArgumentNullException(nameof(value)); } return(new TagValue(utcSampleTime ?? value.UtcSampleTime, numericValue ?? value.NumericValue, textValue ?? value.TextValue, quality ?? value.Quality, units)); }
/// <summary> /// Converts an Elasticsearch <see cref="TagValueDocument"/> into an Aika <see cref="ArchiveCandidateValue"/>. /// </summary> /// <param name="value">The value document.</param> /// <param name="units">Specifies the tag units for the <see cref="TagValue"/> on the <see cref="ArchiveCandidateValue"/>.</param> /// <returns> /// An equivalent <see cref="ArchiveCandidateValue"/>. /// </returns> public static ArchiveCandidateValue ToArchiveCandidateValue(this TagValueDocument value, string units) { if (value == null) { throw new ArgumentNullException(nameof(value)); } var val = value.ToTagValue(units: units); var min = Double.NaN; var max = Double.NaN; object o = null; if (value.Properties?.TryGetValue("CompressionAngleMinimum", out o) ?? false) { min = Convert.ToDouble(o); } if (value.Properties?.TryGetValue("CompressionAngleMaximum", out o) ?? false) { max = Convert.ToDouble(o); } return(new ArchiveCandidateValue(val, min, max)); }