Exemplo n.º 1
0
        public async Task ProcessBundle(SymsorterParameters parameters, string target, CancellationToken token)
        {
            var sortedFilesCount = 0;

            foreach (var file in Directory.EnumerateFiles(target, "*", SearchOption.AllDirectories))
            {
                if (_objectFileParser.TryParse(file, out var result) && result is {})
Exemplo n.º 2
0
        public async Task <StoreResult> Store(Guid batchId, string fileName, Stream stream, CancellationToken token)
        {
            var batch = await GetOpenBatch(batchId, token);

            // TODO: Until parser supports Stream instead of file path, we write the file to TMP before we can validate it.
            var destination = Path.Combine(
                _processingPath,
                batch.BatchType.ToSymsorterPrefix(),
                batchId.ToString(),
                // To avoid files with conflicting name from the same batch
                _random.Next().ToString(CultureInfo.InvariantCulture),
                fileName);
            var tempDestination = Path.Combine(Path.GetTempPath(), destination);

            Directory.CreateDirectory(Path.GetDirectoryName(tempDestination));

            await using (var file = File.OpenWrite(tempDestination))
            {
                await stream.CopyToAsync(file, token);
            }

            if (!_parser.TryParse(tempDestination, out var fileResult) || fileResult is null)
            {
                _logger.LogDebug("Failed parsing {file}.", Path.GetFileName(tempDestination));
                File.Delete(tempDestination);
                return(StoreResult.Invalid);
            }

            _logger.LogInformation("Parsed file with {UnifiedId}", fileResult.UnifiedId);
            var symbol = await GetSymbol(fileResult.UnifiedId, token);

            if (symbol is {})