MonData.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System.Text.Json;
  2. using System.Text.Json.Serialization;
  3. using Quadarax.Foundation.Core.Json.Extensions;
  4. namespace Quadarax.Foundation.Core.QMonitor
  5. {
  6. public class MonData : IEquatable<MonData>
  7. {
  8. [JsonPropertyName("iid")]
  9. public string InstanceIdentifier { get; set; }
  10. [JsonPropertyName("nam")]
  11. public string? Name { get; set; }
  12. [JsonPropertyName("tms-ftutc")]
  13. public long TimestampFtUtc { get; set; }
  14. [JsonPropertyName("dta")]
  15. public string Data { get; set; } = string.Empty;
  16. public IDictionary<string, JsonDocumentExt.DiffOccurrence>? Diff(MonData other)
  17. {
  18. if (other == null) throw new ArgumentNullException(nameof(other));
  19. var thisDoc = JsonDocument.Parse(Data);
  20. var otherDoc = JsonDocument.Parse(other.Data);
  21. thisDoc.Diff(otherDoc);
  22. return thisDoc.Diff(otherDoc);
  23. }
  24. public JsonDocument DataToJsonDocument()
  25. {
  26. return JsonDocument.Parse(Data);
  27. }
  28. public bool Equals(MonData? other)
  29. {
  30. if (ReferenceEquals(null, other)) return false;
  31. if (ReferenceEquals(this, other)) return true;
  32. return InstanceIdentifier == other.InstanceIdentifier && Name == other.Name && Data == other.Data;
  33. }
  34. public override bool Equals(object? obj)
  35. {
  36. if (ReferenceEquals(null, obj)) return false;
  37. if (ReferenceEquals(this, obj)) return true;
  38. if (obj.GetType() != this.GetType()) return false;
  39. return Equals((MonData)obj);
  40. }
  41. public override int GetHashCode()
  42. {
  43. return HashCode.Combine(InstanceIdentifier, Name, Data);
  44. }
  45. }
  46. }