private void InitializeFieldValue(ContentContextBase context, ContentPart part) { var fields = context.ContentItem.Parts .SelectMany(pa => pa.Fields .Where(fi => fi is HiddenStringField) .Select(fi => fi as HiddenStringField)); if (fields.Any()) { var tokens = new Dictionary <string, object> { { "Content", context.ContentItem } }; foreach (var fi in fields) { var settings = fi.PartFieldDefinition .Settings.GetModel <HiddenStringFieldSettings>(); if (string.IsNullOrWhiteSpace(fi.Value) || settings.AutomaticAdjustmentOnEdit) { fi.Value = settings.Tokenized ? _tokenizer.Replace(settings.TemplateString, tokens) : settings.TemplateString; } } } }
private Task AddContextAsync(ContentContextBase context) { // Do not index a preview content item. if (_httpContextAccessor.HttpContext?.Features.Get <ContentPreviewFeature>()?.Previewing == true) { return(Task.CompletedTask); } if (context.ContentItem.Id == 0) { // Ignore that case, when Update is called on a content item which has not be "created" yet. return(Task.CompletedTask); } if (_contexts.Count == 0) { var contexts = _contexts; // Using a local var prevents the lambda from holding a ref on this scoped service. ShellScope.AddDeferredTask(scope => IndexingAsync(scope, contexts)); } _contexts.Add(context); return(Task.CompletedTask); }
private void InvalidateContainerCaches(ContentContextBase context) { var stereotype = context.ContentItem.GetStereotype(); if (string.Equals(stereotype, "Widget", StringComparison.InvariantCultureIgnoreCase)) { InvalidateLayerCaches(CachedLayerRetrievalService.WidgetContainersCacheKey); } }
private Task AddContextAsync(ContentContextBase context) { if (_contexts.Count == 0) { var contexts = _contexts; // Using a local var prevents the lambda from holding a ref on this scoped service. ShellScope.AddDeferredTask(scope => IndexingAsync(scope, contexts)); } _contexts.Add(context); return(Task.CompletedTask); }
private void EnforceResourceSharingOffOnDefault(ContentContextBase context) { if (context.ContentItem.Id != 1) { return; } var settingsPart = context.ContentItem.As <CombinatorSettingsPart>(); if (_shellSettings.Name == ShellSettings.DefaultName && settingsPart.EnableResourceSharing) { settingsPart.EnableResourceSharing = false; } }
private Task TriggerContentEvent(string eventName, ContentContextBase context) { var contentItem = context.ContentItem; // Setup the properties used in the liquid templates var properties = new Dictionary <string, object> { { "Model", contentItem } }; return(Task.WhenAll( // Trigger webhooks for the general content.{event} event _webhooksManager.NotifyAsync($"content.{eventName}", contentItem.Content, properties), // Trigger webhooks for the more specific {content type}.{event} event e.g. article.created _webhooksManager.NotifyAsync($"{contentItem.ContentType.ToLower()}.{eventName}", contentItem.Content, properties) )); }
private Task AddContextAsync(ContentContextBase context) { // A previewed content item is transient, and is marked as such with a negative id. if (context.ContentItem.Id == -1) { return(Task.CompletedTask); } if (_contexts.Count == 0) { var contexts = _contexts; // Using a local var prevents the lambda from holding a ref on this scoped service. ShellScope.AddDeferredTask(scope => IndexingAsync(scope, contexts)); } _contexts.Add(context); return(Task.CompletedTask); }
private void EvictMenuWidgetCaches(ContentContextBase context, MenuPart part) { if (context.Id == 0) { return; } // Get all the menu widgets who's menu contains this Menu Item, but only if the Output Cache Part has been bound to that Content Type var menuWidgetOutputCacheParts = _contentManager.Query <OutputCachePart>().ForType("MenuWidget").List(); foreach (var outputCachePart in menuWidgetOutputCacheParts) { var menuWidgetPart = outputCachePart.ContentItem.As <MenuWidgetPart>(); if (menuWidgetPart != null && menuWidgetPart.MenuContentItemId == part.Menu.Id) { _signals.Trigger(OutputCachePart.ContentSignalName(menuWidgetPart.Id)); } } }
public void UpdateStorage(ContentContextBase context, PackageVersionPart part) { var version = SemVersion.Parse(part.Version); part.Record.VersionMajor = version.Major; part.Record.VersionMinor = version.Minor; part.Record.VersionPatch = version.Patch; // Update package information var container = part.CommonPart.Container.As <PackagePart>(); if (container != null) { part.Record.PackageVersionId = container.PackageId.ToLowerInvariant() + "/" + part.Version; if (String.IsNullOrEmpty(container.LatestVersion) || SemVersion.Parse(container.LatestVersion) < version) { container.LatestVersionUtc = part.CommonPart.ModifiedUtc.Value; container.LatestVersion = part.Version; } } }
private void InvalidateCachesAfteMenuItemChanges(ContentContextBase context) { if (_recipeIsExecuting) { return; } var stereotype = context.ContentItem.GetStereotype(); if (string.Equals(stereotype, "MenuItem", StringComparison.InvariantCultureIgnoreCase)) { var menuItemId = context.ContentItem.Id; //get all menu ids var allMenuIds = _contentManager.Query("Menu").List().Select(ci => ci.Id); var relevantMenuIds = new List <int>(); //foreach menu id, check to see if the menu contains this menu part foreach (var menuId in allMenuIds) { if (_menuService.GetMenuParts(menuId).Select(p => p.Id).Contains(menuItemId)) { relevantMenuIds.Add(menuId); } } //if so, get all menu widgets that use this menu and invalidate cache foreach (var menuId in relevantMenuIds) { var scopedMenuId = menuId; var menuWidgets = _contentManager .Query <MenuWidgetPart>(GetMenuWidgetContentTypes()) .List() .Where(p => p.MenuContentItemId == scopedMenuId); _outputCachedPartsService.InvalidateCachedOutput(menuWidgets); } } }
#pragma warning disable S1172 // some derived contexts don't have a Cancel flag, // so we handle them at the base context level by cancelling the session private void Cancel(ContentContextBase context) { _session.Cancel(); }
void RemoveIndexingTask(ContentContextBase context, ContentPart part) { _indexingTaskManager.CreateDeleteIndexTask(context.ContentItem); }
void CreateIndexingTask(ContentContextBase context, ContentPart part) { _indexingTaskManager.CreateUpdateIndexTask(context.ContentItem); }
private void EmptyCache(ContentContextBase ctx, UrlPermissionPart part) { _signals.Trigger(Signals.UrlPatternsSignal); }