MonItemGeneral.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System.Reflection;
  2. using System.Text;
  3. using System.Text.Json.Serialization;
  4. using Quadarax.Foundation.Core.Data;
  5. namespace Quadarax.Foundation.Core.QMonitor
  6. {
  7. [Serializable]
  8. public class MonItemGeneral
  9. {
  10. [JsonPropertyName("nam")]
  11. public string Name { get; set; }
  12. [JsonPropertyName("cpt")]
  13. public string Caption { get; set; }
  14. [JsonPropertyName("dsc")]
  15. public string Description { get; set; }
  16. [JsonPropertyName("vty")]
  17. public MonViewType ViewType { get; set; }
  18. [JsonPropertyName("key")]
  19. public List<int> KeyOrdinals { get; set; } = new List<int>();
  20. public List<ItemDescriptor> Items { get; set; } = new List<ItemDescriptor>();
  21. public string GetKeyAsString(TypedArgument[] values)
  22. {
  23. if (values== null) throw new ArgumentNullException(nameof(values));
  24. var sb = new StringBuilder();
  25. foreach (var key in KeyOrdinals)
  26. {
  27. var item = Items[key];
  28. var val = values.FirstOrDefault(x =>
  29. string.Equals(x.Name, item.Name, StringComparison.InvariantCultureIgnoreCase));
  30. if (val == null) throw new InvalidOperationException($"Key {item.Name} not found in provided values.");
  31. sb.Append(val.Value).Append("_");
  32. }
  33. var result = sb.ToString();
  34. if (result.Equals("_"))
  35. result = result.Remove(result.Length - 1, 1);
  36. return result;
  37. }
  38. public class ItemDescriptor
  39. {
  40. [JsonPropertyName("nme")]
  41. public string Name { get; set; }
  42. [JsonPropertyName("tnm")]
  43. public string TypeName { get; set; }
  44. [JsonPropertyName("lbl")]
  45. public string Label { get; set; }
  46. [JsonPropertyName("dsc")]
  47. public string Description { get; set; }
  48. [JsonPropertyName("ord")]
  49. public int Order { get; set; }
  50. [NonSerialized] public PropertyInfo? _propertyInfo;
  51. }
  52. public enum MonViewType
  53. {
  54. Item,
  55. List
  56. }
  57. }
  58. }