void IStreamStatusContext.TransitionToPossiblyOff() { _currentStatus = _possiblyOffStatus; _latestStreamOffTime = _timeService.UtcNow; _unitOfWork.Command(u => { u.StateIntegers.StreamStatus = StreamStatus.PossiblyOff; u.StateIntegers.LatestStreamOffTime = _latestStreamOffTime; }); }
void IStreamStatusContext.TransitionToOn(bool updateLatestStreamOnTime) { _currentStatus = _onStatus; if (updateLatestStreamOnTime) { _latestStreamOnTime = _timeService.UtcNow; _unitOfWork.Command(u => { u.StateIntegers.StreamStatus = StreamStatus.On; u.StateIntegers.LatestStreamOnTime = _latestStreamOnTime; }); } else { _unitOfWork.Command(u => u.StateIntegers.StreamStatus = StreamStatus.On); } }
public StreamStateService( IQueryCommandService <IUnitOfWork> unitOfWork, ITimeService timeService, IDownloadMapper downloadMapper, ISettings settings ) { _unitOfWork = unitOfWork; _timeService = timeService; _downloadMapper = downloadMapper; _onStatus = new OnStatus(this); _offStatus = new OffStatus(this); _possiblyOffStatus = new PossiblyOffStatus(this, _unitOfWork, _timeService, settings); var initialStatus = unitOfWork.Query(u => u.StateIntegers.StreamStatus); _latestStreamOnTime = unitOfWork.Query(u => u.StateIntegers.LatestStreamOnTime); _latestStreamOffTime = unitOfWork.Query(u => u.StateIntegers.LatestStreamOffTime); switch (initialStatus) { case StreamStatus.On: _currentStatus = _onStatus; break; case StreamStatus.Off: _currentStatus = _offStatus; break; case StreamStatus.PossiblyOff: _currentStatus = _possiblyOffStatus; break; default: throw new NotSupportedException($"The stream status {initialStatus} is not registered"); } }
void IStreamStatusContext.TransitionToOff() { _currentStatus = _offStatus; _unitOfWork.Command(u => u.StateIntegers.StreamStatus = StreamStatus.Off); }