示例#1
0
 private void RegisterChange(int id, ContentNodeKit kit)
 {
     if (_wchanges == null)
     {
         _wchanges = new List <KeyValuePair <int, ContentNodeKit> >();
     }
     _wchanges.Add(new KeyValuePair <int, ContentNodeKit>(id, kit));
 }
示例#2
0
        private bool ParentExistsLocked(ContentNodeKit kit)
        {
            if (kit.Node.ParentContentId < 0)
            {
                return(true);
            }
            var link = GetParentLink(kit.Node);

            return(link?.Value != null);
        }
示例#3
0
        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);
        }
示例#4
0
        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);
        }
示例#5
0
        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);
            }
        }