Beispiel #1
0
        public async Task ProcessAvailabilityRecord(Guid recordId, CancellationToken cancellationToken)
        {
            var availabilityRecord = await _availabilityRecordRepository.GetById(recordId, cancellationToken)
                                     .ConfigureAwait(false);

            var responseModel = await _availabilityService.Request(availabilityRecord.Url, cancellationToken);

            availabilityRecord.AppendLog((int)responseModel.HttpStatusCode, responseModel.Body,
                                         responseModel.ResponseTime);

            availabilityRecord.ClearOutdatedLogs();

            _availabilityRecordRepository.Update(availabilityRecord);
            await _availabilityRecordRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken)
            .ConfigureAwait(false);
        }
Beispiel #2
0
        public async Task Handle(UpdateAvailabilityRecordCommand notification, CancellationToken cancellationToken)
        {
            var accountId = _claimConverter.GetAccountId(notification.ClaimsPrincipal);

            var availabilityRecord = await _availabilityRecordRepository.GetById(notification.Id, cancellationToken)
                                     .ConfigureAwait(false);

            if (availabilityRecord.AccountId != accountId)
            {
                throw new InvalidOperationException("Invalid account id");
            }

            availabilityRecord.UpdateName(notification.Name);
            availabilityRecord.UpdateUrl(notification.Url);
            availabilityRecord.UpdateExpectedResponse(notification.ExpectedResponse);
            availabilityRecord.UpdateExpectedStatusCode(notification.ExpectedStatusCode);
            availabilityRecord.UpdateLogLifetimeThresholdInHours(notification.LogLifetimeThresholdInHours);

            _availabilityRecordRepository.Update(availabilityRecord);
            await _availabilityRecordRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken);
        }