using Hotline.Application.Exam.Interface.Strategy; namespace Hotline.Application.Exam.Strategy { public class CheckStartTimeStrategy : IExamStrategy { public string ErroMessage { get; private set; } public Func CallBack { get; set; } private IExamStrategy _next; private DateTime _examStartTime; private DateTime? _startTime; private IExamStrategy _current; public CheckStartTimeStrategy(DateTime examStartTime,DateTime? startTime) { _examStartTime = examStartTime; _startTime = startTime; } public void SetNext(IExamStrategy examStrategy) { _next = examStrategy; } public bool Validate() { if (_examStartTime > _startTime) { ErroMessage = "考试未开始"; _current = this; return false; } _current = _next; if (_next == null) return true; return _next.Validate(); } public object GetResult() { if (_current != null && _current.CallBack != null) return _current.CallBack(); return null; } } }