public async Task <Catalogue> RunAsync(
            [ActivityTrigger] SaleFinderCatalogueDownloadInformation downloadInformation,
            ILogger log
            )
        {
            #region null checks
            if (downloadInformation is null)
            {
                throw new ArgumentNullException(nameof(downloadInformation));
            }

            if (log is null)
            {
                throw new ArgumentNullException(nameof(log));
            }
            #endregion

            var catalogue = await saleFinderService.GetCatalogueAsync(downloadInformation.SaleId).ConfigureAwait(false);

            log.LogInformation(S.Plural(catalogue.Pages.Count, "Successfully downloaded and parsed catalogue with 1 page", "Successfully downloaded and parsed catalogue with {0} pages", catalogue.Pages.Count));

            var items = catalogue.Pages
                        .SelectMany(page => page.Items)
                        .Where(item => item.ItemId.HasValue)
                        .Select(item => new CatalogueItem
            {
                Id   = item.ItemId !.Value.ToString(CultureInfo.InvariantCulture),
                Name = item.ItemName,
                Sku  = item.Sku,
                Uri  = item.ItemUrl != null ? new Uri(downloadInformation.BaseUri, item.ItemUrl) : null,
            })
Esempio n. 2
0
        public SendGridMessage Run([ActivityTrigger] Catalogue filteredCatalogue)
        {
            #region null checks
            if (filteredCatalogue is null)
            {
                throw new ArgumentNullException(nameof(filteredCatalogue));
            }
            #endregion

            var summary = S.Plural(filteredCatalogue.Items.Count, "Catalogue Scanner found 1 matching item at {1}", "Catalogue Scanner found {0} matching items at {1}", filteredCatalogue.Store);

            var message = new SendGridMessage()
            {
                From    = new EmailAddress(FromEmail, FromName),
                Subject = summary,
            };

            message.AddTo(options.ToEmail, options.ToName);

            message.AddContent(MimeType.Html, GetHtmlContent(summary !, filteredCatalogue));
            message.AddContent(MimeType.Text, GetPlainTextContent(summary !, filteredCatalogue));

            return(message);
        }