private async Task <PeriodEndViewModel> ShowPath(int collectionYear, int period)
        {
            var pathItemStates = await _periodEndService.GetPathItemStatesAsync(collectionYear, period);

            var state = _stateService.GetMainState(pathItemStates);
            var lastItemJobsFinished = _stateService.AllJobsHaveCompleted(state);

            var pathModel = new PeriodEndViewModel
            {
                Period                   = period,
                Year                     = collectionYear,
                Paths                    = state.Paths,
                CollectionClosed         = state.CollectionClosed,
                PeriodEndStarted         = state.PeriodEndStarted,
                McaReportsReady          = state.McaReportsReady,
                McaReportsPublished      = state.McaReportsPublished,
                ProviderReportsReady     = state.ProviderReportsReady,
                ProviderReportsPublished = state.ProviderReportsPublished,
                PeriodEndFinished        = state.PeriodEndFinished,
                ReferenceDataJobsPaused  = state.ReferenceDataJobsPaused,
                ClosePeriodEndEnabled    = lastItemJobsFinished
            };

            return(pathModel);
        }
        protected override async Task DoWork(CancellationToken cancellationToken)
        {
            try
            {
                // Get state JSON.
                string pathItemStates = await _periodEndService.GetPathItemStatesAsync(null, null, cancellationToken);

                // Send JSON to clients.
                await _periodEndHub.SendMessage(pathItemStates, cancellationToken);
            }
            catch (Exception ex)
            {
                _logger.LogError($"Failed to {nameof(DoWork)} in {nameof(NCSPeriodEndTimedHostedService)}", ex);
            }
        }
Ejemplo n.º 3
0
        private async Task SetButtonStates(CancellationToken cancellationToken)
        {
            var period = await _periodService.ReturnPeriod(CollectionTypes.NCS, cancellationToken);

            var periodClosed = period.PeriodClosed;

            string stateString = await _periodEndService.GetPathItemStatesAsync(period.Year.Value, period.Period, cancellationToken);

            var state = _stateService.GetMainState(stateString);

            var startEnabled = periodClosed && !state.PeriodEndStarted && !state.PeriodEndFinished;

            if (PeriodEndState.CurrentAction != Constants.Action_StartPeriodEndButton)
            {
                await _hubContext.Clients.All.SendAsync(Constants.Action_StartPeriodEndButton, startEnabled, cancellationToken);
            }

            if (PeriodEndState.CurrentAction != Constants.Action_PeriodClosedButton)
            {
                var closeEnabled = periodClosed && !state.PeriodEndFinished && _stateService.AllJobsHaveCompleted(state);
                await _hubContext.Clients.All.SendAsync(Constants.Action_PeriodClosedButton, closeEnabled, cancellationToken);
            }
        }