diff --git a/src/Umbraco.Core/Collections/CompositeStringStringKey.cs b/src/Umbraco.Core/Collections/CompositeStringStringKey.cs
index b0b7ca2b7b..01f94bf149 100644
--- a/src/Umbraco.Core/Collections/CompositeStringStringKey.cs
+++ b/src/Umbraco.Core/Collections/CompositeStringStringKey.cs
@@ -17,7 +17,7 @@ namespace Umbraco.Cms.Core.Collections
///
/// Initializes a new instance of the struct.
///
- public CompositeStringStringKey(string key1, string key2)
+ public CompositeStringStringKey(string? key1, string? key2)
{
_key1 = key1?.ToLowerInvariant() ?? throw new ArgumentNullException(nameof(key1));
_key2 = key2?.ToLowerInvariant() ?? throw new ArgumentNullException(nameof(key2));
diff --git a/src/Umbraco.Core/Extensions/EnumerableExtensions.cs b/src/Umbraco.Core/Extensions/EnumerableExtensions.cs
index 5f5598f226..ba420003e5 100644
--- a/src/Umbraco.Core/Extensions/EnumerableExtensions.cs
+++ b/src/Umbraco.Core/Extensions/EnumerableExtensions.cs
@@ -13,7 +13,7 @@ namespace Umbraco.Extensions
///
public static class EnumerableExtensions
{
- public static bool IsCollectionEmpty(this IReadOnlyCollection list) => list == null || list.Count == 0;
+ public static bool IsCollectionEmpty(this IReadOnlyCollection? list) => list == null || list.Count == 0;
internal static bool HasDuplicates(this IEnumerable items, bool includeNull)
{
diff --git a/src/Umbraco.Core/Extensions/PublishedContentExtensions.cs b/src/Umbraco.Core/Extensions/PublishedContentExtensions.cs
index 63dfd5b884..280f25ad23 100644
--- a/src/Umbraco.Core/Extensions/PublishedContentExtensions.cs
+++ b/src/Umbraco.Core/Extensions/PublishedContentExtensions.cs
@@ -25,7 +25,7 @@ namespace Umbraco.Extensions
/// The content item.
///
/// The specific culture to get the name for. If null is used the current culture is used (Default is null).
- public static string? Name(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string? culture = null)
+ public static string? Name(this IPublishedContent content, IVariationContextAccessor? variationContextAccessor, string? culture = null)
{
if (content == null)
{
@@ -54,7 +54,7 @@ namespace Umbraco.Extensions
/// The content item.
///
/// The specific culture to get the URL segment for. If null is used the current culture is used (Default is null).
- public static string? UrlSegment(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string? culture = null)
+ public static string? UrlSegment(this IPublishedContent content, IVariationContextAccessor? variationContextAccessor, string? culture = null)
{
if (content == null)
{
@@ -927,7 +927,7 @@ namespace Umbraco.Extensions
/// However, if an empty string is specified only invariant children are returned.
///
///
- public static IEnumerable? Children(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string? culture = null)
+ public static IEnumerable? Children(this IPublishedContent content, IVariationContextAccessor? variationContextAccessor, string? culture = null)
{
// handle context culture for variant
if (culture == null)
@@ -1106,7 +1106,7 @@ namespace Umbraco.Extensions
{
return content.Parent != null
? content.Parent.Children(variationContextAccessor, culture)
- : publishedSnapshot?.Content.GetAtRoot().WhereIsInvariantOrHasCulture(variationContextAccessor, culture);
+ : publishedSnapshot?.Content?.GetAtRoot().WhereIsInvariantOrHasCulture(variationContextAccessor, culture);
}
///
@@ -1122,7 +1122,7 @@ namespace Umbraco.Extensions
{
return content.Parent != null
? content.Parent.ChildrenOfType(variationContextAccessor, contentTypeAlias, culture)
- : publishedSnapshot?.Content.GetAtRoot().OfTypes(contentTypeAlias).WhereIsInvariantOrHasCulture(variationContextAccessor, culture);
+ : publishedSnapshot?.Content?.GetAtRoot().OfTypes(contentTypeAlias).WhereIsInvariantOrHasCulture(variationContextAccessor, culture);
}
///
@@ -1139,7 +1139,7 @@ namespace Umbraco.Extensions
{
return content.Parent != null
? content.Parent.Children(variationContextAccessor, culture)
- : publishedSnapshot?.Content.GetAtRoot().OfType().WhereIsInvariantOrHasCulture(variationContextAccessor, culture);
+ : publishedSnapshot?.Content?.GetAtRoot().OfType().WhereIsInvariantOrHasCulture(variationContextAccessor, culture);
}
#endregion
diff --git a/src/Umbraco.Core/Extensions/PublishedSnapshotAccessorExtensions.cs b/src/Umbraco.Core/Extensions/PublishedSnapshotAccessorExtensions.cs
index fa7e4555e6..9fd7da4640 100644
--- a/src/Umbraco.Core/Extensions/PublishedSnapshotAccessorExtensions.cs
+++ b/src/Umbraco.Core/Extensions/PublishedSnapshotAccessorExtensions.cs
@@ -11,6 +11,7 @@ namespace Umbraco.Extensions
{
return publishedSnapshot!;
}
+
throw new InvalidOperationException("Wasn't possible to a get a valid Snapshot");
}
}
diff --git a/src/Umbraco.Core/Models/PublishedContent/IPublishedContentType.cs b/src/Umbraco.Core/Models/PublishedContent/IPublishedContentType.cs
index ba060fa5d0..bd3f77152d 100644
--- a/src/Umbraco.Core/Models/PublishedContent/IPublishedContentType.cs
+++ b/src/Umbraco.Core/Models/PublishedContent/IPublishedContentType.cs
@@ -48,7 +48,7 @@ namespace Umbraco.Cms.Core.Models.PublishedContent
///
/// Gets the content type properties.
///
- IEnumerable? PropertyTypes { get; }
+ IEnumerable PropertyTypes { get; }
///
/// Gets a property type index.
diff --git a/src/Umbraco.Core/Models/PublishedContent/IPublishedMemberCache.cs b/src/Umbraco.Core/Models/PublishedContent/IPublishedMemberCache.cs
index bafe04f3e4..ba8bdc43d4 100644
--- a/src/Umbraco.Core/Models/PublishedContent/IPublishedMemberCache.cs
+++ b/src/Umbraco.Core/Models/PublishedContent/IPublishedMemberCache.cs
@@ -11,7 +11,7 @@ namespace Umbraco.Cms.Core.PublishedCache
///
///
///
- IPublishedContent Get(IMember member);
+ IPublishedContent? Get(IMember member);
///
/// Gets a content type identified by its unique identifier.
diff --git a/src/Umbraco.Core/Models/PublishedContent/PublishedContentBase.cs b/src/Umbraco.Core/Models/PublishedContent/PublishedContentBase.cs
index 0ece44a828..60d3cd4a02 100644
--- a/src/Umbraco.Core/Models/PublishedContent/PublishedContentBase.cs
+++ b/src/Umbraco.Core/Models/PublishedContent/PublishedContentBase.cs
@@ -13,9 +13,9 @@ namespace Umbraco.Cms.Core.Models.PublishedContent
[DebuggerDisplay("Content Id: {Id}")]
public abstract class PublishedContentBase : IPublishedContent
{
- private readonly IVariationContextAccessor _variationContextAccessor;
+ private readonly IVariationContextAccessor? _variationContextAccessor;
- protected PublishedContentBase(IVariationContextAccessor variationContextAccessor)
+ protected PublishedContentBase(IVariationContextAccessor? variationContextAccessor)
{
_variationContextAccessor = variationContextAccessor;
}
@@ -85,7 +85,7 @@ namespace Umbraco.Cms.Core.Models.PublishedContent
#region Tree
///
- public abstract IPublishedContent Parent { get; }
+ public abstract IPublishedContent? Parent { get; }
///
public virtual IEnumerable? Children => this.Children(_variationContextAccessor);
@@ -101,7 +101,7 @@ namespace Umbraco.Cms.Core.Models.PublishedContent
public abstract IEnumerable Properties { get; }
///
- public abstract IPublishedProperty GetProperty(string alias);
+ public abstract IPublishedProperty? GetProperty(string alias);
#endregion
}
diff --git a/src/Umbraco.Core/Models/PublishedContent/PublishedContentExtensionsForModels.cs b/src/Umbraco.Core/Models/PublishedContent/PublishedContentExtensionsForModels.cs
index 731d670184..f1d348d2ff 100644
--- a/src/Umbraco.Core/Models/PublishedContent/PublishedContentExtensionsForModels.cs
+++ b/src/Umbraco.Core/Models/PublishedContent/PublishedContentExtensionsForModels.cs
@@ -13,7 +13,7 @@ namespace Umbraco.Extensions
///
/// The internal published content.
/// The strongly typed published content model.
- public static IPublishedContent? CreateModel(this IPublishedContent content, IPublishedModelFactory publishedModelFactory)
+ public static IPublishedContent? CreateModel(this IPublishedContent content, IPublishedModelFactory? publishedModelFactory)
{
if (publishedModelFactory == null) throw new ArgumentNullException(nameof(publishedModelFactory));
if (content == null)
diff --git a/src/Umbraco.Core/Models/PublishedContent/PublishedContentType.cs b/src/Umbraco.Core/Models/PublishedContent/PublishedContentType.cs
index fbf29ac235..592c2eff5e 100644
--- a/src/Umbraco.Core/Models/PublishedContent/PublishedContentType.cs
+++ b/src/Umbraco.Core/Models/PublishedContent/PublishedContentType.cs
@@ -14,7 +14,7 @@ namespace Umbraco.Cms.Core.Models.PublishedContent
[DebuggerDisplay("{Alias}")]
public class PublishedContentType : IPublishedContentType
{
- private readonly IPublishedPropertyType[]? _propertyTypes;
+ private readonly IPublishedPropertyType[] _propertyTypes = null!;
// fast alias-to-index xref containing both the raw alias and its lowercase version
private readonly Dictionary _indexes = new Dictionary();
@@ -169,7 +169,7 @@ namespace Umbraco.Cms.Core.Models.PublishedContent
#region Properties
///
- public IEnumerable? PropertyTypes => _propertyTypes;
+ public IEnumerable PropertyTypes => _propertyTypes;
///
public int GetPropertyIndex(string alias)
diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/ContentPickerValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/ContentPickerValueConverter.cs
index 3392c504e5..126b4516d1 100644
--- a/src/Umbraco.Core/PropertyEditors/ValueConverters/ContentPickerValueConverter.cs
+++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/ContentPickerValueConverter.cs
@@ -65,7 +65,7 @@ namespace Umbraco.Cms.Core.PropertyEditors.ValueConverters
var publishedSnapshot = _publishedSnapshotAccessor.GetRequiredPublishedSnapshot();
if (inter is int id)
{
- content = publishedSnapshot?.Content.GetById(id);
+ content = publishedSnapshot.Content?.GetById(id);
if (content != null)
return content;
}
@@ -74,7 +74,7 @@ namespace Umbraco.Cms.Core.PropertyEditors.ValueConverters
var udi = inter as GuidUdi;
if (udi is null)
return null;
- content = publishedSnapshot?.Content.GetById(udi.Guid);
+ content = publishedSnapshot.Content?.GetById(udi.Guid);
if (content != null && content.ContentType.ItemType == PublishedItemType.Content)
return content;
}
diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/MediaPickerValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/MediaPickerValueConverter.cs
index ea244cf5a0..2df96fc310 100644
--- a/src/Umbraco.Core/PropertyEditors/ValueConverters/MediaPickerValueConverter.cs
+++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/MediaPickerValueConverter.cs
@@ -76,7 +76,7 @@ namespace Umbraco.Cms.Core.PropertyEditors.ValueConverters
{
var guidUdi = udi as GuidUdi;
if (guidUdi is null) continue;
- var item = publishedSnapshot?.Media.GetById(guidUdi.Guid);
+ var item = publishedSnapshot?.Media?.GetById(guidUdi.Guid);
if (item != null)
mediaItems.Add(item);
}
diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/MultiNodeTreePickerValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/MultiNodeTreePickerValueConverter.cs
index 8211be362f..faab6e712e 100644
--- a/src/Umbraco.Core/PropertyEditors/ValueConverters/MultiNodeTreePickerValueConverter.cs
+++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/MultiNodeTreePickerValueConverter.cs
@@ -96,10 +96,10 @@ namespace Umbraco.Cms.Core.PropertyEditors.ValueConverters
switch (udi.EntityType)
{
case Constants.UdiEntityType.Document:
- multiNodeTreePickerItem = GetPublishedContent(udi, ref objectType, UmbracoObjectTypes.Document, id => publishedSnapshot?.Content.GetById(guidUdi.Guid));
+ multiNodeTreePickerItem = GetPublishedContent(udi, ref objectType, UmbracoObjectTypes.Document, id => publishedSnapshot.Content?.GetById(guidUdi.Guid));
break;
case Constants.UdiEntityType.Media:
- multiNodeTreePickerItem = GetPublishedContent(udi, ref objectType, UmbracoObjectTypes.Media, id => publishedSnapshot?.Media.GetById(guidUdi.Guid));
+ multiNodeTreePickerItem = GetPublishedContent(udi, ref objectType, UmbracoObjectTypes.Media, id => publishedSnapshot.Media?.GetById(guidUdi.Guid));
break;
case Constants.UdiEntityType.Member:
multiNodeTreePickerItem = GetPublishedContent(udi, ref objectType, UmbracoObjectTypes.Member, id =>
diff --git a/src/Umbraco.Core/PublishedCache/IPublishedCache.cs b/src/Umbraco.Core/PublishedCache/IPublishedCache.cs
index 5cf7f58411..5a06d88ee5 100644
--- a/src/Umbraco.Core/PublishedCache/IPublishedCache.cs
+++ b/src/Umbraco.Core/PublishedCache/IPublishedCache.cs
@@ -27,7 +27,7 @@ namespace Umbraco.Cms.Core.PublishedCache
/// The content unique identifier.
/// The content, or null.
/// The value of overrides defaults.
- IPublishedContent GetById(bool preview, Guid contentId);
+ IPublishedContent? GetById(bool preview, Guid contentId);
///
/// Gets a content identified by its Udi identifier.
@@ -36,7 +36,7 @@ namespace Umbraco.Cms.Core.PublishedCache
/// The content Udi identifier.
/// The content, or null.
/// The value of overrides defaults.
- IPublishedContent GetById(bool preview, Udi contentId);
+ IPublishedContent? GetById(bool preview, Udi contentId);
///
/// Gets a content identified by its unique identifier.
@@ -52,7 +52,7 @@ namespace Umbraco.Cms.Core.PublishedCache
/// The content unique identifier.
/// The content, or null.
/// Considers published or unpublished content depending on defaults.
- IPublishedContent GetById(Guid contentId);
+ IPublishedContent? GetById(Guid contentId);
///
/// Gets a content identified by its unique identifier.
@@ -60,7 +60,7 @@ namespace Umbraco.Cms.Core.PublishedCache
/// The content unique identifier.
/// The content, or null.
/// Considers published or unpublished content depending on defaults.
- IPublishedContent GetById(Udi contentId);
+ IPublishedContent? GetById(Udi contentId);
///
/// Gets a value indicating whether the cache contains a specified content.
@@ -104,7 +104,7 @@ namespace Umbraco.Cms.Core.PublishedCache
/// Optional XPath variables.
/// The content, or null.
/// The value of overrides defaults.
- IPublishedContent GetSingleByXPath(bool preview, string xpath, params XPathVariable[] vars);
+ IPublishedContent? GetSingleByXPath(bool preview, string xpath, params XPathVariable[] vars);
///
/// Gets a content resulting from an XPath query.
@@ -113,7 +113,7 @@ namespace Umbraco.Cms.Core.PublishedCache
/// Optional XPath variables.
/// The content, or null.
/// Considers published or unpublished content depending on defaults.
- IPublishedContent GetSingleByXPath(string xpath, params XPathVariable[] vars);
+ IPublishedContent? GetSingleByXPath(string xpath, params XPathVariable[] vars);
///
/// Gets a content resulting from an XPath query.
@@ -123,7 +123,7 @@ namespace Umbraco.Cms.Core.PublishedCache
/// Optional XPath variables.
/// The content, or null.
/// The value of overrides defaults.
- IPublishedContent GetSingleByXPath(bool preview, XPathExpression xpath, params XPathVariable[] vars);
+ IPublishedContent? GetSingleByXPath(bool preview, XPathExpression xpath, params XPathVariable[] vars);
///
/// Gets a content resulting from an XPath query.
@@ -132,7 +132,7 @@ namespace Umbraco.Cms.Core.PublishedCache
/// Optional XPath variables.
/// The content, or null.
/// Considers published or unpublished content depending on defaults.
- IPublishedContent GetSingleByXPath(XPathExpression xpath, params XPathVariable[] vars);
+ IPublishedContent? GetSingleByXPath(XPathExpression xpath, params XPathVariable[] vars);
///
/// Gets contents resulting from an XPath query.
@@ -196,7 +196,7 @@ namespace Umbraco.Cms.Core.PublishedCache
/// compatibility + transition reasons, we should obsolete that one as soon as possible.
/// If the node does not exist, returns null.
///
- XPathNavigator CreateNodeNavigator(int id, bool preview);
+ XPathNavigator? CreateNodeNavigator(int id, bool preview);
///
/// Gets a value indicating whether the cache contains published content.
@@ -218,7 +218,7 @@ namespace Umbraco.Cms.Core.PublishedCache
///
/// The content type unique identifier.
/// The content type, or null.
- IPublishedContentType GetContentType(int id);
+ IPublishedContentType? GetContentType(int id);
///
/// Gets a content type identified by its alias.
@@ -226,7 +226,7 @@ namespace Umbraco.Cms.Core.PublishedCache
/// The content type alias.
/// The content type, or null.
/// The alias is case-insensitive.
- IPublishedContentType GetContentType(string alias);
+ IPublishedContentType? GetContentType(string alias);
///
/// Gets contents of a given content type.
@@ -240,6 +240,6 @@ namespace Umbraco.Cms.Core.PublishedCache
///
/// The content type key.
/// The content type, or null.
- IPublishedContentType GetContentType(Guid key);
+ IPublishedContentType? GetContentType(Guid key);
}
}
diff --git a/src/Umbraco.Core/PublishedCache/IPublishedContentCache.cs b/src/Umbraco.Core/PublishedCache/IPublishedContentCache.cs
index 2958e57f92..4621adcb82 100644
--- a/src/Umbraco.Core/PublishedCache/IPublishedContentCache.cs
+++ b/src/Umbraco.Core/PublishedCache/IPublishedContentCache.cs
@@ -16,7 +16,7 @@ namespace Umbraco.Cms.Core.PublishedCache
/// If is null then the settings value is used.
/// The value of overrides defaults.
///
- IPublishedContent GetByRoute(bool preview, string route, bool? hideTopLevelNode = null, string? culture = null);
+ IPublishedContent? GetByRoute(bool preview, string route, bool? hideTopLevelNode = null, string? culture = null);
///
/// Gets content identified by a route.
@@ -29,7 +29,7 @@ namespace Umbraco.Cms.Core.PublishedCache
/// If is null then the settings value is used.
/// Considers published or unpublished content depending on defaults.
///
- IPublishedContent GetByRoute(string route, bool? hideTopLevelNode = null, string? culture = null);
+ IPublishedContent? GetByRoute(string route, bool? hideTopLevelNode = null, string? culture = null);
///
/// Gets the route for a content identified by its unique identifier.
@@ -44,7 +44,7 @@ namespace Umbraco.Cms.Core.PublishedCache
///
/// The value of overrides defaults.
///
- string GetRouteById(bool preview, int contentId, string? culture = null);
+ string? GetRouteById(bool preview, int contentId, string? culture = null);
///
/// Gets the route for a content identified by its unique identifier.
@@ -56,6 +56,6 @@ namespace Umbraco.Cms.Core.PublishedCache
/// The resulting string is a special encoded route string that may contain the domain ID
/// for the current route. If a domain is present the string will be prefixed with the domain ID integer, example: {domainId}/route-path-of-item
///
- string GetRouteById(int contentId, string? culture = null);
+ string? GetRouteById(int contentId, string? culture = null);
}
}
diff --git a/src/Umbraco.Core/PublishedCache/IPublishedSnapshot.cs b/src/Umbraco.Core/PublishedCache/IPublishedSnapshot.cs
index 3c55b9d699..1f5344df4c 100644
--- a/src/Umbraco.Core/PublishedCache/IPublishedSnapshot.cs
+++ b/src/Umbraco.Core/PublishedCache/IPublishedSnapshot.cs
@@ -13,12 +13,12 @@ namespace Umbraco.Cms.Core.PublishedCache
///
/// Gets the .
///
- IPublishedContentCache Content { get; }
+ IPublishedContentCache? Content { get; }
///
/// Gets the .
///
- IPublishedMediaCache Media { get; }
+ IPublishedMediaCache? Media { get; }
///
/// Gets the .
diff --git a/src/Umbraco.Core/PublishedCache/PublishedCacheBase.cs b/src/Umbraco.Core/PublishedCache/PublishedCacheBase.cs
index 379668a832..b374424b8b 100644
--- a/src/Umbraco.Core/PublishedCache/PublishedCacheBase.cs
+++ b/src/Umbraco.Core/PublishedCache/PublishedCacheBase.cs
@@ -29,14 +29,14 @@ namespace Umbraco.Cms.Core.PublishedCache
public IPublishedContent? GetById(int contentId)
=> GetById(PreviewDefault, contentId);
- public abstract IPublishedContent GetById(bool preview, Guid contentId);
+ public abstract IPublishedContent? GetById(bool preview, Guid contentId);
- public IPublishedContent GetById(Guid contentId)
+ public IPublishedContent? GetById(Guid contentId)
=> GetById(PreviewDefault, contentId);
- public abstract IPublishedContent GetById(bool preview, Udi contentId);
+ public abstract IPublishedContent? GetById(bool preview, Udi contentId);
- public IPublishedContent GetById(Udi contentId)
+ public IPublishedContent? GetById(Udi contentId)
=> GetById(PreviewDefault, contentId);
public abstract bool HasById(bool preview, int contentId);
@@ -51,16 +51,16 @@ namespace Umbraco.Cms.Core.PublishedCache
return GetAtRoot(PreviewDefault, culture);
}
- public abstract IPublishedContent GetSingleByXPath(bool preview, string xpath, XPathVariable[] vars);
+ public abstract IPublishedContent? GetSingleByXPath(bool preview, string xpath, XPathVariable[] vars);
- public IPublishedContent GetSingleByXPath(string xpath, XPathVariable[] vars)
+ public IPublishedContent? GetSingleByXPath(string xpath, XPathVariable[] vars)
{
return GetSingleByXPath(PreviewDefault, xpath, vars);
}
- public abstract IPublishedContent GetSingleByXPath(bool preview, XPathExpression xpath, XPathVariable[] vars);
+ public abstract IPublishedContent? GetSingleByXPath(bool preview, XPathExpression xpath, XPathVariable[] vars);
- public IPublishedContent GetSingleByXPath(XPathExpression xpath, XPathVariable[] vars)
+ public IPublishedContent? GetSingleByXPath(XPathExpression xpath, XPathVariable[] vars)
{
return GetSingleByXPath(PreviewDefault, xpath, vars);
}
@@ -86,7 +86,7 @@ namespace Umbraco.Cms.Core.PublishedCache
return CreateNavigator(PreviewDefault);
}
- public abstract XPathNavigator CreateNodeNavigator(int id, bool preview);
+ public abstract XPathNavigator? CreateNodeNavigator(int id, bool preview);
public abstract bool HasContent(bool preview);
@@ -95,9 +95,9 @@ namespace Umbraco.Cms.Core.PublishedCache
return HasContent(PreviewDefault);
}
- public abstract IPublishedContentType GetContentType(int id);
- public abstract IPublishedContentType GetContentType(string alias);
- public abstract IPublishedContentType GetContentType(Guid key);
+ public abstract IPublishedContentType? GetContentType(int id);
+ public abstract IPublishedContentType? GetContentType(string alias);
+ public abstract IPublishedContentType? GetContentType(Guid key);
public virtual IEnumerable GetByContentType(IPublishedContentType contentType)
{
diff --git a/src/Umbraco.Core/Routing/AliasUrlProvider.cs b/src/Umbraco.Core/Routing/AliasUrlProvider.cs
index 98160aab1a..21fb3e9832 100644
--- a/src/Umbraco.Core/Routing/AliasUrlProvider.cs
+++ b/src/Umbraco.Core/Routing/AliasUrlProvider.cs
@@ -61,7 +61,7 @@ namespace Umbraco.Cms.Core.Routing
public IEnumerable GetOtherUrls(int id, Uri current)
{
var umbracoContext = _umbracoContextAccessor.GetRequiredUmbracoContext();
- var node = umbracoContext.Content.GetById(id);
+ var node = umbracoContext.Content?.GetById(id);
if (node == null)
yield break;
diff --git a/src/Umbraco.Core/Routing/ContentFinderByIdPath.cs b/src/Umbraco.Core/Routing/ContentFinderByIdPath.cs
index daaf84ebe8..6e7238890f 100644
--- a/src/Umbraco.Core/Routing/ContentFinderByIdPath.cs
+++ b/src/Umbraco.Core/Routing/ContentFinderByIdPath.cs
@@ -71,7 +71,7 @@ namespace Umbraco.Cms.Core.Routing
if (nodeId > 0)
{
_logger.LogDebug("Id={NodeId}", nodeId);
- node = umbracoContext?.Content.GetById(nodeId);
+ node = umbracoContext?.Content?.GetById(nodeId);
if (node != null)
{
diff --git a/src/Umbraco.Core/Routing/ContentFinderByPageIdQuery.cs b/src/Umbraco.Core/Routing/ContentFinderByPageIdQuery.cs
index 912381f6c4..95b9faef2a 100644
--- a/src/Umbraco.Core/Routing/ContentFinderByPageIdQuery.cs
+++ b/src/Umbraco.Core/Routing/ContentFinderByPageIdQuery.cs
@@ -35,7 +35,7 @@ namespace Umbraco.Cms.Core.Routing
}
if (int.TryParse(_requestAccessor.GetRequestValue("umbPageID"), NumberStyles.Integer, CultureInfo.InvariantCulture, out int pageId))
{
- IPublishedContent? doc = umbracoContext?.Content.GetById(pageId);
+ IPublishedContent? doc = umbracoContext.Content?.GetById(pageId);
if (doc != null)
{
diff --git a/src/Umbraco.Core/Routing/ContentFinderByRedirectUrl.cs b/src/Umbraco.Core/Routing/ContentFinderByRedirectUrl.cs
index 4259feacca..d1d4873d55 100644
--- a/src/Umbraco.Core/Routing/ContentFinderByRedirectUrl.cs
+++ b/src/Umbraco.Core/Routing/ContentFinderByRedirectUrl.cs
@@ -62,7 +62,7 @@ namespace Umbraco.Cms.Core.Routing
return false;
}
- IPublishedContent? content = umbracoContext.Content.GetById(redirectUrl.ContentId);
+ IPublishedContent? content = umbracoContext.Content?.GetById(redirectUrl.ContentId);
var url = content == null ? "#" : content.Url(_publishedUrlProvider, redirectUrl.Culture);
if (url.StartsWith("#"))
{
diff --git a/src/Umbraco.Core/Routing/ContentFinderByUrl.cs b/src/Umbraco.Core/Routing/ContentFinderByUrl.cs
index b338e03bbf..3a753563df 100644
--- a/src/Umbraco.Core/Routing/ContentFinderByUrl.cs
+++ b/src/Umbraco.Core/Routing/ContentFinderByUrl.cs
@@ -72,7 +72,7 @@ namespace Umbraco.Cms.Core.Routing
_logger.LogDebug("Test route {Route}", route);
- IPublishedContent? node = umbracoContext?.Content.GetByRoute(umbracoContext.InPreviewMode, route, culture: docreq.Culture);
+ IPublishedContent? node = umbracoContext.Content?.GetByRoute(umbracoContext.InPreviewMode, route, culture: docreq.Culture);
if (node != null)
{
docreq.SetPublishedContent(node);
diff --git a/src/Umbraco.Core/Routing/ContentFinderByUrlAlias.cs b/src/Umbraco.Core/Routing/ContentFinderByUrlAlias.cs
index 5d9ac79c81..7e51f63aa4 100644
--- a/src/Umbraco.Core/Routing/ContentFinderByUrlAlias.cs
+++ b/src/Umbraco.Core/Routing/ContentFinderByUrlAlias.cs
@@ -69,7 +69,7 @@ namespace Umbraco.Cms.Core.Routing
return node != null;
}
- private IPublishedContent? FindContentByAlias(IPublishedContentCache cache, int rootNodeId, string? culture, string alias)
+ private IPublishedContent? FindContentByAlias(IPublishedContentCache? cache, int rootNodeId, string? culture, string alias)
{
if (alias == null)
{
@@ -131,16 +131,19 @@ namespace Umbraco.Cms.Core.Routing
// but the only solution is to entirely refactor URL providers to stop being dynamic
if (rootNodeId > 0)
{
- IPublishedContent? rootNode = cache.GetById(rootNodeId);
+ IPublishedContent? rootNode = cache?.GetById(rootNodeId);
return rootNode?.Descendants(_variationContextAccessor).FirstOrDefault(x => IsMatch(x, test1, test2));
}
- foreach (IPublishedContent rootContent in cache.GetAtRoot())
+ if (cache is not null)
{
- IPublishedContent? c = rootContent.DescendantsOrSelf(_variationContextAccessor).FirstOrDefault(x => IsMatch(x, test1, test2));
- if (c != null)
+ foreach (IPublishedContent rootContent in cache.GetAtRoot())
{
- return c;
+ IPublishedContent? c = rootContent.DescendantsOrSelf(_variationContextAccessor).FirstOrDefault(x => IsMatch(x, test1, test2));
+ if (c != null)
+ {
+ return c;
+ }
}
}
diff --git a/src/Umbraco.Core/Routing/DefaultUrlProvider.cs b/src/Umbraco.Core/Routing/DefaultUrlProvider.cs
index 7e3a46f7a8..25e0764349 100644
--- a/src/Umbraco.Core/Routing/DefaultUrlProvider.cs
+++ b/src/Umbraco.Core/Routing/DefaultUrlProvider.cs
@@ -70,7 +70,7 @@ namespace Umbraco.Cms.Core.Routing
public virtual IEnumerable GetOtherUrls(int id, Uri current)
{
IUmbracoContext umbracoContext = _umbracoContextAccessor.GetRequiredUmbracoContext();
- IPublishedContent? node = umbracoContext.Content.GetById(id);
+ IPublishedContent? node = umbracoContext.Content?.GetById(id);
if (node == null)
{
yield break;
@@ -101,7 +101,7 @@ namespace Umbraco.Cms.Core.Routing
var culture = d.Culture;
// although we are passing in culture here, if any node in this path is invariant, it ignores the culture anyways so this is ok
- var route = umbracoContext.Content.GetRouteById(id, culture);
+ var route = umbracoContext.Content?.GetRouteById(id, culture);
if (route == null)
{
continue;
@@ -131,7 +131,7 @@ namespace Umbraco.Cms.Core.Routing
IUmbracoContext umbracoContext = _umbracoContextAccessor.GetRequiredUmbracoContext();
// will not use cache if previewing
- var route = umbracoContext.Content.GetRouteById(content.Id, culture);
+ var route = umbracoContext.Content?.GetRouteById(content.Id, culture);
return GetUrlFromRoute(route, umbracoContext, content.Id, current, mode, culture);
}
diff --git a/src/Umbraco.Core/Routing/Domain.cs b/src/Umbraco.Core/Routing/Domain.cs
index cf09687dae..ecefb07e8b 100644
--- a/src/Umbraco.Core/Routing/Domain.cs
+++ b/src/Umbraco.Core/Routing/Domain.cs
@@ -13,7 +13,7 @@ namespace Umbraco.Cms.Core.Routing
/// The identifier of the content which supports the domain.
/// The culture of the domain.
/// A value indicating whether the domain is a wildcard domain.
- public Domain(int id, string name, int contentId, string culture, bool isWildcard)
+ public Domain(int id, string name, int contentId, string? culture, bool isWildcard)
{
Id = id;
Name = name;
@@ -53,7 +53,7 @@ namespace Umbraco.Cms.Core.Routing
///
/// Gets the culture of the domain.
///
- public string Culture { get; }
+ public string? Culture { get; }
///
/// Gets a value indicating whether the domain is a wildcard domain.
diff --git a/src/Umbraco.Core/Routing/DomainUtilities.cs b/src/Umbraco.Core/Routing/DomainUtilities.cs
index 61b27c3723..9e762a600e 100644
--- a/src/Umbraco.Core/Routing/DomainUtilities.cs
+++ b/src/Umbraco.Core/Routing/DomainUtilities.cs
@@ -39,8 +39,8 @@ namespace Umbraco.Cms.Core.Routing
// get the published route, else the preview route
// if both are null then the content does not exist
- var route = umbracoContext.Content.GetRouteById(contentId) ??
- umbracoContext.Content.GetRouteById(true, contentId);
+ var route = umbracoContext.Content?.GetRouteById(contentId) ??
+ umbracoContext.Content?.GetRouteById(true, contentId);
if (route == null)
return null;
diff --git a/src/Umbraco.Core/Routing/PublishedRouter.cs b/src/Umbraco.Core/Routing/PublishedRouter.cs
index 2850164a3a..aa852c10d7 100644
--- a/src/Umbraco.Core/Routing/PublishedRouter.cs
+++ b/src/Umbraco.Core/Routing/PublishedRouter.cs
@@ -282,7 +282,7 @@ namespace Umbraco.Cms.Core.Routing
bool IsPublishedContentDomain(Domain domain)
{
// just get it from content cache - optimize there, not here
- IPublishedContent? domainDocument = umbracoContext.PublishedSnapshot.Content.GetById(domain.ContentId);
+ IPublishedContent? domainDocument = umbracoContext.PublishedSnapshot.Content?.GetById(domain.ContentId);
// not published - at all
if (domainDocument == null)
@@ -297,7 +297,7 @@ namespace Umbraco.Cms.Core.Routing
}
// variant, ensure that the culture corresponding to the domain's language is published
- return domainDocument.Cultures.ContainsKey(domain.Culture);
+ return domain.Culture is not null && domainDocument.Cultures.ContainsKey(domain.Culture);
}
domains = domains?.Where(IsPublishedContentDomain).ToList();
@@ -510,7 +510,7 @@ namespace Umbraco.Cms.Core.Routing
{
// try and get the redirect node from a legacy integer ID
valid = true;
- internalRedirectNode = umbracoContext.Content.GetById(internalRedirectId);
+ internalRedirectNode = umbracoContext.Content?.GetById(internalRedirectId);
}
else
{
@@ -519,7 +519,7 @@ namespace Umbraco.Cms.Core.Routing
{
// try and get the redirect node from a UDI Guid
valid = true;
- internalRedirectNode = umbracoContext.Content.GetById(udiInternalRedirectId.Guid);
+ internalRedirectNode = umbracoContext.Content?.GetById(udiInternalRedirectId.Guid);
}
}
diff --git a/src/Umbraco.Core/Routing/UrlProvider.cs b/src/Umbraco.Core/Routing/UrlProvider.cs
index c53d75fc31..11597159f7 100644
--- a/src/Umbraco.Core/Routing/UrlProvider.cs
+++ b/src/Umbraco.Core/Routing/UrlProvider.cs
@@ -52,17 +52,17 @@ namespace Umbraco.Cms.Core.Routing
private IPublishedContent? GetDocument(int id)
{
var umbracoContext = _umbracoContextAccessor.GetRequiredUmbracoContext();
- return umbracoContext.Content.GetById(id);
+ return umbracoContext.Content?.GetById(id);
}
- private IPublishedContent GetDocument(Guid id)
+ private IPublishedContent? GetDocument(Guid id)
{
var umbracoContext = _umbracoContextAccessor.GetRequiredUmbracoContext();
- return umbracoContext.Content.GetById(id);
+ return umbracoContext.Content?.GetById(id);
}
- private IPublishedContent GetMedia(Guid id)
+ private IPublishedContent? GetMedia(Guid id)
{
var umbracoContext = _umbracoContextAccessor.GetRequiredUmbracoContext();
- return umbracoContext.Media.GetById(id);
+ return umbracoContext.Media?.GetById(id);
}
///
@@ -189,7 +189,7 @@ namespace Umbraco.Cms.Core.Routing
///
///
public string GetMediaUrl(Guid id, UrlMode mode = UrlMode.Default, string? culture = null, string propertyAlias = Constants.Conventions.Media.File, Uri? current = null)
- => GetMediaUrl(GetMedia(id), mode, culture, propertyAlias, current);
+ => GetMediaUrl( GetMedia(id), mode, culture, propertyAlias, current);
///
/// Gets the URL of a media item.
@@ -206,7 +206,7 @@ namespace Umbraco.Cms.Core.Routing
/// when no culture is specified, the current culture.
/// If the provider is unable to provide a URL, it returns .
///
- public string GetMediaUrl(IPublishedContent content, UrlMode mode = UrlMode.Default, string? culture = null, string propertyAlias = Constants.Conventions.Media.File, Uri? current = null)
+ public string GetMediaUrl(IPublishedContent? content, UrlMode mode = UrlMode.Default, string? culture = null, string propertyAlias = Constants.Conventions.Media.File, Uri? current = null)
{
if (propertyAlias == null)
throw new ArgumentNullException(nameof(propertyAlias));
diff --git a/src/Umbraco.Core/Templates/UmbracoComponentRenderer.cs b/src/Umbraco.Core/Templates/UmbracoComponentRenderer.cs
index 4aee8036a3..45a44d4edb 100644
--- a/src/Umbraco.Core/Templates/UmbracoComponentRenderer.cs
+++ b/src/Umbraco.Core/Templates/UmbracoComponentRenderer.cs
@@ -67,7 +67,7 @@ namespace Umbraco.Cms.Core.Templates
throw new ArgumentException("Invalid content id " + contentId);
}
var umbracoContext = _umbracoContextAccessor.GetRequiredUmbracoContext();
- var content = umbracoContext.Content.GetById(contentId);
+ var content = umbracoContext.Content?.GetById(contentId);
if (content == null)
{
diff --git a/src/Umbraco.Core/UdiParser.cs b/src/Umbraco.Core/UdiParser.cs
index 4a542e9352..907880db13 100644
--- a/src/Umbraco.Core/UdiParser.cs
+++ b/src/Umbraco.Core/UdiParser.cs
@@ -102,7 +102,7 @@ namespace Umbraco.Cms.Core
/// If is true, assemblies are not scanned for types,
/// and therefore only builtin types may be known. Unless scanning already took place.
///
- public static bool TryParse(string s, bool knownTypes, [MaybeNullWhen(returnValue: false)] out Udi udi)
+ public static bool TryParse(string? s, bool knownTypes, [MaybeNullWhen(returnValue: false)] out Udi udi)
{
return ParseInternal(s, true, knownTypes, out udi);
}
diff --git a/src/Umbraco.Core/Web/IUmbracoContext.cs b/src/Umbraco.Core/Web/IUmbracoContext.cs
index d591d23e70..7cfa3876c0 100644
--- a/src/Umbraco.Core/Web/IUmbracoContext.cs
+++ b/src/Umbraco.Core/Web/IUmbracoContext.cs
@@ -35,12 +35,12 @@ namespace Umbraco.Cms.Core.Web
///
/// Gets the published content cache.
///
- IPublishedContentCache Content { get; }
+ IPublishedContentCache? Content { get; }
///
/// Gets the published media cache.
///
- IPublishedMediaCache Media { get; }
+ IPublishedMediaCache? Media { get; }
///
/// Gets the domains cache.
diff --git a/src/Umbraco.Core/Xml/XPath/INavigableContent.cs b/src/Umbraco.Core/Xml/XPath/INavigableContent.cs
index 0e0848088a..c1a4e6c3e4 100644
--- a/src/Umbraco.Core/Xml/XPath/INavigableContent.cs
+++ b/src/Umbraco.Core/Xml/XPath/INavigableContent.cs
@@ -28,7 +28,7 @@ namespace Umbraco.Cms.Core.Xml.XPath
///
/// Gets the unique identifiers of the children of the navigable content.
///
- IList ChildIds { get; }
+ IList? ChildIds { get; }
///
/// Gets the value of a field of the navigable content for XPath navigation use.
@@ -43,7 +43,7 @@ namespace Umbraco.Cms.Core.Xml.XPath
/// and has content (is not empty), null to indicate that the element is empty, or a string
/// which can be empty, whitespace... depending on what the data type wants to expose.
///
- object Value(int index);
+ object? Value(int index);
// TODO: implement the following one
diff --git a/src/Umbraco.Core/Xml/XPath/INavigableContentType.cs b/src/Umbraco.Core/Xml/XPath/INavigableContentType.cs
index 420cd6a487..2e214d5e9a 100644
--- a/src/Umbraco.Core/Xml/XPath/INavigableContentType.cs
+++ b/src/Umbraco.Core/Xml/XPath/INavigableContentType.cs
@@ -8,7 +8,7 @@
///
/// Gets the name of the content type.
///
- string Name { get; }
+ string? Name { get; }
///
/// Gets the field types of the content type.
diff --git a/src/Umbraco.Core/Xml/XPath/INavigableFieldType.cs b/src/Umbraco.Core/Xml/XPath/INavigableFieldType.cs
index a9bbef3821..0b66cc0626 100644
--- a/src/Umbraco.Core/Xml/XPath/INavigableFieldType.cs
+++ b/src/Umbraco.Core/Xml/XPath/INavigableFieldType.cs
@@ -18,6 +18,6 @@ namespace Umbraco.Cms.Core.Xml.XPath
///
/// This is for built-in properties, ie attributes. User-defined properties have their
/// own way to convert their value for XPath.
- Func
public class ContentData
{
+ // Scheduled for removal in V11
[Obsolete("Use ctor with all params, as the pros should be immutable")]
public ContentData()
{
-
+ Name = string.Empty;
+ UrlSegment = string.Empty;
+ Properties = null!;
+ CultureInfos = null!;
}
- public ContentData(string name, string urlSegment, int versionId, DateTime versionDate, int writerId, int? templateId, bool published, IDictionary properties, IReadOnlyDictionary cultureInfos)
+ public ContentData(string? name, string? urlSegment, int versionId, DateTime versionDate, int writerId, int? templateId, bool published, IDictionary? properties, IReadOnlyDictionary? cultureInfos)
{
Name = name ?? throw new ArgumentNullException(nameof(name));
UrlSegment = urlSegment;
@@ -28,7 +33,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache.DataSource
}
public string Name { get; [Obsolete("Do not change this, use ctor with params and have this object immutable.")] set; }
- public string UrlSegment { get; [Obsolete("Do not change this, use ctor with params and have this object immutable.")] set; }
+ public string? UrlSegment { get; [Obsolete("Do not change this, use ctor with params and have this object immutable.")] set; }
public int VersionId { get; [Obsolete("Do not change this, use ctor with params and have this object immutable.")] set; }
public DateTime VersionDate { get; [Obsolete("Do not change this, use ctor with params and have this object immutable.")] set; }
public int WriterId { get; [Obsolete("Do not change this, use ctor with params and have this object immutable.")] set; }
@@ -40,6 +45,6 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache.DataSource
///
/// The collection of language Id to name for the content item
///
- public IReadOnlyDictionary CultureInfos { get; [Obsolete("Do not change this, use ctor with params and have this object immutable.")] set; }
+ public IReadOnlyDictionary? CultureInfos { get; [Obsolete("Do not change this, use ctor with params and have this object immutable.")] set; }
}
}
diff --git a/src/Umbraco.PublishedCache.NuCache/DataSource/ContentSourceDto.cs b/src/Umbraco.PublishedCache.NuCache/DataSource/ContentSourceDto.cs
index 78a8ea6e81..5bdcefcf94 100644
--- a/src/Umbraco.PublishedCache.NuCache/DataSource/ContentSourceDto.cs
+++ b/src/Umbraco.PublishedCache.NuCache/DataSource/ContentSourceDto.cs
@@ -11,7 +11,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache.DataSource
public int ContentTypeId { get; set; }
public int Level { get; set; }
- public string Path { get; set; }
+ public string Path { get; set; } = string.Empty;
public int SortOrder { get; set; }
public int ParentId { get; set; }
@@ -23,25 +23,25 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache.DataSource
// edited data
public int VersionId { get; set; }
- public string EditName { get; set; }
+ public string? EditName { get; set; }
public DateTime EditVersionDate { get; set; }
public int EditWriterId { get; set; }
public int EditTemplateId { get; set; }
- public string EditData { get; set; }
- public byte[] EditDataRaw { get; set; }
+ public string? EditData { get; set; }
+ public byte[]? EditDataRaw { get; set; }
// published data
public int PublishedVersionId { get; set; }
- public string PubName { get; set; }
+ public string? PubName { get; set; }
public DateTime PubVersionDate { get; set; }
public int PubWriterId { get; set; }
public int PubTemplateId { get; set; }
- public string PubData { get; set; }
- public byte[] PubDataRaw { get; set; }
+ public string? PubData { get; set; }
+ public byte[]? PubDataRaw { get; set; }
// Explicit implementation
DateTime IReadOnlyContentBase.UpdateDate => EditVersionDate;
- string IReadOnlyContentBase.Name => EditName;
+ string? IReadOnlyContentBase.Name => EditName;
int IReadOnlyContentBase.WriterId => EditWriterId;
}
}
diff --git a/src/Umbraco.PublishedCache.NuCache/DataSource/CultureVariation.cs b/src/Umbraco.PublishedCache.NuCache/DataSource/CultureVariation.cs
index 17a3b3e4dc..2424793a0c 100644
--- a/src/Umbraco.PublishedCache.NuCache/DataSource/CultureVariation.cs
+++ b/src/Umbraco.PublishedCache.NuCache/DataSource/CultureVariation.cs
@@ -12,11 +12,11 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache.DataSource
{
[DataMember(Order = 0)]
[JsonProperty("nm")]
- public string Name { get; set; }
+ public string? Name { get; set; }
[DataMember(Order = 1)]
[JsonProperty("us")]
- public string UrlSegment { get; set; }
+ public string? UrlSegment { get; set; }
[DataMember(Order = 2)]
[JsonProperty("dt")]
diff --git a/src/Umbraco.PublishedCache.NuCache/DataSource/IContentCacheDataSerializer.cs b/src/Umbraco.PublishedCache.NuCache/DataSource/IContentCacheDataSerializer.cs
index cbc40a9630..d1a5ab1fe3 100644
--- a/src/Umbraco.PublishedCache.NuCache/DataSource/IContentCacheDataSerializer.cs
+++ b/src/Umbraco.PublishedCache.NuCache/DataSource/IContentCacheDataSerializer.cs
@@ -14,7 +14,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache.DataSource
///
/// Deserialize the data into a
///
- ContentCacheDataModel Deserialize(IReadOnlyContentBase content, string stringData, byte[] byteData, bool published);
+ ContentCacheDataModel? Deserialize(IReadOnlyContentBase content, string? stringData, byte[]? byteData, bool published);
///
/// Serializes the
diff --git a/src/Umbraco.PublishedCache.NuCache/DataSource/JsonContentNestedDataSerializer.cs b/src/Umbraco.PublishedCache.NuCache/DataSource/JsonContentNestedDataSerializer.cs
index 9f1bfd39e2..06da8ccec1 100644
--- a/src/Umbraco.PublishedCache.NuCache/DataSource/JsonContentNestedDataSerializer.cs
+++ b/src/Umbraco.PublishedCache.NuCache/DataSource/JsonContentNestedDataSerializer.cs
@@ -24,13 +24,13 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache.DataSource
DateFormatString = "o"
};
private readonly JsonNameTable _propertyNameTable = new DefaultJsonNameTable();
- public ContentCacheDataModel Deserialize(IReadOnlyContentBase content, string stringData, byte[] byteData, bool published)
+ public ContentCacheDataModel? Deserialize(IReadOnlyContentBase content, string? stringData, byte[]? byteData, bool published)
{
if (stringData == null && byteData != null)
throw new NotSupportedException($"{typeof(JsonContentNestedDataSerializer)} does not support byte[] serialization");
JsonSerializer serializer = JsonSerializer.Create(_jsonSerializerSettings);
- using (JsonTextReader reader = new JsonTextReader(new StringReader(stringData)))
+ using (JsonTextReader reader = new JsonTextReader(new StringReader(stringData!)))
{
// reader will get buffer from array pool
reader.ArrayPool = JsonArrayPool.Instance;
@@ -58,12 +58,16 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache.DataSource
return ArrayPool.Shared.Rent(minimumLength);
}
- public void Return(char[] array)
+ public void Return(char[]? array)
{
// return char array to System.Buffers shared pool
- ArrayPool.Shared.Return(array);
+ if (array is not null)
+ {
+ ArrayPool.Shared.Return(array);
+ }
}
}
+
public class AutomaticJsonNameTable : DefaultJsonNameTable
{
int nAutoAdded = 0;
@@ -74,7 +78,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache.DataSource
this.maxToAutoAdd = maxToAdd;
}
- public override string Get(char[] key, int start, int length)
+ public override string? Get(char[] key, int start, int length)
{
var s = base.Get(key, start, length);
diff --git a/src/Umbraco.PublishedCache.NuCache/DataSource/LazyCompressedString.cs b/src/Umbraco.PublishedCache.NuCache/DataSource/LazyCompressedString.cs
index a5edbc2512..c6105f7af6 100644
--- a/src/Umbraco.PublishedCache.NuCache/DataSource/LazyCompressedString.cs
+++ b/src/Umbraco.PublishedCache.NuCache/DataSource/LazyCompressedString.cs
@@ -12,8 +12,8 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache.DataSource
[DebuggerDisplay("{Display}")]
internal struct LazyCompressedString
{
- private byte[] _bytes;
- private string _str;
+ private byte[]? _bytes;
+ private string? _str;
private readonly object _locker;
///
diff --git a/src/Umbraco.PublishedCache.NuCache/DataSource/MsgPackContentNestedDataSerializer.cs b/src/Umbraco.PublishedCache.NuCache/DataSource/MsgPackContentNestedDataSerializer.cs
index ba45dec9a8..ff65271e44 100644
--- a/src/Umbraco.PublishedCache.NuCache/DataSource/MsgPackContentNestedDataSerializer.cs
+++ b/src/Umbraco.PublishedCache.NuCache/DataSource/MsgPackContentNestedDataSerializer.cs
@@ -49,7 +49,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache.DataSource
return json;
}
- public ContentCacheDataModel Deserialize(IReadOnlyContentBase content, string stringData, byte[] byteData, bool published)
+ public ContentCacheDataModel? Deserialize(IReadOnlyContentBase content, string? stringData, byte[]? byteData, bool published)
{
if (byteData != null)
{
@@ -93,17 +93,26 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache.DataSource
///
private void Compress(IReadOnlyContentBase content, ContentCacheDataModel model, bool published)
{
+ if (model.PropertyData is null)
+ {
+ return;
+ }
+
foreach(var propertyAliasToData in model.PropertyData)
{
if (_propertyOptions.IsCompressed(content, propertyAliasToData.Key, published))
{
foreach(var property in propertyAliasToData.Value.Where(x => x.Value != null && x.Value is string))
{
- property.Value = LZ4Pickler.Pickle(Encoding.UTF8.GetBytes((string)property.Value), LZ4Level.L00_FAST);
+ if (property.Value is string propertyValue)
+ {
+ property.Value = LZ4Pickler.Pickle(Encoding.UTF8.GetBytes(propertyValue), LZ4Level.L00_FAST);
+ }
}
+
foreach (var property in propertyAliasToData.Value.Where(x => x.Value != null && x.Value is int intVal))
{
- property.Value = Convert.ToBoolean((int)property.Value);
+ property.Value = Convert.ToBoolean((int?)property.Value);
}
}
}
@@ -117,6 +126,11 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache.DataSource
///
private void Expand(IReadOnlyContentBase content, ContentCacheDataModel nestedData, bool published)
{
+ if (nestedData.PropertyData is null)
+ {
+ return;
+ }
+
foreach (var propertyAliasToData in nestedData.PropertyData)
{
if (_propertyOptions.IsCompressed(content, propertyAliasToData.Key,published))
diff --git a/src/Umbraco.PublishedCache.NuCache/DataSource/PropertyData.cs b/src/Umbraco.PublishedCache.NuCache/DataSource/PropertyData.cs
index befd1698de..fdef5029cd 100644
--- a/src/Umbraco.PublishedCache.NuCache/DataSource/PropertyData.cs
+++ b/src/Umbraco.PublishedCache.NuCache/DataSource/PropertyData.cs
@@ -10,14 +10,14 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache.DataSource
[DataContract] // NOTE: Use DataContract annotations here to control how MessagePack serializes/deserializes the data to use INT keys
public class PropertyData
{
- private string _culture;
- private string _segment;
+ private string? _culture;
+ private string? _segment;
[DataMember(Order = 0)]
[JsonConverter(typeof(AutoInterningStringConverter))]
[DefaultValue("")]
[JsonProperty(DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate, PropertyName = "c")]
- public string Culture
+ public string? Culture
{
get => _culture;
set => _culture = value ?? throw new ArgumentNullException(nameof(value)); // TODO: or fallback to string.Empty? CANNOT be null
@@ -27,7 +27,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache.DataSource
[JsonConverter(typeof(AutoInterningStringConverter))]
[DefaultValue("")]
[JsonProperty(DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate, PropertyName = "s")]
- public string Segment
+ public string? Segment
{
get => _segment;
set => _segment = value ?? throw new ArgumentNullException(nameof(value)); // TODO: or fallback to string.Empty? CANNOT be null
@@ -35,7 +35,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache.DataSource
[DataMember(Order = 2)]
[JsonProperty("v")]
- public object Value { get; set; }
+ public object? Value { get; set; }
// Legacy properties used to deserialize existing nucache db entries
[IgnoreDataMember]
diff --git a/src/Umbraco.PublishedCache.NuCache/DataSource/SerializerBase.cs b/src/Umbraco.PublishedCache.NuCache/DataSource/SerializerBase.cs
index fb2f39f711..620e6bb75c 100644
--- a/src/Umbraco.PublishedCache.NuCache/DataSource/SerializerBase.cs
+++ b/src/Umbraco.PublishedCache.NuCache/DataSource/SerializerBase.cs
@@ -43,7 +43,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache.DataSource
return read(stream);
}
- protected string ReadStringObject(Stream stream, bool intern = false) // required 'cos string is not a struct
+ protected string? ReadStringObject(Stream stream, bool intern = false) // required 'cos string is not a struct
{
var type = PrimitiveSerializer.Char.ReadFrom(stream);
if (type == PrefixNull) return null;
@@ -60,7 +60,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache.DataSource
protected double? ReadDoubleObject(Stream stream) => ReadStruct(stream, PrefixDouble, ReadDouble);
protected DateTime? ReadDateTimeObject(Stream stream) => ReadStruct(stream, PrefixDateTime, ReadDateTime);
- protected object ReadObject(Stream stream)
+ protected object? ReadObject(Stream stream)
=> ReadObject(PrimitiveSerializer.Char.ReadFrom(stream), stream);
///
@@ -73,7 +73,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache.DataSource
/// This will incur boxing because the result is an object but in most cases the value will be a struct.
/// When the type is known use the specific methods like instead
///
- protected object ReadObject(char type, Stream stream)
+ protected object? ReadObject(char type, Stream stream)
{
switch (type)
{
@@ -127,7 +127,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache.DataSource
/// This method will incur boxing if the value is a struct. When the type is known use the
/// to write the value directly.
///
- protected void WriteObject(object value, Stream stream)
+ protected void WriteObject(object? value, Stream stream)
{
if (value == null)
{
diff --git a/src/Umbraco.PublishedCache.NuCache/DomainCacheExtensions.cs b/src/Umbraco.PublishedCache.NuCache/DomainCacheExtensions.cs
index 47cc427217..ff4808b7e6 100644
--- a/src/Umbraco.PublishedCache.NuCache/DomainCacheExtensions.cs
+++ b/src/Umbraco.PublishedCache.NuCache/DomainCacheExtensions.cs
@@ -6,12 +6,12 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
{
public static class DomainCacheExtensions
{
- public static bool GetAssignedWithCulture(this IDomainCache domainCache, string culture, int documentId, bool includeWildcards = false)
+ public static bool GetAssignedWithCulture(this IDomainCache domainCache, string? culture, int documentId, bool includeWildcards = false)
{
var assigned = domainCache.GetAssigned(documentId, includeWildcards);
// It's super important that we always compare cultures with ignore case, since we can't be sure of the casing!
- return culture is null ? assigned.Any() : assigned.Any(x => x.Culture.Equals(culture, StringComparison.InvariantCultureIgnoreCase));
+ return culture is null ? assigned.Any() : assigned.Any(x => x.Culture?.Equals(culture, StringComparison.InvariantCultureIgnoreCase) ?? false);
}
}
}
diff --git a/src/Umbraco.PublishedCache.NuCache/MediaCache.cs b/src/Umbraco.PublishedCache.NuCache/MediaCache.cs
index 78e5050da5..a037c56541 100644
--- a/src/Umbraco.PublishedCache.NuCache/MediaCache.cs
+++ b/src/Umbraco.PublishedCache.NuCache/MediaCache.cs
@@ -31,21 +31,21 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
#region Get, Has
- public override IPublishedContent GetById(bool preview, int contentId)
+ public override IPublishedContent? GetById(bool preview, int contentId)
{
// ignore preview, there's only draft for media
var n = _snapshot.Get(contentId);
return n?.PublishedModel;
}
- public override IPublishedContent GetById(bool preview, Guid contentId)
+ public override IPublishedContent? GetById(bool preview, Guid contentId)
{
// ignore preview, there's only draft for media
var n = _snapshot.Get(contentId);
return n?.PublishedModel;
}
- public override IPublishedContent GetById(bool preview, Udi contentId)
+ public override IPublishedContent? GetById(bool preview, Udi contentId)
{
var guidUdi = contentId as GuidUdi;
if (guidUdi == null)
@@ -74,7 +74,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
culture = _variationContextAccessor?.VariationContext?.Culture ?? "";
var atRoot = _snapshot.GetAtRoot().Select(x => x.PublishedModel);
- return culture == "*" ? atRoot : atRoot.Where(x => x.IsInvariantOrHasCulture(culture));
+ return culture == "*" ? atRoot.WhereNotNull() : atRoot.Where(x => x?.IsInvariantOrHasCulture(culture) ?? false).WhereNotNull();
}
public override bool HasContent(bool preview)
@@ -86,21 +86,21 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
#region XPath
- public override IPublishedContent GetSingleByXPath(bool preview, string xpath, XPathVariable[] vars)
+ public override IPublishedContent? GetSingleByXPath(bool preview, string xpath, XPathVariable[] vars)
{
var navigator = CreateNavigator(preview);
var iterator = navigator.Select(xpath, vars);
return GetSingleByXPath(iterator);
}
- public override IPublishedContent GetSingleByXPath(bool preview, XPathExpression xpath, XPathVariable[] vars)
+ public override IPublishedContent? GetSingleByXPath(bool preview, XPathExpression xpath, XPathVariable[] vars)
{
var navigator = CreateNavigator(preview);
var iterator = navigator.Select(xpath, vars);
return GetSingleByXPath(iterator);
}
- private static IPublishedContent GetSingleByXPath(XPathNodeIterator iterator)
+ private static IPublishedContent? GetSingleByXPath(XPathNodeIterator iterator)
{
if (iterator.MoveNext() == false) return null;
@@ -146,7 +146,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
return navigator;
}
- public override XPathNavigator CreateNodeNavigator(int id, bool preview)
+ public override XPathNavigator? CreateNodeNavigator(int id, bool preview)
{
var source = new Source(this, preview);
var navigator = new NavigableNavigator(source);
@@ -157,11 +157,11 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
#region Content types
- public override IPublishedContentType GetContentType(int id) => _snapshot.GetContentType(id);
+ public override IPublishedContentType? GetContentType(int id) => _snapshot.GetContentType(id);
- public override IPublishedContentType GetContentType(string alias) => _snapshot.GetContentType(alias);
+ public override IPublishedContentType? GetContentType(string alias) => _snapshot.GetContentType(alias);
- public override IPublishedContentType GetContentType(Guid key) => _snapshot.GetContentType(key);
+ public override IPublishedContentType? GetContentType(Guid key) => _snapshot.GetContentType(key);
#endregion
diff --git a/src/Umbraco.PublishedCache.NuCache/MemberCache.cs b/src/Umbraco.PublishedCache.NuCache/MemberCache.cs
index ade291eacf..84c2838ee6 100644
--- a/src/Umbraco.PublishedCache.NuCache/MemberCache.cs
+++ b/src/Umbraco.PublishedCache.NuCache/MemberCache.cs
@@ -33,7 +33,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
public IPublishedContentType GetContentType(string alias) => _contentTypeCache.Get(PublishedItemType.Member, alias);
- public IPublishedContent Get(IMember member)
+ public IPublishedContent? Get(IMember member)
=> PublishedMember.Create(member, GetContentType(member.ContentTypeId), _previewDefault, _publishedSnapshotAccessor, _variationContextAccessor, _publishedModelFactory);
#endregion
diff --git a/src/Umbraco.PublishedCache.NuCache/Navigable/INavigableData.cs b/src/Umbraco.PublishedCache.NuCache/Navigable/INavigableData.cs
index 2dc238d1e4..f629b1e8b7 100644
--- a/src/Umbraco.PublishedCache.NuCache/Navigable/INavigableData.cs
+++ b/src/Umbraco.PublishedCache.NuCache/Navigable/INavigableData.cs
@@ -5,7 +5,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache.Navigable
{
internal interface INavigableData
{
- IPublishedContent GetById(bool preview, int contentId);
+ IPublishedContent? GetById(bool preview, int contentId);
IEnumerable GetAtRoot(bool preview);
}
}
diff --git a/src/Umbraco.PublishedCache.NuCache/Navigable/NavigableContent.cs b/src/Umbraco.PublishedCache.NuCache/Navigable/NavigableContent.cs
index 9d2b2bbbe5..fefb75b6b1 100644
--- a/src/Umbraco.PublishedCache.NuCache/Navigable/NavigableContent.cs
+++ b/src/Umbraco.PublishedCache.NuCache/Navigable/NavigableContent.cs
@@ -8,7 +8,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache.Navigable
internal class NavigableContent : INavigableContent
{
private readonly PublishedContent _content;
- private readonly string[] _builtInValues;
+ private readonly string?[] _builtInValues;
public NavigableContent(IPublishedContent content)
{
@@ -33,7 +33,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache.Navigable
};
}
- private string XmlString(int index, object value)
+ private string? XmlString(int index, object? value)
{
if (value == null) return string.Empty;
var field = Type.FieldTypes[index];
@@ -51,9 +51,9 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache.Navigable
public INavigableContentType Type => NavigableContentType.GetContentType(_content.ContentType);
// returns all child ids, will be filtered by the source
- public IList ChildIds => _content.ChildIds;
+ public IList? ChildIds => _content.ChildIds;
- public object Value(int index)
+ public object? Value(int index)
{
if (index < 0)
throw new ArgumentOutOfRangeException(nameof(index));
diff --git a/src/Umbraco.PublishedCache.NuCache/Navigable/NavigableContentType.cs b/src/Umbraco.PublishedCache.NuCache/Navigable/NavigableContentType.cs
index 9062f66b92..3b40851fbf 100644
--- a/src/Umbraco.PublishedCache.NuCache/Navigable/NavigableContentType.cs
+++ b/src/Umbraco.PublishedCache.NuCache/Navigable/NavigableContentType.cs
@@ -14,7 +14,9 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache.Navigable
// called by the conditional weak table -- must be public
// ReSharper disable EmptyConstructor
+#pragma warning disable CS8618
public NavigableContentType()
+#pragma warning restore CS8618
// ReSharper restore EmptyConstructor
{ }
diff --git a/src/Umbraco.PublishedCache.NuCache/Navigable/NavigablePropertyType.cs b/src/Umbraco.PublishedCache.NuCache/Navigable/NavigablePropertyType.cs
index eed3d1a08d..ddfb08dbe9 100644
--- a/src/Umbraco.PublishedCache.NuCache/Navigable/NavigablePropertyType.cs
+++ b/src/Umbraco.PublishedCache.NuCache/Navigable/NavigablePropertyType.cs
@@ -5,13 +5,13 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache.Navigable
{
internal class NavigablePropertyType : INavigableFieldType
{
- public NavigablePropertyType(string name, Func xmlStringConverter = null)
+ public NavigablePropertyType(string name, Func? xmlStringConverter = null)
{
Name = name;
XmlStringConverter = xmlStringConverter;
}
public string Name { get; }
- public Func XmlStringConverter { get; }
+ public Func? XmlStringConverter { get; }
}
}
diff --git a/src/Umbraco.PublishedCache.NuCache/Navigable/RootContent.cs b/src/Umbraco.PublishedCache.NuCache/Navigable/RootContent.cs
index 68eb41a66a..5f2cd8c165 100644
--- a/src/Umbraco.PublishedCache.NuCache/Navigable/RootContent.cs
+++ b/src/Umbraco.PublishedCache.NuCache/Navigable/RootContent.cs
@@ -22,7 +22,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache.Navigable
public IList ChildIds => _childIds;
- public object Value(int index)
+ public object? Value(int index)
{
// only id has a value
return index == 0 ? "-1" : null;
diff --git a/src/Umbraco.PublishedCache.NuCache/Navigable/Source.cs b/src/Umbraco.PublishedCache.NuCache/Navigable/Source.cs
index ad4f1a2b13..86c92d0fe9 100644
--- a/src/Umbraco.PublishedCache.NuCache/Navigable/Source.cs
+++ b/src/Umbraco.PublishedCache.NuCache/Navigable/Source.cs
@@ -18,7 +18,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache.Navigable
_root = new RootContent(contentAtRoot.Select(x => x.Id));
}
- public INavigableContent Get(int id)
+ public INavigableContent? Get(int id)
{
// wrap in a navigable content
diff --git a/src/Umbraco.PublishedCache.NuCache/Persistence/INuCacheContentRepository.cs b/src/Umbraco.PublishedCache.NuCache/Persistence/INuCacheContentRepository.cs
index dd04a63a66..ea63d11480 100644
--- a/src/Umbraco.PublishedCache.NuCache/Persistence/INuCacheContentRepository.cs
+++ b/src/Umbraco.PublishedCache.NuCache/Persistence/INuCacheContentRepository.cs
@@ -12,7 +12,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache.Persistence
IEnumerable GetBranchMediaSources(int id);
ContentNodeKit GetContentSource(int id);
ContentNodeKit GetMediaSource(int id);
- IEnumerable GetTypeContentSources(IEnumerable ids);
+ IEnumerable GetTypeContentSources(IEnumerable? ids);
IEnumerable GetTypeMediaSources(IEnumerable ids);
///
@@ -37,9 +37,9 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache.Persistence
/// If not null will process content for the matching media types, if empty will process all media
/// If not null will process content for the matching members types, if empty will process all members
void Rebuild(
- IReadOnlyCollection contentTypeIds = null,
- IReadOnlyCollection mediaTypeIds = null,
- IReadOnlyCollection memberTypeIds = null);
+ IReadOnlyCollection? contentTypeIds = null,
+ IReadOnlyCollection? mediaTypeIds = null,
+ IReadOnlyCollection? memberTypeIds = null);
bool VerifyContentDbCache();
bool VerifyMediaDbCache();
diff --git a/src/Umbraco.PublishedCache.NuCache/Persistence/INuCacheContentService.cs b/src/Umbraco.PublishedCache.NuCache/Persistence/INuCacheContentService.cs
index 78ab94fddb..1ae3f94ac2 100644
--- a/src/Umbraco.PublishedCache.NuCache/Persistence/INuCacheContentService.cs
+++ b/src/Umbraco.PublishedCache.NuCache/Persistence/INuCacheContentService.cs
@@ -39,7 +39,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache.Persistence
///
/// MUST be ordered by level + parentId + sortOrder!
///
- IEnumerable GetTypeContentSources(IEnumerable ids);
+ IEnumerable GetTypeContentSources(IEnumerable? ids);
ContentNodeKit GetMediaSource(int id);
@@ -93,9 +93,9 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache.Persistence
/// If not null will process content for the matching media types, if empty will process all media
/// If not null will process content for the matching members types, if empty will process all members
void Rebuild(
- IReadOnlyCollection contentTypeIds = null,
- IReadOnlyCollection mediaTypeIds = null,
- IReadOnlyCollection memberTypeIds = null);
+ IReadOnlyCollection? contentTypeIds = null,
+ IReadOnlyCollection? mediaTypeIds = null,
+ IReadOnlyCollection? memberTypeIds = null);
bool VerifyContentDbCache();
diff --git a/src/Umbraco.PublishedCache.NuCache/Persistence/NuCacheContentRepository.cs b/src/Umbraco.PublishedCache.NuCache/Persistence/NuCacheContentRepository.cs
index 9964195f34..583ffa2799 100644
--- a/src/Umbraco.PublishedCache.NuCache/Persistence/NuCacheContentRepository.cs
+++ b/src/Umbraco.PublishedCache.NuCache/Persistence/NuCacheContentRepository.cs
@@ -117,9 +117,9 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache.Persistence
}
public void Rebuild(
- IReadOnlyCollection contentTypeIds = null,
- IReadOnlyCollection mediaTypeIds = null,
- IReadOnlyCollection memberTypeIds = null)
+ IReadOnlyCollection? contentTypeIds = null,
+ IReadOnlyCollection? mediaTypeIds = null,
+ IReadOnlyCollection? memberTypeIds = null)
{
IContentCacheDataSerializer serializer = _contentCacheDataSerializerFactory.Create(
ContentCacheDataSerializerEntityType.Document
@@ -134,7 +134,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache.Persistence
}
// assumes content tree lock
- private void RebuildContentDbCache(IContentCacheDataSerializer serializer, int groupSize, IReadOnlyCollection contentTypeIds)
+ private void RebuildContentDbCache(IContentCacheDataSerializer serializer, int groupSize, IReadOnlyCollection? contentTypeIds)
{
Guid contentObjectType = Constants.ObjectTypes.Document;
@@ -200,7 +200,7 @@ WHERE cmsContentNu.nodeId IN (
}
// assumes media tree lock
- private void RebuildMediaDbCache(IContentCacheDataSerializer serializer, int groupSize, IReadOnlyCollection contentTypeIds)
+ private void RebuildMediaDbCache(IContentCacheDataSerializer serializer, int groupSize, IReadOnlyCollection? contentTypeIds)
{
var mediaObjectType = Constants.ObjectTypes.Media;
@@ -251,7 +251,7 @@ WHERE cmsContentNu.nodeId IN (
}
// assumes member tree lock
- private void RebuildMemberDbCache(IContentCacheDataSerializer serializer, int groupSize, IReadOnlyCollection contentTypeIds)
+ private void RebuildMemberDbCache(IContentCacheDataSerializer serializer, int groupSize, IReadOnlyCollection? contentTypeIds)
{
Guid memberObjectType = Constants.ObjectTypes.Member;
@@ -388,23 +388,26 @@ AND cmsContentNu.nodeId IS NULL
// sanitize - names should be ok but ... never knows
if (content.ContentType.VariesByCulture())
{
- ContentCultureInfosCollection infos = content is IContent document
+ ContentCultureInfosCollection? infos = content is IContent document
? published
? document.PublishCultureInfos
: document.CultureInfos
: content.CultureInfos;
// ReSharper disable once UseDeconstruction
- foreach (ContentCultureInfos cultureInfo in infos)
+ if (infos is not null)
{
- var cultureIsDraft = !published && content is IContent d && d.IsCultureEdited(cultureInfo.Culture);
- cultureData[cultureInfo.Culture] = new CultureVariation
+ foreach (ContentCultureInfos cultureInfo in infos)
{
- Name = cultureInfo.Name,
- UrlSegment = content.GetUrlSegment(_shortStringHelper, _urlSegmentProviders, cultureInfo.Culture),
- Date = content.GetUpdateDate(cultureInfo.Culture) ?? DateTime.MinValue,
- IsDraft = cultureIsDraft
- };
+ 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
+ };
+ }
}
}
@@ -430,7 +433,7 @@ AND cmsContentNu.nodeId IS NULL
}
// we want arrays, we want them all loaded, not an enumerable
- private Sql SqlContentSourcesSelect(Func> joins = null)
+ private Sql SqlContentSourcesSelect(Func>? joins = null)
{
var sqlTemplate = SqlContext.Templates.Get(Constants.SqlTemplates.NuCacheDatabaseDataSource.ContentSourcesSelect, tsql =>
tsql.Select(x => Alias(x.NodeId, "Id"), x => Alias(x.UniqueId, "Key"),
@@ -538,7 +541,7 @@ AND cmsContentNu.nodeId IS NULL
///
///
///
- private Sql SqlContentSourcesCount(Func> joins = null)
+ private Sql SqlContentSourcesCount(Func>? joins = null)
{
var sqlTemplate = SqlContext.Templates.Get(Constants.SqlTemplates.NuCacheDatabaseDataSource.ContentSourcesCount, tsql =>
tsql.Select(x => Alias(x.NodeId, "Id"))
@@ -562,7 +565,7 @@ AND cmsContentNu.nodeId IS NULL
return sql;
}
- private Sql SqlMediaSourcesSelect(Func> joins = null)
+ private Sql SqlMediaSourcesSelect(Func>? joins = null)
{
var sqlTemplate = SqlContext.Templates.Get(Constants.SqlTemplates.NuCacheDatabaseDataSource.MediaSourcesSelect, tsql =>
tsql.Select(x => Alias(x.NodeId, "Id"), x => Alias(x.UniqueId, "Key"),
@@ -588,7 +591,7 @@ AND cmsContentNu.nodeId IS NULL
return sql;
}
- private Sql SqlMediaSourcesCount(Func> joins = null)
+ private Sql SqlMediaSourcesCount(Func>? joins = null)
{
var sqlTemplate = SqlContext.Templates.Get(Constants.SqlTemplates.NuCacheDatabaseDataSource.MediaSourcesCount, tsql =>
tsql.Select(x => Alias(x.NodeId, "Id")).From());
@@ -668,9 +671,9 @@ AND cmsContentNu.nodeId IS NULL
}
}
- public IEnumerable GetTypeContentSources(IEnumerable ids)
+ public IEnumerable GetTypeContentSources(IEnumerable? ids)
{
- if (!ids.Any())
+ if (!ids?.Any() ?? false)
yield break;
var sql = SqlContentSourcesSelect()
@@ -802,8 +805,8 @@ AND cmsContentNu.nodeId IS NULL
private ContentNodeKit CreateContentNodeKit(ContentSourceDto dto, IContentCacheDataSerializer serializer)
{
- ContentData d = null;
- ContentData p = null;
+ ContentData? d = null;
+ ContentData? p = null;
if (dto.Edited)
{
@@ -823,14 +826,14 @@ AND cmsContentNu.nodeId IS NULL
d = new ContentData(
dto.EditName,
- deserializedContent.UrlSegment,
+ deserializedContent?.UrlSegment,
dto.VersionId,
dto.EditVersionDate,
dto.EditWriterId,
dto.EditTemplateId,
published,
- deserializedContent.PropertyData,
- deserializedContent.CultureData);
+ deserializedContent?.PropertyData,
+ deserializedContent?.CultureData);
}
}
@@ -852,14 +855,14 @@ AND cmsContentNu.nodeId IS NULL
p = new ContentData(
dto.PubName,
- deserializedContent.UrlSegment,
+ deserializedContent?.UrlSegment,
dto.VersionId,
dto.PubVersionDate,
dto.PubWriterId,
dto.PubTemplateId,
published,
- deserializedContent.PropertyData,
- deserializedContent.CultureData);
+ deserializedContent?.PropertyData,
+ deserializedContent?.CultureData);
}
}
@@ -887,8 +890,8 @@ AND cmsContentNu.nodeId IS NULL
dto.CreatorId,
-1,
published,
- deserializedMedia.PropertyData,
- deserializedMedia.CultureData);
+ deserializedMedia?.PropertyData,
+ deserializedMedia?.CultureData);
var n = new ContentNode(dto.Id, dto.Key,
dto.Level, dto.Path, dto.SortOrder, dto.ParentId, dto.CreateDate, dto.CreatorId);
diff --git a/src/Umbraco.PublishedCache.NuCache/Persistence/NuCacheContentService.cs b/src/Umbraco.PublishedCache.NuCache/Persistence/NuCacheContentService.cs
index a86d412d13..18aa7f1658 100644
--- a/src/Umbraco.PublishedCache.NuCache/Persistence/NuCacheContentService.cs
+++ b/src/Umbraco.PublishedCache.NuCache/Persistence/NuCacheContentService.cs
@@ -82,7 +82,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache.Persistence
=> _repository.GetMediaSource(id);
///
- public IEnumerable GetTypeContentSources(IEnumerable ids)
+ public IEnumerable GetTypeContentSources(IEnumerable? ids)
=> _repository.GetTypeContentSources(ids);
///
@@ -115,9 +115,9 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache.Persistence
///
public void Rebuild(
- IReadOnlyCollection contentTypeIds = null,
- IReadOnlyCollection mediaTypeIds = null,
- IReadOnlyCollection memberTypeIds = null)
+ IReadOnlyCollection? contentTypeIds = null,
+ IReadOnlyCollection? mediaTypeIds = null,
+ IReadOnlyCollection? memberTypeIds = null)
{
using (IScope scope = ScopeProvider.CreateScope(repositoryCacheMode: RepositoryCacheMode.Scoped))
{
diff --git a/src/Umbraco.PublishedCache.NuCache/Property.cs b/src/Umbraco.PublishedCache.NuCache/Property.cs
index 0762b5791e..06aea62607 100644
--- a/src/Umbraco.PublishedCache.NuCache/Property.cs
+++ b/src/Umbraco.PublishedCache.NuCache/Property.cs
@@ -26,17 +26,17 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
private readonly object _locko = new object();
// the invariant-neutral source and inter values
- private readonly object _sourceValue;
+ private readonly object? _sourceValue;
private bool _interInitialized;
- private object _interValue;
+ private object? _interValue;
// the variant source and inter values
- private Dictionary _sourceValues;
+ private Dictionary? _sourceValues;
// the variant and non-variant object values
- private CacheValues _cacheValues;
+ private CacheValues? _cacheValues;
- private string _valuesCacheKey;
+ private string? _valuesCacheKey;
// initializes a published content property with no value
public Property(IPublishedPropertyType propertyType, PublishedContent content, IPublishedSnapshotAccessor publishedSnapshotAccessor, PropertyCacheLevel referenceCacheLevel = PropertyCacheLevel.Element)
@@ -44,7 +44,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
{ }
// initializes a published content property with a value
- public Property(IPublishedPropertyType propertyType, PublishedContent content, PropertyData[] sourceValues, IPublishedSnapshotAccessor publishedSnapshotAccessor, PropertyCacheLevel referenceCacheLevel = PropertyCacheLevel.Element)
+ public Property(IPublishedPropertyType propertyType, PublishedContent content, PropertyData[]? sourceValues, IPublishedSnapshotAccessor publishedSnapshotAccessor, PropertyCacheLevel referenceCacheLevel = PropertyCacheLevel.Element)
: base(propertyType, referenceCacheLevel)
{
if (sourceValues != null)
@@ -89,7 +89,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
}
// determines whether a property has value
- public override bool HasValue(string culture = null, string? segment = null)
+ public override bool HasValue(string? culture = null, string? segment = null)
{
_content.VariationContextAccessor.ContextualizeVariation(_variations, _content.Id, ref culture, ref segment);
@@ -126,7 +126,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
{
CacheValues cacheValues;
IPublishedSnapshot publishedSnapshot;
- IAppCache cache;
+ IAppCache? cache;
switch (cacheLevel)
{
case PropertyCacheLevel.None:
@@ -163,15 +163,15 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
return cacheValues;
}
- private CacheValues GetCacheValues(IAppCache cache)
+ private CacheValues GetCacheValues(IAppCache? cache)
{
if (cache == null) // no cache, don't cache
return new CacheValues();
- return (CacheValues) cache.Get(ValuesCacheKey, () => new CacheValues());
+ return (CacheValues) cache.Get(ValuesCacheKey, () => new CacheValues())!;
}
// this is always invoked from within a lock, so does not require its own lock
- private object GetInterValue(string culture, string segment)
+ private object? GetInterValue(string? culture, string? segment)
{
if (culture == "" && segment == "")
{
@@ -194,7 +194,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
return vvalue.InterValue;
}
- public override object GetSourceValue(string culture = null, string? segment = null)
+ public override object? GetSourceValue(string? culture = null, string? segment = null)
{
_content.VariationContextAccessor.ContextualizeVariation(_variations, _content.Id, ref culture, ref segment);
@@ -208,11 +208,11 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
}
}
- public override object GetValue(string culture = null, string? segment = null)
+ public override object? GetValue(string? culture = null, string? segment = null)
{
_content.VariationContextAccessor.ContextualizeVariation(_variations, _content.Id, ref culture, ref segment);
- object value;
+ object? value;
lock (_locko)
{
var cacheValues = GetCacheValues(PropertyType.CacheLevel).For(culture, segment);
@@ -229,7 +229,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
return value;
}
- public override object GetXPathValue(string culture = null, string? segment = null)
+ public override object? GetXPathValue(string? culture = null, string? segment = null)
{
_content.VariationContextAccessor.ContextualizeVariation(_variations, _content.Id, ref culture, ref segment);
@@ -252,17 +252,17 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
private class CacheValue
{
public bool ObjectInitialized { get; set; }
- public object ObjectValue { get; set; }
+ public object? ObjectValue { get; set; }
public bool XPathInitialized { get; set; }
- public object XPathValue { get; set; }
+ public object? XPathValue { get; set; }
}
private class CacheValues : CacheValue
{
- private Dictionary _values;
+ private Dictionary? _values;
// this is always invoked from within a lock, so does not require its own lock
- public CacheValue For(string culture, string segment)
+ public CacheValue For(string? culture, string? segment)
{
if (culture == "" && segment == "")
return this;
@@ -280,22 +280,22 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
private class SourceInterValue
{
- private string _culture;
- private string _segment;
+ private string? _culture;
+ private string? _segment;
- public string Culture
+ public string? Culture
{
get => _culture;
internal set => _culture = value?.ToLowerInvariant();
}
- public string Segment
+ public string? Segment
{
get => _segment;
internal set => _segment = value?.ToLowerInvariant();
}
- public object SourceValue { get; set; }
+ public object? SourceValue { get; set; }
public bool InterInitialized { get; set; }
- public object InterValue { get; set; }
+ public object? InterValue { get; set; }
}
#endregion
diff --git a/src/Umbraco.PublishedCache.NuCache/PublishedContent.cs b/src/Umbraco.PublishedCache.NuCache/PublishedContent.cs
index 596c97a670..0579f3eb28 100644
--- a/src/Umbraco.PublishedCache.NuCache/PublishedContent.cs
+++ b/src/Umbraco.PublishedCache.NuCache/PublishedContent.cs
@@ -13,18 +13,18 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
internal class PublishedContent : PublishedContentBase
{
private readonly IPublishedSnapshotAccessor _publishedSnapshotAccessor;
- private readonly IPublishedModelFactory _publishedModelFactory;
+ private readonly IPublishedModelFactory? _publishedModelFactory;
private readonly ContentNode _contentNode;
- private readonly string _urlSegment;
+ private readonly string? _urlSegment;
#region Constructors
public PublishedContent(
ContentNode contentNode,
ContentData contentData,
- IPublishedSnapshotAccessor publishedSnapshotAccessor,
- IVariationContextAccessor variationContextAccessor,
- IPublishedModelFactory publishedModelFactory) : base(variationContextAccessor)
+ IPublishedSnapshotAccessor? publishedSnapshotAccessor,
+ IVariationContextAccessor? variationContextAccessor,
+ IPublishedModelFactory? publishedModelFactory) : base(variationContextAccessor)
{
_contentNode = contentNode ?? throw new ArgumentNullException(nameof(contentNode));
ContentData = contentData ?? throw new ArgumentNullException(nameof(contentData));
@@ -90,13 +90,13 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
// this is for tests purposes
// args are: current published snapshot (may be null), previewing, content id - returns: content
- internal static Func GetContentByIdFunc { get; set; }
- = (publishedShapshot, previewing, id) => publishedShapshot.Content.GetById(previewing, id);
+ internal static Func GetContentByIdFunc { get; set; }
+ = (publishedShapshot, previewing, id) => publishedShapshot.Content?.GetById(previewing, id);
- internal static Func GetMediaByIdFunc { get; set; }
- = (publishedShapshot, previewing, id) => publishedShapshot.Media.GetById(previewing, id);
+ internal static Func GetMediaByIdFunc { get; set; }
+ = (publishedShapshot, previewing, id) => publishedShapshot.Media?.GetById(previewing, id);
- private Func GetGetterById()
+ private Func GetGetterById()
{
switch (ContentType.ItemType)
{
@@ -158,7 +158,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
// ReSharper disable once CollectionNeverUpdated.Local
private static readonly IReadOnlyDictionary EmptyCultures = new Dictionary();
- private IReadOnlyDictionary _cultures;
+ private IReadOnlyDictionary? _cultures;
///
public override IReadOnlyDictionary Cultures
@@ -185,7 +185,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
public override PublishedItemType ItemType => _contentNode.ContentType.ItemType;
///
- public override bool IsDraft(string culture = null)
+ public override bool IsDraft(string? culture = null)
{
// if this is the 'published' published content, nothing can be draft
if (ContentData.Published)
@@ -201,11 +201,11 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
// not the 'published' published content, and varies
// = depends on the culture
- return ContentData.CultureInfos.TryGetValue(culture, out var cvar) && cvar.IsDraft;
+ return ContentData.CultureInfos is not null && ContentData.CultureInfos.TryGetValue(culture, out var cvar) && cvar.IsDraft;
}
///
- public override bool IsPublished(string culture = null)
+ public override bool IsPublished(string? culture = null)
{
// whether we are the 'draft' or 'published' content, need to determine whether
// there is a 'published' version for the specified culture (or at all, for
@@ -233,7 +233,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
#region Tree
///
- public override IPublishedContent Parent
+ public override IPublishedContent? Parent
{
get
{
@@ -299,7 +299,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
public override IEnumerable Properties => PropertiesArray;
///
- public override IPublishedProperty GetProperty(string alias)
+ public override IPublishedProperty? GetProperty(string alias)
{
var index = _contentNode.ContentType.GetPropertyIndex(alias);
if (index < 0) return null; // happens when 'alias' does not match a content type property alias
@@ -314,7 +314,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
#region Caching
// beware what you use that one for - you don't want to cache its result
- private IAppCache GetAppropriateCache()
+ private IAppCache? GetAppropriateCache()
{
var publishedSnapshot = _publishedSnapshotAccessor.GetRequiredPublishedSnapshot();
var cache = publishedSnapshot == null
@@ -325,7 +325,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
return cache;
}
- private IAppCache GetCurrentSnapshotCache()
+ private IAppCache? GetCurrentSnapshotCache()
{
var publishedSnapshot = _publishedSnapshotAccessor.GetRequiredPublishedSnapshot();
return publishedSnapshot?.SnapshotCache;
@@ -348,7 +348,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
// includes all children, published or unpublished
// NavigableNavigator takes care of selecting those it wants
// note: this is not efficient - we do not try to be (would require a double-linked list)
- internal IList ChildIds => Children.Select(x => x.Id).ToList();
+ internal IList? ChildIds => Children?.Select(x => x.Id).ToList();
// used by Property
// gets a value indicating whether the content or media exists in
@@ -356,19 +356,19 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
// properties should refer to published, or draft content
internal bool IsPreviewing { get; }
- private string _asPreviewingCacheKey;
+ private string? _asPreviewingCacheKey;
private string AsPreviewingCacheKey => _asPreviewingCacheKey ?? (_asPreviewingCacheKey = CacheKeys.PublishedContentAsPreviewing(Key));
// used by ContentCache
- internal IPublishedContent AsDraft()
+ internal IPublishedContent? AsDraft()
{
if (IsPreviewing)
return this;
var cache = GetAppropriateCache();
if (cache == null) return new PublishedContent(this).CreateModel(_publishedModelFactory);
- return (IPublishedContent)cache.Get(AsPreviewingCacheKey, () => new PublishedContent(this).CreateModel(_publishedModelFactory));
+ return (IPublishedContent?)cache.Get(AsPreviewingCacheKey, () => new PublishedContent(this).CreateModel(_publishedModelFactory));
}
// used by Navigable.Source,...
diff --git a/src/Umbraco.PublishedCache.NuCache/PublishedMember.cs b/src/Umbraco.PublishedCache.NuCache/PublishedMember.cs
index 53cc597cf5..5670877499 100644
--- a/src/Umbraco.PublishedCache.NuCache/PublishedMember.cs
+++ b/src/Umbraco.PublishedCache.NuCache/PublishedMember.cs
@@ -26,7 +26,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
Member = member;
}
- public static IPublishedContent Create(
+ public static IPublishedContent? Create(
IMember member,
IPublishedContentType contentType,
bool previewing,
@@ -88,7 +88,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
return properties;
}
- private static void AddIf(IPublishedContentType contentType, IDictionary properties, string alias, object value)
+ private static void AddIf(IPublishedContentType contentType, IDictionary properties, string alias, object? value)
{
var propertyType = contentType.GetPropertyType(alias);
if (propertyType == null || propertyType.IsUserProperty) return;
@@ -103,7 +103,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
public string UserName => Member.Username;
- public string Comments => Member.Comments;
+ public string? Comments => Member.Comments;
public bool IsApproved => Member.IsApproved;
diff --git a/src/Umbraco.PublishedCache.NuCache/PublishedSnapshot.cs b/src/Umbraco.PublishedCache.NuCache/PublishedSnapshot.cs
index 68446b1dcc..74239f42dc 100644
--- a/src/Umbraco.PublishedCache.NuCache/PublishedSnapshot.cs
+++ b/src/Umbraco.PublishedCache.NuCache/PublishedSnapshot.cs
@@ -8,9 +8,9 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
// implements published snapshot
public class PublishedSnapshot : IPublishedSnapshot, IDisposable
{
- private readonly PublishedSnapshotService _service;
+ private readonly PublishedSnapshotService? _service;
private bool _defaultPreview;
- private PublishedSnapshotElements _elements;
+ private PublishedSnapshotElements? _elements;
#region Constructors
@@ -23,19 +23,19 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
public class PublishedSnapshotElements : IDisposable
{
#pragma warning disable IDE1006 // Naming Styles
- public ContentCache ContentCache;
- public MediaCache MediaCache;
- public MemberCache MemberCache;
- public DomainCache DomainCache;
- public IAppCache SnapshotCache;
- public IAppCache ElementsCache;
+ public ContentCache? ContentCache;
+ public MediaCache? MediaCache;
+ public MemberCache? MemberCache;
+ public DomainCache? DomainCache;
+ public IAppCache? SnapshotCache;
+ public IAppCache? ElementsCache;
#pragma warning restore IDE1006 // Naming Styles
public void Dispose()
{
- ContentCache.Dispose();
- MediaCache.Dispose();
- MemberCache.Dispose();
+ ContentCache?.Dispose();
+ MediaCache?.Dispose();
+ MemberCache?.Dispose();
}
}
@@ -62,23 +62,23 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
#region Caches
- public IAppCache SnapshotCache => Elements.SnapshotCache;
+ public IAppCache? SnapshotCache => Elements.SnapshotCache;
- public IAppCache ElementsCache => Elements.ElementsCache;
+ public IAppCache? ElementsCache => Elements.ElementsCache;
#endregion
#region IPublishedSnapshot
- public IPublishedContentCache Content => Elements.ContentCache;
+ public IPublishedContentCache? Content => Elements.ContentCache;
- public IPublishedMediaCache Media => Elements.MediaCache;
+ public IPublishedMediaCache? Media => Elements.MediaCache;
- public IPublishedMemberCache Members => Elements.MemberCache;
+ public IPublishedMemberCache? Members => Elements.MemberCache;
- public IDomainCache Domains => Elements.DomainCache;
+ public IDomainCache? Domains => Elements.DomainCache;
- public IDisposable ForcedPreview(bool preview, Action callback = null)
+ public IDisposable ForcedPreview(bool preview, Action? callback = null)
{
return new ForcedPreviewObject(this, preview, callback);
}
@@ -87,9 +87,9 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
{
private readonly PublishedSnapshot _publishedSnapshot;
private readonly bool _origPreview;
- private readonly Action _callback;
+ private readonly Action? _callback;
- public ForcedPreviewObject(PublishedSnapshot publishedShapshot, bool preview, Action callback)
+ public ForcedPreviewObject(PublishedSnapshot publishedShapshot, bool preview, Action? callback)
{
_publishedSnapshot = publishedShapshot;
_callback = callback;
diff --git a/src/Umbraco.PublishedCache.NuCache/PublishedSnapshotService.cs b/src/Umbraco.PublishedCache.NuCache/PublishedSnapshotService.cs
index 80dfc8b73d..dee5231031 100644
--- a/src/Umbraco.PublishedCache.NuCache/PublishedSnapshotService.cs
+++ b/src/Umbraco.PublishedCache.NuCache/PublishedSnapshotService.cs
@@ -51,23 +51,23 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
private bool _isReady;
private bool _isReadSet;
- private object _isReadyLock;
+ private object? _isReadyLock;
- private ContentStore _contentStore;
- private ContentStore _mediaStore;
- private SnapDictionary _domainStore;
+ private ContentStore _contentStore = null!;
+ private ContentStore _mediaStore = null!;
+ private SnapDictionary _domainStore = null!;
private readonly object _storesLock = new object();
private readonly object _elementsLock = new object();
- private BPlusTree _localContentDb;
- private BPlusTree _localMediaDb;
+ private BPlusTree? _localContentDb;
+ private BPlusTree? _localMediaDb;
private bool _localContentDbExists;
private bool _localMediaDbExists;
private long _contentGen;
private long _mediaGen;
private long _domainGen;
- private IAppCache _elementsCache;
+ private IAppCache? _elementsCache;
// define constant - determines whether to use cache when previewing
// to store eg routes, property converted values, anything - caching
@@ -114,12 +114,12 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
_publishedModelFactory = publishedModelFactory;
}
- protected PublishedSnapshot CurrentPublishedSnapshot
+ protected PublishedSnapshot? CurrentPublishedSnapshot
{
get
{
_publishedSnapshotAccessor.TryGetPublishedSnapshot(out var publishedSnapshot);
- return (PublishedSnapshot)publishedSnapshot;
+ return (PublishedSnapshot?)publishedSnapshot;
}
}
@@ -150,9 +150,9 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
return GetUid(_mediaStore, id);
}
- private int GetId(ContentStore store, Guid uid) => store.LiveSnapshot.Get(uid)?.Id ?? 0;
+ private int GetId(ContentStore? store, Guid uid) => store?.LiveSnapshot.Get(uid)?.Id ?? 0;
- private Guid GetUid(ContentStore store, int id) => store.LiveSnapshot.Get(id)?.Uid ?? Guid.Empty;
+ private Guid GetUid(ContentStore? store, int id) => store?.LiveSnapshot.Get(id)?.Uid ?? Guid.Empty;
///
/// Install phase of
@@ -309,7 +309,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
// first get a writer, then a scope
// if there already is a scope, the writer will attach to it
// otherwise, it will only exist here - cheap
- using (_contentStore.GetScopedWriteLock(_scopeProvider))
+ using (_contentStore?.GetScopedWriteLock(_scopeProvider))
using (var scope = _scopeProvider.CreateScope())
{
scope.ReadLock(Constants.Locks.ContentTree);
@@ -325,9 +325,9 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
// contentStore is wlocked (1 thread)
// content (and types) are read-locked
- var contentTypes = _serviceContext.ContentTypeService.GetAll().ToList();
+ var contentTypes = _serviceContext.ContentTypeService?.GetAll().ToList();
- _contentStore.SetAllContentTypesLocked(contentTypes.Select(x => _publishedContentTypeFactory.CreateContentType(x)));
+ _contentStore.SetAllContentTypesLocked(contentTypes?.Select(x => _publishedContentTypeFactory.CreateContentType(x)));
using (_profilingLogger.TraceDuration("Loading content from database"))
{
@@ -344,7 +344,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
private bool LoadContentFromLocalDbLocked(bool onStartup)
{
- var contentTypes = _serviceContext.ContentTypeService.GetAll()
+ var contentTypes = _serviceContext.ContentTypeService?.GetAll()
.Select(x => _publishedContentTypeFactory.CreateContentType(x));
_contentStore.SetAllContentTypesLocked(contentTypes);
@@ -360,7 +360,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
private bool LockAndLoadMedia(Func action)
{
// see note in LockAndLoadContent
- using (_mediaStore.GetScopedWriteLock(_scopeProvider))
+ using (_mediaStore?.GetScopedWriteLock(_scopeProvider))
using (var scope = _scopeProvider.CreateScope())
{
scope.ReadLock(Constants.Locks.MediaTree);
@@ -373,7 +373,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
private bool LoadMediaFromDatabaseLocked(bool onStartup)
{
// locks & notes: see content
- var mediaTypes = _serviceContext.MediaTypeService.GetAll()
+ var mediaTypes = _serviceContext.MediaTypeService?.GetAll()
.Select(x => _publishedContentTypeFactory.CreateContentType(x));
_mediaStore.SetAllContentTypesLocked(mediaTypes);
@@ -392,7 +392,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
private bool LoadMediaFromLocalDbLocked(bool onStartup)
{
- var mediaTypes = _serviceContext.MediaTypeService.GetAll()
+ var mediaTypes = _serviceContext.MediaTypeService?.GetAll()
.Select(x => _publishedContentTypeFactory.CreateContentType(x));
_mediaStore.SetAllContentTypesLocked(mediaTypes);
@@ -405,15 +405,15 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
}
}
- private bool LoadEntitiesFromLocalDbLocked(bool onStartup, BPlusTree localDb, ContentStore store, string entityType)
+ private bool LoadEntitiesFromLocalDbLocked(bool onStartup, BPlusTree? localDb, ContentStore store, string entityType)
{
- var kits = localDb.Select(x => x.Value)
+ var kits = localDb?.Select(x => x.Value)
.OrderBy(x => x.Node.Level)
.ThenBy(x => x.Node.ParentContentId)
.ThenBy(x => x.Node.SortOrder) // IMPORTANT sort by level + parentId + sortOrder
.ToList();
- if (kits.Count == 0)
+ if (kits is null || kits.Count == 0)
{
// If there's nothing in the local cache file, we should return false? YES even though the site legitately might be empty.
// Is it possible that the cache file is empty but the database is not? YES... (well, it used to be possible)
@@ -440,7 +440,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
private void LockAndLoadDomains()
{
// see note in LockAndLoadContent
- using (_domainStore.GetScopedWriteLock(_scopeProvider))
+ using (_domainStore?.GetScopedWriteLock(_scopeProvider))
using (var scope = _scopeProvider.CreateScope())
{
scope.ReadLock(Constants.Locks.Domains);
@@ -451,12 +451,15 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
private void LoadDomainsLocked()
{
- var domains = _serviceContext.DomainService.GetAll(true);
- foreach (var domain in domains
- .Where(x => x.RootContentId.HasValue && x.LanguageIsoCode.IsNullOrWhiteSpace() == false)
- .Select(x => new Domain(x.Id, x.DomainName, x.RootContentId.Value, x.LanguageIsoCode, x.IsWildcard)))
+ var domains = _serviceContext.DomainService?.GetAll(true);
+ if (domains is not null)
{
- _domainStore.SetLocked(domain.Id, domain);
+ foreach (var domain in domains
+ .Where(x => x.RootContentId.HasValue && x.LanguageIsoCode.IsNullOrWhiteSpace() == false)
+ .Select(x => new Domain(x.Id, x.DomainName, x.RootContentId!.Value, x.LanguageIsoCode!, x.IsWildcard)))
+ {
+ _domainStore.SetLocked(domain.Id, domain);
+ }
}
}
@@ -718,7 +721,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
CurrentPublishedSnapshot?.Resync();
}
- private void Notify(ContentStore store, ContentTypeCacheRefresher.JsonPayload[] payloads, Action, List, List, List> action)
+ private void Notify(ContentStore store, ContentTypeCacheRefresher.JsonPayload[] payloads, Action?, List?, List?, List?> action)
where T : IContentTypeComposition
{
if (payloads.Length == 0)
@@ -728,7 +731,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
var nameOfT = typeof(T).Name;
- List removedIds = null, refreshedIds = null, otherIds = null, newIds = null;
+ List? removedIds = null, refreshedIds = null, otherIds = null, newIds = null;
foreach (var payload in payloads)
{
@@ -829,7 +832,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
_domainStore.ClearLocked(payload.Id);
break;
case DomainChangeTypes.Refresh:
- var domain = _serviceContext.DomainService.GetById(payload.Id);
+ var domain = _serviceContext.DomainService?.GetById(payload.Id);
if (domain == null)
continue;
if (domain.RootContentId.HasValue == false)
@@ -845,51 +848,56 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
}
// Methods used to prevent allocations of lists
- private void AddToList(ref List list, int val) => GetOrCreateList(ref list).Add(val);
+ private void AddToList(ref List? list, int val) => GetOrCreateList(ref list).Add(val);
- private List GetOrCreateList(ref List list) => list ?? (list = new List());
+ private List GetOrCreateList(ref List? list) => list ?? (list = new List());
- private IReadOnlyCollection CreateContentTypes(PublishedItemType itemType, int[] ids)
+ private IReadOnlyCollection CreateContentTypes(PublishedItemType itemType, int[]? ids)
{
// XxxTypeService.GetAll(empty) returns everything!
- if (ids.Length == 0)
+ if (ids is null || ids.Length == 0)
{
return Array.Empty();
}
- IEnumerable contentTypes;
+ IEnumerable? contentTypes;
switch (itemType)
{
case PublishedItemType.Content:
- contentTypes = _serviceContext.ContentTypeService.GetAll(ids);
+ contentTypes = _serviceContext.ContentTypeService?.GetAll(ids);
break;
case PublishedItemType.Media:
- contentTypes = _serviceContext.MediaTypeService.GetAll(ids);
+ contentTypes = _serviceContext.MediaTypeService?.GetAll(ids);
break;
case PublishedItemType.Member:
- contentTypes = _serviceContext.MemberTypeService.GetAll(ids);
+ contentTypes = _serviceContext.MemberTypeService?.GetAll(ids);
break;
default:
throw new ArgumentOutOfRangeException(nameof(itemType));
}
+ if (contentTypes is null)
+ {
+ return Array.Empty();
+ }
+
// some may be missing - not checking here
return contentTypes.Select(x => _publishedContentTypeFactory.CreateContentType(x)).ToList();
}
- private IPublishedContentType CreateContentType(PublishedItemType itemType, int id)
+ private IPublishedContentType? CreateContentType(PublishedItemType itemType, int id)
{
- IContentTypeComposition contentType;
+ IContentTypeComposition? contentType;
switch (itemType)
{
case PublishedItemType.Content:
- contentType = _serviceContext.ContentTypeService.Get(id);
+ contentType = _serviceContext.ContentTypeService?.Get(id);
break;
case PublishedItemType.Media:
- contentType = _serviceContext.MediaTypeService.Get(id);
+ contentType = _serviceContext.MediaTypeService?.Get(id);
break;
case PublishedItemType.Member:
- contentType = _serviceContext.MemberTypeService.Get(id);
+ contentType = _serviceContext.MemberTypeService?.Get(id);
break;
default:
throw new ArgumentOutOfRangeException(nameof(itemType));
@@ -898,7 +906,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
return contentType == null ? null : _publishedContentTypeFactory.CreateContentType(contentType);
}
- private void RefreshContentTypesLocked(List removedIds, List refreshedIds, List otherIds, List newIds)
+ private void RefreshContentTypesLocked(List? removedIds, List? refreshedIds, List? otherIds, List? newIds)
{
if (removedIds.IsCollectionEmpty() && refreshedIds.IsCollectionEmpty() && otherIds.IsCollectionEmpty() && newIds.IsCollectionEmpty())
{
@@ -915,7 +923,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
var typesA = refreshedIds.IsCollectionEmpty()
? Array.Empty()
- : CreateContentTypes(PublishedItemType.Content, refreshedIds.ToArray()).ToArray();
+ : CreateContentTypes(PublishedItemType.Content, refreshedIds?.ToArray()).ToArray();
var kits = refreshedIds.IsCollectionEmpty()
? Array.Empty()
@@ -924,19 +932,19 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
_contentStore.UpdateContentTypesLocked(removedIds, typesA, kits);
if (!otherIds.IsCollectionEmpty())
{
- _contentStore.UpdateContentTypesLocked(CreateContentTypes(PublishedItemType.Content, otherIds.ToArray()));
+ _contentStore.UpdateContentTypesLocked(CreateContentTypes(PublishedItemType.Content, otherIds?.ToArray()));
}
if (!newIds.IsCollectionEmpty())
{
- _contentStore.NewContentTypesLocked(CreateContentTypes(PublishedItemType.Content, newIds.ToArray()));
+ _contentStore.NewContentTypesLocked(CreateContentTypes(PublishedItemType.Content, newIds?.ToArray()));
}
scope.Complete();
}
}
- private void RefreshMediaTypesLocked(List removedIds, List refreshedIds, List otherIds, List newIds)
+ private void RefreshMediaTypesLocked(List? removedIds, List? refreshedIds, List? otherIds, List? newIds)
{
if (removedIds.IsCollectionEmpty() && refreshedIds.IsCollectionEmpty() && otherIds.IsCollectionEmpty() && newIds.IsCollectionEmpty())
{
@@ -962,12 +970,12 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
_mediaStore.UpdateContentTypesLocked(removedIds, typesA, kits);
if (!otherIds.IsCollectionEmpty())
{
- _mediaStore.UpdateContentTypesLocked(CreateContentTypes(PublishedItemType.Media, otherIds.ToArray()).ToArray());
+ _mediaStore.UpdateContentTypesLocked(CreateContentTypes(PublishedItemType.Media, otherIds?.ToArray()).ToArray());
}
if (!newIds.IsCollectionEmpty())
{
- _mediaStore.NewContentTypesLocked(CreateContentTypes(PublishedItemType.Media, newIds.ToArray()).ToArray());
+ _mediaStore.NewContentTypesLocked(CreateContentTypes(PublishedItemType.Media, newIds?.ToArray()).ToArray());
}
scope.Complete();
@@ -1006,7 +1014,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
// ie FastDictionaryAppCache (thread safe and all)
ContentStore.Snapshot contentSnap, mediaSnap;
SnapDictionary.Snapshot domainSnap;
- IAppCache elementsCache;
+ IAppCache? elementsCache;
// Here we are reading/writing to shared objects so we need to lock (can't be _storesLock which manages the actual nucache files
// and would result in a deadlock). Even though we are locking around underlying readlocks (within CreateSnapshot) it's because
@@ -1015,7 +1023,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
lock (_elementsLock)
{
- IScopeContext scopeContext = _scopeProvider.Context;
+ IScopeContext? scopeContext = _scopeProvider.Context;
if (scopeContext == null)
{
@@ -1041,7 +1049,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
scopeContext.Enlist("Umbraco.Web.PublishedCache.NuCache.PublishedSnapshotService.Resync", () => this, (completed, svc) =>
{
- svc.CurrentPublishedSnapshot?.Resync();
+ svc?.CurrentPublishedSnapshot?.Resync();
}, int.MaxValue);
}
@@ -1075,9 +1083,9 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
///
public void Rebuild(
- IReadOnlyCollection contentTypeIds = null,
- IReadOnlyCollection mediaTypeIds = null,
- IReadOnlyCollection memberTypeIds = null)
+ IReadOnlyCollection? contentTypeIds = null,
+ IReadOnlyCollection? mediaTypeIds = null,
+ IReadOnlyCollection? memberTypeIds = null)
=> _publishedContentService.Rebuild(contentTypeIds, mediaTypeIds, memberTypeIds);
public async Task CollectAsync()
@@ -1094,7 +1102,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
return _contentStore;
}
- internal ContentStore GetMediaStore()
+ internal ContentStore? GetMediaStore()
{
EnsureCaches();
return _mediaStore;
diff --git a/src/Umbraco.PublishedCache.NuCache/PublishedSnapshotStatus.cs b/src/Umbraco.PublishedCache.NuCache/PublishedSnapshotStatus.cs
index 6a75e3e021..3c1d2cabda 100644
--- a/src/Umbraco.PublishedCache.NuCache/PublishedSnapshotStatus.cs
+++ b/src/Umbraco.PublishedCache.NuCache/PublishedSnapshotStatus.cs
@@ -8,10 +8,10 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
///
internal class PublishedSnapshotStatus : IPublishedSnapshotStatus
{
- private readonly PublishedSnapshotService _service;
+ private readonly PublishedSnapshotService? _service;
private readonly INuCacheContentService _publishedContentService;
- public PublishedSnapshotStatus(IPublishedSnapshotService service, INuCacheContentService publishedContentService)
+ public PublishedSnapshotStatus(IPublishedSnapshotService? service, INuCacheContentService publishedContentService)
{
_service = service as PublishedSnapshotService;
_publishedContentService = publishedContentService;
@@ -26,7 +26,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
if (_service == null)
{
return $"The current {typeof(IPublishedSnapshotService)} is not the default type. A status cannot be determined.";
- }
+ }
// TODO: This should be private
_service.EnsureCaches();
@@ -37,15 +37,15 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
? "ok"
: "NOT ok (rebuild?)";
- ContentStore contentStore = _service.GetContentStore();
- ContentStore mediaStore = _service.GetMediaStore();
+ ContentStore? contentStore = _service.GetContentStore();
+ ContentStore? mediaStore = _service.GetMediaStore();
- var contentStoreGen = contentStore.GenCount;
- var mediaStoreGen = mediaStore.GenCount;
- var contentStoreSnap = contentStore.SnapCount;
- var mediaStoreSnap = mediaStore.SnapCount;
- var contentStoreCount = contentStore.Count;
- var mediaStoreCount = mediaStore.Count;
+ var contentStoreGen = contentStore?.GenCount;
+ var mediaStoreGen = mediaStore?.GenCount;
+ var contentStoreSnap = contentStore?.SnapCount;
+ var mediaStoreSnap = mediaStore?.SnapCount;
+ var contentStoreCount = contentStore?.Count;
+ var mediaStoreCount = mediaStore?.Count;
string contentStoreCountPlural = contentStoreCount > 1 ? "s" : string.Empty;
string contentStoreGenPlural = contentStoreGen > 1 ? "s" : string.Empty;
diff --git a/src/Umbraco.PublishedCache.NuCache/Snap/GenObj.cs b/src/Umbraco.PublishedCache.NuCache/Snap/GenObj.cs
index a5dc6ae06b..25a0435f65 100644
--- a/src/Umbraco.PublishedCache.NuCache/Snap/GenObj.cs
+++ b/src/Umbraco.PublishedCache.NuCache/Snap/GenObj.cs
@@ -14,7 +14,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache.Snap
public GenRef GetGenRef()
{
// not thread-safe but always invoked from within a lock
- var genRef = (GenRef)WeakGenRef.Target;
+ var genRef = (GenRef?)WeakGenRef.Target;
if (genRef == null)
WeakGenRef.Target = genRef = new GenRef(this);
return genRef;
diff --git a/src/Umbraco.PublishedCache.NuCache/Snap/LinkedNode.cs b/src/Umbraco.PublishedCache.NuCache/Snap/LinkedNode.cs
index df82b47e94..a9fd07f88f 100644
--- a/src/Umbraco.PublishedCache.NuCache/Snap/LinkedNode.cs
+++ b/src/Umbraco.PublishedCache.NuCache/Snap/LinkedNode.cs
@@ -7,9 +7,9 @@
///
///
internal class LinkedNode
- where TValue : class
+ where TValue : class?
{
- public LinkedNode(TValue value, long gen, LinkedNode next = null)
+ public LinkedNode(TValue? value, long gen, LinkedNode? next = null)
{
Value = value; // This is allowed to be null, we actually explicitly set this to null in ClearLocked
Gen = gen;
@@ -20,7 +20,7 @@
// reading & writing references is thread-safe on all .NET platforms
// mark as volatile to ensure we always read the correct value
- public volatile TValue Value;
- public volatile LinkedNode Next;
+ public volatile TValue? Value;
+ public volatile LinkedNode? Next;
}
}
diff --git a/src/Umbraco.PublishedCache.NuCache/SnapDictionary.cs b/src/Umbraco.PublishedCache.NuCache/SnapDictionary.cs
index bd250027bb..7437527d2a 100644
--- a/src/Umbraco.PublishedCache.NuCache/SnapDictionary.cs
+++ b/src/Umbraco.PublishedCache.NuCache/SnapDictionary.cs
@@ -12,6 +12,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
{
public class SnapDictionary
where TValue : class
+ where TKey : notnull
{
// read
// http://www.codeproject.com/Articles/548406/Dictionary-plus-Locking-versus-ConcurrentDictionar
@@ -29,12 +30,12 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
private readonly ConcurrentDictionary> _items;
private readonly ConcurrentQueue _genObjs;
- private GenObj _genObj;
+ private GenObj? _genObj;
private readonly object _wlocko = new object();
private readonly object _rlocko = new object();
private long _liveGen, _floorGen;
private bool _nextGen, _collectAuto;
- private Task _collectTask;
+ private Task? _collectTask;
// minGenDelta to be adjusted
// we may want to throttle collects even if delta is reached
@@ -107,7 +108,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
// the dict is write-locked until the write-lock is released
// which happens when it is disposed (non-scoped)
// or when the scope context exits (scoped)
- public IDisposable GetScopedWriteLock(IScopeProvider scopeProvider)
+ public IDisposable? GetScopedWriteLock(IScopeProvider scopeProvider)
{
return ScopeContextualBase.Get(scopeProvider, _instanceId, scoped => new ScopedWriteLock(this, scoped));
}
@@ -191,13 +192,13 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
public int Count => _items.Count;
- private LinkedNode GetHead(TKey key)
+ private LinkedNode? GetHead(TKey key)
{
_items.TryGetValue(key, out var link); // else null
return link;
}
- public void SetLocked(TKey key, TValue value)
+ public void SetLocked(TKey key, TValue? value)
{
EnsureLocked();
@@ -253,7 +254,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
}
}
- public TValue Get(TKey key, long gen)
+ public TValue? Get(TKey key, long gen)
{
// look ma, no lock!
var link = GetHead(key);
@@ -396,7 +397,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
while (_genObjs.TryPeek(out var genObj) && (genObj.Count == 0 || genObj.WeakGenRef.IsAlive == false))
{
_genObjs.TryDequeue(out genObj); // cannot fail since TryPeek has succeeded
- _floorGen = genObj.Gen;
+ _floorGen = genObj!.Gen;
}
Collect(_items);
@@ -476,7 +477,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
#region Unit testing
- private TestHelper _unitTesting;
+ private TestHelper? _unitTesting;
// note: nothing here is thread-safe
internal class TestHelper
@@ -499,7 +500,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
set => _dict._collectAuto = value;
}
- public GenObj GenObj => _dict._genObj;
+ public GenObj? GenObj => _dict._genObj;
public ConcurrentQueue GenObjs => _dict._genObjs;
@@ -523,14 +524,14 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
public class GenVal
{
- public GenVal(long gen, TValue value)
+ public GenVal(long gen, TValue? value)
{
Gen = gen;
Value = value;
}
public long Gen { get; }
- public TValue Value { get; }
+ public TValue? Value { get; }
}
}
@@ -543,7 +544,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
public class Snapshot : IDisposable
{
private readonly SnapDictionary _store;
- private readonly GenRef _genRef;
+ private readonly GenRef? _genRef;
private readonly long _gen; // copied for perfs
private int _disposed;
@@ -571,7 +572,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
throw new ObjectDisposedException("snapshot" /*+ " (" + _thisCount + ")"*/);
}
- public TValue Get(TKey key)
+ public TValue? Get(TKey key)
{
EnsureNotDisposed();
return _store.Get(key, _gen);
diff --git a/src/Umbraco.PublishedCache.NuCache/Umbraco.PublishedCache.NuCache.csproj b/src/Umbraco.PublishedCache.NuCache/Umbraco.PublishedCache.NuCache.csproj
index 0caba0b128..3d4926b44d 100644
--- a/src/Umbraco.PublishedCache.NuCache/Umbraco.PublishedCache.NuCache.csproj
+++ b/src/Umbraco.PublishedCache.NuCache/Umbraco.PublishedCache.NuCache.csproj
@@ -3,10 +3,10 @@
net6.0
Umbraco.Cms.Infrastructure.PublishedCache
- 8
Umbraco.Cms.PublishedCache.NuCache
Umbraco CMS Published Cache
Contains the Published Cache assembly needed to run Umbraco Cms. This package only contains the assembly, and can be used for package development. Use the template in the Umbraco.Templates package to setup Umbraco
+ enable
diff --git a/src/Umbraco.Web.Common/Templates/TemplateRenderer.cs b/src/Umbraco.Web.Common/Templates/TemplateRenderer.cs
index 46d5856c9d..982ec53ed9 100644
--- a/src/Umbraco.Web.Common/Templates/TemplateRenderer.cs
+++ b/src/Umbraco.Web.Common/Templates/TemplateRenderer.cs
@@ -76,7 +76,7 @@ namespace Umbraco.Cms.Web.Common.Templates
// terribly much for this implementation since we are just creating a doc content request to modify it's properties manually.
var requestBuilder = await _publishedRouter.CreateRequestAsync(umbracoContext.CleanedUmbracoUrl);
- var doc = umbracoContext.Content.GetById(pageId);
+ var doc = umbracoContext.Content?.GetById(pageId);
if (doc == null)
{
diff --git a/src/Umbraco.Web.Common/Umbraco.Web.Common.csproj b/src/Umbraco.Web.Common/Umbraco.Web.Common.csproj
index b023b5ecdc..a2f7bfdc32 100644
--- a/src/Umbraco.Web.Common/Umbraco.Web.Common.csproj
+++ b/src/Umbraco.Web.Common/Umbraco.Web.Common.csproj
@@ -7,6 +7,7 @@
Umbraco.Cms.Web.Common
Umbraco CMS Web
Contains the Web assembly needed to run Umbraco Cms. This package only contains the assembly, and can be used for package development. Use the template in the Umbraco.Templates package to setup Umbraco
+ enable
diff --git a/src/Umbraco.Web.Common/UmbracoContext/UmbracoContext.cs b/src/Umbraco.Web.Common/UmbracoContext/UmbracoContext.cs
index 98f3db5483..c24db1502b 100644
--- a/src/Umbraco.Web.Common/UmbracoContext/UmbracoContext.cs
+++ b/src/Umbraco.Web.Common/UmbracoContext/UmbracoContext.cs
@@ -88,10 +88,10 @@ namespace Umbraco.Cms.Web.Common.UmbracoContext
public IPublishedSnapshot PublishedSnapshot => _publishedSnapshot.Value;
///
- public IPublishedContentCache Content => PublishedSnapshot.Content;
+ public IPublishedContentCache? Content => PublishedSnapshot.Content;
///
- public IPublishedMediaCache Media => PublishedSnapshot.Media;
+ public IPublishedMediaCache? Media => PublishedSnapshot.Media;
///
public IDomainCache? Domains => PublishedSnapshot.Domains;
diff --git a/src/Umbraco.Web.Common/UmbracoHelper.cs b/src/Umbraco.Web.Common/UmbracoHelper.cs
index c7e29a7302..1b41a6b2fd 100644
--- a/src/Umbraco.Web.Common/UmbracoHelper.cs
+++ b/src/Umbraco.Web.Common/UmbracoHelper.cs
@@ -183,7 +183,7 @@ namespace Umbraco.Cms.Web.Common
private IPublishedContent? ContentForObject(object id) => _publishedContentQuery.Content(id);
- public IPublishedContent ContentSingleAtXPath(string xpath, params XPathVariable[] vars)
+ public IPublishedContent? ContentSingleAtXPath(string xpath, params XPathVariable[] vars)
{
return _publishedContentQuery.ContentSingleAtXPath(xpath, vars);
}
@@ -200,7 +200,7 @@ namespace Umbraco.Cms.Web.Common
///
/// The key of the content item.
/// The content, or null of the content item is not in the cache.
- public IPublishedContent Content(Guid id) => _publishedContentQuery.Content(id);
+ public IPublishedContent? Content(Guid id) => _publishedContentQuery.Content(id);
///
/// Gets a content item from the cache.
@@ -322,7 +322,7 @@ namespace Umbraco.Cms.Web.Common
public IPublishedContent? Media(Udi id) => _publishedContentQuery.Media(id);
- public IPublishedContent Media(Guid id) => _publishedContentQuery.Media(id);
+ public IPublishedContent? Media(Guid id) => _publishedContentQuery.Media(id);
///
/// Overloaded method accepting an 'object' type