fix(code-quality): resolve CS0628 warnings - change protected to private in sealed classes. (#21193)

* fix(code-quality): resolve CS0628 warnings - change protected to private in sealed classes

Changed protected members to private in sealed classes across 26 files. Protected members in sealed classes serve no purpose since sealed classes cannot be inherited. This eliminates 57 CS0628 compiler warnings.

* fix: use public for NUnit SetUp methods per Copilot review

NUnit requires SetUp methods to be at least protected. Using public
avoids CS0628 while allowing NUnit to discover and execute the methods.

* Clean up

- Renames internal fields to clearer names and aligns with conventions
- Changes internal cache holder to use auto-properties for state ( fixes another build warning )
- Removes an unused exception type from the loader and cleans up unused usings
- Adds "Umbraco" to the list of known spellings in .vsCode settings file, amazed this wasn't already there :)

* Improvements to fix CodeScene Code Health Review issues.

- Introduces debug-only logging helpers and routes all log messages through them for consistency
- Centralizes retrieval of discoverable types and scanning logic to simplify paths
- Aligns logging of cached vs non-cached and slow paths with new helpers
- Documents data-holding structure used to store type lists for clarity

* Refactoring to make CodeScene happy, removing code duplication :)
This commit is contained in:
Chris Houston
2025-12-18 19:28:13 +01:00
committed by GitHub
parent ebb6590bad
commit 0d4f24300a
27 changed files with 186 additions and 233 deletions
+1
View File
@@ -3,6 +3,7 @@
"backoffice",
"pickable",
"Pickable",
"Umbraco",
"unprovide",
"Unproviding"
],
+90 -156
View File
@@ -1,9 +1,6 @@
using System.Reflection;
using System.Runtime.Serialization;
using Microsoft.Extensions.Logging;
using Umbraco.Cms.Core.Cache;
using Umbraco.Cms.Core.Collections;
using Umbraco.Cms.Core.Logging;
using Umbraco.Extensions;
namespace Umbraco.Cms.Core.Composing;
@@ -20,13 +17,21 @@ namespace Umbraco.Cms.Core.Composing;
/// </remarks>
public sealed class TypeLoader
{
private readonly Lock _locko = new();
private readonly Lock _typesLock = new();
private readonly ILogger<TypeLoader> _logger;
private readonly Dictionary<CompositeTypeTypeKey, TypeList> _types = new();
private IEnumerable<Assembly>? _assemblies;
private bool IsDebugEnabled => _logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug);
/// <summary>
/// Initializes a new instance of the <see cref="TypeLoader"/> class.
/// </summary>
/// <param name="typeFinder">The type finder used to discover types.</param>
/// <param name="logger">The logger instance.</param>
/// <param name="assembliesToScan">Optional set of assemblies to scan.</param>
public TypeLoader(
ITypeFinder typeFinder,
ILogger<TypeLoader> logger,
@@ -105,10 +110,7 @@ public sealed class TypeLoader
/// <remarks>Caching is disabled when using specific assemblies.</remarks>
public IEnumerable<Type> GetTypes<T>(bool cache = true, IEnumerable<Assembly>? specificAssemblies = null)
{
if (_logger == null)
{
throw new InvalidOperationException("Cannot get types from a test/blank type loader.");
}
EnsureInitialized();
// do not cache anything from specific assemblies
cache &= specificAssemblies == null;
@@ -116,14 +118,11 @@ public sealed class TypeLoader
// if not IDiscoverable, directly get types
if (!typeof(IDiscoverable).IsAssignableFrom(typeof(T)))
{
// warn
if (_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
{
_logger.LogDebug(
"Running a full, " + (cache ? string.Empty : "non-") +
"cached, scan for non-discoverable type {TypeName} (slow).",
LogDebugIf(
true,
"Running a full, {CacheStatus}cached, scan for non-discoverable type {TypeName} (slow).",
CacheStatus(cache),
typeof(T).FullName);
}
return GetTypesInternal(
typeof(T),
@@ -134,23 +133,12 @@ public sealed class TypeLoader
}
// get IDiscoverable and always cache
IEnumerable<Type> discovered = GetTypesInternal(
typeof(IDiscoverable),
null,
() => TypeFinder.FindClassesOfType<IDiscoverable>(AssembliesToScan),
"scanning assemblies",
true);
IEnumerable<Type> discovered = GetDiscoverableTypes();
// warn
if (!cache)
{
if (_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
{
_logger.LogDebug(
"Running a non-cached, filter for discoverable type {TypeName} (slowish).",
typeof(T).FullName);
}
}
LogDebugIf(
!cache,
"Running a non-cached, filter for discoverable type {TypeName} (slowish).",
typeof(T).FullName);
// filter the cached discovered types (and maybe cache the result)
return GetTypesInternal(
@@ -175,10 +163,7 @@ public sealed class TypeLoader
IEnumerable<Assembly>? specificAssemblies = null)
where TAttribute : Attribute
{
if (_logger == null)
{
throw new InvalidOperationException("Cannot get types from a test/blank type loader.");
}
EnsureInitialized();
// do not cache anything from specific assemblies
cache &= specificAssemblies == null;
@@ -186,14 +171,12 @@ public sealed class TypeLoader
// if not IDiscoverable, directly get types
if (!typeof(IDiscoverable).IsAssignableFrom(typeof(T)))
{
if (_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
{
_logger.LogDebug(
"Running a full, " + (cache ? string.Empty : "non-") +
"cached, scan for non-discoverable type {TypeName} / attribute {AttributeName} (slow).",
LogDebugIf(
true,
"Running a full, {CacheStatus}cached, scan for non-discoverable type {TypeName} / attribute {AttributeName} (slow).",
CacheStatus(cache),
typeof(T).FullName,
typeof(TAttribute).FullName);
}
return GetTypesInternal(
typeof(T),
@@ -204,24 +187,13 @@ public sealed class TypeLoader
}
// get IDiscoverable and always cache
IEnumerable<Type> discovered = GetTypesInternal(
typeof(IDiscoverable),
null,
() => TypeFinder.FindClassesOfType<IDiscoverable>(AssembliesToScan),
"scanning assemblies",
true);
IEnumerable<Type> discovered = GetDiscoverableTypes();
// warn
if (!cache)
{
if (_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
{
_logger.LogDebug(
"Running a non-cached, filter for discoverable type {TypeName} / attribute {AttributeName} (slowish).",
typeof(T).FullName,
typeof(TAttribute).FullName);
}
}
LogDebugIf(
!cache,
"Running a non-cached, filter for discoverable type {TypeName} / attribute {AttributeName} (slowish).",
typeof(T).FullName,
typeof(TAttribute).FullName);
// filter the cached discovered types (and maybe cache the result)
return GetTypesInternal(
@@ -247,23 +219,15 @@ public sealed class TypeLoader
IEnumerable<Assembly>? specificAssemblies = null)
where TAttribute : Attribute
{
if (_logger == null)
{
throw new InvalidOperationException("Cannot get types from a test/blank type loader.");
}
EnsureInitialized();
// do not cache anything from specific assemblies
cache &= specificAssemblies == null;
if (!cache)
{
if (_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
{
_logger.LogDebug(
"Running a full, non-cached, scan for types / attribute {AttributeName} (slow).",
typeof(TAttribute).FullName);
}
}
LogDebugIf(
!cache,
"Running a full, non-cached, scan for types / attribute {AttributeName} (slow).",
typeof(TAttribute).FullName);
return GetTypesInternal(
typeof(object),
@@ -280,6 +244,38 @@ public sealed class TypeLoader
return s;
}
private void EnsureInitialized()
{
if (_logger == null)
{
throw new InvalidOperationException("Cannot get types from a test/blank type loader.");
}
}
private IEnumerable<Type> GetDiscoverableTypes() =>
GetTypesInternal(
typeof(IDiscoverable),
null,
() => TypeFinder.FindClassesOfType<IDiscoverable>(AssembliesToScan),
"scanning assemblies",
true);
/// <summary>
/// Logs a debug message if the specified condition is true and debug logging is enabled.
/// </summary>
/// <param name="condition">The condition that must be true to log.</param>
/// <param name="message">The log message template.</param>
/// <param name="args">The message arguments.</param>
private void LogDebugIf(bool condition, string message, params object?[] args)
{
if (condition && IsDebugEnabled)
{
_logger.LogDebug(message, args);
}
}
private string CacheStatus(bool cache) => cache ? string.Empty : "non-";
private IEnumerable<Type> GetTypesInternal(
Type baseType,
Type? attributeType,
@@ -291,7 +287,7 @@ public sealed class TypeLoader
// lock at a time, and we don't have non-upgradeable readers, and quite probably the type
// loader is mostly not going to be used in any kind of massively multi-threaded scenario - so,
// a plain lock is enough
lock (_locko)
lock (_typesLock)
{
return GetTypesInternalLocked(baseType, attributeType, finder, action, cache);
}
@@ -305,34 +301,21 @@ public sealed class TypeLoader
bool cache)
{
// check if the TypeList already exists, if so return it, if not we'll create it
Type tobject = typeof(object); // CompositeTypeTypeKey does not support null values
var listKey = new CompositeTypeTypeKey(baseType ?? tobject, attributeType ?? tobject);
TypeList? typeList = null;
Type objectType = typeof(object); // CompositeTypeTypeKey does not support null values
var listKey = new CompositeTypeTypeKey(baseType ?? objectType, attributeType ?? objectType);
if (cache)
// need to put some logging here to try to figure out why this is happening: http://issues.umbraco.org/issue/U4-3505
if (cache && _types.TryGetValue(listKey, out TypeList? cachedList))
{
_types.TryGetValue(listKey, out typeList); // else null
LogDebugIf(true, "Getting {TypeName}: found a cached type list.", GetName(baseType, attributeType));
return cachedList.Types;
}
// if caching and found, return
if (typeList != null)
{
// need to put some logging here to try to figure out why this is happening: http://issues.umbraco.org/issue/U4-3505
if (_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
{
_logger.LogDebug("Getting {TypeName}: found a cached type list.", GetName(baseType, attributeType));
}
return typeList.Types;
}
// else proceed,
typeList = new TypeList(baseType, attributeType);
// else proceed
var typeList = new TypeList(baseType, attributeType);
// either we had to scan, or we could not get the types from the cache file - scan now
if (_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
{
_logger.LogDebug("Getting {TypeName}: " + action + ".", GetName(baseType, attributeType));
}
LogDebugIf(true, "Getting {TypeName}: " + action + ".", GetName(baseType, attributeType));
foreach (Type t in finder())
{
@@ -343,17 +326,11 @@ public sealed class TypeLoader
if (cache)
{
var added = _types.TryAdd(listKey, typeList);
if (_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
{
_logger.LogDebug("Got {TypeName}, caching ({CacheType}).", GetName(baseType, attributeType), added.ToString().ToLowerInvariant());
}
LogDebugIf(true, "Got {TypeName}, caching ({CacheType}).", GetName(baseType, attributeType), added.ToString().ToLowerInvariant());
}
else
{
if (_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
{
_logger.LogDebug("Got {TypeName}.", GetName(baseType, attributeType));
}
LogDebugIf(true, "Got {TypeName}.", GetName(baseType, attributeType));
}
return typeList.Types;
@@ -371,14 +348,25 @@ public sealed class TypeLoader
{
private readonly HashSet<Type> _types = new();
/// <summary>
/// Initializes a new instance of the <see cref="TypeList"/> class.
/// </summary>
/// <param name="baseType">The base type to filter by.</param>
/// <param name="attributeType">The attribute type to filter by.</param>
public TypeList(Type? baseType, Type? attributeType)
{
BaseType = baseType;
AttributeType = attributeType;
}
/// <summary>
/// Gets the base type used for filtering.
/// </summary>
public Type? BaseType { get; }
/// <summary>
/// Gets the attribute type used for filtering.
/// </summary>
public Type? AttributeType { get; }
/// <summary>
@@ -402,59 +390,5 @@ public sealed class TypeLoader
}
}
/// <summary>
/// Represents the error that occurs when a type was not found in the cache type list with the specified
/// TypeResolutionKind.
/// </summary>
/// <seealso cref="System.Exception" />
[Serializable]
internal sealed class CachedTypeNotFoundInFileException : Exception
{
/// <summary>
/// Initializes a new instance of the <see cref="CachedTypeNotFoundInFileException" /> class.
/// </summary>
public CachedTypeNotFoundInFileException()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="CachedTypeNotFoundInFileException" /> class.
/// </summary>
/// <param name="message">The message that describes the error.</param>
public CachedTypeNotFoundInFileException(string message)
: base(message)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="CachedTypeNotFoundInFileException" /> class.
/// </summary>
/// <param name="message">The error message that explains the reason for the exception.</param>
/// <param name="innerException">
/// The exception that is the cause of the current exception, or a null reference (
/// <see langword="Nothing" /> in Visual Basic) if no inner exception is specified.
/// </param>
public CachedTypeNotFoundInFileException(string message, Exception innerException)
: base(message, innerException)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="CachedTypeNotFoundInFileException" /> class.
/// </summary>
/// <param name="info">
/// The <see cref="T:System.Runtime.Serialization.SerializationInfo" /> that holds the serialized object
/// data about the exception being thrown.
/// </param>
/// <param name="context">
/// The <see cref="T:System.Runtime.Serialization.StreamingContext" /> that contains contextual
/// information about the source or destination.
/// </param>
protected CachedTypeNotFoundInFileException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
#endregion
}
+1 -1
View File
@@ -44,7 +44,7 @@ public class LogProfiler : IProfiler
private readonly Action<long> _callback;
private readonly Stopwatch _stopwatch = Stopwatch.StartNew();
protected internal LightDisposableTimer(Action<long> callback)
internal LightDisposableTimer(Action<long> callback)
{
_callback = callback ?? throw new ArgumentNullException(nameof(callback));
}
@@ -4,18 +4,21 @@ using Umbraco.Extensions;
namespace Umbraco.Cms.Core.PublishedCache;
/// <summary>
/// Represents a property of a published element with caching support for property value conversions.
/// </summary>
internal sealed class PublishedElementPropertyBase : PublishedPropertyBase
{
protected readonly IPublishedElement Element;
private readonly IPublishedElement _element;
// define constant - determines whether to use cache when previewing
// to store eg routes, property converted values, anything - caching
// means faster execution, but uses memory - not sure if we want it
// so making it configurable.
private readonly Lock _locko = new();
private readonly Lock _cacheLock = new();
private readonly object? _sourceValue;
protected readonly bool IsMember;
protected readonly bool IsPreviewing;
private readonly bool _isMember;
private readonly bool _isPreviewing;
private readonly VariationContext _variationContext;
private readonly ICacheManager? _cacheManager;
private CacheValues? _cacheValues;
@@ -24,6 +27,16 @@ internal sealed class PublishedElementPropertyBase : PublishedPropertyBase
private object? _interValue;
private string? _valuesCacheKey;
/// <summary>
/// Initializes a new instance of the <see cref="PublishedElementPropertyBase"/> class.
/// </summary>
/// <param name="propertyType">The published property type.</param>
/// <param name="element">The published element that owns this property.</param>
/// <param name="previewing">Whether this is a preview request.</param>
/// <param name="referenceCacheLevel">The reference cache level.</param>
/// <param name="variationContext">The variation context for culture and segment.</param>
/// <param name="cacheManager">The cache manager.</param>
/// <param name="sourceValue">The source value of the property.</param>
public PublishedElementPropertyBase(
IPublishedPropertyType propertyType,
IPublishedElement element,
@@ -35,11 +48,11 @@ internal sealed class PublishedElementPropertyBase : PublishedPropertyBase
: base(propertyType, referenceCacheLevel)
{
_sourceValue = sourceValue;
Element = element;
IsPreviewing = previewing;
_element = element;
_isPreviewing = previewing;
_variationContext = variationContext;
_cacheManager = cacheManager;
IsMember = propertyType.ContentType?.ItemType == PublishedItemType.Member;
_isMember = propertyType.ContentType?.ItemType == PublishedItemType.Member;
}
// used to cache the CacheValues of this property
@@ -47,9 +60,11 @@ internal sealed class PublishedElementPropertyBase : PublishedPropertyBase
private string ValuesCacheKey => _valuesCacheKey ??= PropertyCacheValuesKey();
private string PropertyCacheValuesKey() =>
$"PublishedSnapshot.Property.CacheValues[{(IsPreviewing ? "D:" : "P:")}{Element.Key}:{Alias}:{_variationContext.Culture.IfNullOrWhiteSpace("inv")}+{_variationContext.Segment.IfNullOrWhiteSpace("inv")}]";
$"PublishedSnapshot.Property.CacheValues[{(_isPreviewing ? "D:" : "P:")}{_element.Key}:{Alias}:{_variationContext.Culture.IfNullOrWhiteSpace("inv")}+{_variationContext.Segment.IfNullOrWhiteSpace("inv")}]";
// ReSharper restore InconsistentlySynchronizedField
/// <inheritdoc />
public override bool HasValue(string? culture = null, string? segment = null)
{
var hasValue = PropertyType.IsValue(_sourceValue, PropertyValueLevel.Source);
@@ -60,7 +75,7 @@ internal sealed class PublishedElementPropertyBase : PublishedPropertyBase
GetCacheLevels(out PropertyCacheLevel cacheLevel, out PropertyCacheLevel referenceCacheLevel);
lock (_locko)
lock (_cacheLock)
{
var value = GetInterValue();
hasValue = PropertyType.IsValue(value, PropertyValueLevel.Inter);
@@ -73,7 +88,7 @@ internal sealed class PublishedElementPropertyBase : PublishedPropertyBase
if (!cacheValues.ObjectInitialized)
{
cacheValues.ObjectValue =
PropertyType.ConvertInterToObject(Element, referenceCacheLevel, value, IsPreviewing);
PropertyType.ConvertInterToObject(_element, referenceCacheLevel, value, _isPreviewing);
cacheValues.ObjectInitialized = true;
}
@@ -82,6 +97,7 @@ internal sealed class PublishedElementPropertyBase : PublishedPropertyBase
}
}
/// <inheritdoc />
public override object? GetSourceValue(string? culture = null, string? segment = null) => _sourceValue;
private void GetCacheLevels(out PropertyCacheLevel cacheLevel, out PropertyCacheLevel referenceCacheLevel)
@@ -151,16 +167,17 @@ internal sealed class PublishedElementPropertyBase : PublishedPropertyBase
return _interValue;
}
_interValue = PropertyType.ConvertSourceToInter(Element, _sourceValue, IsPreviewing);
_interValue = PropertyType.ConvertSourceToInter(_element, _sourceValue, _isPreviewing);
_interInitialized = true;
return _interValue;
}
/// <inheritdoc />
public override object? GetValue(string? culture = null, string? segment = null)
{
GetCacheLevels(out PropertyCacheLevel cacheLevel, out PropertyCacheLevel referenceCacheLevel);
lock (_locko)
lock (_cacheLock)
{
CacheValues cacheValues = GetCacheValues(cacheLevel);
if (cacheValues.ObjectInitialized)
@@ -169,12 +186,13 @@ internal sealed class PublishedElementPropertyBase : PublishedPropertyBase
}
cacheValues.ObjectValue =
PropertyType.ConvertInterToObject(Element, referenceCacheLevel, GetInterValue(), IsPreviewing);
PropertyType.ConvertInterToObject(_element, referenceCacheLevel, GetInterValue(), _isPreviewing);
cacheValues.ObjectInitialized = true;
return cacheValues.ObjectValue;
}
}
/// <inheritdoc />
public override object? GetDeliveryApiValue(bool expanding, string? culture = null, string? segment = null)
{
PropertyCacheLevel cacheLevel, referenceCacheLevel;
@@ -187,11 +205,11 @@ internal sealed class PublishedElementPropertyBase : PublishedPropertyBase
GetDeliveryApiCacheLevels(out cacheLevel, out referenceCacheLevel);
}
lock (_locko)
lock (_cacheLock)
{
CacheValues cacheValues = GetCacheValues(cacheLevel);
object? GetDeliveryApiObject() => PropertyType.ConvertInterToDeliveryApiObject(Element, referenceCacheLevel, GetInterValue(), IsPreviewing, expanding);
object? GetDeliveryApiObject() => PropertyType.ConvertInterToDeliveryApiObject(_element, referenceCacheLevel, GetInterValue(), _isPreviewing, expanding);
return expanding
? GetDeliveryApiExpandedObject(cacheValues, GetDeliveryApiObject)
: GetDeliveryApiDefaultObject(cacheValues, GetDeliveryApiObject);
@@ -220,15 +238,15 @@ internal sealed class PublishedElementPropertyBase : PublishedPropertyBase
return cacheValues.DeliveryApiExpandedObjectValue;
}
protected class CacheValues
private class CacheValues
{
public bool ObjectInitialized;
public object? ObjectValue;
public bool XPathInitialized;
public object? XPathValue;
public bool DeliveryApiDefaultObjectInitialized;
public object? DeliveryApiDefaultObjectValue;
public bool DeliveryApiExpandedObjectInitialized;
public object? DeliveryApiExpandedObjectValue;
public bool ObjectInitialized { get; set; }
public object? ObjectValue { get; set; }
public bool XPathInitialized { get; set; }
public object? XPathValue { get; set; }
public bool DeliveryApiDefaultObjectInitialized { get; set; }
public object? DeliveryApiDefaultObjectValue { get; set; }
public bool DeliveryApiExpandedObjectInitialized { get; set; }
public object? DeliveryApiExpandedObjectValue { get; set; }
}
}
@@ -25,7 +25,7 @@ namespace Umbraco.Cms.Core.Cache;
internal sealed class FullDataSetRepositoryCachePolicy<TEntity, TId> : RepositoryCachePolicyBase<TEntity, TId>
where TEntity : class, IEntity
{
protected static readonly TId[] EmptyIds = new TId[0]; // const
private static readonly TId[] EmptyIds = new TId[0]; // const
private readonly Func<TEntity, TId> _entityGetId;
private readonly bool _expires;
@@ -54,9 +54,9 @@ internal sealed class FullDataSetRepositoryCachePolicy<TEntity, TId> : Repositor
}
}
protected string GetEntityTypeCacheKey() => RepositoryCacheKeys.GetKey<TEntity>();
private string GetEntityTypeCacheKey() => RepositoryCacheKeys.GetKey<TEntity>();
protected void InsertEntities(TEntity[]? entities)
private void InsertEntities(TEntity[]? entities)
{
if (entities is null)
{
@@ -1,4 +1,4 @@
using NPoco;
using NPoco;
using Umbraco.Cms.Core;
using Umbraco.Cms.Infrastructure.Persistence.DatabaseAnnotations;
using Umbraco.Extensions;
@@ -122,7 +122,7 @@ internal sealed class PropertyDataDto
PropertyTypeDto = PropertyTypeDto,
};
protected bool Equals(PropertyDataDto other) => Id == other.Id;
private bool Equals(PropertyDataDto other) => Id == other.Id;
public override bool Equals(object? other) =>
!ReferenceEquals(null, other) // other is not null
@@ -160,7 +160,7 @@ internal sealed class ContentTypeRepository : ContentTypeRepositoryBase<IContent
: Enumerable.Empty<IContentType>();
}
protected IEnumerable<int> PerformGetByQuery(IQuery<PropertyType> query)
private IEnumerable<int> PerformGetByQuery(IQuery<PropertyType> query)
{
// used by DataTypeService to remove properties
// from content types if they have a deleted data type - see
@@ -272,7 +272,7 @@ internal sealed class ContentTypeRepository : ContentTypeRepositoryBase<IContent
entity.ResetDirtyProperties();
}
protected void PersistTemplates(IContentType entity, bool clearAll)
private void PersistTemplates(IContentType entity, bool clearAll)
{
// remove and insert, if required
Sql<ISqlContext> sql = Sql()
@@ -55,7 +55,7 @@ internal sealed class DataTypeRepository : EntityRepositoryBase<int, IDataType>,
_dataTypeLogger = loggerFactory.CreateLogger<IDataType>();
}
protected Guid NodeObjectTypeId => Constants.ObjectTypes.DataType;
private Guid NodeObjectTypeId => Constants.ObjectTypes.DataType;
public IDataType? Get(Guid key) => GetMany().FirstOrDefault(x => x.Key == key);
@@ -194,7 +194,7 @@ internal sealed class DomainRepository : EntityRepositoryBase<int, IDomain>, IDo
entity.ResetDirtyProperties();
}
protected int GetNewSortOrder(int? rootContentId, bool isWildcard)
private int GetNewSortOrder(int? rootContentId, bool isWildcard)
=> isWildcard
? -1
: Database.ExecuteScalar<int>(
@@ -624,7 +624,7 @@ internal sealed class EntityRepository : RepositoryBase, IEntityRepositoryExtend
#region Sql
protected Sql<ISqlContext> GetVariantInfos(IEnumerable<int> ids) =>
private Sql<ISqlContext> GetVariantInfos(IEnumerable<int> ids) =>
Sql()
.Select<NodeDto>(x => x.NodeId)
.AndSelect<LanguageDto>(x => x.IsoCode)
@@ -659,7 +659,7 @@ internal sealed class EntityRepository : RepositoryBase, IEntityRepositoryExtend
.OrderBy<LanguageDto>(x => x.Id);
// gets the full sql for a given object type and a given unique id
protected Sql<ISqlContext> GetFullSqlForEntityType(bool isContent, bool isMedia, bool isMember, Guid objectType,
private Sql<ISqlContext> GetFullSqlForEntityType(bool isContent, bool isMedia, bool isMember, Guid objectType,
Guid uniqueId)
{
Sql<ISqlContext> sql = GetBaseWhere(isContent, isMedia, isMember, false, objectType, uniqueId);
@@ -667,7 +667,7 @@ internal sealed class EntityRepository : RepositoryBase, IEntityRepositoryExtend
}
// gets the full sql for a given object type and a given node id
protected Sql<ISqlContext> GetFullSqlForEntityType(bool isContent, bool isMedia, bool isMember, Guid objectType,
private Sql<ISqlContext> GetFullSqlForEntityType(bool isContent, bool isMedia, bool isMember, Guid objectType,
int nodeId)
{
Sql<ISqlContext> sql = GetBaseWhere(isContent, isMedia, isMember, false, objectType, nodeId);
@@ -675,14 +675,14 @@ internal sealed class EntityRepository : RepositoryBase, IEntityRepositoryExtend
}
// gets the full sql for a given object type, with a given filter
protected Sql<ISqlContext> GetFullSqlForEntityType(bool isContent, bool isMedia, bool isMember, Guid objectType,
private Sql<ISqlContext> GetFullSqlForEntityType(bool isContent, bool isMedia, bool isMember, Guid objectType,
Action<Sql<ISqlContext>>? filter)
{
Sql<ISqlContext> sql = GetBaseWhere(isContent, isMedia, isMember, false, filter, new[] { objectType });
return AddGroupBy(isContent, isMedia, isMember, sql, true);
}
protected Sql<ISqlContext> GetFullSqlForEntityType(
private Sql<ISqlContext> GetFullSqlForEntityType(
bool isContent,
bool isMedia,
bool isMember,
@@ -691,7 +691,7 @@ internal sealed class EntityRepository : RepositoryBase, IEntityRepositoryExtend
Action<Sql<ISqlContext>>? filter)
=> GetFullSqlForEntityType(isContent, isMedia, isMember, [objectType], ordering, filter);
protected Sql<ISqlContext> GetFullSqlForEntityType(
private Sql<ISqlContext> GetFullSqlForEntityType(
bool isContent,
bool isMedia,
bool isMember,
@@ -706,12 +706,12 @@ internal sealed class EntityRepository : RepositoryBase, IEntityRepositoryExtend
return sql;
}
protected Sql<ISqlContext> GetBase(bool isContent, bool isMedia, bool isMember, Action<Sql<ISqlContext>>? filter, bool isCount = false)
private Sql<ISqlContext> GetBase(bool isContent, bool isMedia, bool isMember, Action<Sql<ISqlContext>>? filter, bool isCount = false)
=> GetBase(isContent, isMedia, isMember, filter, [], isCount);
// gets the base SELECT + FROM [+ filter] sql
// always from the 'current' content version
protected Sql<ISqlContext> GetBase(bool isContent, bool isMedia, bool isMember, Action<Sql<ISqlContext>>? filter, Guid[] objectTypes, bool isCount = false)
private Sql<ISqlContext> GetBase(bool isContent, bool isMedia, bool isMember, Action<Sql<ISqlContext>>? filter, Guid[] objectTypes, bool isCount = false)
{
Sql<ISqlContext> sql = Sql();
ISqlSyntaxProvider syntax = SqlContext.SqlSyntax;
@@ -810,7 +810,7 @@ internal sealed class EntityRepository : RepositoryBase, IEntityRepositoryExtend
// gets the base SELECT + FROM [+ filter] + WHERE sql
// for a given object type, with a given filter
protected Sql<ISqlContext> GetBaseWhere(bool isContent, bool isMedia, bool isMember, bool isCount,
private Sql<ISqlContext> GetBaseWhere(bool isContent, bool isMedia, bool isMember, bool isCount,
Action<Sql<ISqlContext>>? filter, Guid[] objectTypes)
{
Sql<ISqlContext> sql = GetBase(isContent, isMedia, isMember, filter, objectTypes, isCount);
@@ -824,7 +824,7 @@ internal sealed class EntityRepository : RepositoryBase, IEntityRepositoryExtend
// gets the base SELECT + FROM + WHERE sql
// for a given node id
protected Sql<ISqlContext> GetBaseWhere(bool isContent, bool isMedia, bool isMember, bool isCount, int id)
private Sql<ISqlContext> GetBaseWhere(bool isContent, bool isMedia, bool isMember, bool isCount, int id)
{
Sql<ISqlContext> sql = GetBase(isContent, isMedia, isMember, null, isCount)
.Where<NodeDto>(x => x.NodeId == id);
@@ -833,7 +833,7 @@ internal sealed class EntityRepository : RepositoryBase, IEntityRepositoryExtend
// gets the base SELECT + FROM + WHERE sql
// for a given unique id
protected Sql<ISqlContext> GetBaseWhere(bool isContent, bool isMedia, bool isMember, bool isCount, Guid uniqueId)
private Sql<ISqlContext> GetBaseWhere(bool isContent, bool isMedia, bool isMember, bool isCount, Guid uniqueId)
{
Sql<ISqlContext> sql = GetBase(isContent, isMedia, isMember, null, isCount)
.Where<NodeDto>(x => x.UniqueId == uniqueId);
@@ -842,21 +842,21 @@ internal sealed class EntityRepository : RepositoryBase, IEntityRepositoryExtend
// gets the base SELECT + FROM + WHERE sql
// for a given object type and node id
protected Sql<ISqlContext> GetBaseWhere(bool isContent, bool isMedia, bool isMember, bool isCount, Guid objectType,
private Sql<ISqlContext> GetBaseWhere(bool isContent, bool isMedia, bool isMember, bool isCount, Guid objectType,
int nodeId) =>
GetBase(isContent, isMedia, isMember, null, isCount)
.Where<NodeDto>(x => x.NodeId == nodeId && x.NodeObjectType == objectType);
// gets the base SELECT + FROM + WHERE sql
// for a given object type and unique id
protected Sql<ISqlContext> GetBaseWhere(bool isContent, bool isMedia, bool isMember, bool isCount, Guid objectType,
private Sql<ISqlContext> GetBaseWhere(bool isContent, bool isMedia, bool isMember, bool isCount, Guid objectType,
Guid uniqueId) =>
GetBase(isContent, isMedia, isMember, null, isCount)
.Where<NodeDto>(x => x.UniqueId == uniqueId && x.NodeObjectType == objectType);
// gets the GROUP BY / ORDER BY sql
// required in order to count children
protected Sql<ISqlContext> AddGroupBy(bool isContent, bool isMedia, bool isMember, Sql<ISqlContext> sql,
private Sql<ISqlContext> AddGroupBy(bool isContent, bool isMedia, bool isMember, Sql<ISqlContext> sql,
bool defaultSort)
{
sql
@@ -139,7 +139,7 @@ internal sealed class LanguageRepository : EntityRepositoryBase<int, ILanguage>,
protected override IRepositoryCachePolicy<ILanguage, int> CreateCachePolicy() =>
new FullDataSetRepositoryCachePolicy<ILanguage, int>(GlobalIsolatedCache, ScopeAccessor, RepositoryCacheVersionService, CacheSyncService, GetEntityId, /*expires:*/ false);
protected ILanguage ConvertFromDto(LanguageDto dto)
private ILanguage ConvertFromDto(LanguageDto dto)
{
lock (_codeIdMap)
{
@@ -34,7 +34,7 @@ internal sealed class MemberGroupRepository : EntityRepositoryBase<int, IMemberG
cacheSyncService) =>
_eventMessagesFactory = eventMessagesFactory;
protected Guid NodeObjectTypeId => Constants.ObjectTypes.MemberGroup;
private Guid NodeObjectTypeId => Constants.ObjectTypes.MemberGroup;
public IMemberGroup? Get(Guid uniqueId)
{
@@ -123,7 +123,7 @@ internal sealed class MemberTypeRepository : ContentTypeRepositoryBase<IMemberTy
return sql;
}
protected Sql<ISqlContext> GetSubquery()
private Sql<ISqlContext> GetSubquery()
{
Sql<ISqlContext> sql = Sql()
.Select($"DISTINCT({QuoteTableName("umbracoNode")}.id)")
@@ -13,7 +13,7 @@ internal sealed class PartialViewRepository : FileRepository<string, IPartialVie
{
}
protected PartialViewRepository(IFileSystem? fileSystem)
private PartialViewRepository(IFileSystem? fileSystem)
: base(fileSystem)
{
}
@@ -401,7 +401,7 @@ internal sealed class TemplateRepository : EntityRepositoryBase<int, ITemplate>,
return list;
}
protected Guid NodeObjectTypeId => Constants.ObjectTypes.Template;
private Guid NodeObjectTypeId => Constants.ObjectTypes.Template;
protected override void PersistNewItem(ITemplate entity)
{
@@ -48,7 +48,7 @@ internal sealed class PublishedRequestFilterAttribute : ResultFilterAttribute
/// <summary>
/// Gets the <see cref="UmbracoRouteValues" />
/// </summary>
protected static UmbracoRouteValues GetUmbracoRouteValues(ResultExecutingContext context)
private static UmbracoRouteValues GetUmbracoRouteValues(ResultExecutingContext context)
{
UmbracoRouteValues? routeVals = context.HttpContext.Features.Get<UmbracoRouteValues>();
if (routeVals == null)
@@ -21,11 +21,11 @@ internal sealed class DocumentUrlServiceTests : UmbracoIntegrationTestWithConten
private const string SubSubPage2Key = "48AE405E-5142-4EBE-929F-55EB616F51F2";
private const string SubSubPage3Key = "AACF2979-3F53-4184-B071-BA34D3338497";
protected IDocumentUrlService DocumentUrlService => GetRequiredService<IDocumentUrlService>();
private IDocumentUrlService DocumentUrlService => GetRequiredService<IDocumentUrlService>();
protected ILanguageService LanguageService => GetRequiredService<ILanguageService>();
private ILanguageService LanguageService => GetRequiredService<ILanguageService>();
protected IDomainService DomainService => GetRequiredService<IDomainService>();
private IDomainService DomainService => GetRequiredService<IDomainService>();
protected override void CustomTestSetup(IUmbracoBuilder builder)
{
@@ -17,8 +17,8 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Core.Services;
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest, Logger = UmbracoTestOptions.Logger.Console)]
internal sealed class DocumentUrlServiceTests_HideTopLevel_False : UmbracoIntegrationTestWithContent
{
protected IDocumentUrlService DocumentUrlService => GetRequiredService<IDocumentUrlService>();
protected ILanguageService LanguageService => GetRequiredService<ILanguageService>();
private IDocumentUrlService DocumentUrlService => GetRequiredService<IDocumentUrlService>();
private ILanguageService LanguageService => GetRequiredService<ILanguageService>();
protected override void CustomTestSetup(IUmbracoBuilder builder)
{
@@ -37,11 +37,11 @@ internal sealed class DynamicRootServiceTests : UmbracoIntegrationTest
FurthestDescendantOrSelf,
}
protected IContentTypeService ContentTypeService => GetRequiredService<IContentTypeService>();
private IContentTypeService ContentTypeService => GetRequiredService<IContentTypeService>();
protected IFileService FileService => GetRequiredService<IFileService>();
private IFileService FileService => GetRequiredService<IFileService>();
protected ContentService ContentService => (ContentService)GetRequiredService<IContentService>();
private ContentService ContentService => (ContentService)GetRequiredService<IContentService>();
private DynamicRootService DynamicRootService => (GetRequiredService<IDynamicRootService>() as DynamicRootService)!;
@@ -14,13 +14,13 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Core.Services;
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
internal sealed class MediaEditingServiceTests : UmbracoIntegrationTest
{
protected IMediaTypeService MediaTypeService => GetRequiredService<IMediaTypeService>();
private IMediaTypeService MediaTypeService => GetRequiredService<IMediaTypeService>();
protected IMediaEditingService MediaEditingService => GetRequiredService<IMediaEditingService>();
private IMediaEditingService MediaEditingService => GetRequiredService<IMediaEditingService>();
protected IMediaType ImageMediaType { get; set; }
private IMediaType ImageMediaType { get; set; }
protected IMediaType ArticleMediaType { get; set; }
private IMediaType ArticleMediaType { get; set; }
[SetUp]
public async Task Setup()
@@ -21,7 +21,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence;
internal sealed class LocksTests : UmbracoIntegrationTest
{
[SetUp]
protected void SetUp()
public void SetUp()
{
// create a few lock objects
using (var scope = ScopeProvider.CreateScope())
@@ -13,7 +13,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.NPoco
internal sealed class NPocoFetchTests : UmbracoIntegrationTest
{
[SetUp]
protected void SeedDatabase()
public void SeedDatabase()
{
using (var scope = ScopeProvider.CreateScope())
{
@@ -342,7 +342,7 @@ internal sealed class ScriptRepositoryTest : UmbracoIntegrationTest
}
}
protected Stream CreateStream(string contents = null)
private Stream CreateStream(string contents = null)
{
if (string.IsNullOrEmpty(contents))
{
@@ -362,7 +362,7 @@ internal sealed class StylesheetRepositoryTest : UmbracoIntegrationTest
}
}
protected Stream CreateStream(string contents = null)
private Stream CreateStream(string contents = null)
{
if (string.IsNullOrEmpty(contents))
{
@@ -568,7 +568,7 @@ internal sealed class TemplateRepositoryTest : UmbracoIntegrationTest
}
}
protected Stream CreateStream(string contents = null)
private Stream CreateStream(string contents = null)
{
if (string.IsNullOrEmpty(contents))
{
@@ -28,15 +28,15 @@ internal sealed class ContentServicePerformanceTest : UmbracoIntegrationTest
[SetUp]
public void SetUpData() => CreateTestData();
protected DocumentRepository DocumentRepository => (DocumentRepository)GetRequiredService<IDocumentRepository>();
private DocumentRepository DocumentRepository => (DocumentRepository)GetRequiredService<IDocumentRepository>();
protected IFileService FileService => GetRequiredService<IFileService>();
private IFileService FileService => GetRequiredService<IFileService>();
protected IContentTypeService ContentTypeService => GetRequiredService<IContentTypeService>();
private IContentTypeService ContentTypeService => GetRequiredService<IContentTypeService>();
protected IContentService ContentService => GetRequiredService<IContentService>();
private IContentService ContentService => GetRequiredService<IContentService>();
protected IContentType ContentType { get; set; }
private IContentType ContentType { get; set; }
[Test]
public void Profiler() => Assert.IsInstanceOf<TestProfiler>(GetRequiredService<IProfiler>());
@@ -32,7 +32,7 @@ internal sealed class EFCoreLockTests : UmbracoIntegrationTest
}
[SetUp]
protected async Task SetUp()
public async Task SetUp()
{
// create a few lock objects
using var scope = EFScopeProvider.CreateScope();