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, _publishedModelFactory).CreateModel(_publishedModelFactory); // 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 ??= m); } }
private ScriptVars ScriptContext(ContentData?newData, ContentData?oldData, Status newStatus, Status oldStatus) { return(A <ScriptVars> .That.Matches(x => M(x, newData, oldData, newStatus, oldStatus))); }
public static async Task NormalizeAsync(this ITagService tagService, DomainId appId, DomainId schemaId, Schema schema, ContentData newData, ContentData?oldData) { Guard.NotNull(tagService, nameof(tagService)); Guard.NotNull(schema, nameof(schema)); Guard.NotNull(newData, nameof(newData)); var newValues = new HashSet <string>(); var newArrays = new List <JsonArray>(); var oldValues = new HashSet <string>(); var oldArrays = new List <JsonArray>(); GetValues(schema, newValues, newArrays, newData); if (oldData != null) { GetValues(schema, oldValues, oldArrays, oldData); } if (newValues.Count > 0) { var normalized = await tagService.NormalizeTagsAsync(appId, TagGroups.Schemas(schemaId), newValues, oldValues); foreach (var array in newArrays) { for (var i = 0; i < array.Count; i++) { if (normalized.TryGetValue(array[i].ToString(), out var result)) { array[i] = JsonValue.Create(result); } } } } }
public static IEnrichedContentEntity Create(NamedId <DomainId> appId, NamedId <DomainId> schemaId, DomainId id, DomainId refId, DomainId assetId, ContentData?data = null) { var now = SystemClock.Instance.GetCurrentInstant(); data ??= new ContentData() .AddField("my-string", new ContentFieldData() .AddLocalized("de", "value")) .AddField("my-string2", new ContentFieldData() .AddInvariant(null)) .AddField("my-assets", new ContentFieldData() .AddInvariant(JsonValue.Array(assetId.ToString()))) .AddField("2_numbers", new ContentFieldData() .AddInvariant(22)) .AddField("2-numbers", new ContentFieldData() .AddInvariant(23)) .AddField("my-number", new ContentFieldData() .AddInvariant(1.0)) .AddField("my_number", new ContentFieldData() .AddInvariant(null)) .AddField("my-boolean", new ContentFieldData() .AddInvariant(true)) .AddField("my-datetime", new ContentFieldData() .AddInvariant(now)) .AddField("my-tags", new ContentFieldData() .AddInvariant(JsonValue.Array("tag1", "tag2"))) .AddField("my-references", new ContentFieldData() .AddInvariant(JsonValue.Array(refId.ToString()))) .AddField("my-union", new ContentFieldData() .AddInvariant(JsonValue.Array(refId.ToString()))) .AddField("my-geolocation", new ContentFieldData() .AddInvariant(JsonValue.Object().Add("latitude", 10).Add("longitude", 20))) .AddField("my-json", new ContentFieldData() .AddInvariant(JsonValue.Object().Add("value", 1))) .AddField("my-localized", new ContentFieldData() .AddLocalized("de-DE", "de-DE")) .AddField("my-array", new ContentFieldData() .AddInvariant(JsonValue.Array( JsonValue.Object() .Add("nested-number", 10) .Add("nested_number", null) .Add("nested-boolean", true), JsonValue.Object() .Add("nested-number", 20) .Add("nested_number", null) .Add("nested-boolean", false)))); var content = new ContentEntity { Id = id, AppId = appId, Version = 1, Created = now, CreatedBy = RefToken.User("user1"), LastModified = now, LastModifiedBy = RefToken.User("user2"), Data = data, SchemaId = schemaId, Status = Status.Draft, StatusColor = "red" }; return(content); }
public ContentNodeKit(ContentNode node, int contentTypeId, ContentData?draftData, ContentData?publishedData) { Node = node; ContentTypeId = contentTypeId; DraftData = draftData; PublishedData = publishedData; }
public static IEnrichedContentEntity Create(DomainId id, DomainId refId = default, DomainId assetId = default, ContentData?data = null) { var now = SystemClock.Instance.GetCurrentInstant(); data ??= new ContentData() .AddField("my-localized-string", new ContentFieldData() .AddLocalized("de-DE", "de-DE")) .AddField("my-string", new ContentFieldData() .AddInvariant(null)) .AddField("my-assets", new ContentFieldData() .AddInvariant(JsonValue.Array(assetId.ToString()))) .AddField("my-number", new ContentFieldData() .AddInvariant(1.0)) .AddField("my-boolean", new ContentFieldData() .AddInvariant(true)) .AddField("my-datetime", new ContentFieldData() .AddInvariant(now)) .AddField("my-tags", new ContentFieldData() .AddInvariant(JsonValue.Array("tag1", "tag2"))) .AddField("my-references", new ContentFieldData() .AddInvariant(JsonValue.Array(refId.ToString()))) .AddField("my-union", new ContentFieldData() .AddInvariant(JsonValue.Array(refId.ToString()))) .AddField("my-geolocation", new ContentFieldData() .AddInvariant( JsonValue.Object() .Add("latitude", 10) .Add("longitude", 20))) .AddField("my-component", new ContentFieldData() .AddInvariant( JsonValue.Object() .Add(Component.Discriminator, TestSchemas.Ref1.Id) .Add("schemaRef1Field", "Component1"))) .AddField("my-components", new ContentFieldData() .AddInvariant( JsonValue.Array( JsonValue.Object() .Add(Component.Discriminator, TestSchemas.Ref1.Id) .Add("schemaRef1Field", "Component1"), JsonValue.Object() .Add(Component.Discriminator, TestSchemas.Ref2.Id) .Add("schemaRef2Field", "Component2")))) .AddField("my-json", new ContentFieldData() .AddInvariant( JsonValue.Object() .Add("value", 1))) .AddField("my-array", new ContentFieldData() .AddInvariant(JsonValue.Array( JsonValue.Object() .Add("nested-number", 10) .Add("nested-boolean", true), JsonValue.Object() .Add("nested-number", 20) .Add("nested-boolean", false)))); var content = new ContentEntity { Id = id, AppId = TestApp.DefaultId, Version = 1, Created = now, CreatedBy = RefToken.User("user1"), LastModified = now, LastModifiedBy = RefToken.Client("client1"), Data = data, SchemaId = TestSchemas.DefaultId, Status = Status.Draft, StatusColor = "red", NewStatus = Status.Published, NewStatusColor = "blue" }; return(content); }
public bool Equals(ContentData?other) { return(other != null && (ReferenceEquals(this, other) || this.EqualsDictionary(other))); }
private ContentEntity CreateContent(ContentData?data = null) { return(new ContentEntity { SchemaId = schemaId, Data = data ! });
// two-phase ctor, phase 2 public void SetContentTypeAndData(IPublishedContentType contentType, ContentData?draftData, ContentData?publishedData, IPublishedSnapshotAccessor publishedSnapshotAccessor, IVariationContextAccessor variationContextAccessor, IPublishedModelFactory publishedModelFactory) { ContentType = contentType; if (draftData == null && publishedData == null) { throw new ArgumentException("Both draftData and publishedData cannot be null at the same time."); } _publishedSnapshotAccessor = publishedSnapshotAccessor; _variationContextAccessor = variationContextAccessor; _publishedModelFactory = publishedModelFactory; _draftData = draftData; _publishedData = publishedData; }
private ContentNodeKit CreateContentNodeKit(ContentSourceDto dto, IContentCacheDataSerializer serializer) { ContentData?d = null; ContentData?p = null; if (dto.Edited) { if (dto.EditData == null && dto.EditDataRaw == null) { if (Debugger.IsAttached) { throw new InvalidOperationException("Missing cmsContentNu edited content for node " + dto.Id + ", consider rebuilding."); } _logger.LogWarning("Missing cmsContentNu edited content for node {NodeId}, consider rebuilding.", dto.Id); } else { bool published = false; var deserializedContent = serializer.Deserialize(dto, dto.EditData, dto.EditDataRaw, published); d = new ContentData( dto.EditName, deserializedContent?.UrlSegment, dto.VersionId, dto.EditVersionDate, dto.EditWriterId, dto.EditTemplateId, published, deserializedContent?.PropertyData, deserializedContent?.CultureData); } } if (dto.Published) { if (dto.PubData == null && dto.PubDataRaw == null) { if (Debugger.IsAttached) { throw new InvalidOperationException("Missing cmsContentNu published content for node " + dto.Id + ", consider rebuilding."); } _logger.LogWarning("Missing cmsContentNu published content for node {NodeId}, consider rebuilding.", dto.Id); } else { bool published = true; var deserializedContent = serializer.Deserialize(dto, dto.PubData, dto.PubDataRaw, published); p = new ContentData( dto.PubName, deserializedContent?.UrlSegment, dto.VersionId, dto.PubVersionDate, dto.PubWriterId, dto.PubTemplateId, published, deserializedContent?.PropertyData, deserializedContent?.CultureData); } } var n = new ContentNode(dto.Id, dto.Key, dto.Level, dto.Path, dto.SortOrder, dto.ParentId, dto.CreateDate, dto.CreatorId); var s = new ContentNodeKit(n, dto.ContentTypeId, d, p); return(s); }