* Run code cleanup * Start manual cleanup after dotnet format * Finish up manual pass * Fix up missed warnings * Fix after merge * Update src/Umbraco.Core/Cache/ContentTypeCacheRefresher.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Cache/DataTypeCacheRefresher.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Cache/DeepCloneAppCache.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Cache/DomainCacheRefresher.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Cache/FastDictionaryAppCacheBase.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Cache/FastDictionaryAppCacheBase.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Cache/FastDictionaryAppCacheBase.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Cache/FastDictionaryAppCacheBase.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Cache/FastDictionaryAppCacheBase.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Cache/MacroCacheRefresher.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Cache/MediaCacheRefresher.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Cache/MemberCacheRefresher.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Cache/MemberGroupCacheRefresher.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Composing/OrderedCollectionBuilderBase.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Configuration/Models/RequestHandlerSettings.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Composing/SetCollectionBuilderBase.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Composing/WeightedCollectionBuilderBase.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/ContentApps/ContentAppFactoryCollectionBuilder.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Dashboards/DashboardCollectionBuilder.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/StringExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/StringExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/StringExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/StringExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/StringExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/StringExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/StringExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/ContentTypeRefreshedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/ContentTypeSavedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/ContentTypeSavingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/DictionaryCacheRefresherNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/DataTypeCacheRefresherNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/ContentUnpublishingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/DictionaryItemDeletingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/DictionaryItemSavedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/DictionaryItemSavingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/DomainCacheRefresherNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/LanguageCacheRefresherNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MacroCacheRefresherNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaCacheRefresherNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaEmptiedRecycleBinNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaEmptyingRecycleBinNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaMovedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaMovedToRecycleBinNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/StringExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/StringExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/StringExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/StringExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/StringExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/StringExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaMovedToRecycleBinNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaMovingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaMovingToRecycleBinNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaTreeChangeNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaTreeChangeNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaTypeChangedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaTypeDeletingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaTypeMovedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaTypeMovingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaTypeMovingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaTypeRefreshedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MemberCacheRefresherNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MemberGroupCacheRefresherNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MemberGroupDeletingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MemberGroupSavedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MemberGroupSavingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MemberTypeChangedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MemberTypeDeletedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MemberTypeDeletingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MemberTypeMovedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MemberTypeMovedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MemberTypeMovingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MemberTypeMovingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MemberTypeRefreshedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MemberTypeSavingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/StringExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/UriExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MovedToRecycleBinNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MovedToRecycleBinNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MovingToRecycleBinNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MovingToRecycleBinNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/PartialViewDeletingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/UriExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/IO/PhysicalFileSystem.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/IO/PhysicalFileSystem.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/IO/ShadowWrapper.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Logging/DisposableTimer.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Install/InstallSteps/UpgradeStep.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Mapping/MapDefinitionCollectionBuilder.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Media/EmbedProviders/EmbedProvidersCollectionBuilder.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/PartialViewSavedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Models/ContentEditing/ContentVariationDisplay.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/PartialViewSavingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/PublicAccessCacheRefresherNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/PublicAccessEntryDeletedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/PublicAccessEntryDeletingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/PublicAccessEntryDeletingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/PublicAccessEntrySavedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/PublicAccessEntrySavingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/PublicAccessEntrySavingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/RelationTypeCacheRefresherNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/RelationTypeDeletingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/RelationTypeSavedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/RelationTypeSavingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/StatefulNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/StylesheetDeletingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/StylesheetSavingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Models/DeepCloneHelper.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Models/File.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Models/PropertyGroupExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Models/PropertyGroupExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Fix based on review * Fix after merge Signed-off-by: Zeegaan <nge@umbraco.dk> Co-authored-by: Nikolaj Geisle <niko737@edu.ucl.dk> Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> Co-authored-by: Zeegaan <nge@umbraco.dk>
236 lines
9.7 KiB
C#
236 lines
9.7 KiB
C#
using System.Collections.Concurrent;
|
|
using System.ComponentModel;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
|
|
namespace Umbraco.Cms.Core;
|
|
|
|
public sealed class UdiParser
|
|
{
|
|
private static readonly ConcurrentDictionary<string, Udi> RootUdis = new();
|
|
|
|
static UdiParser() =>
|
|
|
|
// initialize with known (built-in) Udi types
|
|
// we will add scanned types later on
|
|
UdiTypes = new ConcurrentDictionary<string, UdiType>(GetKnownUdiTypes());
|
|
|
|
internal static ConcurrentDictionary<string, UdiType> UdiTypes { get; private set; }
|
|
|
|
/// <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>(GetKnownUdiTypes());
|
|
|
|
/// <summary>
|
|
/// Converts the string representation of an entity identifier into the equivalent Udi instance.
|
|
/// </summary>
|
|
/// <param name="s">The string to convert.</param>
|
|
/// <returns>An Udi instance that contains the value that was parsed.</returns>
|
|
public static Udi Parse(string s)
|
|
{
|
|
ParseInternal(s, false, false, out Udi? udi);
|
|
return udi!;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts the string representation of an entity identifier into the equivalent Udi instance.
|
|
/// </summary>
|
|
/// <param name="s">The string to convert.</param>
|
|
/// <param name="knownTypes">A value indicating whether to only deal with known types.</param>
|
|
/// <returns>An Udi instance that contains the value that was parsed.</returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// If <paramref name="knownTypes" /> is <c>true</c>, and the string could not be parsed because
|
|
/// the entity type was not known, the method succeeds but sets <c>udi</c>to an
|
|
/// <see cref="UnknownTypeUdi" /> value.
|
|
/// </para>
|
|
/// <para>
|
|
/// If <paramref name="knownTypes" /> is <c>true</c>, assemblies are not scanned for types,
|
|
/// and therefore only builtin types may be known. Unless scanning already took place.
|
|
/// </para>
|
|
/// </remarks>
|
|
public static Udi Parse(string s, bool knownTypes)
|
|
{
|
|
ParseInternal(s, false, knownTypes, out Udi? udi);
|
|
return udi!;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts the string representation of an entity identifier into the equivalent Udi instance.
|
|
/// </summary>
|
|
/// <param name="s">The string to convert.</param>
|
|
/// <param name="udi">An Udi instance that contains the value that was parsed.</param>
|
|
/// <returns>A boolean value indicating whether the string could be parsed.</returns>
|
|
public static bool TryParse(string s, [MaybeNullWhen(false)] out Udi udi) => ParseInternal(s, true, false, out udi);
|
|
|
|
/// <summary>
|
|
/// Converts the string representation of an entity identifier into the equivalent Udi instance.
|
|
/// </summary>
|
|
/// <param name="s">The string to convert.</param>
|
|
/// <param name="udi">An Udi instance that contains the value that was parsed.</param>
|
|
/// <returns>A boolean value indicating whether the string could be parsed.</returns>
|
|
public static bool TryParse<T>(string? s, [MaybeNullWhen(false)] out T udi)
|
|
where T : Udi?
|
|
{
|
|
var result = ParseInternal(s, true, false, out Udi? parsed);
|
|
if (result && parsed is T)
|
|
{
|
|
udi = (T)parsed;
|
|
return true;
|
|
}
|
|
|
|
udi = null;
|
|
return false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts the string representation of an entity identifier into the equivalent Udi instance.
|
|
/// </summary>
|
|
/// <param name="s">The string to convert.</param>
|
|
/// <param name="knownTypes">A value indicating whether to only deal with known types.</param>
|
|
/// <param name="udi">An Udi instance that contains the value that was parsed.</param>
|
|
/// <returns>A boolean value indicating whether the string could be parsed.</returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// If <paramref name="knownTypes" /> is <c>true</c>, and the string could not be parsed because
|
|
/// the entity type was not known, the method returns <c>false</c> but still sets <c>udi</c>
|
|
/// to an <see cref="UnknownTypeUdi" /> value.
|
|
/// </para>
|
|
/// <para>
|
|
/// If <paramref name="knownTypes" /> is <c>true</c>, assemblies are not scanned for types,
|
|
/// and therefore only builtin types may be known. Unless scanning already took place.
|
|
/// </para>
|
|
/// </remarks>
|
|
public static bool TryParse(string? s, bool knownTypes, [MaybeNullWhen(false)] out Udi udi) =>
|
|
ParseInternal(s, true, knownTypes, out udi);
|
|
|
|
/// <summary>
|
|
/// Registers a custom entity type.
|
|
/// </summary>
|
|
/// <param name="entityType"></param>
|
|
/// <param name="udiType"></param>
|
|
public static void RegisterUdiType(string entityType, UdiType udiType) => UdiTypes.TryAdd(entityType, udiType);
|
|
|
|
internal static Udi GetRootUdi(string entityType) =>
|
|
RootUdis.GetOrAdd(entityType, x =>
|
|
{
|
|
if (UdiTypes.TryGetValue(x, out UdiType udiType) == false)
|
|
{
|
|
throw new ArgumentException(string.Format("Unknown entity type \"{0}\".", entityType));
|
|
}
|
|
|
|
return udiType == UdiType.StringUdi
|
|
? new StringUdi(entityType, string.Empty)
|
|
: new GuidUdi(entityType, Guid.Empty);
|
|
});
|
|
|
|
private static bool ParseInternal(string? s, bool tryParse, bool knownTypes, [MaybeNullWhen(false)] out Udi udi)
|
|
{
|
|
udi = null;
|
|
if (Uri.IsWellFormedUriString(s, UriKind.Absolute) == false
|
|
|| Uri.TryCreate(s, UriKind.Absolute, out Uri? uri) == false)
|
|
{
|
|
if (tryParse)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
throw new FormatException(string.Format("String \"{0}\" is not a valid udi.", s));
|
|
}
|
|
|
|
var entityType = uri.Host;
|
|
if (UdiTypes.TryGetValue(entityType, out UdiType udiType) == false)
|
|
{
|
|
if (knownTypes)
|
|
{
|
|
// not knowing the type is not an error
|
|
// just return the unknown type udi
|
|
udi = UnknownTypeUdi.Instance;
|
|
return false;
|
|
}
|
|
|
|
if (tryParse)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
throw new FormatException(string.Format("Unknown entity type \"{0}\".", entityType));
|
|
}
|
|
|
|
var path = uri.AbsolutePath.TrimStart('/');
|
|
|
|
if (udiType == UdiType.GuidUdi)
|
|
{
|
|
if (path == string.Empty)
|
|
{
|
|
udi = GetRootUdi(uri.Host);
|
|
return true;
|
|
}
|
|
|
|
if (Guid.TryParse(path, out Guid guid) == false)
|
|
{
|
|
if (tryParse)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
throw new FormatException(string.Format("String \"{0}\" is not a valid udi.", s));
|
|
}
|
|
|
|
udi = new GuidUdi(uri.Host, guid);
|
|
return true;
|
|
}
|
|
|
|
if (udiType == UdiType.StringUdi)
|
|
{
|
|
udi = path == string.Empty ? GetRootUdi(uri.Host) : new StringUdi(uri.Host, Uri.UnescapeDataString(path));
|
|
return true;
|
|
}
|
|
|
|
if (tryParse)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
throw new InvalidOperationException(string.Format("Invalid udi type \"{0}\".", udiType));
|
|
}
|
|
|
|
public static Dictionary<string, UdiType> GetKnownUdiTypes() =>
|
|
new()
|
|
{
|
|
{ Constants.UdiEntityType.Unknown, UdiType.Unknown },
|
|
{ Constants.UdiEntityType.AnyGuid, UdiType.GuidUdi },
|
|
{ Constants.UdiEntityType.Element, 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 },
|
|
};
|
|
}
|