Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Umbraco.ModelsBuilder.Embedded v16.5.0+8b2c22a
//
// Changes to this file will be lost if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using System;
using System.Linq.Expressions;
using Umbraco.Cms.Core.Models.PublishedContent;
using Umbraco.Cms.Core.PublishedCache;
using Umbraco.Cms.Infrastructure.ModelsBuilder;
using Umbraco.Cms.Core;
using Umbraco.Extensions;

namespace Umbraco.Cms.Web.Common.PublishedModels
{
// Mixin Content Type with alias "uTPro__ContentLayout"
/// <summary>Content Layout</summary>
public partial interface IUTpro__ContentLayout : IPublishedContent
{
/// <summary>Bottom Component</summary>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Umbraco.ModelsBuilder.Embedded", "16.5.0+8b2c22a")]
[global::System.Diagnostics.CodeAnalysis.MaybeNull]
global::Umbraco.Cms.Core.Models.Blocks.BlockGridModel BottomComponent { get; }

/// <summary>Top Component</summary>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Umbraco.ModelsBuilder.Embedded", "16.5.0+8b2c22a")]
[global::System.Diagnostics.CodeAnalysis.MaybeNull]
global::Umbraco.Cms.Core.Models.Blocks.BlockGridModel TopComponent { get; }
}

/// <summary>Content Layout</summary>
[PublishedModel("uTPro__ContentLayout")]
public partial class UTpro__ContentLayout : PublishedContentModel, IUTpro__ContentLayout
{
// helpers
#pragma warning disable 0109 // new is redundant
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Umbraco.ModelsBuilder.Embedded", "16.5.0+8b2c22a")]
public new const string ModelTypeAlias = "uTPro__ContentLayout";
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Umbraco.ModelsBuilder.Embedded", "16.5.0+8b2c22a")]
public new const PublishedItemType ModelItemType = PublishedItemType.Content;
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Umbraco.ModelsBuilder.Embedded", "16.5.0+8b2c22a")]
[return: global::System.Diagnostics.CodeAnalysis.MaybeNull]
public new static IPublishedContentType GetModelContentType(IPublishedContentTypeCache contentTypeCache)
=> PublishedModelUtility.GetModelContentType(contentTypeCache, ModelItemType, ModelTypeAlias);
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Umbraco.ModelsBuilder.Embedded", "16.5.0+8b2c22a")]
[return: global::System.Diagnostics.CodeAnalysis.MaybeNull]
public static IPublishedPropertyType GetModelPropertyType<TValue>(IPublishedContentTypeCache contentTypeCache, Expression<Func<UTpro__ContentLayout, TValue>> selector)
=> PublishedModelUtility.GetModelPropertyType(GetModelContentType(contentTypeCache), selector);
#pragma warning restore 0109

private IPublishedValueFallback _publishedValueFallback;

// ctor
public UTpro__ContentLayout(IPublishedContent content, IPublishedValueFallback publishedValueFallback)
: base(content, publishedValueFallback)
{
_publishedValueFallback = publishedValueFallback;
}

// properties

///<summary>
/// Bottom Component
///</summary>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Umbraco.ModelsBuilder.Embedded", "16.5.0+8b2c22a")]
[global::System.Diagnostics.CodeAnalysis.MaybeNull]
[ImplementPropertyType("bottomComponent")]
public virtual global::Umbraco.Cms.Core.Models.Blocks.BlockGridModel BottomComponent => GetBottomComponent(this, _publishedValueFallback);

/// <summary>Static getter for Bottom Component</summary>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Umbraco.ModelsBuilder.Embedded", "16.5.0+8b2c22a")]
[return: global::System.Diagnostics.CodeAnalysis.MaybeNull]
public static global::Umbraco.Cms.Core.Models.Blocks.BlockGridModel GetBottomComponent(IUTpro__ContentLayout that, IPublishedValueFallback publishedValueFallback) => that.Value<global::Umbraco.Cms.Core.Models.Blocks.BlockGridModel>(publishedValueFallback, "bottomComponent");

///<summary>
/// Top Component
///</summary>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Umbraco.ModelsBuilder.Embedded", "16.5.0+8b2c22a")]
[global::System.Diagnostics.CodeAnalysis.MaybeNull]
[ImplementPropertyType("topComponent")]
public virtual global::Umbraco.Cms.Core.Models.Blocks.BlockGridModel TopComponent => GetTopComponent(this, _publishedValueFallback);

/// <summary>Static getter for Top Component</summary>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Umbraco.ModelsBuilder.Embedded", "16.5.0+8b2c22a")]
[return: global::System.Diagnostics.CodeAnalysis.MaybeNull]
public static global::Umbraco.Cms.Core.Models.Blocks.BlockGridModel GetTopComponent(IUTpro__ContentLayout that, IPublishedValueFallback publishedValueFallback) => that.Value<global::Umbraco.Cms.Core.Models.Blocks.BlockGridModel>(publishedValueFallback, "topComponent");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace Umbraco.Cms.Web.Common.PublishedModels
{
/// <summary>Page Home</summary>
[PublishedModel("uTPro__PageHome")]
public partial class UTpro__PageHome : PublishedContentModel, IGlobalPageHeadMetaSetting, IGlobalPageHeadSocialMetaSetting, IGlobalPageNavigationConfigSettingForHomePage, IGlobalPageNavigationSetting, IGlobalPageScriptSetting, IGlobalPageSitemapSetting
public partial class UTpro__PageHome : PublishedContentModel, IGlobalPageHeadMetaSetting, IGlobalPageHeadSocialMetaSetting, IGlobalPageNavigationConfigSettingForHomePage, IGlobalPageNavigationSetting, IGlobalPageScriptSetting, IGlobalPageSitemapSetting, IUTpro__ContentLayout
{
// helpers
#pragma warning disable 0109 // new is redundant
Expand Down Expand Up @@ -284,5 +284,21 @@ public UTpro__PageHome(IPublishedContent content, IPublishedValueFallback publis
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Umbraco.ModelsBuilder.Embedded", "16.5.0+8b2c22a")]
[ImplementPropertyType("sitemapXmlPriority")]
public virtual decimal SitemapXmlPriority => global::Umbraco.Cms.Web.Common.PublishedModels.GlobalPageSitemapSetting.GetSitemapXmlPriority(this, _publishedValueFallback);

///<summary>
/// Bottom Component
///</summary>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Umbraco.ModelsBuilder.Embedded", "16.5.0+8b2c22a")]
[global::System.Diagnostics.CodeAnalysis.MaybeNull]
[ImplementPropertyType("bottomComponent")]
public virtual global::Umbraco.Cms.Core.Models.Blocks.BlockGridModel BottomComponent => global::Umbraco.Cms.Web.Common.PublishedModels.UTpro__ContentLayout.GetBottomComponent(this, _publishedValueFallback);

///<summary>
/// Top Component
///</summary>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Umbraco.ModelsBuilder.Embedded", "16.5.0+8b2c22a")]
[global::System.Diagnostics.CodeAnalysis.MaybeNull]
[ImplementPropertyType("topComponent")]
public virtual global::Umbraco.Cms.Core.Models.Blocks.BlockGridModel TopComponent => global::Umbraco.Cms.Web.Common.PublishedModels.UTpro__ContentLayout.GetTopComponent(this, _publishedValueFallback);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace Umbraco.Cms.Web.Common.PublishedModels
{
/// <summary>Page Standard</summary>
[PublishedModel("uTPro__PageStandard")]
public partial class UTpro__PageStandard : PublishedContentModel, IGlobalPageHeadMetaSetting, IGlobalPageHeadSocialMetaSetting, IGlobalPageScriptSetting, IGlobalPageSitemapSetting
public partial class UTpro__PageStandard : PublishedContentModel, IGlobalPageHeadMetaSetting, IGlobalPageHeadSocialMetaSetting, IGlobalPageScriptSetting, IGlobalPageSitemapSetting, IUTpro__ContentLayout
{
// helpers
#pragma warning disable 0109 // new is redundant
Expand Down Expand Up @@ -236,5 +236,21 @@ public UTpro__PageStandard(IPublishedContent content, IPublishedValueFallback pu
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Umbraco.ModelsBuilder.Embedded", "16.5.0+8b2c22a")]
[ImplementPropertyType("sitemapXmlPriority")]
public virtual decimal SitemapXmlPriority => global::Umbraco.Cms.Web.Common.PublishedModels.GlobalPageSitemapSetting.GetSitemapXmlPriority(this, _publishedValueFallback);

///<summary>
/// Bottom Component
///</summary>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Umbraco.ModelsBuilder.Embedded", "16.5.0+8b2c22a")]
[global::System.Diagnostics.CodeAnalysis.MaybeNull]
[ImplementPropertyType("bottomComponent")]
public virtual global::Umbraco.Cms.Core.Models.Blocks.BlockGridModel BottomComponent => global::Umbraco.Cms.Web.Common.PublishedModels.UTpro__ContentLayout.GetBottomComponent(this, _publishedValueFallback);

///<summary>
/// Top Component
///</summary>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Umbraco.ModelsBuilder.Embedded", "16.5.0+8b2c22a")]
[global::System.Diagnostics.CodeAnalysis.MaybeNull]
[ImplementPropertyType("topComponent")]
public virtual global::Umbraco.Cms.Core.Models.Blocks.BlockGridModel TopComponent => global::Umbraco.Cms.Web.Common.PublishedModels.UTpro__ContentLayout.GetTopComponent(this, _publishedValueFallback);
}
}
48 changes: 14 additions & 34 deletions uTPro/Extension/uTPro.Extension.CurrentSite/CurrentItemExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ public interface ICurrentItemExtension
IPublishedContent? PageHome { get; }
IPublishedContent? PageErrors { get; }
}
internal class CurrentItemExtension : ICurrentItemExtension, IDisposable
internal class CurrentItemExtension(
ILogger<CurrentItemExtension> logger,
ICurrentSiteExtension currentSite
) : ICurrentItemExtension, IDisposable
{
~CurrentItemExtension()
{
Expand All @@ -46,19 +49,8 @@ protected virtual void Dispose(bool disposing)
// free native resources if there are any.
}

readonly ICurrentSiteExtension _currentSite;
readonly ILogger<CurrentItemExtension> _logger;

#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
public CurrentItemExtension(
ILogger<CurrentItemExtension> logger,
ICurrentSiteExtension currentSite)
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
{
_logger = logger;
_currentSite = currentSite;

}
readonly ICurrentSiteExtension _currentSite = currentSite;
readonly ILogger<CurrentItemExtension> _logger = logger;

public GlobalRoot Root
{
Expand All @@ -73,10 +65,7 @@ public GlobalFolderSites FolderSite
get
{
var folderSite = this.PageHome?.Parent<GlobalFolderSites>() ?? null;
if (folderSite == null)
{
folderSite = (GlobalFolderSites)GetItemByAlias(this.PageHome, GlobalFolderSites.ModelTypeAlias, true);
}
folderSite ??= (GlobalFolderSites)GetItemByAlias(this.PageHome, GlobalFolderSites.ModelTypeAlias, true);
return folderSite ?? throw new Exception(nameof(GlobalFolderSites) + " is null");
}
}
Expand Down Expand Up @@ -105,19 +94,12 @@ public IPublishedContent? Current
{
get
{
IPublishedContent? currentItem = null;
if (_currentSite.UContext.PublishedRequest?.PublishedContent != null)
{
currentItem = _currentSite.UContext.PublishedRequest?.PublishedContent;
}
else
{
currentItem = this.PageHome;
}
return currentItem;
var published = _currentSite.UContext.PublishedRequest?.PublishedContent;
return published ?? this.PageHome;
}
}


public IPublishedContent? PageHome
{
get
Expand Down Expand Up @@ -181,9 +163,7 @@ public IPublishedContent? PageErrors
private IPublishedContent GetItemByAlias(IPublishedContent? item, string alias, bool isFirst)
{
// Start from provided item
var current = item;
if (current == null)
throw new Exception("Not found item: " + alias);
var current = item ?? throw new Exception("Not found item: " + alias);

// quick check
if (string.Equals(current.ContentType?.Alias, alias, StringComparison.OrdinalIgnoreCase))
Expand Down Expand Up @@ -231,7 +211,7 @@ private static (string, string?) GetIdParent(string pathId, bool isRoot = false)
if (pathId.StartsWith("-1", StringComparison.Ordinal))
{
int firstComma = pathId.IndexOf(',');
pathIds = (firstComma >= 0 && firstComma + 1 < pathId.Length) ? pathId.Substring(firstComma + 1) : string.Empty;
pathIds = (firstComma >= 0 && firstComma + 1 < pathId.Length) ? pathId[(firstComma + 1)..] : string.Empty;
}

if (string.IsNullOrEmpty(pathIds))
Expand All @@ -240,7 +220,7 @@ private static (string, string?) GetIdParent(string pathId, bool isRoot = false)
if (isRoot)
{
int firstComma = pathIds.IndexOf(',');
var root = firstComma >= 0 ? pathIds.Substring(0, firstComma) : pathIds;
var root = firstComma >= 0 ? pathIds[..firstComma] : pathIds;
return (root ?? string.Empty, pathIds);
}

Expand All @@ -257,7 +237,7 @@ private static (string, string?) GetIdParent(string pathId, bool isRoot = false)
}
else
{
parent = pathIds.Substring(0, lastComma);
parent = pathIds[..lastComma];
}
return (parent, pathIds);
}
Expand Down
28 changes: 11 additions & 17 deletions uTPro/Extension/uTPro.Extension.CurrentSite/CurrentSiteExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,7 @@ public CultureInfo CurrentCulture
{
get
{
if (this._currentCulture == null)
{
this._currentCulture = Thread.CurrentThread.CurrentCulture;
}
this._currentCulture ??= Thread.CurrentThread.CurrentCulture;
return this._currentCulture;
}
}
Expand Down Expand Up @@ -129,10 +126,7 @@ public IUmbracoContext UContext
{
get
{
if (this._umbracoContext == null)
{
this._umbracoContext = _umbracoContextFactory.EnsureUmbracoContext().UmbracoContext;
}
this._umbracoContext ??= _umbracoContextFactory.EnsureUmbracoContext().UmbracoContext;

return this._umbracoContext ?? throw new Exception("UmbracoContext is null");
}
Expand Down Expand Up @@ -166,8 +160,8 @@ public string GetDictionaryValue(string key, string valueDefault = "", bool show
}

// Simple in-memory cache for all domains to reduce repeated UContext access
private static readonly object _domainsLock = new object();
private static IEnumerable<Domain> _cachedAllDomains = Enumerable.Empty<Domain>();
private static readonly Lock _domainsLock = new();
private static IEnumerable<Domain> _cachedAllDomains = [];
private static DateTime _cachedAllDomainsExpires = DateTime.MinValue;
private const int CachedAllDomainsSeconds = 60;

Expand All @@ -181,7 +175,7 @@ public Task<IEnumerable<Domain>> GetDomains(bool isGetAll)
return Task.FromResult(_cachedAllDomains);
}

var all = UContext?.Domains?.GetAll(true) ?? new List<Domain>();
var all = UContext?.Domains?.GetAll(true) ?? [];
lock (_domainsLock)
{
_cachedAllDomains = all;
Expand All @@ -192,7 +186,7 @@ public Task<IEnumerable<Domain>> GetDomains(bool isGetAll)

var idItem = this.GetItem().Current?.Id;
var domain = UContext?.Domains?.GetAssigned(idItem ?? 0, true);
return Task.FromResult(domain ?? new List<Domain>());
return Task.FromResult(domain ?? []);
}

public void SetCurrentCulture(CultureInfo cul) => this._currentCulture = cul;
Expand All @@ -205,11 +199,11 @@ public string GetUrlWithCulture(IPublishedContent content, string? culture = nul

if (domain != null)
{
var domainUrl = domain.Name.StartsWith("/")
|| domain.Name.StartsWith("http://", StringComparison.OrdinalIgnoreCase)
|| domain.Name.StartsWith("https://", StringComparison.OrdinalIgnoreCase)
? domain.Name
: "https://" + domain.Name;
var domainUrl = !(domain.Name.StartsWith('/')
|| domain.Name.StartsWith("http://", StringComparison.OrdinalIgnoreCase)
|| domain.Name.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
? "https://" + domain.Name
: domain.Name;

var uri = new Uri(domainUrl, UriKind.RelativeOrAbsolute);
var segment = uri.AbsolutePath.Trim('/');
Expand Down
21 changes: 21 additions & 0 deletions uTPro/Extension/uTPro.Extension/ContentExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Net.NetworkInformation;
using Umbraco.Cms.Core.Models.PublishedContent;
using System.Linq;

namespace uTPro.Extension
{
public static class ContentExtensions
{
public static T? GetInherited<T>(this IPublishedContent content, string alias)
{
var node = content.AncestorsOrSelf()
.FirstOrDefault(x => x.HasValue(alias));

if (node == null)
return default;

return node.Value<T>(alias);
}
}

}
Loading
Loading