// clone for previewing as draft a published content that is published and has no draft private PublishedContent( PublishedContent origin, IUmbracoContextAccessor umbracoContextAccessor) : base(umbracoContextAccessor) { _publishedSnapshotAccessor = origin._publishedSnapshotAccessor; VariationContextAccessor = origin.VariationContextAccessor; _contentNode = origin._contentNode; ContentData = origin.ContentData; _urlSegment = origin._urlSegment; IsPreviewing = true; // clone properties so _isPreviewing is true PropertiesArray = origin.PropertiesArray.Select(x => (IPublishedProperty) new Property((Property)x, this)).ToArray(); }
// two-phase ctor, phase 2 public void SetContentTypeAndData(PublishedContentType contentType, ContentData draftData, ContentData publishedData, IPublishedSnapshotAccessor publishedSnapshotAccessor, IVariationContextAccessor variationContextAccessor) { ContentType = contentType; if (draftData == null && publishedData == null) { throw new ArgumentException("Both draftData and publishedData cannot be null at the same time."); } if (draftData != null) { Draft = new PublishedContent(this, draftData, publishedSnapshotAccessor, variationContextAccessor).CreateModel(); } if (publishedData != null) { Published = new PublishedContent(this, publishedData, publishedSnapshotAccessor, variationContextAccessor).CreateModel(); } }
// (see ContentNode.CloneParent) public PublishedContent( ContentNode contentNode, PublishedContent origin, IUmbracoContextAccessor umbracoContextAccessor) : base(umbracoContextAccessor) { _contentNode = contentNode; _publishedSnapshotAccessor = origin._publishedSnapshotAccessor; VariationContextAccessor = origin.VariationContextAccessor; ContentData = origin.ContentData; _urlSegment = origin._urlSegment; IsPreviewing = origin.IsPreviewing; // here is the main benefit: we do not re-create properties so if anything // is cached locally, we share the cache - which is fine - if anything depends // on the tree structure, it should not be cached locally to begin with PropertiesArray = origin.PropertiesArray; }
// clone with new content type public ContentNode(ContentNode origin, PublishedContentType contentType, IPublishedSnapshotAccessor publishedSnapshotAccessor, IVariationContextAccessor variationContextAccessor) { Id = origin.Id; Uid = origin.Uid; ContentType = contentType; // change! Level = origin.Level; Path = origin.Path; SortOrder = origin.SortOrder; ParentContentId = origin.ParentContentId; CreateDate = origin.CreateDate; CreatorId = origin.CreatorId; var originDraft = origin.Draft == null ? null : PublishedContent.UnwrapIPublishedContent(origin.Draft); var originPublished = origin.Published == null ? null : PublishedContent.UnwrapIPublishedContent(origin.Published); Draft = originDraft == null ? null : new PublishedContent(this, originDraft._contentData, publishedSnapshotAccessor, variationContextAccessor).CreateModel(); Published = originPublished == null ? null : new PublishedContent(this, originPublished._contentData, publishedSnapshotAccessor, variationContextAccessor).CreateModel(); ChildContentIds = origin.ChildContentIds; // can be the *same* list FIXME oh really? }
// clone with new content type public ContentNode(ContentNode origin, PublishedContentType contentType, IPublishedSnapshotAccessor publishedSnapshotAccessor, IVariationContextAccessor variationContextAccessor, IUmbracoContextAccessor umbracoContextAccessor) { Id = origin.Id; Uid = origin.Uid; ContentType = contentType; // change! Level = origin.Level; Path = origin.Path; SortOrder = origin.SortOrder; ParentContentId = origin.ParentContentId; CreateDate = origin.CreateDate; CreatorId = origin.CreatorId; var originDraft = origin.DraftContent; var originPublished = origin.PublishedContent; DraftContent = originDraft == null ? null : new PublishedContent(this, originDraft.ContentData, publishedSnapshotAccessor, variationContextAccessor, umbracoContextAccessor); DraftModel = DraftContent?.CreateModel(); PublishedContent = originPublished == null ? null : new PublishedContent(this, originPublished.ContentData, publishedSnapshotAccessor, variationContextAccessor, umbracoContextAccessor); PublishedModel = PublishedContent?.CreateModel(); ChildContentIds = origin.ChildContentIds; // can be the *same* list }
// clone parent private ContentNode(ContentNode origin) { // everything is the same, except for the child items // list which is a clone of the original list Id = origin.Id; Uid = origin.Uid; ContentType = origin.ContentType; Level = origin.Level; Path = origin.Path; SortOrder = origin.SortOrder; ParentContentId = origin.ParentContentId; CreateDate = origin.CreateDate; CreatorId = origin.CreatorId; var originDraft = origin.Draft == null ? null : PublishedContent.UnwrapIPublishedContent(origin.Draft); var originPublished = origin.Published == null ? null : PublishedContent.UnwrapIPublishedContent(origin.Published); Draft = originDraft == null ? null : new PublishedContent(this, originDraft).CreateModel(); Published = originPublished == null ? null : new PublishedContent(this, originPublished).CreateModel(); ChildContentIds = new List <int>(origin.ChildContentIds); // needs to be *another* list }
private IPublishedContent GetModel(ref IPublishedContent model, ContentData contentData) { if (model != null) { return(model); } if (contentData == null) { return(null); } // create the model - we want to be fast, so no lock here: we may create // more than 1 instance, but the lock below ensures we only ever return // 1 unique instance - and locking is a nice explicit way to ensure this var m = new PublishedContent(this, contentData, _publishedSnapshotAccessor, _variationContextAccessor).CreateModel(); // locking 'this' is not a best-practice but ContentNode is internal and // we know what we do, so it is fine here and avoids allocating an object lock (this) { return(model = model ?? m); } }
// initializes a published content property with no value public Property(IPublishedPropertyType propertyType, PublishedContent content, IPublishedSnapshotAccessor publishedSnapshotAccessor, PropertyCacheLevel referenceCacheLevel = PropertyCacheLevel.Element) : this(propertyType, content, null, publishedSnapshotAccessor, referenceCacheLevel) { }