Example #1
0
        public async Task ExecuteAsync(RecipeExecutionContext context)
        {
            if (!string.Equals(context.Name, StepName, StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            try
            {
                _logger.LogInformation("Running {StepName} for {RecipeName} recipe.", StepName, context.RecipeDescriptor.Name);

                Stopwatch stopwatch = Stopwatch.StartNew();

                ContentStepModel?model = context.Step.ToObject <ContentStepModel>();
                JArray?          data  = model?.Data;
                if (data == null)
                {
                    return;
                }

                foreach (JToken?token in data)
                {
                    ContentItem?contentItem = token.ToObject <ContentItem>();
                    if (contentItem == null)
                    {
                        continue;
                    }

                    // assume item doesn't currently exist (for speed!)

                    _logger.LogInformation("Saving '{DisplayText}' {ContentType} to SQL DB.", contentItem.DisplayText, contentItem.ContentType);
                    _session.Save(contentItem);
                    _logger.LogInformation("Publishing '{DisplayText}' {ContentType} to graphs.", contentItem.DisplayText, contentItem.ContentType);
                    await _syncOrchestrator.Publish(contentItem);
                }

                _logger.LogInformation("Created content items in {TimeTaken}.", stopwatch.Elapsed);

                //todo: should we still collect?
#pragma warning disable S1215
                GC.Collect();
#pragma warning restore S1215
            }
            catch (Exception ex)
            {
                _logger.LogWarning(ex, "ContentNoCacheStep execute exception.");
                throw;
            }
        }
Example #2
0
 public override async Task PublishingAsync(PublishContentContext context)
 {
     try
     {
         if (!await _syncOrchestrator.Publish(context.ContentItem))
         {
             // sad paths have already been notified to the user and logged
             Cancel(context);
         }
     }
     catch (Exception ex)
     {
         // we log the exception, even though some exceptions will have already been logged,
         // as there might have been an 'unexpected' exception thrown
         _logger.LogError(ex, "Exception publishing.");
         Cancel(context);
     }
 }
Example #3
0
        public async Task <bool> UpdatedAsync(ContentItem term, ContentItem taxonomy)
        {
            if (term.ContentType != ContentTypes.PageLocation)
            {
                return(true);
            }

            List <ContentItem> allPages = await _contentItemsService.GetActive(ContentTypes.Page);

            List <ContentItem> associatedPages = allPages.Where(x => x.Content.Page.PageLocations.TermContentItemIds[0] == term.ContentItemId).ToList();

            var groups = associatedPages.GroupBy(x => x.ContentItemId);

            foreach (var group in groups)
            {
                var pages = group.ToList();

                foreach (var page in pages)
                {
                    //rebuild the Full URL to ensure it matches the current state of the term
                    var pageUrlName = page.As <PageLocationPart>().UrlName;
                    var termUrl     = _taxonomyHelper.BuildTermUrl(JObject.FromObject(term), JObject.FromObject(taxonomy));

                    var fullUrl = string.IsNullOrWhiteSpace(termUrl)
                        ? $"/{pageUrlName}"
                        : $"/{termUrl}/{pageUrlName}";

                    page.Alter <PageLocationPart>(part => part.FullUrl = fullUrl);

                    _session.Save(page);
                }

                try
                {
                    if (pages.Count > 1)
                    {
                        var publishedPage = pages.Single(x => x.Published);
                        var draftPage     = pages.Single(x => x.Latest);

                        if (!await _syncOrchestrator.Update(publishedPage, draftPage))
                        {
                            _session.Cancel();
                        }
                    }
                    else
                    {
                        var page = pages.Single();

                        if (page.Published && !await _syncOrchestrator.Publish(page))
                        {
                            _session.Cancel();
                        }
                        else if (!page.Published && !await _syncOrchestrator.SaveDraft(page))
                        {
                            _session.Cancel();
                        }
                    }
                }
                catch (Exception)
                {
                    _session.Cancel();
                    return(false);
                }
            }

            return(true);
        }