ColourCastDto.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. using EInk.Dtos;
  2. namespace EInk.Dtos
  3. {
  4. public class ColourCastDto
  5. {
  6. public string id { get; set; }
  7. public string slidesNumber { get; set; }
  8. public string createTime { get; set; }
  9. public string topic { get; set; }
  10. public string pattern { get; set; }
  11. public string result { get; set; }
  12. public List<double> values { get; set; } = new List<double>();
  13. public List<int> alarmLocation { get; set; } = new List<int>();
  14. public List<double> threshold { get; set; } = new List<double>();
  15. public void Valid()
  16. {
  17. if (String.IsNullOrEmpty(id) || String.IsNullOrEmpty(id.Trim()))
  18. {
  19. throw new Exception("Empty id");
  20. }
  21. if (String.IsNullOrEmpty(slidesNumber) || String.IsNullOrEmpty(slidesNumber.Trim()))
  22. {
  23. throw new Exception("Empty slidesNumber");
  24. }
  25. if (String.IsNullOrEmpty(createTime) || String.IsNullOrEmpty(createTime.Trim()))
  26. {
  27. throw new Exception("Empty createTime");
  28. }
  29. try
  30. {
  31. DateTime valid = Convert.ToDateTime(createTime);
  32. }
  33. catch
  34. {
  35. throw new Exception("Incorrect createTime");
  36. }
  37. if (String.IsNullOrEmpty(topic) || String.IsNullOrEmpty(topic.Trim()))
  38. {
  39. throw new Exception("Empty topic");
  40. }
  41. if (String.IsNullOrEmpty(pattern) || String.IsNullOrEmpty(pattern.Trim()))
  42. {
  43. throw new Exception("Empty pattern");
  44. }
  45. if (String.IsNullOrEmpty(result) || (result != "NG" && result != "OK"))
  46. {
  47. throw new Exception("Incorrect result");
  48. }
  49. if (values.Count != 15)
  50. {
  51. throw new Exception("Incorrect values length");
  52. }
  53. try
  54. {
  55. foreach (var item in values)
  56. {
  57. Convert.ToDouble(item);
  58. }
  59. }
  60. catch
  61. {
  62. throw new Exception("Incorrect values");
  63. }
  64. if (alarmLocation.Count != 15)
  65. {
  66. throw new Exception("Incorrect alarmLocation length");
  67. }
  68. try
  69. {
  70. foreach (var item in alarmLocation)
  71. {
  72. int judge = Convert.ToInt32(item);
  73. if (judge != 0 && judge != 1)
  74. {
  75. throw new Exception("Incorrect alarmLocation");
  76. }
  77. }
  78. }
  79. catch
  80. {
  81. throw new Exception("Incorrect alarmLocation");
  82. }
  83. if (threshold.Count != 2)
  84. {
  85. throw new Exception("Incorrect threshold length");
  86. }
  87. try
  88. {
  89. foreach (var item in threshold)
  90. {
  91. Convert.ToDouble(item);
  92. }
  93. }
  94. catch
  95. {
  96. throw new Exception("Incorrect threshold");
  97. }
  98. }
  99. }
  100. }