Moves Udi, UriParser and others to abstractions
This commit is contained in:
@@ -12,7 +12,7 @@ namespace Umbraco.Core
|
||||
[TypeConverter(typeof(UdiTypeConverter))]
|
||||
public abstract class Udi : IComparable<Udi>
|
||||
{
|
||||
internal readonly Uri UriValue; // internal for UdiRange
|
||||
public Uri UriValue { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the Udi class.
|
||||
@@ -104,7 +104,7 @@ namespace Umbraco.Core
|
||||
return new GuidUdi(entityType, id);
|
||||
}
|
||||
|
||||
internal static Udi Create(Uri uri)
|
||||
public static Udi Create(Uri uri)
|
||||
{
|
||||
// if it's a know type go fast and use ctors
|
||||
// else fallback to parsing the string (and guess the type)
|
||||
@@ -1,5 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace Umbraco.Core
|
||||
{
|
||||
@@ -12,13 +14,16 @@ namespace Umbraco.Core
|
||||
{
|
||||
// initialize with known (built-in) Udi types
|
||||
// we will add scanned types later on
|
||||
UdiTypes = new ConcurrentDictionary<string, UdiType>(UdiEntityTypeHelper.GetTypes());
|
||||
UdiTypes = new ConcurrentDictionary<string, UdiType>(GetKnownUdiTypes());
|
||||
}
|
||||
|
||||
// for tests, totally unsafe
|
||||
internal static void ResetUdiTypes()
|
||||
/// <summary>
|
||||
/// Internal API for tests to resets all udi types back to only the known udi types.
|
||||
/// </summary>
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public static void ResetUdiTypes()
|
||||
{
|
||||
UdiTypes = new ConcurrentDictionary<string, UdiType>(UdiEntityTypeHelper.GetTypes());
|
||||
UdiTypes = new ConcurrentDictionary<string, UdiType>(GetKnownUdiTypes());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -175,5 +180,43 @@ namespace Umbraco.Core
|
||||
/// <param name="entityType"></param>
|
||||
/// <param name="udiType"></param>
|
||||
public static void RegisterUdiType(string entityType, UdiType udiType) => UdiTypes.TryAdd(entityType, udiType);
|
||||
|
||||
public static Dictionary<string, UdiType> GetKnownUdiTypes() =>
|
||||
new Dictionary<string, UdiType>
|
||||
{
|
||||
{ Constants.UdiEntityType.Unknown, UdiType.Unknown },
|
||||
|
||||
{ Constants.UdiEntityType.AnyGuid, UdiType.GuidUdi },
|
||||
{ Constants.UdiEntityType.Document, UdiType.GuidUdi },
|
||||
{ Constants.UdiEntityType.DocumentBlueprint, UdiType.GuidUdi },
|
||||
{ Constants.UdiEntityType.Media, UdiType.GuidUdi },
|
||||
{ Constants.UdiEntityType.Member, UdiType.GuidUdi },
|
||||
{ Constants.UdiEntityType.DictionaryItem, UdiType.GuidUdi },
|
||||
{ Constants.UdiEntityType.Macro, UdiType.GuidUdi },
|
||||
{ Constants.UdiEntityType.Template, UdiType.GuidUdi },
|
||||
{ Constants.UdiEntityType.DocumentType, UdiType.GuidUdi },
|
||||
{ Constants.UdiEntityType.DocumentTypeContainer, UdiType.GuidUdi },
|
||||
{ Constants.UdiEntityType.DocumentTypeBluePrints, UdiType.GuidUdi },
|
||||
{ Constants.UdiEntityType.MediaType, UdiType.GuidUdi },
|
||||
{ Constants.UdiEntityType.MediaTypeContainer, UdiType.GuidUdi },
|
||||
{ Constants.UdiEntityType.DataType, UdiType.GuidUdi },
|
||||
{ Constants.UdiEntityType.DataTypeContainer, UdiType.GuidUdi },
|
||||
{ Constants.UdiEntityType.MemberType, UdiType.GuidUdi },
|
||||
{ Constants.UdiEntityType.MemberGroup, UdiType.GuidUdi },
|
||||
{ Constants.UdiEntityType.RelationType, UdiType.GuidUdi },
|
||||
{ Constants.UdiEntityType.FormsForm, UdiType.GuidUdi },
|
||||
{ Constants.UdiEntityType.FormsPreValue, UdiType.GuidUdi },
|
||||
{ Constants.UdiEntityType.FormsDataSource, UdiType.GuidUdi },
|
||||
|
||||
{ Constants.UdiEntityType.AnyString, UdiType.StringUdi },
|
||||
{ Constants.UdiEntityType.Language, UdiType.StringUdi },
|
||||
{ Constants.UdiEntityType.MacroScript, UdiType.StringUdi },
|
||||
{ Constants.UdiEntityType.MediaFile, UdiType.StringUdi },
|
||||
{ Constants.UdiEntityType.TemplateFile, UdiType.StringUdi },
|
||||
{ Constants.UdiEntityType.Script, UdiType.StringUdi },
|
||||
{ Constants.UdiEntityType.PartialView, UdiType.StringUdi },
|
||||
{ Constants.UdiEntityType.PartialViewMacro, UdiType.StringUdi },
|
||||
{ Constants.UdiEntityType.Stylesheet, UdiType.StringUdi }
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,4 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using Umbraco.Core.CodeAnnotations;
|
||||
using Umbraco.Core.CodeAnnotations;
|
||||
|
||||
namespace Umbraco.Core.Models
|
||||
{
|
||||
|
||||
@@ -6,43 +6,7 @@ namespace Umbraco.Core
|
||||
{
|
||||
public static class UdiEntityTypeHelper
|
||||
{
|
||||
internal static Dictionary<string, UdiType> GetTypes() =>
|
||||
new Dictionary<string, UdiType>
|
||||
{
|
||||
{ Constants.UdiEntityType.Unknown, UdiType.Unknown },
|
||||
|
||||
{ Constants.UdiEntityType.AnyGuid, UdiType.GuidUdi },
|
||||
{ Constants.UdiEntityType.Document, UdiType.GuidUdi },
|
||||
{ Constants.UdiEntityType.DocumentBlueprint, UdiType.GuidUdi },
|
||||
{ Constants.UdiEntityType.Media, UdiType.GuidUdi },
|
||||
{ Constants.UdiEntityType.Member, UdiType.GuidUdi },
|
||||
{ Constants.UdiEntityType.DictionaryItem, UdiType.GuidUdi },
|
||||
{ Constants.UdiEntityType.Macro, UdiType.GuidUdi },
|
||||
{ Constants.UdiEntityType.Template, UdiType.GuidUdi },
|
||||
{ Constants.UdiEntityType.DocumentType, UdiType.GuidUdi },
|
||||
{ Constants.UdiEntityType.DocumentTypeContainer, UdiType.GuidUdi },
|
||||
{ Constants.UdiEntityType.DocumentTypeBluePrints, UdiType.GuidUdi },
|
||||
{ Constants.UdiEntityType.MediaType, UdiType.GuidUdi },
|
||||
{ Constants.UdiEntityType.MediaTypeContainer, UdiType.GuidUdi },
|
||||
{ Constants.UdiEntityType.DataType, UdiType.GuidUdi },
|
||||
{ Constants.UdiEntityType.DataTypeContainer, UdiType.GuidUdi },
|
||||
{ Constants.UdiEntityType.MemberType, UdiType.GuidUdi },
|
||||
{ Constants.UdiEntityType.MemberGroup, UdiType.GuidUdi },
|
||||
{ Constants.UdiEntityType.RelationType, UdiType.GuidUdi },
|
||||
{ Constants.UdiEntityType.FormsForm, UdiType.GuidUdi },
|
||||
{ Constants.UdiEntityType.FormsPreValue, UdiType.GuidUdi },
|
||||
{ Constants.UdiEntityType.FormsDataSource, UdiType.GuidUdi },
|
||||
|
||||
{ Constants.UdiEntityType.AnyString, UdiType.StringUdi },
|
||||
{ Constants.UdiEntityType.Language, UdiType.StringUdi },
|
||||
{ Constants.UdiEntityType.MacroScript, UdiType.StringUdi },
|
||||
{ Constants.UdiEntityType.MediaFile, UdiType.StringUdi },
|
||||
{ Constants.UdiEntityType.TemplateFile, UdiType.StringUdi },
|
||||
{ Constants.UdiEntityType.Script, UdiType.StringUdi },
|
||||
{ Constants.UdiEntityType.PartialView, UdiType.StringUdi },
|
||||
{ Constants.UdiEntityType.PartialViewMacro, UdiType.StringUdi },
|
||||
{ Constants.UdiEntityType.Stylesheet, UdiType.StringUdi }
|
||||
};
|
||||
|
||||
|
||||
public static string FromUmbracoObjectType(UmbracoObjectTypes umbracoObjectType)
|
||||
{
|
||||
|
||||
@@ -527,7 +527,6 @@
|
||||
<Compile Include="Events\UninstallPackageEventArgs.cs" />
|
||||
<Compile Include="Composing\LightInject\LightInjectException.cs" />
|
||||
<Compile Include="FileResources\Files.Designer.cs" />
|
||||
<Compile Include="GuidUdi.cs" />
|
||||
<Compile Include="HttpContextExtensions.cs" />
|
||||
<Compile Include="IO\FileSecurityException.cs" />
|
||||
<Compile Include="IO\FileSystemExtensions.cs" />
|
||||
@@ -1095,20 +1094,15 @@
|
||||
<Compile Include="Compose\RelateOnCopyComponent.cs" />
|
||||
<Compile Include="Compose\RelateOnTrashComponent.cs" />
|
||||
<Compile Include="Strings\UrlSegmentProviderCollectionBuilder.cs" />
|
||||
<Compile Include="StringUdi.cs" />
|
||||
<Compile Include="Sync\ApplicationUrlHelper.cs" />
|
||||
<Compile Include="Sync\DatabaseServerMessenger.cs" />
|
||||
<Compile Include="Sync\RefreshInstruction.cs" />
|
||||
<Compile Include="Sync\ServerMessengerBase.cs" />
|
||||
<Compile Include="Udi.cs" />
|
||||
<Compile Include="UdiDefinitionAttribute.cs" />
|
||||
<Compile Include="UdiEntityTypeHelper.cs" />
|
||||
<Compile Include="UdiGetterExtensions.cs" />
|
||||
<Compile Include="UdiParser.cs" />
|
||||
<Compile Include="UdiParserServiceConnectors.cs" />
|
||||
<Compile Include="UdiRange.cs" />
|
||||
<Compile Include="UdiTypeConverter.cs" />
|
||||
<Compile Include="UnknownTypeUdi.cs" />
|
||||
<Compile Include="UriExtensions.cs" />
|
||||
<Compile Include="PackageActions\IPackageAction.cs" />
|
||||
<Compile Include="PackageActions\PackageActionCollection.cs" />
|
||||
|
||||
@@ -250,7 +250,7 @@ namespace Umbraco.Tests.CoreThings
|
||||
[Test]
|
||||
public void ValidateUdiEntityType()
|
||||
{
|
||||
var types = UdiEntityTypeHelper.GetTypes();
|
||||
var types = UdiParser.GetKnownUdiTypes();
|
||||
|
||||
foreach (var fi in typeof(Constants.UdiEntityType).GetFields(BindingFlags.Public | BindingFlags.Static))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user