* Renaming AppData Models Builder mode * Renaming PureLive Models Builder mode to Runtime * ModelsBuilderAssembly attribute flags if models are "Live" or not * Updated ModelsMode names * Only add tag if it is not a pull request. Apparently this is not allowed when it is from a fork. * Revert "Only add tag if it is not a pull request. Apparently this is not allowed when it is from a fork." This reverts commit 92b33f3c Co-authored-by: Bjarke Berg <mail@bergmania.dk>
53 lines
1.7 KiB
C#
53 lines
1.7 KiB
C#
// Copyright (c) Umbraco.
|
|
// See LICENSE for more details.
|
|
|
|
using System;
|
|
using Umbraco.Cms.Core.Models.PublishedContent;
|
|
|
|
namespace Umbraco.Extensions
|
|
{
|
|
/// <summary>
|
|
/// Provides extension methods for <see cref="IPublishedModelFactory"/>.
|
|
/// </summary>
|
|
public static class PublishedModelFactoryExtensions
|
|
{
|
|
/// <summary>
|
|
/// Returns true if the current <see cref="IPublishedModelFactory"/> is an implementation of <see cref="ILivePublishedModelFactory2"/> 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 can't determine if it's enabled or not so return true
|
|
return true;
|
|
}
|
|
|
|
/// <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();
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|