public ContentBuilder WithContentCultureInfosCollection( ContentCultureInfosCollection contentCultureInfosCollection) { _contentCultureInfosCollectionBuilder = null; _contentCultureInfosCollection = contentCultureInfosCollection; return(this); }
public ContentCultureInfosCollectionBuilder AddContentCultureInfosCollection() { _contentCultureInfosCollection = null; var builder = new ContentCultureInfosCollectionBuilder(this); _contentCultureInfosCollectionBuilder = builder; return(builder); }
/// <inheritdoc /> public object DeepClone() { var clone = new ContentCultureInfosCollection(); foreach (ContentCultureInfos item in this) { var itemClone = (ContentCultureInfos)item.DeepClone(); itemClone.ResetDirtyProperties(false); clone.Add(itemClone); } return(clone); }
public override Content Build() { var id = _id ?? 0; var versionId = _versionId ?? 0; Guid key = _key ?? Guid.NewGuid(); var parentId = _parentId ?? -1; IContent parent = _parent ?? null; DateTime createDate = _createDate ?? DateTime.Now; DateTime updateDate = _updateDate ?? DateTime.Now; var name = _name ?? Guid.NewGuid().ToString(); var creatorId = _creatorId ?? 0; var level = _level ?? 1; var path = _path ?? $"-1,{id}"; var sortOrder = _sortOrder ?? 0; var trashed = _trashed ?? false; var culture = _cultureInfo?.Name ?? null; var propertyValues = _propertyValues ?? null; var propertyValuesCulture = _propertyValuesCulture ?? null; var propertyValuesSegment = _propertyValuesSegment ?? null; if (_contentTypeBuilder is null && _contentType is null) { throw new InvalidOperationException("A content item cannot be constructed without providing a content type. Use AddContentType() or WithContentType()."); } IContentType contentType = _contentType ?? _contentTypeBuilder.Build(); Content content; if (parent != null) { content = new Content(name, parent, contentType, culture); } else { content = new Content(name, parentId, contentType, culture); } content.Id = id; content.VersionId = versionId; content.Key = key; content.CreateDate = createDate; content.UpdateDate = updateDate; content.CreatorId = creatorId; content.Level = level; content.Path = path; content.SortOrder = sortOrder; content.Trashed = trashed; foreach (KeyValuePair <string, string> cultureName in _cultureNames) { content.SetCultureName(cultureName.Value, cultureName.Key); } if (_propertyDataBuilder != null || propertyValues != null) { if (_propertyDataBuilder != null) { IDictionary <string, object> propertyData = _propertyDataBuilder.Build(); foreach (KeyValuePair <string, object> keyValuePair in propertyData) { content.SetValue(keyValuePair.Key, keyValuePair.Value); } } else { content.PropertyValues(propertyValues, propertyValuesCulture, propertyValuesSegment); } content.ResetDirtyProperties(false); } if (_contentCultureInfosCollection is not null || _contentCultureInfosCollectionBuilder is not null) { ContentCultureInfosCollection contentCultureInfos = _contentCultureInfosCollection ?? _contentCultureInfosCollectionBuilder.Build(); content.PublishCultureInfos = contentCultureInfos; } return(content); }
private ContentNuDto GetDto(IContentBase content, bool published, IContentCacheDataSerializer serializer) { // should inject these in ctor // BUT for the time being we decide not to support ConvertDbToXml/String // var propertyEditorResolver = PropertyEditorResolver.Current; // var dataTypeService = ApplicationContext.Current.Services.DataTypeService; var propertyData = new Dictionary <string, PropertyData[]>(); foreach (IProperty prop in content.Properties) { var pdatas = new List <PropertyData>(); foreach (IPropertyValue pvalue in prop.Values) { // sanitize - properties should be ok but ... never knows if (!prop.PropertyType.SupportsVariation(pvalue.Culture, pvalue.Segment)) { continue; } // note: at service level, invariant is 'null', but here invariant becomes 'string.Empty' var value = published ? pvalue.PublishedValue : pvalue.EditedValue; if (value != null) { pdatas.Add(new PropertyData { Culture = pvalue.Culture ?? string.Empty, Segment = pvalue.Segment ?? string.Empty, Value = value }); } } propertyData[prop.Alias] = pdatas.ToArray(); } var cultureData = new Dictionary <string, CultureVariation>(); // sanitize - names should be ok but ... never knows if (content.ContentType.VariesByCulture()) { ContentCultureInfosCollection infos = content is IContent document ? published ? document.PublishCultureInfos : document.CultureInfos : content.CultureInfos; // ReSharper disable once UseDeconstruction foreach (ContentCultureInfos cultureInfo in infos) { var cultureIsDraft = !published && content is IContent d && d.IsCultureEdited(cultureInfo.Culture); cultureData[cultureInfo.Culture] = new CultureVariation { Name = cultureInfo.Name, UrlSegment = content.GetUrlSegment(_shortStringHelper, _urlSegmentProviders, cultureInfo.Culture), Date = content.GetUpdateDate(cultureInfo.Culture) ?? DateTime.MinValue, IsDraft = cultureIsDraft }; } } // the dictionary that will be serialized var contentCacheData = new ContentCacheDataModel { PropertyData = propertyData, CultureData = cultureData, UrlSegment = content.GetUrlSegment(_shortStringHelper, _urlSegmentProviders) }; var serialized = serializer.Serialize(ReadOnlyContentBaseAdapter.Create(content), contentCacheData, published); var dto = new ContentNuDto { NodeId = content.Id, Published = published, Data = serialized.StringData, RawData = serialized.ByteData }; return(dto); }