MonData.cs 1.8 KB

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