Exemplo n.º 1
0
        private async Task ImportOrder(NotificationDto notification)
        {
            logger.LogInformation($"Processing notification for order {notification.Order.OrderId}");
            foreach (var nItem in notification.Items)
            {
                logger.LogInformation($"Downloading details for item {nItem.ItemId}: item details");
                var item = await fomaSdk.GetData <ItemDto>(nItem.Links[LinkRels.Self].Href);

                logger.LogInformation($"Downloading details for item {nItem.ItemId}: manufacturing details");
                var manufacturingDetails = await fomaSdk.GetData <ManufacturingDetailDto>(item.Links[LinkRels.ManufacturingDetails].Href);

                logger.LogInformation($"Downloading details for item {nItem.ItemId}: order details");
                var order = await fomaSdk.GetData <OrderDto>(item.Order.Links[LinkRels.Self].Href);

                logger.LogInformation($"Downloading details for item {nItem.ItemId}: artwork / document");
                using (var response = await fomaSdk.Download(item.Links[LinkRels.Document].Href))
                {
                    var suggestedFilename = response.Content.Headers.ContentDisposition.FileNameStar;
                    var ext = (string.IsNullOrEmpty(suggestedFilename) ? ".pdf" : Path.GetExtension(suggestedFilename)) ?? ".pdf";
                    using (var fileStream = File.OpenWrite($"imported-item-{item.ItemId}{ext}"))
                    {
                        await response.Content.CopyToAsync(fileStream);
                    }
                }

                logger.LogInformation($"Importing item {nItem.ItemId}");
                var dataToImport = (item, manufacturingDetails, order);
                File.WriteAllText($"imported-item-{item.ItemId}.json", JsonConvert.SerializeObject(dataToImport));
            }
        }