ColourCastDto.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 int NGCode { get; set; }
  14. //public List<int> alarmLocation { get; set; } = new List<int>();
  15. //public string threshold { get; set; }
  16. public void Valid()
  17. {
  18. if (String.IsNullOrEmpty(id) || String.IsNullOrEmpty(id.Trim()))
  19. {
  20. throw new Exception("Empty id");
  21. }
  22. if (String.IsNullOrEmpty(slidesNumber) || String.IsNullOrEmpty(slidesNumber.Trim()))
  23. {
  24. throw new Exception("Empty slidesNumber");
  25. }
  26. if (String.IsNullOrEmpty(createTime) || String.IsNullOrEmpty(createTime.Trim()))
  27. {
  28. throw new Exception("Empty createTime");
  29. }
  30. try
  31. {
  32. DateTime valid = Convert.ToDateTime(createTime);
  33. }
  34. catch
  35. {
  36. throw new Exception("Incorrect createTime");
  37. }
  38. if (String.IsNullOrEmpty(topic) || String.IsNullOrEmpty(topic.Trim()))
  39. {
  40. throw new Exception("Empty topic");
  41. }
  42. if (String.IsNullOrEmpty(pattern) || String.IsNullOrEmpty(pattern.Trim()))
  43. {
  44. throw new Exception("Empty pattern");
  45. }
  46. if (String.IsNullOrEmpty(result) || (result != "NG" && result != "OK"))
  47. {
  48. throw new Exception("Incorrect result");
  49. }
  50. if (values.Count != 15)
  51. {
  52. throw new Exception("Incorrect values length");
  53. }
  54. try
  55. {
  56. foreach (var item in values)
  57. {
  58. Convert.ToDouble(item);
  59. }
  60. }
  61. catch
  62. {
  63. throw new Exception("Incorrect values");
  64. }
  65. if (NGCode < 0 || NGCode > 32767)
  66. {
  67. throw new Exception("Incorrect NGCode");
  68. }
  69. //if (alarmLocation.Count != 15)
  70. //{
  71. // throw new Exception("Incorrect alarmLocation length");
  72. //}
  73. //try
  74. //{
  75. // foreach (var item in alarmLocation)
  76. // {
  77. // int judge = Convert.ToInt32(item);
  78. // if (judge != 0 && judge != 1)
  79. // {
  80. // throw new Exception("Incorrect alarmLocation");
  81. // }
  82. // }
  83. //}
  84. //catch
  85. //{
  86. // throw new Exception("Incorrect alarmLocation");
  87. //}
  88. }
  89. }
  90. }