Refactor getting urls

This commit is contained in:
Stephan
2018-04-29 20:02:38 +02:00
parent 7dd1efb29f
commit bcd0c95ec1
48 changed files with 512 additions and 522 deletions

View File

@@ -1,17 +1,14 @@
namespace Umbraco.Core.Models.PublishedContent
{
/// <summary>
/// Represents the published variation context.
/// Represents the current variation.
/// </summary>
/// <remarks>
/// <para>The published variation context indicates which variation is the current default variation.</para>
/// </remarks>
public class PublishedVariationContext
public class CurrentVariation
{
/// <summary>
/// Initializes a new instance of the <see cref="PublishedVariationContext"/> class.
/// Initializes a new instance of the <see cref="CurrentVariation"/> class.
/// </summary>
public PublishedVariationContext(string culture = null, string segment = null)
public CurrentVariation(string culture = null, string segment = null)
{
Culture = culture;
Segment = segment;
@@ -27,4 +24,4 @@
/// </summary>
public string Segment { get; set; }
}
}
}

View File

@@ -0,0 +1,13 @@
namespace Umbraco.Core.Models.PublishedContent
{
/// <summary>
/// Gives access to the current <see cref="PublishedContent.CurrentVariation"/>.
/// </summary>
public interface ICurrentVariationAccessor
{
/// <summary>
/// Gets or sets the current <see cref="PublishedContent.CurrentVariation"/>.
/// </summary>
CurrentVariation CurrentVariation { get; set; }
}
}

View File

@@ -31,9 +31,8 @@ namespace Umbraco.Core.Models.PublishedContent
/// </summary>
/// <remarks>
/// <para>The value of this property is contextual. When the content type is multi-lingual,
/// this is the name for the 'current' culture.</para>
/// this is the name for the 'current' culture. Otherwise, it is the invariant name.</para>
/// </remarks>
/// FIXME culture aware - returns the value for the 'current' culture whatever it is + see ?? for others
string Name { get; }
/// <summary>
@@ -41,9 +40,8 @@ namespace Umbraco.Core.Models.PublishedContent
/// </summary>
/// <remarks>
/// <para>The value of this property is contextual. When the content type is multi-lingual,
/// this is the name for the 'current' culture.</para>
/// this is the name for the 'current' culture. Otherwise, it is the invariant url segment.</para>
/// </remarks>
/// FIXME rename UrlSegment + culture aware
string UrlSegment { get; }
/// <summary>
@@ -96,7 +94,8 @@ namespace Umbraco.Core.Models.PublishedContent
/// </summary>
/// <remarks>
/// <para>For published content items, this is also the date the item was published.</para>
/// <para>This date is global to the content item, see FIXME for per-culture dates</para>
/// <para>This date is always global to the content item, see GetCulture().Date for the
/// date each culture was published.</para>
/// </remarks>
DateTime UpdateDate { get; }
@@ -104,17 +103,35 @@ namespace Umbraco.Core.Models.PublishedContent
/// Gets the url of the content item.
/// </summary>
/// <remarks>
/// <para>The value of this property is contextual. It depends on the 'current' </para>
/// <para>In addition, when the content type is multi-lingual, this is the url for the
/// 'current' culture.</para>
/// <para>The value of this property is contextual. It depends on the 'current' request uri,
/// if any. In addition, when the content type is multi-lingual, this is the url for the
/// 'current' culture. Otherwise, it is the invariant url.</para>
/// </remarks>
/// FIXME explain what 'current' means here
string Url { get; }
// fixme document
//PublishedCultureInfos Culture(string culture = ".");
//string GetName(string culture = "."); // best naming? GetName? CultureName?
/// <summary>
/// Gets the url of the content item.
/// </summary>
/// <remarks>
/// <para>The value of this property is contextual. It depends on the 'current' request uri,
/// if any. In addition, when the content type is multi-lingual, this is the url for the
/// specified culture. Otherwise, it is the invariant url.</para>
/// </remarks>
string GetUrl(string culture = ".");
/// <summary>
/// Gets culture infos for a culture.
/// </summary>
PublishedCultureInfos GetCulture(string culture = ".");
/// <summary>
/// Gets culture infos.
/// </summary>
/// <remarks>
/// <para>Contains only those culture that are available. For a published content, these are
/// the cultures that are published. For a draft content, those that are 'available' ie
/// have a non-empty content name.</para>
/// </remarks>
IReadOnlyDictionary<string, PublishedCultureInfos> Cultures { get; }
/// <summary>

View File

@@ -1,13 +0,0 @@
namespace Umbraco.Core.Models.PublishedContent
{
/// <summary>
/// Gives access to the current <see cref="PublishedVariationContext"/>.
/// </summary>
public interface IPublishedVariationContextAccessor
{
/// <summary>
/// Gets or sets the current <see cref="PublishedVariationContext"/>.
/// </summary>
PublishedVariationContext Context { get; set; }
}
}

View File

@@ -96,6 +96,9 @@ namespace Umbraco.Core.Models.PublishedContent
/// <inheritdoc />
public virtual string Url => _content.Url;
/// <inheritdoc />
public virtual string GetUrl(string culture = ".") => _content.GetUrl(culture);
/// <inheritdoc />
public PublishedCultureInfos GetCulture(string culture = ".") => _content.GetCulture(culture);

View File

@@ -11,7 +11,7 @@ namespace Umbraco.Core.Models.PublishedContent
/// <summary>
/// Initializes a new instance of the <see cref="PublishedCultureInfos"/> class.
/// </summary>
public PublishedCultureInfos(string culture, string name, bool published, DateTime publishedDate)
public PublishedCultureInfos(string culture, string name, bool published, DateTime date)
{
if (string.IsNullOrWhiteSpace(culture)) throw new ArgumentNullOrEmptyException(nameof(culture));
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullOrEmptyException(nameof(name));
@@ -20,7 +20,7 @@ namespace Umbraco.Core.Models.PublishedContent
Name = name;
UrlSegment = name.ToUrlSegment(culture);
Published = published;
PublishedDate = publishedDate;
Date = date;
}
/// <summary>
@@ -48,8 +48,13 @@ namespace Umbraco.Core.Models.PublishedContent
public bool Published { get; }
/// <summary>
/// Gets the date when fixme?
/// Gets the date associated with the culture.
/// </summary>
public DateTime PublishedDate { get; } // fixme - model? model.UpdateDate - here?
/// <remarks>
/// <para>For published culture, this is the date the culture was published. For draft
/// cultures, this is the date the culture was made available, ie the last time its
/// name changed.</para>
/// </remarks>
public DateTime Date { get; }
}
}

View File

@@ -5,18 +5,18 @@ using System.Threading;
namespace Umbraco.Core.Models.PublishedContent
{
/// <summary>
/// Provides a CurrentUICulture-based implementation of <see cref="IPublishedVariationContextAccessor"/>.
/// Provides a CurrentUICulture-based implementation of <see cref="ICurrentVariationAccessor"/>.
/// </summary>
/// <remarks>
/// <para>This accessor does not support segments. There is no need to set the current context.</para>
/// </remarks>
public class ThreadCulturePublishedVariationContextAccessor : IPublishedVariationContextAccessor
public class ThreadCultureCurrentVariationAccessor : ICurrentVariationAccessor
{
private readonly ConcurrentDictionary<string, PublishedVariationContext> _contexts = new ConcurrentDictionary<string, PublishedVariationContext>();
private readonly ConcurrentDictionary<string, CurrentVariation> _contexts = new ConcurrentDictionary<string, CurrentVariation>();
public PublishedVariationContext Context
public CurrentVariation CurrentVariation
{
get => _contexts.GetOrAdd(Thread.CurrentThread.CurrentUICulture.Name, culture => new PublishedVariationContext { Culture = culture });
get => _contexts.GetOrAdd(Thread.CurrentThread.CurrentUICulture.Name, culture => new CurrentVariation { Culture = culture });
set => throw new NotSupportedException();
}
}

View File

@@ -3,18 +3,18 @@
namespace Umbraco.Core.Models.PublishedContent
{
/// <summary>
/// Provides a ThreadStatic-based implementation of <see cref="IPublishedVariationContextAccessor"/>.
/// Provides a ThreadStatic-based implementation of <see cref="ICurrentVariationAccessor"/>.
/// </summary>
/// <remarks>
/// <para>Something must set the current context.</para>
/// </remarks>
public class ThreadStaticPublishedVariationContextAccessor : IPublishedVariationContextAccessor
public class ThreadStaticCurrentVariationAccessor : ICurrentVariationAccessor
{
[ThreadStatic]
private static PublishedVariationContext _context;
private static CurrentVariation _context;
/// <inheritdoc />
public PublishedVariationContext Context
public CurrentVariation CurrentVariation
{
get => _context;
set => _context = value;

View File

@@ -1166,7 +1166,8 @@ namespace Umbraco.Core
/// <param name="text">The text to filter.</param>
/// <param name="culture">The culture.</param>
/// <returns>The safe url segment.</returns>
public static string ToUrlSegment(this string text, CultureInfo culture) // fixme obsolete that one, use the string one?
// todo: obsolete that one and use the string one (requires changes to IShortStringHelper)
public static string ToUrlSegment(this string text, CultureInfo culture)
{
return Current.ShortStringHelper.CleanStringForUrlSegment(text, culture);
}

View File

@@ -14,7 +14,7 @@ namespace Umbraco.Core.Strings
/// </summary>
/// <param name="content">The content.</param>
/// <returns>The url segment.</returns>
string GetUrlSegment(IContentBase content);
string GetUrlSegment(IContentBase content); // fixme do we need to have both?
/// <summary>
/// Gets the url segment for a specified content and culture.

View File

@@ -369,11 +369,11 @@
<Compile Include="Models\Entities\TreeEntityBase.cs" />
<Compile Include="Models\PropertyTagsExtensions.cs" />
<Compile Include="Models\PublishedContent\PublishedCultureInfos.cs" />
<Compile Include="Models\PublishedContent\IPublishedVariationContextAccessor.cs" />
<Compile Include="Models\PublishedContent\ICurrentVariationAccessor.cs" />
<Compile Include="Models\PublishedContent\IPublishedValueFallback.cs" />
<Compile Include="Models\PublishedContent\PublishedVariationContext.cs" />
<Compile Include="Models\PublishedContent\ThreadCulturePublishedVariationContextAccessor.cs" />
<Compile Include="Models\PublishedContent\ThreadStaticPublishedVariationContextAccessor.cs" />
<Compile Include="Models\PublishedContent\CurrentVariation.cs" />
<Compile Include="Models\PublishedContent\ThreadCultureCurrentVariationAccessor.cs" />
<Compile Include="Models\PublishedContent\ThreadStaticCurrentVariationAccessor.cs" />
<Compile Include="Persistence\Dtos\AuditEntryDto.cs" />
<Compile Include="Persistence\Dtos\ConsentDto.cs" />
<Compile Include="Persistence\Dtos\ContentVersionCultureVariationDto.cs" />