public async Task <IMessage> ProvideAsync(CancellationToken cancellationToken) { var fileContentCache = (Cache <string>)_messageCache; if (string.IsNullOrEmpty(fileContentCache.Item)) { Stream fileStream = await _streamProvider.Provide(cancellationToken); if (fileStream == null) { return(null); } fileStream.Seek(0, SeekOrigin.Begin); UTF8Encoding utF8Encoding = new UTF8Encoding(false, true); using (StreamReader reader = new StreamReader(fileStream, utF8Encoding, true, 1024, true)) { fileContentCache.Item = reader.ReadToEnd(); } fileStream.Seek(0, SeekOrigin.Begin); return(_xmlSerializationService.Deserialize <Message>(fileStream)); } return(_xmlSerializationService.Deserialize <Message>(fileContentCache.Item)); }
public async Task <IMessage> ProvideAsync(CancellationToken cancellationToken) { using (var stream = await _streamProvider.Provide(cancellationToken)) { stream.Seek(0, SeekOrigin.Begin); return(_xmlSerializationService.Deserialize <Message>(stream)); } }
public async Task ExecuteAsync(IPreValidationContext validationContext, CancellationToken cancellationToken) { var stopWatch = new Stopwatch(); stopWatch.Start(); try { // get ILR data from file await _errorLookupPopulationService.PopulateAsync(cancellationToken).ConfigureAwait(false); _logger.LogDebug($"Error lookup service completed in: {stopWatch.ElapsedMilliseconds}"); // Todo: Remove this when XML is known to be schema valid Stream fileStream = await _streamProvider.Provide(cancellationToken); if (fileStream != null) { fileStream.Seek(0, SeekOrigin.Begin); UTF8Encoding utF8Encoding = new UTF8Encoding(false, true); using (StreamReader reader = new StreamReader(fileStream, utF8Encoding, true, 1024, true)) { Cache <string> fileContentCache = (Cache <string>)_cache; fileContentCache.Item = reader.ReadToEnd(); } } if (_validationErrorCache.ValidationErrors.Any()) { return; } cancellationToken.ThrowIfCancellationRequested(); // Call XSD validation _validateXmlSchemaService.Validate(); _logger.LogDebug($"XML validation schema service completed in: {stopWatch.ElapsedMilliseconds}"); if (_validationErrorCache.ValidationErrors.Any(IsErrorOrFail)) { _logger.LogDebug( $"Possible xsd validation failure: {_validationErrorCache.ValidationErrors.Count}"); return; } await _preValidationPopulationService.PopulateAsync(cancellationToken).ConfigureAwait(false); _logger.LogDebug($"Population service completed in: {stopWatch.ElapsedMilliseconds}"); // Set the filename _fileDataCache.FileName = validationContext.Input; // File Validation await _ruleSetOrchestrationService.Execute(cancellationToken).ConfigureAwait(false); cancellationToken.ThrowIfCancellationRequested(); if (_validationErrorCache.ValidationErrors.Any(IsErrorOrFail)) { _logger.LogDebug( $"Header validation failed, so will not execute learner validation actors, error count: {_validationErrorCache.ValidationErrors.Count}"); return; } await ExecuteValidationActors(validationContext, cancellationToken).ConfigureAwait(false); _logger.LogDebug( $"Actors results collated {_validationErrorCache.ValidationErrors.Count} validation errors"); } finally { cancellationToken.ThrowIfCancellationRequested(); await _validationOutputService.ProcessAsync(cancellationToken).ConfigureAwait(false); _logger.LogDebug($"Validation final results persisted in {stopWatch.ElapsedMilliseconds}"); } }