private void RegisterChange(int id, ContentNodeKit kit) { if (_wchanges == null) { _wchanges = new List <KeyValuePair <int, ContentNodeKit> >(); } _wchanges.Add(new KeyValuePair <int, ContentNodeKit>(id, kit)); }
private bool ParentExistsLocked(ContentNodeKit kit) { if (kit.Node.ParentContentId < 0) { return(true); } var link = GetParentLink(kit.Node); return(link?.Value != null); }
private bool ParentPublishedLocked(ContentNodeKit kit) { if (kit.Node.ParentContentId < 0) { return(true); } var link = GetParentLink(kit.Node); var node = link?.Value; return(node?.Published != null); }
private bool BuildKit(ContentNodeKit kit) { // make sure the kit is valid if (kit.DraftData == null && kit.PublishedData == null) { return(false); } // unknown = bad if (_contentTypesById.TryGetValue(kit.ContentTypeId, out LinkedNode <PublishedContentType> link) == false || link.Value == null) { return(false); } // check whether parent is published var canBePublished = ParentPublishedLocked(kit); // and use kit.Build(link.Value, _publishedSnapshotAccessor, _variationContextAccessor, canBePublished); return(true); }
public void Set(ContentNodeKit kit) { // ReSharper disable LocalizableElement if (kit.IsEmpty) { throw new ArgumentException("Kit is empty.", nameof(kit)); } if (kit.Node.ChildContentIds.Count > 0) { throw new ArgumentException("Kit content cannot have children.", nameof(kit)); } // ReSharper restore LocalizableElement _logger.Debug <ContentStore>("Set content ID: {KitNodeId}", kit.Node.Id); var lockInfo = new WriteLockInfo(); try { Lock(lockInfo); // get existing _contentNodes.TryGetValue(kit.Node.Id, out LinkedNode <ContentNode> link); var existing = link?.Value; // else ignore, what else could we do? if (ParentExistsLocked(kit) == false || BuildKit(kit) == false) { return; } // moving? var moving = existing != null && existing.ParentContentId != kit.Node.ParentContentId; // manage children if (existing != null) { kit.Node.ChildContentIds = existing.ChildContentIds; } // set SetValueLocked(_contentNodes, kit.Node.Id, kit.Node); if (_localDb != null) { RegisterChange(kit.Node.Id, kit); } // manage the tree if (existing == null) { // new, add to parent AddToParentLocked(kit.Node); } else if (moving) { // moved, remove existing from its parent, add content to its parent RemoveFromParentLocked(existing); AddToParentLocked(kit.Node); } _xmap[kit.Node.Uid] = kit.Node.Id; } finally { Release(lockInfo); } }