Exemplo n.º 1
0
        /// <inheritdoc />
        public async Task Invoke(PerformContext context)
        {
            context.WriteLine($"> Get Blueprint part and attach image");
            byte[] data;
            using (var webClient = new WebClient()) {
                var stream       = webClient.OpenRead(new Uri(BlueprintImageUrl));
                var memoryStream = new MemoryStream();
                await stream.CopyToAsync(memoryStream);

                data = memoryStream.ToArray();
            }
            var blueprintImage = await _persister.AddOrUpdateImage(new Image()
            {
                Data = data,
            });

            var blueprintPart = await _context.PrimeParts.FirstOrDefaultAsync(p => p.Name == "Blueprint");

            blueprintPart.ImageId = blueprintImage.Id;
            blueprintPart.Image   = blueprintImage;
            var collarBlueprintPart = await _context.PrimeParts.FirstOrDefaultAsync(p => p.Name == "Collar Blueprint");

            collarBlueprintPart.ImageId = blueprintImage.Id;
            collarBlueprintPart.Image   = blueprintImage;
            await _context.SaveChangesAsync();

            context.WriteLine($"< Image attached");
        }