using System; namespace ZB.MOM.WW.LmxProxy.Host.Domain { /// /// Value, Timestamp, and Quality structure for SCADA data. /// public readonly struct Vtq : IEquatable { /// /// Gets the value. /// public object? Value { get; } /// /// Gets the timestamp when the value was read. /// public DateTime Timestamp { get; } /// /// Gets the quality of the value. /// public Quality Quality { get; } /// /// Initializes a new instance of the struct. /// /// The value. /// The timestamp when the value was read. /// The quality of the value. public Vtq(object? value, DateTime timestamp, Quality quality) { Value = value; Timestamp = timestamp; Quality = quality; } /// /// Creates a new instance with the specified value and quality, using the current UTC timestamp. /// /// The value. /// The quality of the value. /// A new instance. public static Vtq New(object value, Quality quality) => new(value, DateTime.UtcNow, quality); /// /// Creates a new instance with the specified value, timestamp, and quality. /// /// The value. /// The timestamp when the value was read. /// The quality of the value. /// A new instance. public static Vtq New(object value, DateTime timestamp, Quality quality) => new(value, timestamp, quality); /// /// Creates a instance with good quality and the current UTC timestamp. /// /// The value. /// A new instance with good quality. public static Vtq Good(object value) => new(value, DateTime.UtcNow, Quality.Good); /// /// Creates a instance with bad quality and the current UTC timestamp. /// /// The value. Optional. /// A new instance with bad quality. public static Vtq Bad(object? value = null) => new(value, DateTime.UtcNow, Quality.Bad); /// /// Creates a instance with uncertain quality and the current UTC timestamp. /// /// The value. /// A new instance with uncertain quality. public static Vtq Uncertain(object value) => new(value, DateTime.UtcNow, Quality.Uncertain); /// /// Determines whether the specified is equal to the current . /// /// The to compare with the current . /// true if the specified is equal to the current ; otherwise, false. public bool Equals(Vtq other) => Equals(Value, other.Value) && Timestamp.Equals(other.Timestamp) && Quality == other.Quality; /// /// Determines whether the specified object is equal to the current . /// /// The object to compare with the current . /// true if the specified object is equal to the current ; otherwise, false. public override bool Equals(object obj) => obj is Vtq other && Equals(other); /// /// Returns the hash code for this instance. /// /// A 32-bit signed integer hash code. public override int GetHashCode() { unchecked { int hashCode = Value != null ? Value.GetHashCode() : 0; hashCode = (hashCode * 397) ^ Timestamp.GetHashCode(); hashCode = (hashCode * 397) ^ (int)Quality; return hashCode; } } /// /// Returns a string that represents the current object. /// /// A string that represents the current object. public override string ToString() => $"{{Value={Value}, Timestamp={Timestamp:yyyy-MM-dd HH:mm:ss.fff}, Quality={Quality}}}"; /// /// Determines whether two specified instances of are equal. /// /// The first to compare. /// The second to compare. /// true if left and right are equal; otherwise, false. public static bool operator ==(Vtq left, Vtq right) => left.Equals(right); /// /// Determines whether two specified instances of are not equal. /// /// The first to compare. /// The second to compare. /// true if left and right are not equal; otherwise, false. public static bool operator !=(Vtq left, Vtq right) => !left.Equals(right); } }