mirror of https://github.com/abpframework/abp.git
24 changed files with 404 additions and 147 deletions
@ -0,0 +1,90 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
using Volo.Abp.ObjectExtending; |
||||
|
using Volo.Abp.Reflection; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending |
||||
|
{ |
||||
|
public class CachedObjectExtensionsDtoService : ICachedObjectExtensionsDtoService, ISingletonDependency |
||||
|
{ |
||||
|
private volatile ObjectExtensionsDto _cachedValue; |
||||
|
private readonly object _syncLock = new object(); |
||||
|
|
||||
|
public virtual ObjectExtensionsDto Get() |
||||
|
{ |
||||
|
if (_cachedValue == null) |
||||
|
{ |
||||
|
lock (_syncLock) |
||||
|
{ |
||||
|
if (_cachedValue == null) |
||||
|
{ |
||||
|
_cachedValue = GenerateCacheValue(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return _cachedValue; |
||||
|
} |
||||
|
|
||||
|
protected virtual ObjectExtensionsDto GenerateCacheValue() |
||||
|
{ |
||||
|
var objectExtensionsDto = new ObjectExtensionsDto |
||||
|
{ |
||||
|
Modules = new Dictionary<string, ModuleExtensionDto>() |
||||
|
}; |
||||
|
|
||||
|
foreach (var moduleConfig in ObjectExtensionManager.Instance.Modules) |
||||
|
{ |
||||
|
var moduleExtensionDto = objectExtensionsDto.Modules[moduleConfig.Key] = new ModuleExtensionDto |
||||
|
{ |
||||
|
Objects = new Dictionary<string, ModuleObjectExtensionDto>() |
||||
|
}; |
||||
|
|
||||
|
foreach (var objectConfig in moduleConfig.Value) |
||||
|
{ |
||||
|
var moduleObjectExtensionDto = moduleExtensionDto.Objects[objectConfig.Key] = |
||||
|
new ModuleObjectExtensionDto |
||||
|
{ |
||||
|
ExtraProperties = new Dictionary<string, ModuleObjectExtraPropertyExtensionDto>() |
||||
|
}; |
||||
|
|
||||
|
foreach (var propertyConfig in objectConfig.Value.GetProperties()) |
||||
|
{ |
||||
|
var propertyExtensionDto = moduleObjectExtensionDto.ExtraProperties[propertyConfig.Name] = |
||||
|
new ModuleObjectExtraPropertyExtensionDto |
||||
|
{ |
||||
|
Type = TypeHelper.GetFullNameHandlingNullableAndGenerics(propertyConfig.Type), |
||||
|
TypeSimple = TypeHelper.GetSimplifiedName(propertyConfig.Type), |
||||
|
Attributes = new List<ModuleObjectExtraPropertyAttributeDto>(), |
||||
|
DisplayName = LocalizedDisplayNameDto.CreateOrNull(propertyConfig.DisplayName), |
||||
|
Ui = new ModuleObjectExtraPropertyUiExtensionDto |
||||
|
{ |
||||
|
CreateForm = new ModuleObjectExtraPropertyUiFormExtensionDto |
||||
|
{ |
||||
|
Visible = true |
||||
|
}, |
||||
|
EditForm = new ModuleObjectExtraPropertyUiFormExtensionDto |
||||
|
{ |
||||
|
Visible = true |
||||
|
}, |
||||
|
Table = new ModuleObjectExtraPropertyUiTableExtensionDto |
||||
|
{ |
||||
|
Visible = true |
||||
|
} |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
foreach (var attribute in propertyConfig.Attributes) |
||||
|
{ |
||||
|
propertyExtensionDto.Attributes.Add( |
||||
|
ModuleObjectExtraPropertyAttributeDto.Create(attribute) |
||||
|
); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return objectExtensionsDto; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,7 @@ |
|||||
|
namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending |
||||
|
{ |
||||
|
public interface ICachedObjectExtensionsDtoService |
||||
|
{ |
||||
|
ObjectExtensionsDto Get(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,37 @@ |
|||||
|
using System; |
||||
|
using JetBrains.Annotations; |
||||
|
using Volo.Abp.Localization; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending |
||||
|
{ |
||||
|
[Serializable] |
||||
|
public class LocalizedDisplayNameDto |
||||
|
{ |
||||
|
public string Name { get; set; } |
||||
|
|
||||
|
public string Resource { get; set; } |
||||
|
|
||||
|
[CanBeNull] |
||||
|
public static LocalizedDisplayNameDto CreateOrNull(ILocalizableString localizableString) |
||||
|
{ |
||||
|
if (localizableString is LocalizableString localizableStringInstance) |
||||
|
{ |
||||
|
return new LocalizedDisplayNameDto |
||||
|
{ |
||||
|
Name = localizableStringInstance.Name, |
||||
|
Resource = LocalizationResourceNameAttribute.GetName(localizableStringInstance.ResourceType) |
||||
|
}; |
||||
|
} |
||||
|
|
||||
|
if (localizableString is FixedLocalizableString fixedLocalizableString) |
||||
|
{ |
||||
|
return new LocalizedDisplayNameDto |
||||
|
{ |
||||
|
Name = fixedLocalizableString.Value, |
||||
|
}; |
||||
|
} |
||||
|
|
||||
|
return null; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,11 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending |
||||
|
{ |
||||
|
[Serializable] |
||||
|
public class ModuleObjectExtensionDto |
||||
|
{ |
||||
|
public Dictionary<string, ModuleObjectExtraPropertyExtensionDto> ExtraProperties { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,36 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.ComponentModel.DataAnnotations; |
||||
|
using Volo.Abp.Reflection; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending |
||||
|
{ |
||||
|
[Serializable] |
||||
|
public class ModuleObjectExtraPropertyAttributeDto |
||||
|
{ |
||||
|
public string Type { get; set; } |
||||
|
public string TypeSimple { get; set; } |
||||
|
public Dictionary<string, object> Configuration { get; set; } |
||||
|
|
||||
|
public static ModuleObjectExtraPropertyAttributeDto Create(Attribute attribute) |
||||
|
{ |
||||
|
var attributeType = attribute.GetType(); |
||||
|
var dto = new ModuleObjectExtraPropertyAttributeDto |
||||
|
{ |
||||
|
Type = TypeHelper.GetFullNameHandlingNullableAndGenerics(attributeType), |
||||
|
TypeSimple = TypeHelper.GetSimplifiedName(attributeType), |
||||
|
Configuration = new Dictionary<string, object>() |
||||
|
}; |
||||
|
|
||||
|
if (attribute is StringLengthAttribute stringLengthAttribute) |
||||
|
{ |
||||
|
dto.Configuration["MaximumLength"] = stringLengthAttribute.MaximumLength; |
||||
|
dto.Configuration["MinimumLength"] = stringLengthAttribute.MinimumLength; |
||||
|
} |
||||
|
|
||||
|
//TODO: Others!
|
||||
|
|
||||
|
return dto; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,19 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending |
||||
|
{ |
||||
|
[Serializable] |
||||
|
public class ModuleObjectExtraPropertyExtensionDto |
||||
|
{ |
||||
|
public string Type { get; set; } |
||||
|
|
||||
|
public string TypeSimple { get; set; } |
||||
|
|
||||
|
public LocalizedDisplayNameDto DisplayName { get; set; } |
||||
|
|
||||
|
public ModuleObjectExtraPropertyUiExtensionDto Ui { get; set; } |
||||
|
|
||||
|
public List<ModuleObjectExtraPropertyAttributeDto> Attributes { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,12 @@ |
|||||
|
using System; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending |
||||
|
{ |
||||
|
[Serializable] |
||||
|
public class ModuleObjectExtraPropertyUiExtensionDto |
||||
|
{ |
||||
|
public ModuleObjectExtraPropertyUiTableExtensionDto Table { get; set; } |
||||
|
public ModuleObjectExtraPropertyUiFormExtensionDto CreateForm { get; set; } |
||||
|
public ModuleObjectExtraPropertyUiFormExtensionDto EditForm { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,10 @@ |
|||||
|
using System; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending |
||||
|
{ |
||||
|
[Serializable] |
||||
|
public class ModuleObjectExtraPropertyUiFormExtensionDto |
||||
|
{ |
||||
|
public bool Visible { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,10 @@ |
|||||
|
using System; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending |
||||
|
{ |
||||
|
[Serializable] |
||||
|
public class ModuleObjectExtraPropertyUiTableExtensionDto |
||||
|
{ |
||||
|
public bool Visible { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,12 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending |
||||
|
{ |
||||
|
[Serializable] |
||||
|
public class ModuleExtensionDto |
||||
|
{ |
||||
|
public Dictionary<string, ModuleObjectExtensionDto> Objects { get; set; } |
||||
|
} |
||||
|
} |
||||
|
|
||||
@ -0,0 +1,11 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending |
||||
|
{ |
||||
|
[Serializable] |
||||
|
public class ObjectExtensionsDto |
||||
|
{ |
||||
|
public Dictionary<string, ModuleExtensionDto> Modules { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -1,127 +0,0 @@ |
|||||
using System; |
|
||||
using System.Collections.Generic; |
|
||||
using System.Linq; |
|
||||
using JetBrains.Annotations; |
|
||||
|
|
||||
namespace Volo.Abp.Http.Modeling |
|
||||
{ |
|
||||
public static class ModelingTypeHelper |
|
||||
{ |
|
||||
public static string GetFullNameHandlingNullableAndGenerics([NotNull] Type type) |
|
||||
{ |
|
||||
Check.NotNull(type, nameof(type)); |
|
||||
|
|
||||
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>)) |
|
||||
{ |
|
||||
return type.GenericTypeArguments[0].FullName + "?"; |
|
||||
} |
|
||||
|
|
||||
if (type.IsGenericType) |
|
||||
{ |
|
||||
var genericType = type.GetGenericTypeDefinition(); |
|
||||
return $"{genericType.FullName.Left(genericType.FullName.IndexOf('`'))}<{type.GenericTypeArguments.Select(GetFullNameHandlingNullableAndGenerics).JoinAsString(",")}>"; |
|
||||
} |
|
||||
|
|
||||
return type.FullName; |
|
||||
} |
|
||||
|
|
||||
public static string GetSimplifiedName([NotNull] Type type) |
|
||||
{ |
|
||||
Check.NotNull(type, nameof(type)); |
|
||||
|
|
||||
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>)) |
|
||||
{ |
|
||||
return GetSimplifiedName(type.GenericTypeArguments[0]) + "?"; |
|
||||
} |
|
||||
|
|
||||
if (type.IsGenericType) |
|
||||
{ |
|
||||
var genericType = type.GetGenericTypeDefinition(); |
|
||||
return $"{genericType.FullName.Left(genericType.FullName.IndexOf('`'))}<{type.GenericTypeArguments.Select(GetSimplifiedName).JoinAsString(",")}>"; |
|
||||
} |
|
||||
|
|
||||
if (type == typeof(string)) |
|
||||
{ |
|
||||
return "string"; |
|
||||
} |
|
||||
else if (type == typeof(int)) |
|
||||
{ |
|
||||
return "number"; |
|
||||
} |
|
||||
else if (type == typeof(long)) |
|
||||
{ |
|
||||
return "number"; |
|
||||
} |
|
||||
else if (type == typeof(bool)) |
|
||||
{ |
|
||||
return "boolean"; |
|
||||
} |
|
||||
else if (type == typeof(char)) |
|
||||
{ |
|
||||
return "string"; |
|
||||
} |
|
||||
else if (type == typeof(double)) |
|
||||
{ |
|
||||
return "number"; |
|
||||
} |
|
||||
else if (type == typeof(float)) |
|
||||
{ |
|
||||
return "number"; |
|
||||
} |
|
||||
else if (type == typeof(decimal)) |
|
||||
{ |
|
||||
return "number"; |
|
||||
} |
|
||||
else if (type == typeof(DateTime)) |
|
||||
{ |
|
||||
return "string"; |
|
||||
} |
|
||||
else if (type == typeof(DateTimeOffset)) |
|
||||
{ |
|
||||
return "string"; |
|
||||
} |
|
||||
else if (type == typeof(TimeSpan)) |
|
||||
{ |
|
||||
return "string"; |
|
||||
} |
|
||||
else if (type == typeof(Guid)) |
|
||||
{ |
|
||||
return "string"; |
|
||||
} |
|
||||
else if (type == typeof(byte)) |
|
||||
{ |
|
||||
return "number"; |
|
||||
} |
|
||||
else if (type == typeof(sbyte)) |
|
||||
{ |
|
||||
return "number"; |
|
||||
} |
|
||||
else if (type == typeof(short)) |
|
||||
{ |
|
||||
return "number"; |
|
||||
} |
|
||||
else if (type == typeof(ushort)) |
|
||||
{ |
|
||||
return "number"; |
|
||||
} |
|
||||
else if (type == typeof(uint)) |
|
||||
{ |
|
||||
return "number"; |
|
||||
} |
|
||||
else if (type == typeof(ulong)) |
|
||||
{ |
|
||||
return "number"; |
|
||||
} |
|
||||
else if (type == typeof(IntPtr)) |
|
||||
{ |
|
||||
return "number"; |
|
||||
} |
|
||||
else if (type == typeof(UIntPtr)) |
|
||||
{ |
|
||||
return "number"; |
|
||||
} |
|
||||
|
|
||||
return type.FullName; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
Loading…
Reference in new issue