Exemplo n.º 1
0
        protected static CmsApiSharedContentModel BuildValidCmsApiSharedContentModel()
        {
            var model = new CmsApiSharedContentModel()
            {
                ItemId = new Guid("2c9da1b3-3529-4834-afc9-9cd741e59788"),
                Id     = new Guid("2c9da1b3-3529-4834-afc9-9cd741e59788")
            };

            return(model);
        }
Exemplo n.º 2
0
        private static CmsApiSharedContentModel BuildValidCmsApiSharedContentModel()
        {
            var model = new CmsApiSharedContentModel()
            {
                Title       = "an-article",
                Url         = new Uri("/aaa/bbb", UriKind.Relative),
                Published   = DateTime.Now,
                CreatedDate = DateTime.Now,
                ItemId      = new Guid("2c9da1b3-3529-4834-afc9-9cd741e59788"),
                Id          = new Guid("2c9da1b3-3529-4834-afc9-9cd741e59788"),
            };

            return(model);
        }
        public async Task ProcessSummaryListAsync(CmsApiSharedContentModel sharedContent, CancellationToken stoppingToken)
        {
            logger.LogInformation("Process summary list started");

            if (stoppingToken.IsCancellationRequested)
            {
                logger.LogWarning("Process summary list cancelled");

                return;
            }

            await GetAndSaveItemAsync(sharedContent, stoppingToken).ConfigureAwait(false);


            logger.LogInformation("Process summary list completed");
        }
        public async Task GetAndSaveItemAsync(CmsApiSharedContentModel item, CancellationToken stoppingToken)
        {
            _ = item ?? throw new ArgumentNullException(nameof(item));

            try
            {
                if (stoppingToken.IsCancellationRequested)
                {
                    logger.LogWarning("Process item get and save cancelled");

                    return;
                }

                logger.LogInformation($"Updating cache with {item.Title} - {item.Url}");
                item.Id = item.ItemId.Value;
                var result = await eventMessageService.UpdateAsync(item).ConfigureAwait(false);

                if (result == HttpStatusCode.NotFound)
                {
                    logger.LogInformation($"Does not exist, creating cache with {item.Title} - {item.Url}");

                    result = await eventMessageService.CreateAsync(item).ConfigureAwait(false);

                    if (result == HttpStatusCode.Created)
                    {
                        logger.LogInformation($"Created cache with {item.Title} - {item.Url}");
                    }
                    else
                    {
                        logger.LogError($"Cache create error status {result} from {item.Title} - {item.Url}");
                    }
                }
                else
                {
                    logger.LogInformation($"Updated cache with {item.Title} - {item.Url}");
                }
            }
            catch (Exception ex)
            {
                logger.LogError(ex, $"Error in get and save for {item.Title} - {item.Url}");
            }
        }