CheckStartTimeStrategy.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using Hotline.Application.Exam.Interface.Strategy;
  2. namespace Hotline.Application.Exam.Strategy
  3. {
  4. public class CheckStartTimeStrategy : IExamStrategy
  5. {
  6. public string ErroMessage { get; private set; }
  7. public Func<object> CallBack { get; set; }
  8. private IExamStrategy _next;
  9. private DateTime _examStartTime;
  10. private DateTime? _startTime;
  11. private IExamStrategy _current;
  12. public CheckStartTimeStrategy(DateTime examStartTime,DateTime? startTime)
  13. {
  14. _examStartTime = examStartTime;
  15. _startTime = startTime;
  16. }
  17. public void SetNext(IExamStrategy examStrategy)
  18. {
  19. _next = examStrategy;
  20. }
  21. public bool Validate()
  22. {
  23. if (_examStartTime > _startTime)
  24. {
  25. ErroMessage = "考试未开始";
  26. _current = this;
  27. return false;
  28. }
  29. _current = _next;
  30. if (_next == null) return true;
  31. return _next.Validate();
  32. }
  33. public object GetResult()
  34. {
  35. if (_current != null && _current.CallBack != null)
  36. return _current.CallBack();
  37. return null;
  38. }
  39. }
  40. }