DetectDto.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.ComponentModel.DataAnnotations;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using XdCxRhDW.Dto.Attribute;
  9. namespace XdCxRhDW.Dto
  10. {
  11. /// <summary>
  12. /// 检测计算模型
  13. /// </summary>
  14. public class DetectDto : IValidatableObject
  15. {
  16. /// <summary>
  17. /// 调用Upload接口上传文件后返回的文件名
  18. /// </summary>
  19. [FileMustExist]
  20. public string file1 { get; set; }
  21. /// <summary>
  22. /// 检测类型
  23. /// </summary>
  24. public DmcType dmcType { get; set; }
  25. /// <summary>
  26. /// 采样率 Hz
  27. /// </summary>
  28. [RangeDouble(0, 100e6)]
  29. public double fsHz { get; set; }
  30. /// <summary>
  31. /// 信号带宽(KHz,只对IBS信号有效,默认25KHz)
  32. /// </summary>
  33. [RangeDouble(0, 100)]
  34. public double? band { get; set; } = 25;
  35. public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
  36. {
  37. var fields = typeof(DmcType).GetFields().Where(p => p.FieldType.IsEnum);
  38. bool hasError = true;
  39. foreach (var field in fields)
  40. {
  41. var value = field.GetValue(null);
  42. if (this.dmcType.HasFlag((Enum)value))
  43. {
  44. hasError = false;
  45. break;
  46. }
  47. }
  48. if (hasError)
  49. yield return new ValidationResult("检测类型错误", new[] { nameof(this.dmcType) });
  50. else
  51. yield return null;
  52. }
  53. }
  54. /// <summary>
  55. /// 检测类型
  56. /// </summary>
  57. [Flags]
  58. public enum DmcType
  59. {
  60. /// <summary>
  61. /// DAMA检测
  62. /// </summary>
  63. [Display(Name = "DAMA检测")]
  64. DAMA = 1,
  65. /// <summary>
  66. /// IBS检测
  67. /// </summary>
  68. [Display(Name = "IBS检测")]
  69. IBS = 2,
  70. /// <summary>
  71. /// 能量检测
  72. /// </summary>
  73. [Display(Name = "能量检测")]
  74. Ky5758 = 4
  75. }
  76. }