DetectDto.cs 2.7 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 EnumSigCheckTypeDto dmcType { get; set; }
  25. /// <summary>
  26. /// 采样率 Hz
  27. /// </summary>
  28. [RangeDouble(0, 100e6, IncludeMin = true)]
  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. /// <summary>
  36. /// 超时时间(秒)
  37. /// </summary>
  38. [RangeInt(1)]
  39. public int TimeoutSeconds { get; set; } = 30;
  40. /// <summary>
  41. ///
  42. /// </summary>
  43. /// <param name="validationContext"></param>
  44. /// <returns></returns>
  45. public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
  46. {
  47. var fields = typeof(EnumSigCheckTypeDto).GetFields().Where(p => p.FieldType.IsEnum);
  48. bool hasError = true;
  49. foreach (var field in fields)
  50. {
  51. var value = field.GetValue(null);
  52. if (this.dmcType.HasFlag((Enum)value))
  53. {
  54. hasError = false;
  55. break;
  56. }
  57. }
  58. if (hasError)
  59. yield return new ValidationResult("检测类型错误", new[] { nameof(this.dmcType) });
  60. else
  61. {
  62. if (dmcType.HasFlag(EnumSigCheckTypeDto.Normal))
  63. {
  64. yield return new ValidationResult("常规信号不需要检测", new[] { nameof(this.dmcType) });
  65. }
  66. if (dmcType.HasFlag(EnumSigCheckTypeDto.DAMA) && fsHz != 96000)
  67. {
  68. yield return new ValidationResult("DAMA检测采样率只支持96K", new[] { nameof(this.fsHz) });
  69. }
  70. if (dmcType.HasFlag(EnumSigCheckTypeDto.IBS) && band != 5 && band != 25)
  71. {
  72. yield return new ValidationResult("IBS检测信号带宽只支持5K、25K两种", new[] { nameof(this.band) });
  73. }
  74. }
  75. yield return null;
  76. }
  77. }
  78. }