/// <summary> /// Creates a strongly typed published content model for an internal published content. /// </summary> /// <param name="content">The internal published content.</param> /// <returns>The strongly typed published content model.</returns> public static IPublishedContent CreateModel(this IPublishedContent content, IPublishedModelFactory publishedModelFactory) { if (publishedModelFactory == null) { throw new ArgumentNullException(nameof(publishedModelFactory)); } if (content == null) { return(null); } // get model // if factory returns nothing, throw var model = publishedModelFactory.CreateModel(content); if (model == null) { throw new InvalidOperationException("Factory returned null."); } // if factory returns a different type, throw if (!(model is IPublishedContent publishedContent)) { throw new InvalidOperationException($"Factory returned model of type {model.GetType().FullName} which does not implement IPublishedContent."); } return(publishedContent); }
/// <summary> /// Sets the published content model factory. /// </summary> /// <param name="builder">The builder.</param> /// <param name="factory">A published content model factory.</param> public static IUmbracoBuilder SetPublishedContentModelFactory( this IUmbracoBuilder builder, IPublishedModelFactory factory) { builder.Services.AddUnique(factory); return(builder); }
public ContentTypeCacheRefresher(AppCaches appCaches, IPublishedSnapshotService publishedSnapshotService, IPublishedModelFactory publishedModelFactory, IdkMap idkMap) : base(appCaches) { _publishedSnapshotService = publishedSnapshotService; _publishedModelFactory = publishedModelFactory; _idkMap = idkMap; }
public MediaPickerValueConverter(IPublishedSnapshotAccessor publishedSnapshotAccessor, IPublishedModelFactory publishedModelFactory) { _publishedSnapshotAccessor = publishedSnapshotAccessor ?? throw new ArgumentNullException(nameof(publishedSnapshotAccessor)); _publishedModelFactory = publishedModelFactory; }
public static IPublishedContent Create( IMember member, IPublishedContentType contentType, bool previewing, IPublishedSnapshotAccessor publishedSnapshotAccessor, IVariationContextAccessor variationContextAccessor, IPublishedModelFactory publishedModelFactory) { var d = new ContentData { Name = member.Name, Published = previewing, TemplateId = -1, VersionDate = member.UpdateDate, WriterId = member.CreatorId, // what else? Properties = GetPropertyValues(contentType, member) }; var n = new ContentNode( member.Id, member.Key, contentType, member.Level, member.Path, member.SortOrder, member.ParentId, member.CreateDate, member.CreatorId); return(new PublishedMember(member, n, d, publishedSnapshotAccessor, variationContextAccessor, publishedModelFactory) .CreateModel(publishedModelFactory)); }
/// <summary> /// Sets a flag to reset the ModelsBuilder models if the <see cref="IPublishedModelFactory"/> is <see cref="ILivePublishedModelFactory"/> /// </summary> /// <param name="factory"></param> /// <param name="action"></param> /// <remarks> /// This does not recompile the pure live models, only sets a flag to tell models builder to recompile when they are requested. /// </remarks> internal static void WithSafeLiveFactoryReset(this IPublishedModelFactory factory, Action action) { if (factory is ILivePublishedModelFactory liveFactory) { lock (liveFactory.SyncRoot) { // TODO: Fix this in 8.3! - We need to change the ILivePublishedModelFactory interface to have a Reset method and then when we have an embedded MB // version we will publicize the ResetModels (and change the name to Reset). // For now, this will suffice and we'll use reflection, there should be no other implementation of ILivePublishedModelFactory. // Calling ResetModels resets the MB flag so that the next time EnsureModels is called (which is called when nucache lazily calls CreateModel) it will // trigger the recompiling of pure live models. var resetMethod = liveFactory.GetType().GetMethod("ResetModels", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic); if (resetMethod != null) { resetMethod.Invoke(liveFactory, null); } action(); } } else { action(); } }
public PublishedContent( ContentNode contentNode, ContentData contentData, IPublishedSnapshotAccessor publishedSnapshotAccessor, IVariationContextAccessor variationContextAccessor, IPublishedModelFactory publishedModelFactory) : base(variationContextAccessor) { _contentNode = contentNode ?? throw new ArgumentNullException(nameof(contentNode)); ContentData = contentData ?? throw new ArgumentNullException(nameof(contentData)); _publishedSnapshotAccessor = publishedSnapshotAccessor ?? throw new ArgumentNullException(nameof(publishedSnapshotAccessor)); _publishedModelFactory = publishedModelFactory; VariationContextAccessor = variationContextAccessor ?? throw new ArgumentNullException(nameof(variationContextAccessor)); _urlSegment = ContentData.UrlSegment; IsPreviewing = ContentData.Published == false; var properties = new IPublishedProperty[_contentNode.ContentType.PropertyTypes.Count()]; int i = 0; foreach (var propertyType in _contentNode.ContentType.PropertyTypes) { // add one property per property type - this is required, for the indexing to work // if contentData supplies pdatas, use them, else use null contentData.Properties.TryGetValue(propertyType.Alias, out var pdatas); // else will be null properties[i++] = new Property(propertyType, this, pdatas, _publishedSnapshotAccessor); } PropertiesArray = properties; }
/// <summary> /// Sets a flag to reset the ModelsBuilder models if the <see cref="IPublishedModelFactory"/> is <see cref="ILivePublishedModelFactory"/> /// </summary> /// <param name="factory"></param> /// <param name="action"></param> /// <remarks> /// This does not recompile the pure live models, only sets a flag to tell models builder to recompile when they are requested. /// </remarks> internal static void WithSafeLiveFactoryReset(this IPublishedModelFactory factory, Action action) { if (factory is ILivePublishedModelFactory liveFactory) { lock (liveFactory.SyncRoot) { if (liveFactory is ILivePublishedModelFactory2 liveFactory2) { liveFactory2.Reset(); } else { // This is purely here for backwards compat and to avoid breaking changes but this code will probably never get executed var resetMethod = liveFactory.GetType().GetMethod("ResetModels", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic); if (resetMethod != null) { resetMethod.Invoke(liveFactory, null); } } action(); } } else { action(); } }
public DataTypeCacheRefresher(AppCaches appCaches, IJsonSerializer serializer, IPublishedSnapshotService publishedSnapshotService, IPublishedModelFactory publishedModelFactory, IdkMap idkMap) : base(appCaches, serializer) { _publishedSnapshotService = publishedSnapshotService; _publishedModelFactory = publishedModelFactory; _idkMap = idkMap; }
public BlockEditorConverter( IPublishedSnapshotAccessor publishedSnapshotAccessor, IPublishedModelFactory publishedModelFactory) { _publishedSnapshotAccessor = publishedSnapshotAccessor; _publishedModelFactory = publishedModelFactory; }
protected NestedContentValueConverterBase( IPublishedSnapshotAccessor publishedSnapshotAccessor, IPublishedModelFactory publishedModelFactory) { _publishedSnapshotAccessor = publishedSnapshotAccessor; PublishedModelFactory = publishedModelFactory; }
public ContentNodeKit Clone(IPublishedModelFactory publishedModelFactory) => new ContentNodeKit { ContentTypeId = ContentTypeId, DraftData = DraftData, PublishedData = PublishedData, Node = new ContentNode(Node, publishedModelFactory) };
public ContentTypeCacheRefresher(AppCaches appCaches, IJsonSerializer serializer, IPublishedSnapshotService publishedSnapshotService, IPublishedModelFactory publishedModelFactory, IdkMap idkMap, IContentTypeCommonRepository contentTypeCommonRepository) : base(appCaches, serializer) { _publishedSnapshotService = publishedSnapshotService; _publishedModelFactory = publishedModelFactory; _idkMap = idkMap; _contentTypeCommonRepository = contentTypeCommonRepository; }
public ModelBindingExceptionFilter( IOptionsSnapshot <ExceptionFilterSettings> exceptionFilterSettings, IPublishedModelFactory publishedModelFactory) { _exceptionFilterSettings = exceptionFilterSettings.Value; _publishedModelFactory = publishedModelFactory ?? throw new ArgumentNullException(nameof(publishedModelFactory)); }
public EmbeddedContentService(IContentTypeService contentTypeService, IDataTypeService dataTypeService, IAppPolicyCache runtimeCache, IPublishedModelFactory publishedModelFactory, ILogger logger) { _contentTypeService = contentTypeService; _dataTypeService = dataTypeService; _runtimeCache = runtimeCache; _publishedModelFactory = publishedModelFactory; _logger = logger; }
private PublishedMember( IMember member, ContentNode contentNode, ContentData contentData, IPublishedSnapshotAccessor publishedSnapshotAccessor, IVariationContextAccessor variationContextAccessor, IPublishedModelFactory publishedModelFactory) : base(contentNode, contentData, publishedSnapshotAccessor, variationContextAccessor, publishedModelFactory) =>
public PublishedElementHelper() { _contentTypeService = Current.Services.ContentTypeService; _publishedContentTypeFactory = Current.PublishedContentTypeFactory; _logger = Current.Logger; _dataTypeService = Current.Services.DataTypeService; _publishedModelFactory = Current.Factory.GetInstance <IPublishedModelFactory>(); _propertyEditors = Current.PropertyEditors; }
/// <summary> /// Returns true if the current <see cref="IPublishedModelFactory"/> is an implementation of <see cref="IAutoPublishedModelFactory"/> and is enabled /// </summary> public static bool IsLiveFactoryEnabled(this IPublishedModelFactory factory) { if (factory is IAutoPublishedModelFactory liveFactory) { return(liveFactory.Enabled); } // if it's not ILivePublishedModelFactory we know we're not using a live factory return(false); }
/// <summary> /// Returns true if the current <see cref="IPublishedModelFactory"/> is an implementation of <see cref="ILivePublishedModelFactory2"/> and is enabled /// </summary> /// <param name="factory"></param> /// <returns></returns> public static bool IsLiveFactoryEnabled(this IPublishedModelFactory factory) { if (factory is ILivePublishedModelFactory2 liveFactory2) { return(liveFactory2.Enabled); } // if it's not ILivePublishedModelFactory2 we can't determine if it's enabled or not so return true return(factory is ILivePublishedModelFactory); }
public ContentBlocksValueConverter( IContentTypeService contentTypeService, IPublishedModelFactory publishedModelFactory, IPublishedSnapshotAccessor publishedSnapshotAccessor) : base() { _contentTypeService = contentTypeService; _publishedModelFactory = publishedModelFactory; _publishedSnapshotAccessor = publishedSnapshotAccessor; }
public DocTypeGridEditorHelper(AppCaches appCaches, IUmbracoContextAccessor umbracoContextAccessor, PropertyEditorCollection dataEditors, ILoggerFactory loggerFactory, IDataTypeService dataTypeService, IPublishedModelFactory publishedModelFactory, IContentTypeService contentTypeService, IPublishedContentTypeFactory publishedContentTypeFactory) { _appCaches = appCaches; _umbracoContext = umbracoContextAccessor; _dataEditors = dataEditors; _logger = loggerFactory.CreateLogger <DocTypeGridEditorHelper>(); _dataTypeService = dataTypeService; _publishedModelFactory = publishedModelFactory; _contentTypeService = contentTypeService; _publishedContentTypeFactory = publishedContentTypeFactory; }
public PreviewController( IProfilingLogger profilingLogger, IPublishedContentTypeFactory publishedContentTypeFactory, IPublishedModelFactory publishedModelFactory, IPublishedSnapshotAccessor publishedSnapshotAccessor) { _profilingLogger = profilingLogger; _publishedContentTypeFactory = publishedContentTypeFactory; _publishedModelFactory = publishedModelFactory; _publishedSnapshotAccessor = publishedSnapshotAccessor; }
/// <summary> /// This constructor is for tests and is not intended to be used directly from application code. /// </summary> /// <remarks> /// <para>Values are assumed to be consistent and are not checked.</para> /// <para>The new published property type does not belong to a published content type.</para> /// </remarks> public PublishedPropertyType(string propertyTypeAlias, int dataTypeId, bool isUserProperty, ContentVariation variations, PropertyValueConverterCollection propertyValueConverters, IPublishedModelFactory publishedModelFactory, IPublishedContentTypeFactory factory) { _publishedModelFactory = publishedModelFactory ?? throw new ArgumentNullException(nameof(publishedModelFactory)); _propertyValueConverters = propertyValueConverters ?? throw new ArgumentNullException(nameof(propertyValueConverters)); Alias = propertyTypeAlias; IsUserProperty = isUserProperty; Variations = variations; DataType = factory.GetDataType(dataTypeId); }
public ContentNode(int id, Guid uid, IPublishedContentType contentType, int level, string path, int sortOrder, int parentContentId, DateTime createDate, int creatorId, ContentData draftData, ContentData publishedData, IPublishedSnapshotAccessor publishedSnapshotAccessor, IVariationContextAccessor variationContextAccessor, IPublishedModelFactory publishedModelFactory) : this(id, uid, level, path, sortOrder, parentContentId, createDate, creatorId) { SetContentTypeAndData(contentType, draftData, publishedData, publishedSnapshotAccessor, variationContextAccessor, publishedModelFactory); }
public MemberCache( bool previewDefault, PublishedContentTypeCache contentTypeCache, IPublishedSnapshotAccessor publishedSnapshotAccessor, IVariationContextAccessor variationContextAccessor, IPublishedModelFactory publishedModelFactory) { _publishedSnapshotAccessor = publishedSnapshotAccessor; _variationContextAccessor = variationContextAccessor; _publishedModelFactory = publishedModelFactory; _previewDefault = previewDefault; _contentTypeCache = contentTypeCache; }
public DataTypeCacheRefresher( AppCaches appCaches, IJsonSerializer serializer, IPublishedSnapshotService publishedSnapshotService, IPublishedModelFactory publishedModelFactory, IIdKeyMap idKeyMap, IEventAggregator eventAggregator, ICacheRefresherNotificationFactory factory) : base(appCaches, serializer, eventAggregator, factory) { _publishedSnapshotService = publishedSnapshotService; _publishedModelFactory = publishedModelFactory; _idKeyMap = idKeyMap; }
public PreviewController( IProfilingLogger profilingLogger, IPublishedContentTypeFactory publishedContentTypeFactory, IPublishedModelFactory publishedModelFactory, IPublishedSnapshotAccessor publishedSnapshotAccessor, BlockEditorConverter blockConverter) { _profilingLogger = profilingLogger; _publishedContentTypeFactory = publishedContentTypeFactory; _publishedModelFactory = publishedModelFactory; _publishedSnapshotAccessor = publishedSnapshotAccessor; _blockConverter = blockConverter; _blockListEditorDataConverter = new BlockListEditorDataConverter(); }
/// <summary> /// Executes an action with a safe live factory/ /// </summary> /// <remarks> /// <para>If the factory is a live factory, ensures it is refreshed and locked while executing the action.</para> /// </remarks> public static void WithSafeLiveFactory(this IPublishedModelFactory factory, Action action) { if (factory is ILivePublishedModelFactory liveFactory) { lock (liveFactory.SyncRoot) { liveFactory.Refresh(); action(); } } else { action(); } }
/// <summary> /// Sets a flag to reset the ModelsBuilder models if the <see cref="IPublishedModelFactory"/> is <see cref="IAutoPublishedModelFactory"/> /// </summary> /// <remarks> /// This does not recompile the InMemory models, only sets a flag to tell models builder to recompile when they are requested. /// </remarks> internal static void WithSafeLiveFactoryReset(this IPublishedModelFactory factory, Action action) { if (factory is IAutoPublishedModelFactory liveFactory) { lock (liveFactory.SyncRoot) { liveFactory.Reset(); action(); } } else { action(); } }
// 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; }