Beispiel #1
0
        public async Task RunAsync(CancellationToken token)
        {
            if (!_options.Output.Exists)
            {
                _options.Output.Create();
            }

            await foreach (var plate in GetAvailableContainers(token).WithCancellation(token))
            {
                var outputFile = new FileInfo(Path.Combine(_options.Output.FullName, plate));

                if (_options.SkipExisting && outputFile.Exists)
                {
                    _logger.LogWarning("Plate {PlateFile} already exists. Skipping.");

                    continue;
                }

                _logger.LogInformation("Downloading {PlateFile}", outputFile.Name);

                try
                {
                    using (var fs = outputFile.OpenWrite())
                    {
                        fs.SetLength(0);

                        var count = await _downloader.DownloadPlateFileAsync(plate, fs, _options.Levels, token);

                        if (count == 0)
                        {
                            _logger.LogWarning("No content added for {PlateFile}", outputFile.Name);
                        }
                    }
                }
                catch (Exception e)
                {
                    _logger.LogError(e, "Unexpected error getting {PlateName}", outputFile.Name);

                    if (outputFile.Exists)
                    {
                        outputFile.Delete();
                    }
                }

                var size = FormatSize(outputFile.Length);

                _logger.LogInformation("Completed {PlateFile} download. Resulting file is {Size}", outputFile.Name, size);
            }
        }
Beispiel #2
0
        public async Task <Stream> GetDevDataAsync(int maxLevel, CancellationToken token)
        {
            var ms = new MemoryStream();

            using (var zip = new ZipArchive(ms, ZipArchiveMode.Update, leaveOpen: true))
            {
                foreach (var plateFile in _plateFiles)
                {
                    var entry = zip.CreateEntry($"coredata/{plateFile}");
                    using var stream = entry.Open();

                    await _downloader.DownloadPlateFileAsync(plateFile, stream, maxLevel, token);
                }
            }

            ms.Position = 0;
            return(ms);
        }