DetectDto.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 EnumSigCheckTypeDto dmcType { get; set; }
  25. /// <summary>
  26. /// 多个检测类型时是否合并检测结果(重叠的信号只算一个,重叠区域超过500样点则认为是同一个)
  27. /// </summary>
  28. public bool mergeRes { get; set; } = false;
  29. /// <summary>
  30. /// 采样率 Hz
  31. /// </summary>
  32. [RangeDouble(0, 100e6, IncludeMin = true)]
  33. public double fsHz { get; set; }
  34. /// <summary>
  35. /// 信号带宽(KHz,只对IBS信号有效,默认25KHz)
  36. /// </summary>
  37. [RangeDouble(0, 100)]
  38. public double? band { get; set; } = 25;
  39. /// <summary>
  40. /// 超时时间(单位秒,默认30秒)
  41. /// </summary>
  42. [RangeInt(10, 600, IncludeMin = true)]
  43. public int TimeoutSeconds { get; set; } = 30;
  44. /// <summary>
  45. ///
  46. /// </summary>
  47. /// <param name="validationContext"></param>
  48. /// <returns></returns>
  49. public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
  50. {
  51. var fields = typeof(EnumSigCheckTypeDto).GetFields().Where(p => p.FieldType.IsEnum);
  52. bool hasError = true;
  53. foreach (var field in fields)
  54. {
  55. var value = field.GetValue(null);
  56. if (this.dmcType.HasFlag((Enum)value))
  57. {
  58. hasError = false;
  59. break;
  60. }
  61. }
  62. if (hasError)
  63. yield return new ValidationResult("检测类型错误", new[] { nameof(this.dmcType) });
  64. else
  65. {
  66. if (dmcType.HasFlag(EnumSigCheckTypeDto.Normal))
  67. {
  68. yield return new ValidationResult("常规信号不需要检测", new[] { nameof(this.dmcType) });
  69. }
  70. if (dmcType.HasFlag(EnumSigCheckTypeDto.DAMA) && fsHz != 96000)
  71. {
  72. yield return new ValidationResult("DAMA检测采样率只支持96K", new[] { nameof(this.fsHz) });
  73. }
  74. if (dmcType.HasFlag(EnumSigCheckTypeDto.IBS) && band != 5 && band != 25)
  75. {
  76. yield return new ValidationResult("IBS检测信号带宽只支持5K、25K两种", new[] { nameof(this.band) });
  77. }
  78. }
  79. yield return null;
  80. }
  81. }
  82. }