Files
Umbraco-CMS/src/Umbraco.Web/PublishedCache/NuCache/ContentNode.cs

147 lines
5.6 KiB
C#
Raw Normal View History

2016-05-27 14:26:28 +02:00
using System;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Web.PublishedCache.NuCache.DataSource;
namespace Umbraco.Web.PublishedCache.NuCache
{
// represents a content "node" ie a pair of draft + published versions
// internal, never exposed, to be accessed from ContentStore (only!)
internal class ContentNode
{
2019-04-22 17:51:07 +02:00
// special ctor for root pseudo node
public ContentNode()
{
FirstChildContentId = -1;
NextSiblingContentId = -1;
}
2019-04-22 17:51:07 +02:00
2016-05-27 14:26:28 +02:00
// special ctor with no content data - for members
2019-04-15 13:04:14 +02:00
public ContentNode(int id, Guid uid, IPublishedContentType contentType,
2016-05-27 14:26:28 +02:00
int level, string path, int sortOrder,
int parentContentId,
DateTime createDate, int creatorId)
: this()
2016-05-27 14:26:28 +02:00
{
Id = id;
Uid = uid;
ContentType = contentType;
Level = level;
Path = path;
SortOrder = sortOrder;
ParentContentId = parentContentId;
CreateDate = createDate;
CreatorId = creatorId;
}
2019-04-15 13:04:14 +02:00
public ContentNode(int id, Guid uid, IPublishedContentType contentType,
2016-05-27 14:26:28 +02:00
int level, string path, int sortOrder,
int parentContentId,
DateTime createDate, int creatorId,
2016-05-30 19:54:36 +02:00
ContentData draftData, ContentData publishedData,
IPublishedSnapshotAccessor publishedSnapshotAccessor,
IVariationContextAccessor variationContextAccessor)
2016-05-27 14:26:28 +02:00
: this(id, uid, level, path, sortOrder, parentContentId, createDate, creatorId)
{
SetContentTypeAndData(contentType, draftData, publishedData, publishedSnapshotAccessor, variationContextAccessor);
2016-05-27 14:26:28 +02:00
}
// 2-phases ctor, phase 1
public ContentNode(int id, Guid uid,
int level, string path, int sortOrder,
int parentContentId,
DateTime createDate, int creatorId)
{
Id = id;
Uid = uid;
Level = level;
Path = path;
SortOrder = sortOrder;
ParentContentId = parentContentId;
2019-04-22 17:51:07 +02:00
FirstChildContentId = -1;
NextSiblingContentId = -1;
2016-05-27 14:26:28 +02:00
CreateDate = createDate;
CreatorId = creatorId;
}
// two-phase ctor, phase 2
public void SetContentTypeAndData(IPublishedContentType contentType, ContentData draftData, ContentData publishedData, IPublishedSnapshotAccessor publishedSnapshotAccessor, IVariationContextAccessor variationContextAccessor)
2016-05-27 14:26:28 +02:00
{
ContentType = contentType;
if (draftData == null && publishedData == null)
throw new ArgumentException("Both draftData and publishedData cannot be null at the same time.");
if (draftData != null)
2019-01-28 20:07:22 +01:00
{
DraftContent = new PublishedContent(this, draftData, publishedSnapshotAccessor, variationContextAccessor);
2019-01-28 20:07:22 +01:00
DraftModel = DraftContent.CreateModel();
}
2016-05-27 14:26:28 +02:00
if (publishedData != null)
2019-01-28 20:07:22 +01:00
{
PublishedContent = new PublishedContent(this, publishedData, publishedSnapshotAccessor, variationContextAccessor);
2019-01-28 20:07:22 +01:00
PublishedModel = PublishedContent.CreateModel();
}
2016-05-27 14:26:28 +02:00
}
2019-04-22 17:51:07 +02:00
// clone
public ContentNode(ContentNode origin, IPublishedContentType contentType = null)
2016-05-27 14:26:28 +02:00
{
Id = origin.Id;
Uid = origin.Uid;
2019-04-22 17:51:07 +02:00
ContentType = contentType ?? origin.ContentType;
2016-05-27 14:26:28 +02:00
Level = origin.Level;
Path = origin.Path;
SortOrder = origin.SortOrder;
ParentContentId = origin.ParentContentId;
2019-04-22 17:51:07 +02:00
FirstChildContentId = origin.FirstChildContentId;
NextSiblingContentId = origin.NextSiblingContentId;
2016-05-27 14:26:28 +02:00
CreateDate = origin.CreateDate;
CreatorId = origin.CreatorId;
2019-01-28 20:07:22 +01:00
var originDraft = origin.DraftContent;
var originPublished = origin.PublishedContent;
2016-05-27 14:26:28 +02:00
2019-04-22 17:51:07 +02:00
DraftContent = originDraft == null ? null : new PublishedContent(this, originDraft);
PublishedContent = originPublished == null ? null : new PublishedContent(this, originPublished);
2019-01-28 14:15:47 +01:00
DraftModel = DraftContent?.CreateModel();
PublishedModel = PublishedContent?.CreateModel();
2016-05-27 14:26:28 +02:00
}
// everything that is common to both draft and published versions
// keep this as small as possible
public readonly int Id;
public readonly Guid Uid;
2019-04-15 13:04:14 +02:00
public IPublishedContentType ContentType;
2016-05-27 14:26:28 +02:00
public readonly int Level;
public readonly string Path;
public readonly int SortOrder;
public readonly int ParentContentId;
2019-04-22 17:51:07 +02:00
public int FirstChildContentId;
public int NextSiblingContentId;
2016-05-27 14:26:28 +02:00
public readonly DateTime CreateDate;
public readonly int CreatorId;
2019-01-28 14:15:47 +01:00
// draft and published version (either can be null, but not both)
// are the direct PublishedContent instances
public PublishedContent DraftContent;
public PublishedContent PublishedContent;
2016-05-27 14:26:28 +02:00
// draft and published version (either can be null, but not both)
// are models not direct PublishedContent instances
2019-01-28 14:15:47 +01:00
public IPublishedContent DraftModel;
public IPublishedContent PublishedModel;
2016-05-27 14:26:28 +02:00
public ContentNodeKit ToKit()
2019-04-22 17:51:07 +02:00
=> new ContentNodeKit
{
Node = this,
ContentTypeId = ContentType.Id,
DraftData = DraftContent?.ContentData,
PublishedData = PublishedContent?.ContentData
};
2016-05-27 14:26:28 +02:00
}
}