From c8be359697e52dc98a915bc7fcc3f24a20de141a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Sat, 25 Apr 2020 13:46:37 +0300 Subject: [PATCH 01/67] Remove GlobalizationHelper. --- .../AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs | 7 +++-- .../Localization/AbpLanguagesController.cs | 4 +-- .../Mvc/Localization/GlobalizationHelper.cs | 26 ------------------- .../Volo/Abp/Localization/CultureHelper.cs | 18 +++++++++++++ 4 files changed, 25 insertions(+), 30 deletions(-) delete mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Localization/GlobalizationHelper.cs diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs index 7e469f4195..d49e2c15e6 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs @@ -90,8 +90,11 @@ namespace Volo.Abp.AspNetCore.Mvc var mvcCoreBuilder = context.Services.AddMvcCore(); context.Services.ExecutePreConfiguredActions(mvcCoreBuilder); - - var abpMvcDataAnnotationsLocalizationOptions = context.Services.ExecutePreConfiguredActions(new AbpMvcDataAnnotationsLocalizationOptions()); + + var abpMvcDataAnnotationsLocalizationOptions = context.Services + .ExecutePreConfiguredActions( + new AbpMvcDataAnnotationsLocalizationOptions() + ); context.Services .AddSingleton>( diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Localization/AbpLanguagesController.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Localization/AbpLanguagesController.cs index 6428cf485e..9b376ab540 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Localization/AbpLanguagesController.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Localization/AbpLanguagesController.cs @@ -2,7 +2,7 @@ using Microsoft.AspNetCore.Localization; using Microsoft.AspNetCore.Mvc; using System; -using Volo.Abp.Settings; +using Volo.Abp.Localization; namespace Volo.Abp.AspNetCore.Mvc.Localization { @@ -13,7 +13,7 @@ namespace Volo.Abp.AspNetCore.Mvc.Localization [HttpGet] public IActionResult Switch(string culture, string uiCulture = "", string returnUrl = "") { - if (!GlobalizationHelper.IsValidCultureCode(culture)) + if (!CultureHelper.IsValidCultureCode(culture)) { throw new AbpException("Unknown language: " + culture + ". It must be a valid culture!"); } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Localization/GlobalizationHelper.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Localization/GlobalizationHelper.cs deleted file mode 100644 index a84faeb8f9..0000000000 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Localization/GlobalizationHelper.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System; -using System.Globalization; - -namespace Volo.Abp.AspNetCore.Mvc.Localization -{ - internal static class GlobalizationHelper - { - public static bool IsValidCultureCode(string cultureCode) - { - if (cultureCode.IsNullOrWhiteSpace()) - { - return false; - } - - try - { - CultureInfo.GetCultureInfo(cultureCode); - return true; - } - catch (CultureNotFoundException) - { - return false; - } - } - } -} \ No newline at end of file diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/Localization/CultureHelper.cs b/framework/src/Volo.Abp.Core/Volo/Abp/Localization/CultureHelper.cs index 92320f737c..64f6a4a6f9 100644 --- a/framework/src/Volo.Abp.Core/Volo/Abp/Localization/CultureHelper.cs +++ b/framework/src/Volo.Abp.Core/Volo/Abp/Localization/CultureHelper.cs @@ -29,5 +29,23 @@ namespace Volo.Abp.Localization CultureInfo.CurrentUICulture = currentUiCulture; }); } + + public static bool IsValidCultureCode(string cultureCode) + { + if (cultureCode.IsNullOrWhiteSpace()) + { + return false; + } + + try + { + CultureInfo.GetCultureInfo(cultureCode); + return true; + } + catch (CultureNotFoundException) + { + return false; + } + } } } From de81fca5db3870c56cfbdd6ff86e4a7468935820 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Sat, 25 Apr 2020 14:44:15 +0300 Subject: [PATCH 02/67] Added binder for extra properties --- .../AspNetCore/Mvc/AbpMvcOptionsExtensions.cs | 1 + ...PropertiesDictionaryModelBinderProvider.cs | 48 +++++++++++ .../AbpExtraPropertyModelBinder.cs | 79 +++++++++++++++++++ 3 files changed, 128 insertions(+) create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ModelBinding/AbpExtraPropertiesDictionaryModelBinderProvider.cs create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ModelBinding/AbpExtraPropertyModelBinder.cs diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpMvcOptionsExtensions.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpMvcOptionsExtensions.cs index f1225f1abf..59166d3e1d 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpMvcOptionsExtensions.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpMvcOptionsExtensions.cs @@ -48,6 +48,7 @@ namespace Volo.Abp.AspNetCore.Mvc private static void AddModelBinders(MvcOptions options) { options.ModelBinderProviders.Insert(0, new AbpDateTimeModelBinderProvider()); + options.ModelBinderProviders.Insert(0, new AbpExtraPropertiesDictionaryModelBinderProvider()); } private static void AddMetadataProviders(MvcOptions options, IServiceCollection services) diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ModelBinding/AbpExtraPropertiesDictionaryModelBinderProvider.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ModelBinding/AbpExtraPropertiesDictionaryModelBinderProvider.cs new file mode 100644 index 0000000000..3ed1eda3a1 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ModelBinding/AbpExtraPropertiesDictionaryModelBinderProvider.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.ModelBinding; +using Microsoft.AspNetCore.Mvc.ModelBinding.Binders; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; +using Volo.Abp.Data; + +namespace Volo.Abp.AspNetCore.Mvc.ModelBinding +{ + public class AbpExtraPropertiesDictionaryModelBinderProvider : IModelBinderProvider + { + public IModelBinder GetBinder(ModelBinderProviderContext context) + { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + if (context.Metadata.ModelType != typeof(Dictionary)) + { + return null; + } + + if (!context.Metadata.ContainerType.IsAssignableTo()) + { + return null; + } + + var binderType = typeof(DictionaryModelBinder); + var keyBinder = context.CreateBinder(context.MetadataProvider.GetMetadataForType(typeof(string))); + var valueBinder = new AbpExtraPropertyModelBinder(context.Metadata.ContainerType); + var loggerFactory = context.Services.GetRequiredService(); + var mvcOptions = context.Services.GetRequiredService>().Value; + + return (IModelBinder)Activator.CreateInstance( + binderType, + keyBinder, + valueBinder, + loggerFactory, + true /* allowValidatingTopLevelNodes */, + mvcOptions); + } + } +} diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ModelBinding/AbpExtraPropertyModelBinder.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ModelBinding/AbpExtraPropertyModelBinder.cs new file mode 100644 index 0000000000..da199cae90 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ModelBinding/AbpExtraPropertyModelBinder.cs @@ -0,0 +1,79 @@ +using System; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc.ModelBinding; +using Volo.Abp.ObjectExtending; + +namespace Volo.Abp.AspNetCore.Mvc.ModelBinding +{ + public class AbpExtraPropertyModelBinder : IModelBinder + { + public Type ExtensibleObjectType { get; } + + public AbpExtraPropertyModelBinder(Type extensibleObjectType) + { + ExtensibleObjectType = extensibleObjectType; + } + + public virtual Task BindModelAsync(ModelBindingContext bindingContext) + { + var valueProviderResult = bindingContext.ValueProvider.GetValue(bindingContext.ModelName); + if (valueProviderResult == ValueProviderResult.None) + { + return Task.CompletedTask; + } + + bindingContext.ModelState.SetModelValue(bindingContext.ModelName, valueProviderResult); + + var model = ConvertStringToPropertyType( + bindingContext, + valueProviderResult.FirstValue + ); + + bindingContext.Result = ModelBindingResult.Success(model); + + return Task.CompletedTask; + } + + protected virtual object ConvertStringToPropertyType(ModelBindingContext bindingContext, string value) + { + if (bindingContext.ModelMetadata.ConvertEmptyStringToNull && string.IsNullOrWhiteSpace(value)) + { + return null; + } + + var extensionInfo = ObjectExtensionManager.Instance.GetOrNull(ExtensibleObjectType); + if (extensionInfo == null) + { + return value; + } + + var propertyName = ExtractExtraPropertyName(bindingContext.ModelName); + if (propertyName == null) + { + return value; + } + + var propertyInfo = extensionInfo.GetPropertyOrNull(propertyName); + if (propertyInfo == null) + { + return value; + } + + return Convert.ChangeType(value, propertyInfo.Type); + } + + /* modelName is a string like "UserInfo.ExtraProperties[SocialSecurityNumber]" + * This method returns "SocialSecurityNumber" for this example. */ + protected virtual string ExtractExtraPropertyName(string modelName) + { + //TODO: Use regex(?) and add unit test (by extracting to a helper class) + var index = modelName.IndexOf(".ExtraProperties[", StringComparison.Ordinal); + if (index < 0) + { + return null; + } + + return modelName.Substring(index + 17, modelName.Length - index - 18); + } + } +} \ No newline at end of file From 660ce383fb47265eb551d0464a99dec7c941c98e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Sat, 25 Apr 2020 15:55:11 +0300 Subject: [PATCH 03/67] Added AbpModelExpressionProvider and AbpExtraPropertyValidationMetadataProvider --- .../AspNetCore/Mvc/AbpMvcOptionsExtensions.cs | 2 + .../AbpExtraPropertyModelBinder.cs | 16 +---- .../ExtraPropertyBindingHelper.cs | 37 ++++++++++ ...ExtraPropertyValidationMetadataProvider.cs | 53 ++++++++++++++ .../ModelBinding/MyModelExpressionProvider.cs | 72 +++++++++++++++++++ .../ObjectExtensionManagerExtensions.cs | 14 ++++ 6 files changed, 179 insertions(+), 15 deletions(-) create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ModelBinding/ExtraPropertyBindingHelper.cs create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ModelBinding/Metadata/AbpExtraPropertyValidationMetadataProvider.cs create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ModelBinding/MyModelExpressionProvider.cs diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpMvcOptionsExtensions.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpMvcOptionsExtensions.cs index 59166d3e1d..55998a512f 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpMvcOptionsExtensions.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpMvcOptionsExtensions.cs @@ -5,6 +5,7 @@ using Volo.Abp.AspNetCore.Mvc.Conventions; using Volo.Abp.AspNetCore.Mvc.ExceptionHandling; using Volo.Abp.AspNetCore.Mvc.Features; using Volo.Abp.AspNetCore.Mvc.ModelBinding; +using Volo.Abp.AspNetCore.Mvc.ModelBinding.Metadata; using Volo.Abp.AspNetCore.Mvc.Response; using Volo.Abp.AspNetCore.Mvc.Uow; using Volo.Abp.AspNetCore.Mvc.Validation; @@ -56,6 +57,7 @@ namespace Volo.Abp.AspNetCore.Mvc options.ModelMetadataDetailsProviders.Add( new AbpDataAnnotationAutoLocalizationMetadataDetailsProvider(services) ); + options.ModelMetadataDetailsProviders.Add(new AbpExtraPropertyValidationMetadataProvider()); } } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ModelBinding/AbpExtraPropertyModelBinder.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ModelBinding/AbpExtraPropertyModelBinder.cs index da199cae90..d3f570b1ce 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ModelBinding/AbpExtraPropertyModelBinder.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ModelBinding/AbpExtraPropertyModelBinder.cs @@ -47,7 +47,7 @@ namespace Volo.Abp.AspNetCore.Mvc.ModelBinding return value; } - var propertyName = ExtractExtraPropertyName(bindingContext.ModelName); + var propertyName = ExtraPropertyBindingHelper.ExtractExtraPropertyName(bindingContext.ModelName); if (propertyName == null) { return value; @@ -61,19 +61,5 @@ namespace Volo.Abp.AspNetCore.Mvc.ModelBinding return Convert.ChangeType(value, propertyInfo.Type); } - - /* modelName is a string like "UserInfo.ExtraProperties[SocialSecurityNumber]" - * This method returns "SocialSecurityNumber" for this example. */ - protected virtual string ExtractExtraPropertyName(string modelName) - { - //TODO: Use regex(?) and add unit test (by extracting to a helper class) - var index = modelName.IndexOf(".ExtraProperties[", StringComparison.Ordinal); - if (index < 0) - { - return null; - } - - return modelName.Substring(index + 17, modelName.Length - index - 18); - } } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ModelBinding/ExtraPropertyBindingHelper.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ModelBinding/ExtraPropertyBindingHelper.cs new file mode 100644 index 0000000000..cfc8754415 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ModelBinding/ExtraPropertyBindingHelper.cs @@ -0,0 +1,37 @@ +using System; + +namespace Volo.Abp.AspNetCore.Mvc.ModelBinding +{ + public static class ExtraPropertyBindingHelper + { + /// + /// modelName is a string like "UserInfo.ExtraProperties[SocialSecurityNumber]" + /// This method returns "SocialSecurityNumber" for this example. */ + /// + public static string ExtractExtraPropertyName(string modelName) + { + var index = modelName.IndexOf(".ExtraProperties[", StringComparison.Ordinal); + if (index < 0) + { + return null; + } + + return modelName.Substring(index + 17, modelName.Length - index - 18); + } + + /// + /// modelName is a string like "UserInfo.ExtraProperties[SocialSecurityNumber]" + /// This method returns "UserInfo" for this example. + /// + public static string ExtractContainerName(string modelName) + { + var index = modelName.IndexOf(".ExtraProperties[", StringComparison.Ordinal); + if (index < 0) + { + return null; + } + + return modelName.Left(index); + } + } +} diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ModelBinding/Metadata/AbpExtraPropertyValidationMetadataProvider.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ModelBinding/Metadata/AbpExtraPropertyValidationMetadataProvider.cs new file mode 100644 index 0000000000..2d47882d13 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ModelBinding/Metadata/AbpExtraPropertyValidationMetadataProvider.cs @@ -0,0 +1,53 @@ +using System; +using System.Threading; +using Microsoft.AspNetCore.Mvc.ModelBinding.Metadata; +using Volo.Abp.ObjectExtending; + +namespace Volo.Abp.AspNetCore.Mvc.ModelBinding.Metadata +{ + public class AbpExtraPropertyValidationMetadataProvider : IValidationMetadataProvider + { + public static AsyncLocal CurrentModeInfo { get; } = new AsyncLocal(); + + public void CreateValidationMetadata(ValidationMetadataProviderContext context) + { + if (CurrentModeInfo.Value == null) + { + return; + } + + var currentModel = CurrentModeInfo.Value; + + CurrentModeInfo.Value = null; + + var propertyInfo = ObjectExtensionManager.Instance.GetPropertyOrNull( + currentModel.ExtensibleObjectType, + currentModel.PropertyName + ); + + if (propertyInfo == null) + { + return; + } + + foreach (var validationAttribute in propertyInfo.ValidationAttributes) + { + context.ValidationMetadata.ValidatorMetadata.Add(validationAttribute); + } + } + + public class ExtraPropertyModelInfo + { + public Type ExtensibleObjectType { get; } + public string PropertyName { get; } + + public ExtraPropertyModelInfo( + Type extensibleObjectType, + string propertyName) + { + ExtensibleObjectType = extensibleObjectType; + PropertyName = propertyName; + } + } + } +} diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ModelBinding/MyModelExpressionProvider.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ModelBinding/MyModelExpressionProvider.cs new file mode 100644 index 0000000000..7499d1ce85 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ModelBinding/MyModelExpressionProvider.cs @@ -0,0 +1,72 @@ +using System; +using System.Linq; +using System.Linq.Expressions; +using Microsoft.AspNetCore.Mvc.ViewFeatures; +using Volo.Abp.AspNetCore.Mvc.ModelBinding.Metadata; +using Volo.Abp.Data; +using Volo.Abp.DependencyInjection; + +namespace Volo.Abp.AspNetCore.Mvc.ModelBinding +{ + [Dependency(ReplaceServices = true)] + public class AbpModelExpressionProvider : IModelExpressionProvider, ITransientDependency + { + private readonly ModelExpressionProvider _modelExpressionProvider; + + public AbpModelExpressionProvider(ModelExpressionProvider modelExpressionProvider) + { + _modelExpressionProvider = modelExpressionProvider; + } + + public ModelExpression CreateModelExpression( + ViewDataDictionary viewData, + Expression> expression) + { + var result = _modelExpressionProvider.CreateModelExpression( + viewData, + expression + ); + + if (result.ModelExplorer.Container == null) + { + return result; + } + + var extraPropertyName = ExtraPropertyBindingHelper.ExtractExtraPropertyName(result.Name); + if (extraPropertyName == null) + { + return result; + } + + var containerName = ExtraPropertyBindingHelper.ExtractContainerName(result.Name); + if (containerName == null) + { + return result; + } + + var containerModelExpolorer = result + .ModelExplorer + .Container + .Properties + .FirstOrDefault(p => p.Metadata.Name == containerName); + + if (containerModelExpolorer == null) + { + return result; + } + + if (!containerModelExpolorer.ModelType.IsAssignableTo()) + { + return result; + } + + AbpExtraPropertyValidationMetadataProvider.CurrentModeInfo.Value + = new AbpExtraPropertyValidationMetadataProvider.ExtraPropertyModelInfo( + containerModelExpolorer.ModelType, + extraPropertyName + ); + + return result; + } + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionManagerExtensions.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionManagerExtensions.cs index 21d139913b..1dd8bfb6b1 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionManagerExtensions.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionManagerExtensions.cs @@ -79,5 +79,19 @@ namespace Volo.Abp.ObjectExtending ); }); } + + public static ObjectExtensionPropertyInfo GetPropertyOrNull( + [NotNull] this ObjectExtensionManager objectExtensionManager, + [NotNull] Type objectType, + [NotNull] string propertyName) + { + Check.NotNull(objectExtensionManager, nameof(objectExtensionManager)); + Check.NotNull(objectType, nameof(objectType)); + Check.NotNull(propertyName, nameof(propertyName)); + + return objectExtensionManager + .GetOrNull(objectType)? + .GetPropertyOrNull(propertyName); + } } } \ No newline at end of file From 92baeb95b751c80c9ec17fc989f100e8b2ca07b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Sat, 25 Apr 2020 16:05:25 +0300 Subject: [PATCH 04/67] rename file: AbpModelExpressionProvider --- ...ModelExpressionProvider.cs => AbpModelExpressionProvider.cs} | 2 ++ 1 file changed, 2 insertions(+) rename framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ModelBinding/{MyModelExpressionProvider.cs => AbpModelExpressionProvider.cs} (96%) diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ModelBinding/MyModelExpressionProvider.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ModelBinding/AbpModelExpressionProvider.cs similarity index 96% rename from framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ModelBinding/MyModelExpressionProvider.cs rename to framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ModelBinding/AbpModelExpressionProvider.cs index 7499d1ce85..a89127c158 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ModelBinding/MyModelExpressionProvider.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ModelBinding/AbpModelExpressionProvider.cs @@ -27,6 +27,8 @@ namespace Volo.Abp.AspNetCore.Mvc.ModelBinding expression ); + AbpExtraPropertyValidationMetadataProvider.CurrentModeInfo.Value = null; + if (result.ModelExplorer.Container == null) { return result; From 8f906ad49ffee7a5712897248d7e0971290daef6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Sat, 25 Apr 2020 17:06:33 +0300 Subject: [PATCH 05/67] Added more extension methods for ObjectExtensionManager --- .../ObjectExtensionManagerExtensions.cs | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionManagerExtensions.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionManagerExtensions.cs index 1dd8bfb6b1..4344152345 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionManagerExtensions.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionManagerExtensions.cs @@ -1,4 +1,6 @@ using System; +using System.Collections.Generic; +using System.Collections.Immutable; using JetBrains.Annotations; using Volo.Abp.Data; @@ -80,6 +82,16 @@ namespace Volo.Abp.ObjectExtending }); } + public static ObjectExtensionPropertyInfo GetPropertyOrNull( + [NotNull] this ObjectExtensionManager objectExtensionManager, + [NotNull] string propertyName) + { + return objectExtensionManager.GetPropertyOrNull( + typeof(TObject), + propertyName + ); + } + public static ObjectExtensionPropertyInfo GetPropertyOrNull( [NotNull] this ObjectExtensionManager objectExtensionManager, [NotNull] Type objectType, @@ -93,5 +105,26 @@ namespace Volo.Abp.ObjectExtending .GetOrNull(objectType)? .GetPropertyOrNull(propertyName); } + + private static readonly ImmutableList EmptyPropertyList + = new List().ToImmutableList(); + + public static ImmutableList GetProperties( + [NotNull] this ObjectExtensionManager objectExtensionManager, + [NotNull] Type objectType, + [NotNull] string propertyName) + { + Check.NotNull(objectExtensionManager, nameof(objectExtensionManager)); + Check.NotNull(objectType, nameof(objectType)); + Check.NotNull(propertyName, nameof(propertyName)); + + var extensionInfo = objectExtensionManager.GetOrNull(objectType); + if (extensionInfo == null) + { + return EmptyPropertyList; + } + + return extensionInfo.GetProperties(); + } } } \ No newline at end of file From 7278f0c949300945853d0f58b51f2240bcbfef63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Sat, 25 Apr 2020 17:09:35 +0300 Subject: [PATCH 06/67] Update ObjectExtensionManagerExtensions.cs --- .../ObjectExtensionManagerExtensions.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionManagerExtensions.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionManagerExtensions.cs index 4344152345..7870d18f37 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionManagerExtensions.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionManagerExtensions.cs @@ -109,14 +109,18 @@ namespace Volo.Abp.ObjectExtending private static readonly ImmutableList EmptyPropertyList = new List().ToImmutableList(); + public static ImmutableList GetProperties( + [NotNull] this ObjectExtensionManager objectExtensionManager) + { + return objectExtensionManager.GetProperties(typeof(TObject)); + } + public static ImmutableList GetProperties( [NotNull] this ObjectExtensionManager objectExtensionManager, - [NotNull] Type objectType, - [NotNull] string propertyName) + [NotNull] Type objectType) { Check.NotNull(objectExtensionManager, nameof(objectExtensionManager)); Check.NotNull(objectType, nameof(objectType)); - Check.NotNull(propertyName, nameof(propertyName)); var extensionInfo = objectExtensionManager.GetOrNull(objectType); if (extensionInfo == null) From ccf759ed27193cb460b7e1eaea132ab7e32bda00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Sat, 25 Apr 2020 17:28:53 +0300 Subject: [PATCH 07/67] Added DisplayName to ObjectExtensionPropertyInfo --- .../Volo.Abp.ObjectExtending.csproj | 2 +- .../AbpObjectExtendingModule.cs | 6 +++++- .../ObjectExtensionPropertyInfo.cs | 20 +++++++++++++++++-- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo.Abp.ObjectExtending.csproj b/framework/src/Volo.Abp.ObjectExtending/Volo.Abp.ObjectExtending.csproj index 43da943f8b..e50ff26d5f 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo.Abp.ObjectExtending.csproj +++ b/framework/src/Volo.Abp.ObjectExtending/Volo.Abp.ObjectExtending.csproj @@ -15,7 +15,7 @@ - + \ No newline at end of file diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/AbpObjectExtendingModule.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/AbpObjectExtendingModule.cs index 9392429fd3..f8b585594e 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/AbpObjectExtendingModule.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/AbpObjectExtendingModule.cs @@ -1,7 +1,11 @@ -using Volo.Abp.Modularity; +using Volo.Abp.Localization; +using Volo.Abp.Modularity; namespace Volo.Abp.ObjectExtending { + [DependsOn( + typeof(AbpLocalizationAbstractionsModule) + )] public class AbpObjectExtendingModule : AbpModule { diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionPropertyInfo.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionPropertyInfo.cs index e6dbbfd6ce..f1d0392c76 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionPropertyInfo.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionPropertyInfo.cs @@ -2,11 +2,14 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using JetBrains.Annotations; +using Volo.Abp.Localization; namespace Volo.Abp.ObjectExtending { public class ObjectExtensionPropertyInfo { + [NotNull] private ILocalizableString _displayName; + [NotNull] public ObjectExtensionInfo ObjectExtension { get; } @@ -22,6 +25,17 @@ namespace Volo.Abp.ObjectExtending [NotNull] public List> Validators { get; } + [NotNull] + public ILocalizableString DisplayName + { + get => _displayName; + set + { + Check.NotNull(value, nameof(value)); + _displayName = value; + } + } + /// /// Indicates whether to check the other side of the object mapping /// if it explicitly defines the property. This property is used in; @@ -40,14 +54,16 @@ namespace Volo.Abp.ObjectExtending public Dictionary Configuration { get; } public ObjectExtensionPropertyInfo( - [NotNull] ObjectExtensionInfo objectExtension, - [NotNull] Type type, + [NotNull] ObjectExtensionInfo objectExtension, + [NotNull] Type type, [NotNull] string name) { ObjectExtension = Check.NotNull(objectExtension, nameof(objectExtension)); Type = Check.NotNull(type, nameof(type)); Name = Check.NotNull(name, nameof(name)); + DisplayName = new FixedLocalizableString(Name); + Configuration = new Dictionary(); ValidationAttributes = new List(); Validators = new List>(); From 8a318cb1ea1b54c933f0d6967b6b9d701cbc37b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Sat, 25 Apr 2020 23:38:16 +0300 Subject: [PATCH 08/67] Should check IsMappedToFieldForEfCore --- .../Volo/Abp/EntityFrameworkCore/AbpDbContext.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs index b1bb2df421..80482a886f 100644 --- a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs +++ b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs @@ -265,7 +265,11 @@ namespace Volo.Abp.EntityFrameworkCore return; } - foreach (var property in objectExtension.GetProperties()) + var efMappedProperties = ObjectExtensionManager.Instance + .GetProperties(entityType) + .Where(p => p.IsMappedToFieldForEfCore()); + + foreach (var property in efMappedProperties) { if (!entity.HasProperty(property.Name)) { From 55016d84462ef26c30f8a20f637699c0a014a4f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Sun, 26 Apr 2020 00:21:43 +0300 Subject: [PATCH 09/67] ExtensibleObject should set default values for defined properties. --- .../Volo/Abp/Reflection/TypeHelper.cs | 15 ++++++++ .../Volo/Abp/Domain/Entities/AggregateRoot.cs | 9 +++-- .../Abp/Data/HasExtraPropertiesExtensions.cs | 30 +++++++++++++++ .../Abp/ObjectExtending/ExtensibleObject.cs | 12 ++++++ .../ObjectExtending/ExtensibleObject_Tests.cs | 37 +++++++++++++++++++ .../TestObjects/ExtensibleTestPerson.cs | 9 +++++ 6 files changed, 109 insertions(+), 3 deletions(-) create mode 100644 framework/test/Volo.Abp.ObjectExtending.Tests/Volo/Abp/ObjectExtending/ExtensibleObject_Tests.cs diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/Reflection/TypeHelper.cs b/framework/src/Volo.Abp.Core/Volo/Abp/Reflection/TypeHelper.cs index 5f66f4788e..eeb0259321 100644 --- a/framework/src/Volo.Abp.Core/Volo/Abp/Reflection/TypeHelper.cs +++ b/framework/src/Volo.Abp.Core/Volo/Abp/Reflection/TypeHelper.cs @@ -131,5 +131,20 @@ namespace Volo.Abp.Reflection type == typeof(TimeSpan) || type == typeof(Guid); } + + public static object GetDefaultValue() + { + return GetDefaultValue(typeof(T)); + } + + public static object GetDefaultValue(Type type) + { + if (type.IsValueType) + { + return Activator.CreateInstance(type); + } + + return null; + } } } diff --git a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/AggregateRoot.cs b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/AggregateRoot.cs index be02f3d398..b0c20131ef 100644 --- a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/AggregateRoot.cs +++ b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/AggregateRoot.cs @@ -25,8 +25,9 @@ namespace Volo.Abp.Domain.Entities protected AggregateRoot() { - ExtraProperties = new Dictionary(); ConcurrencyStamp = Guid.NewGuid().ToString("N"); + ExtraProperties = new Dictionary(); + this.SetDefaultsForExtraProperties(); } protected virtual void AddLocalEvent(object eventData) @@ -85,15 +86,17 @@ namespace Volo.Abp.Domain.Entities protected AggregateRoot() { - ExtraProperties = new Dictionary(); ConcurrencyStamp = Guid.NewGuid().ToString("N"); + ExtraProperties = new Dictionary(); + this.SetDefaultsForExtraProperties(); } protected AggregateRoot(TKey id) : base(id) { - ExtraProperties = new Dictionary(); ConcurrencyStamp = Guid.NewGuid().ToString("N"); + ExtraProperties = new Dictionary(); + this.SetDefaultsForExtraProperties(); } protected virtual void AddLocalEvent(object eventData) diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/Data/HasExtraPropertiesExtensions.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/Data/HasExtraPropertiesExtensions.cs index 2b75e5fc8f..febf95bd22 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/Data/HasExtraPropertiesExtensions.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/Data/HasExtraPropertiesExtensions.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Globalization; +using Volo.Abp.ObjectExtending; using Volo.Abp.Reflection; namespace Volo.Abp.Data @@ -49,5 +50,34 @@ namespace Volo.Abp.Data source.ExtraProperties.Remove(name); return source; } + + public static TSource SetDefaultsForExtraProperties(this TSource source, Type objectType = null) + where TSource : IHasExtraProperties + { + var properties = ObjectExtensionManager.Instance + .GetProperties(objectType ?? typeof(TSource)); + + foreach (var property in properties) + { + if (source.HasProperty(property.Name)) + { + continue; + } + + source.ExtraProperties[property.Name] = TypeHelper.GetDefaultValue(property.Type); + } + + return source; + } + + public static void SetDefaultsForExtraProperties(object source, Type objectType) + { + if (!(source is IHasExtraProperties)) + { + throw new ArgumentException($"Given {nameof(source)} object does not implement the {nameof(IHasExtraProperties)} interface!", nameof(source)); + } + + ((IHasExtraProperties) source).SetDefaultsForExtraProperties(objectType); + } } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ExtensibleObject.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ExtensibleObject.cs index c9c601fce9..d83efac53f 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ExtensibleObject.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ExtensibleObject.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using Volo.Abp.Data; +using Volo.Abp.DynamicProxy; namespace Volo.Abp.ObjectExtending { @@ -11,8 +12,19 @@ namespace Volo.Abp.ObjectExtending public Dictionary ExtraProperties { get; protected set; } public ExtensibleObject() + : this(true) + { + + } + + public ExtensibleObject(bool setDefaultsForExtraProperties) { ExtraProperties = new Dictionary(); + + if (setDefaultsForExtraProperties) + { + this.SetDefaultsForExtraProperties(ProxyHelper.UnProxy(this).GetType()); + } } public virtual IEnumerable Validate(ValidationContext validationContext) diff --git a/framework/test/Volo.Abp.ObjectExtending.Tests/Volo/Abp/ObjectExtending/ExtensibleObject_Tests.cs b/framework/test/Volo.Abp.ObjectExtending.Tests/Volo/Abp/ObjectExtending/ExtensibleObject_Tests.cs new file mode 100644 index 0000000000..fdd7f600f6 --- /dev/null +++ b/framework/test/Volo.Abp.ObjectExtending.Tests/Volo/Abp/ObjectExtending/ExtensibleObject_Tests.cs @@ -0,0 +1,37 @@ +using Shouldly; +using Volo.Abp.Data; +using Volo.Abp.ObjectExtending.TestObjects; +using Xunit; + +namespace Volo.Abp.ObjectExtending +{ + public class ExtensibleObject_Tests : AbpObjectExtendingTestBase + { + [Fact] + public void Should_Set_Default_Values_For_Defined_Properties_On_Create() + { + var person = new ExtensibleTestPerson(); + + person.HasProperty("Name").ShouldBeTrue(); + person.HasProperty("Age").ShouldBeTrue(); + person.HasProperty("NoPairCheck").ShouldBeTrue(); + person.HasProperty("CityName").ShouldBeTrue(); + + person.GetProperty("Name").ShouldBeNull(); + person.GetProperty("Age").ShouldBe(0); + person.GetProperty("NoPairCheck").ShouldBeNull(); + person.GetProperty("CityName").ShouldBeNull(); + } + + [Fact] + public void Should_Not_Set_Default_Values_For_Defined_Properties_If_Requested() + { + var person = new ExtensibleTestPerson(false); + + person.HasProperty("Name").ShouldBeFalse(); + person.HasProperty("Age").ShouldBeFalse(); + person.HasProperty("NoPairCheck").ShouldBeFalse(); + person.HasProperty("CityName").ShouldBeFalse(); + } + } +} diff --git a/framework/test/Volo.Abp.ObjectExtending.Tests/Volo/Abp/ObjectExtending/TestObjects/ExtensibleTestPerson.cs b/framework/test/Volo.Abp.ObjectExtending.Tests/Volo/Abp/ObjectExtending/TestObjects/ExtensibleTestPerson.cs index bd24209212..25bce6e45a 100644 --- a/framework/test/Volo.Abp.ObjectExtending.Tests/Volo/Abp/ObjectExtending/TestObjects/ExtensibleTestPerson.cs +++ b/framework/test/Volo.Abp.ObjectExtending.Tests/Volo/Abp/ObjectExtending/TestObjects/ExtensibleTestPerson.cs @@ -2,6 +2,15 @@ { public class ExtensibleTestPerson : ExtensibleObject { + public ExtensibleTestPerson() + { + } + + public ExtensibleTestPerson(bool setDefaultsForExtraProperties) + : base(setDefaultsForExtraProperties) + { + + } } } From 41b6c7337a125a8112c0a2c7c423797e4af07dda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Sun, 26 Apr 2020 01:58:58 +0300 Subject: [PATCH 10/67] Update ObjectExtensionPropertyInfo.cs --- .../Volo/Abp/ObjectExtending/ObjectExtensionPropertyInfo.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionPropertyInfo.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionPropertyInfo.cs index f1d0392c76..8e8c0ecc03 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionPropertyInfo.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionPropertyInfo.cs @@ -8,8 +8,6 @@ namespace Volo.Abp.ObjectExtending { public class ObjectExtensionPropertyInfo { - [NotNull] private ILocalizableString _displayName; - [NotNull] public ObjectExtensionInfo ObjectExtension { get; } @@ -35,6 +33,7 @@ namespace Volo.Abp.ObjectExtending _displayName = value; } } + private ILocalizableString _displayName; /// /// Indicates whether to check the other side of the object mapping From 8a31febcb5897497ac8fe314ddd2a5053d0fc5f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Sun, 26 Apr 2020 02:29:38 +0300 Subject: [PATCH 11/67] Fix tests for the object extension manager. --- ...AutoMapperExtensibleDtoExtensions_Tests.cs | 4 +- .../AbpObjectExtendingTestModule.cs | 2 +- .../ExtensibleObjectValidator_Tests.cs | 68 ++++++------------- ...opertiesObjectExtendingExtensions_Tests.cs | 8 +-- 4 files changed, 26 insertions(+), 56 deletions(-) diff --git a/framework/test/Volo.Abp.AutoMapper.Tests/AutoMapper/AbpAutoMapperExtensibleDtoExtensions_Tests.cs b/framework/test/Volo.Abp.AutoMapper.Tests/AutoMapper/AbpAutoMapperExtensibleDtoExtensions_Tests.cs index d0ee7db52d..4ec19bb84e 100644 --- a/framework/test/Volo.Abp.AutoMapper.Tests/AutoMapper/AbpAutoMapperExtensibleDtoExtensions_Tests.cs +++ b/framework/test/Volo.Abp.AutoMapper.Tests/AutoMapper/AbpAutoMapperExtensibleDtoExtensions_Tests.cs @@ -34,10 +34,10 @@ namespace AutoMapper personDto.GetProperty("Name").ShouldBe("John"); //Defined in both classes personDto.GetProperty("ExistingDtoProperty").ShouldBe("existing-value"); //Should not clear existing values + personDto.GetProperty("ChildCount").ShouldBe(0); //Not defined in the source, but was set to the default value by ExtensibleTestPersonDto constructor + personDto.GetProperty("CityName").ShouldBeNull(); //Ignored, but was set to the default value by ExtensibleTestPersonDto constructor personDto.HasProperty("Age").ShouldBeFalse(); //Not defined on the destination - personDto.HasProperty("ChildCount").ShouldBeFalse(); //Not defined in the source personDto.HasProperty("Sex").ShouldBeFalse(); //Not defined in both classes - personDto.HasProperty("CityName").ShouldBeFalse(); //Ignored } } } diff --git a/framework/test/Volo.Abp.ObjectExtending.Tests/Volo/Abp/ObjectExtending/AbpObjectExtendingTestModule.cs b/framework/test/Volo.Abp.ObjectExtending.Tests/Volo/Abp/ObjectExtending/AbpObjectExtendingTestModule.cs index 3eff9846f7..ba7091befa 100644 --- a/framework/test/Volo.Abp.ObjectExtending.Tests/Volo/Abp/ObjectExtending/AbpObjectExtendingTestModule.cs +++ b/framework/test/Volo.Abp.ObjectExtending.Tests/Volo/Abp/ObjectExtending/AbpObjectExtendingTestModule.cs @@ -23,7 +23,7 @@ namespace Volo.Abp.ObjectExtending .AddOrUpdateProperty("CityName") .AddOrUpdateProperty("Name") .AddOrUpdateProperty("ChildCount") - .AddOrUpdateProperty("CityName"); + .AddOrUpdateProperty("CityName"); }); } } diff --git a/framework/test/Volo.Abp.ObjectExtending.Tests/Volo/Abp/ObjectExtending/ExtensibleObjectValidator_Tests.cs b/framework/test/Volo.Abp.ObjectExtending.Tests/Volo/Abp/ObjectExtending/ExtensibleObjectValidator_Tests.cs index 8c27844e22..83ecc3100f 100644 --- a/framework/test/Volo.Abp.ObjectExtending.Tests/Volo/Abp/ObjectExtending/ExtensibleObjectValidator_Tests.cs +++ b/framework/test/Volo.Abp.ObjectExtending.Tests/Volo/Abp/ObjectExtending/ExtensibleObjectValidator_Tests.cs @@ -55,7 +55,7 @@ namespace Volo.Abp.ObjectExtending context.ValidationErrors.Add( new ValidationResult( "If you specify a password, then please correctly repeat it!", - new[] {"Password", "PasswordRepeat"} + new[] { "Password", "PasswordRepeat" } ) ); } @@ -84,14 +84,9 @@ namespace Volo.Abp.ObjectExtending { ExtensibleObjectValidator .GetValidationErrors( - new ExtensiblePersonObject - { - ExtraProperties = - { - {"Name", "John"}, - {"Age", "42"}, - } - } + new ExtensiblePersonObject() + .SetProperty("Name", "John") + .SetProperty("Age", 42) ).Count.ShouldBe(0); //All Valid } @@ -105,62 +100,37 @@ namespace Volo.Abp.ObjectExtending ExtensibleObjectValidator .GetValidationErrors( - new ExtensiblePersonObject - { - ExtraProperties = - { - {"Address", new string('x', 256) } - } - } + new ExtensiblePersonObject() + .SetProperty("Address", new string('x', 256)) ).Count.ShouldBe(3); // Name, Age & Address ExtensibleObjectValidator .GetValidationErrors( - new ExtensiblePersonObject - { - ExtraProperties = - { - {"Age", "42" } - } - } + new ExtensiblePersonObject() + .SetProperty("Age", 42) ).Count.ShouldBe(1); // Name ExtensibleObjectValidator .GetValidationErrors( - new ExtensiblePersonObject - { - ExtraProperties = - { - {"Address", new string('x', 256) }, - {"Age", "100" } - } - } + new ExtensiblePersonObject() + .SetProperty("Address", new string('x', 256)) + .SetProperty("Age", 100) ).Count.ShouldBe(3); // Name, Age & Address ExtensibleObjectValidator .GetValidationErrors( - new ExtensiblePersonObject - { - ExtraProperties = - { - {"Name", "John"}, - {"Age", "42"}, - {"Password", "123"}, - {"PasswordRepeat", "1256"} - } - } + new ExtensiblePersonObject() + .SetProperty("Name", "John") + .SetProperty("Age", 42) + .SetProperty("Password", "123") + .SetProperty("PasswordRepeat", "1256") ).Count.ShouldBe(1); // PasswordRepeat != Password ExtensibleObjectValidator .GetValidationErrors( - new ExtensiblePersonObject - { - ExtraProperties = - { - {"Name", "BadValue"}, - {"Age", "42"}, - } - } + new ExtensiblePersonObject() + .SetProperty("Name", "BadValue") + .SetProperty("Age", 42) ).Count.ShouldBe(1); //Name is 'BadValue'! } diff --git a/framework/test/Volo.Abp.ObjectExtending.Tests/Volo/Abp/ObjectExtending/HasExtraPropertiesObjectExtendingExtensions_Tests.cs b/framework/test/Volo.Abp.ObjectExtending.Tests/Volo/Abp/ObjectExtending/HasExtraPropertiesObjectExtendingExtensions_Tests.cs index e871aeb056..5d019daf48 100644 --- a/framework/test/Volo.Abp.ObjectExtending.Tests/Volo/Abp/ObjectExtending/HasExtraPropertiesObjectExtendingExtensions_Tests.cs +++ b/framework/test/Volo.Abp.ObjectExtending.Tests/Volo/Abp/ObjectExtending/HasExtraPropertiesObjectExtendingExtensions_Tests.cs @@ -34,7 +34,7 @@ namespace Volo.Abp.ObjectExtending _personDto.GetProperty("NoPairCheck").ShouldBe("test-value"); //CheckPairDefinitionOnMapping = false _personDto.GetProperty("ExistingDtoProperty").ShouldBe("existing-value"); //Should not clear existing values _personDto.HasProperty("Age").ShouldBeFalse(); //Not defined on the destination - _personDto.HasProperty("ChildCount").ShouldBeFalse(); //Not defined in the source + _personDto.GetProperty("ChildCount").ShouldBe(0); //Not defined in the source, but was set to the default in the constructor _personDto.HasProperty("Sex").ShouldBeFalse(); //Not defined in both classes } @@ -46,9 +46,9 @@ namespace Volo.Abp.ObjectExtending _personDto.GetProperty("Name").ShouldBe("John"); //Defined in both classes _personDto.GetProperty("NoPairCheck").ShouldBe("test-value"); //CheckPairDefinitionOnMapping = false _personDto.GetProperty("ExistingDtoProperty").ShouldBe("existing-value"); //Should not clear existing values - _personDto.HasProperty("CityName").ShouldBeFalse(); //Ignored! + _personDto.GetProperty("CityName").ShouldBeNull(); //Ignored, but was set to the default in the constructor _personDto.HasProperty("Age").ShouldBeFalse(); //Not defined on the destination - _personDto.HasProperty("ChildCount").ShouldBeFalse(); //Not defined in the source + _personDto.GetProperty("ChildCount").ShouldBe(0); //Not defined in the source, but was set to the default in the constructor _personDto.HasProperty("Sex").ShouldBeFalse(); //Not defined in both classes } @@ -61,7 +61,7 @@ namespace Volo.Abp.ObjectExtending _personDto.GetProperty("CityName").ShouldBe("Adana"); //Defined in both classes _personDto.GetProperty("Age").ShouldBe(42); //Defined in source _personDto.GetProperty("ExistingDtoProperty").ShouldBe("existing-value"); //Should not clear existing values - _personDto.HasProperty("ChildCount").ShouldBeFalse(); //Not defined in the source + _personDto.GetProperty("ChildCount").ShouldBe(0); //Not defined in the source, but was set to the default in the constructor _personDto.HasProperty("Sex").ShouldBeFalse(); //Not defined in both classes } From 932410b2fb06cd95bae33c27831c5652317a120a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Mon, 27 Apr 2020 00:56:26 +0300 Subject: [PATCH 12/67] Implemented AbpValidationHtmlAttributeProvider --- .../AspNetCore/Mvc/AbpMvcOptionsExtensions.cs | 1 - .../AbpModelExpressionProvider.cs | 74 -------------- ...ExtraPropertyValidationMetadataProvider.cs | 53 ---------- .../AbpValidationHtmlAttributeProvider.cs | 98 +++++++++++++++++++ 4 files changed, 98 insertions(+), 128 deletions(-) delete mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ModelBinding/AbpModelExpressionProvider.cs delete mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ModelBinding/Metadata/AbpExtraPropertyValidationMetadataProvider.cs create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ViewFeatures/AbpValidationHtmlAttributeProvider.cs diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpMvcOptionsExtensions.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpMvcOptionsExtensions.cs index 55998a512f..4aa183a43d 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpMvcOptionsExtensions.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpMvcOptionsExtensions.cs @@ -57,7 +57,6 @@ namespace Volo.Abp.AspNetCore.Mvc options.ModelMetadataDetailsProviders.Add( new AbpDataAnnotationAutoLocalizationMetadataDetailsProvider(services) ); - options.ModelMetadataDetailsProviders.Add(new AbpExtraPropertyValidationMetadataProvider()); } } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ModelBinding/AbpModelExpressionProvider.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ModelBinding/AbpModelExpressionProvider.cs deleted file mode 100644 index a89127c158..0000000000 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ModelBinding/AbpModelExpressionProvider.cs +++ /dev/null @@ -1,74 +0,0 @@ -using System; -using System.Linq; -using System.Linq.Expressions; -using Microsoft.AspNetCore.Mvc.ViewFeatures; -using Volo.Abp.AspNetCore.Mvc.ModelBinding.Metadata; -using Volo.Abp.Data; -using Volo.Abp.DependencyInjection; - -namespace Volo.Abp.AspNetCore.Mvc.ModelBinding -{ - [Dependency(ReplaceServices = true)] - public class AbpModelExpressionProvider : IModelExpressionProvider, ITransientDependency - { - private readonly ModelExpressionProvider _modelExpressionProvider; - - public AbpModelExpressionProvider(ModelExpressionProvider modelExpressionProvider) - { - _modelExpressionProvider = modelExpressionProvider; - } - - public ModelExpression CreateModelExpression( - ViewDataDictionary viewData, - Expression> expression) - { - var result = _modelExpressionProvider.CreateModelExpression( - viewData, - expression - ); - - AbpExtraPropertyValidationMetadataProvider.CurrentModeInfo.Value = null; - - if (result.ModelExplorer.Container == null) - { - return result; - } - - var extraPropertyName = ExtraPropertyBindingHelper.ExtractExtraPropertyName(result.Name); - if (extraPropertyName == null) - { - return result; - } - - var containerName = ExtraPropertyBindingHelper.ExtractContainerName(result.Name); - if (containerName == null) - { - return result; - } - - var containerModelExpolorer = result - .ModelExplorer - .Container - .Properties - .FirstOrDefault(p => p.Metadata.Name == containerName); - - if (containerModelExpolorer == null) - { - return result; - } - - if (!containerModelExpolorer.ModelType.IsAssignableTo()) - { - return result; - } - - AbpExtraPropertyValidationMetadataProvider.CurrentModeInfo.Value - = new AbpExtraPropertyValidationMetadataProvider.ExtraPropertyModelInfo( - containerModelExpolorer.ModelType, - extraPropertyName - ); - - return result; - } - } -} \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ModelBinding/Metadata/AbpExtraPropertyValidationMetadataProvider.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ModelBinding/Metadata/AbpExtraPropertyValidationMetadataProvider.cs deleted file mode 100644 index 2d47882d13..0000000000 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ModelBinding/Metadata/AbpExtraPropertyValidationMetadataProvider.cs +++ /dev/null @@ -1,53 +0,0 @@ -using System; -using System.Threading; -using Microsoft.AspNetCore.Mvc.ModelBinding.Metadata; -using Volo.Abp.ObjectExtending; - -namespace Volo.Abp.AspNetCore.Mvc.ModelBinding.Metadata -{ - public class AbpExtraPropertyValidationMetadataProvider : IValidationMetadataProvider - { - public static AsyncLocal CurrentModeInfo { get; } = new AsyncLocal(); - - public void CreateValidationMetadata(ValidationMetadataProviderContext context) - { - if (CurrentModeInfo.Value == null) - { - return; - } - - var currentModel = CurrentModeInfo.Value; - - CurrentModeInfo.Value = null; - - var propertyInfo = ObjectExtensionManager.Instance.GetPropertyOrNull( - currentModel.ExtensibleObjectType, - currentModel.PropertyName - ); - - if (propertyInfo == null) - { - return; - } - - foreach (var validationAttribute in propertyInfo.ValidationAttributes) - { - context.ValidationMetadata.ValidatorMetadata.Add(validationAttribute); - } - } - - public class ExtraPropertyModelInfo - { - public Type ExtensibleObjectType { get; } - public string PropertyName { get; } - - public ExtraPropertyModelInfo( - Type extensibleObjectType, - string propertyName) - { - ExtensibleObjectType = extensibleObjectType; - PropertyName = propertyName; - } - } - } -} diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ViewFeatures/AbpValidationHtmlAttributeProvider.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ViewFeatures/AbpValidationHtmlAttributeProvider.cs new file mode 100644 index 0000000000..50ac9ddf02 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ViewFeatures/AbpValidationHtmlAttributeProvider.cs @@ -0,0 +1,98 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Reflection; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.DataAnnotations; +using Microsoft.AspNetCore.Mvc.ModelBinding; +using Microsoft.AspNetCore.Mvc.ModelBinding.Metadata; +using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; +using Microsoft.AspNetCore.Mvc.Rendering; +using Microsoft.AspNetCore.Mvc.ViewFeatures; +using Microsoft.Extensions.Localization; +using Microsoft.Extensions.Options; +using Volo.Abp.AspNetCore.Mvc.ModelBinding; +using Volo.Abp.DependencyInjection; +using Volo.Abp.ObjectExtending; +using Volo.Abp.Validation.Localization; + +namespace Volo.Abp.AspNetCore.Mvc.ViewFeatures +{ + [Dependency(ReplaceServices = true)] + [ExposeServices(typeof(ValidationHtmlAttributeProvider))] + public class AbpValidationHtmlAttributeProvider + : DefaultValidationHtmlAttributeProvider, ISingletonDependency + { + private readonly IModelMetadataProvider _metadataProvider; + private readonly IStringLocalizerFactory _stringLocalizerFactory; + private readonly IStringLocalizer _validationStringLocalizer; + private readonly IValidationAttributeAdapterProvider _validationAttributeAdapterProvider; + + public AbpValidationHtmlAttributeProvider( + IOptions optionsAccessor, + IModelMetadataProvider metadataProvider, + ClientValidatorCache clientValidatorCache, + IValidationAttributeAdapterProvider validationAttributeAdapterProvider, + IStringLocalizerFactory stringLocalizerFactory, + IStringLocalizer validationStringLocalizer) + : base( + optionsAccessor, + metadataProvider, + clientValidatorCache) + { + _metadataProvider = metadataProvider; + _validationAttributeAdapterProvider = validationAttributeAdapterProvider; + _stringLocalizerFactory = stringLocalizerFactory; + _validationStringLocalizer = validationStringLocalizer; + } + + public override void AddValidationAttributes( + ViewContext viewContext, + ModelExplorer modelExplorer, + IDictionary attributes) + { + base.AddValidationAttributes(viewContext, modelExplorer, attributes); + + var nameAttribute = attributes.GetOrDefault("name"); + var propertyName = ExtraPropertyBindingHelper.ExtractExtraPropertyName(nameAttribute); + if (propertyName == null) + { + return; + } + + //NOTE: containerName can be null on controller actions..? + + var containerName = ExtraPropertyBindingHelper.ExtractContainerName(nameAttribute); + if (containerName == null) + { + return; + } + + var extensibleObjectType = modelExplorer.Container.ModelType + .GetProperty(containerName, BindingFlags.Instance | BindingFlags.Public) + .PropertyType; + + var propertyInfo = ObjectExtensionManager.Instance.GetPropertyOrNull(extensibleObjectType, propertyName); + + modelExplorer.Metadata.As().DisplayMetadata.DisplayName = () => propertyInfo.DisplayName.Localize(_stringLocalizerFactory); + + foreach (var validationAttribute in propertyInfo.ValidationAttributes) + { + var validationContext = new ClientModelValidationContext( + viewContext, + modelExplorer.Metadata, + _metadataProvider, + attributes); + + validationAttribute.ErrorMessage = ValidationAttributeErrorMessageStringProperty.GetValue(validationAttribute) as string; + + _validationAttributeAdapterProvider.GetAttributeAdapter(validationAttribute, _validationStringLocalizer) + .AddValidation(validationContext); + } + } + + private static readonly PropertyInfo ValidationAttributeErrorMessageStringProperty = typeof(ValidationAttribute) + .GetProperty("ErrorMessageString", BindingFlags.Instance | BindingFlags.NonPublic); + + } +} From fbfd912a1492a695369c35753237a00827710067 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Mon, 27 Apr 2020 01:05:17 +0300 Subject: [PATCH 13/67] ExtraPropertyBindingHelper should supported containerless expressions. Added tests. --- .../ExtraPropertyBindingHelper.cs | 16 +++---- .../ExtraPropertyBindingHelper_Tests.cs | 48 +++++++++++++++++++ 2 files changed, 56 insertions(+), 8 deletions(-) create mode 100644 framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/ModelBinding/ExtraPropertyBindingHelper_Tests.cs diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ModelBinding/ExtraPropertyBindingHelper.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ModelBinding/ExtraPropertyBindingHelper.cs index cfc8754415..0bd4c43173 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ModelBinding/ExtraPropertyBindingHelper.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ModelBinding/ExtraPropertyBindingHelper.cs @@ -5,33 +5,33 @@ namespace Volo.Abp.AspNetCore.Mvc.ModelBinding public static class ExtraPropertyBindingHelper { /// - /// modelName is a string like "UserInfo.ExtraProperties[SocialSecurityNumber]" + /// is a string like "UserInfo.ExtraProperties[SocialSecurityNumber]" /// This method returns "SocialSecurityNumber" for this example. */ /// - public static string ExtractExtraPropertyName(string modelName) + public static string ExtractExtraPropertyName(string expression) { - var index = modelName.IndexOf(".ExtraProperties[", StringComparison.Ordinal); + var index = expression.IndexOf("ExtraProperties[", StringComparison.Ordinal); if (index < 0) { return null; } - return modelName.Substring(index + 17, modelName.Length - index - 18); + return expression.Substring(index + 16, expression.Length - index - 17); } /// - /// modelName is a string like "UserInfo.ExtraProperties[SocialSecurityNumber]" + /// is a string like "UserInfo.ExtraProperties[SocialSecurityNumber]" /// This method returns "UserInfo" for this example. /// - public static string ExtractContainerName(string modelName) + public static string ExtractContainerName(string expression) { - var index = modelName.IndexOf(".ExtraProperties[", StringComparison.Ordinal); + var index = expression.IndexOf("ExtraProperties[", StringComparison.Ordinal); if (index < 0) { return null; } - return modelName.Left(index); + return expression.Left(index).TrimEnd('.'); } } } diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/ModelBinding/ExtraPropertyBindingHelper_Tests.cs b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/ModelBinding/ExtraPropertyBindingHelper_Tests.cs new file mode 100644 index 0000000000..4f96fae3f5 --- /dev/null +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/ModelBinding/ExtraPropertyBindingHelper_Tests.cs @@ -0,0 +1,48 @@ +using Shouldly; +using Xunit; + +namespace Volo.Abp.AspNetCore.Mvc.ModelBinding +{ + public class ExtraPropertyBindingHelper_Tests + { + [Fact] + public void ExtractExtraPropertyName_Tests() + { + ExtraPropertyBindingHelper.ExtractExtraPropertyName( + "MyObject.UserInfo.ExtraProperties[SocialSecurityNumber]" + ).ShouldBe("SocialSecurityNumber"); + + ExtraPropertyBindingHelper.ExtractExtraPropertyName( + "UserInfo.ExtraProperties[SocialSecurityNumber]" + ).ShouldBe("SocialSecurityNumber"); + + ExtraPropertyBindingHelper.ExtractExtraPropertyName( + "ExtraProperties[SocialSecurityNumber]" + ).ShouldBe("SocialSecurityNumber"); + + ExtraPropertyBindingHelper.ExtractExtraPropertyName( + "SocialSecurityNumber" + ).ShouldBeNull(); + } + + [Fact] + public void ExtractContainerName_Tests() + { + ExtraPropertyBindingHelper.ExtractContainerName( + "MyObject.UserInfo.ExtraProperties[SocialSecurityNumber]" + ).ShouldBe("MyObject.UserInfo"); + + ExtraPropertyBindingHelper.ExtractContainerName( + "UserInfo.ExtraProperties[SocialSecurityNumber]" + ).ShouldBe("UserInfo"); + + ExtraPropertyBindingHelper.ExtractContainerName( + "ExtraProperties[SocialSecurityNumber]" + ).ShouldBe(""); + + ExtraPropertyBindingHelper.ExtractContainerName( + "SocialSecurityNumber" + ).ShouldBeNull(); + } + } +} From 53e295363eb3596921a42bb09593572df01a61d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Mon, 27 Apr 2020 01:20:06 +0300 Subject: [PATCH 14/67] Refactored AbpValidationHtmlAttributeProvider --- .../Metadata/AbpModelMetadataProvider.cs | 12 +-- .../Validation/ValidationAttributeHelper.cs | 20 +++++ .../AbpValidationHtmlAttributeProvider.cs | 88 +++++++++++++------ 3 files changed, 82 insertions(+), 38 deletions(-) create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Validation/ValidationAttributeHelper.cs diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ModelBinding/Metadata/AbpModelMetadataProvider.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ModelBinding/Metadata/AbpModelMetadataProvider.cs index b77354aab2..94a08a0507 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ModelBinding/Metadata/AbpModelMetadataProvider.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ModelBinding/Metadata/AbpModelMetadataProvider.cs @@ -1,11 +1,11 @@ using System.ComponentModel.DataAnnotations; using System.Linq; -using System.Reflection; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.ModelBinding; using Microsoft.AspNetCore.Mvc.ModelBinding.Metadata; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; +using Volo.Abp.AspNetCore.Mvc.Validation; using Volo.Abp.DependencyInjection; namespace Volo.Abp.AspNetCore.Mvc.ModelBinding.Metadata @@ -14,14 +14,6 @@ namespace Volo.Abp.AspNetCore.Mvc.ModelBinding.Metadata [ExposeServices(typeof(IModelMetadataProvider))] public class AbpModelMetadataProvider : DefaultModelMetadataProvider { - private static readonly PropertyInfo ValidationAttributeErrorMessageStringProperty; - - static AbpModelMetadataProvider() - { - ValidationAttributeErrorMessageStringProperty = typeof(ValidationAttribute) - .GetProperty("ErrorMessageString", BindingFlags.Instance | BindingFlags.NonPublic); - } - public AbpModelMetadataProvider(ICompositeMetadataDetailsProvider detailsProvider) : base(detailsProvider) { @@ -56,7 +48,7 @@ namespace Volo.Abp.AspNetCore.Mvc.ModelBinding.Metadata { if (validationAttribute.ErrorMessage == null) { - validationAttribute.ErrorMessage = ValidationAttributeErrorMessageStringProperty.GetValue(validationAttribute) as string; + ValidationAttributeHelper.SetDefaultErrorMessage(validationAttribute); } } } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Validation/ValidationAttributeHelper.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Validation/ValidationAttributeHelper.cs new file mode 100644 index 0000000000..955b83c48f --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Validation/ValidationAttributeHelper.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Reflection; +using System.Text; + +namespace Volo.Abp.AspNetCore.Mvc.Validation +{ + public static class ValidationAttributeHelper + { + private static readonly PropertyInfo ValidationAttributeErrorMessageStringProperty = typeof(ValidationAttribute) + .GetProperty("ErrorMessageString", BindingFlags.Instance | BindingFlags.NonPublic); + + public static void SetDefaultErrorMessage(ValidationAttribute validationAttribute) + { + validationAttribute.ErrorMessage = + ValidationAttributeErrorMessageStringProperty.GetValue(validationAttribute) as string; + } + } +} diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ViewFeatures/AbpValidationHtmlAttributeProvider.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ViewFeatures/AbpValidationHtmlAttributeProvider.cs index 50ac9ddf02..0f7237ed31 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ViewFeatures/AbpValidationHtmlAttributeProvider.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ViewFeatures/AbpValidationHtmlAttributeProvider.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; +using System.Collections.Generic; using System.Reflection; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.DataAnnotations; @@ -12,6 +10,7 @@ using Microsoft.AspNetCore.Mvc.ViewFeatures; using Microsoft.Extensions.Localization; using Microsoft.Extensions.Options; using Volo.Abp.AspNetCore.Mvc.ModelBinding; +using Volo.Abp.AspNetCore.Mvc.Validation; using Volo.Abp.DependencyInjection; using Volo.Abp.ObjectExtending; using Volo.Abp.Validation.Localization; @@ -20,7 +19,7 @@ namespace Volo.Abp.AspNetCore.Mvc.ViewFeatures { [Dependency(ReplaceServices = true)] [ExposeServices(typeof(ValidationHtmlAttributeProvider))] - public class AbpValidationHtmlAttributeProvider + public class AbpValidationHtmlAttributeProvider : DefaultValidationHtmlAttributeProvider, ISingletonDependency { private readonly IModelMetadataProvider _metadataProvider; @@ -29,15 +28,15 @@ namespace Volo.Abp.AspNetCore.Mvc.ViewFeatures private readonly IValidationAttributeAdapterProvider _validationAttributeAdapterProvider; public AbpValidationHtmlAttributeProvider( - IOptions optionsAccessor, - IModelMetadataProvider metadataProvider, + IOptions optionsAccessor, + IModelMetadataProvider metadataProvider, ClientValidatorCache clientValidatorCache, - IValidationAttributeAdapterProvider validationAttributeAdapterProvider, - IStringLocalizerFactory stringLocalizerFactory, - IStringLocalizer validationStringLocalizer) + IValidationAttributeAdapterProvider validationAttributeAdapterProvider, + IStringLocalizerFactory stringLocalizerFactory, + IStringLocalizer validationStringLocalizer) : base( - optionsAccessor, - metadataProvider, + optionsAccessor, + metadataProvider, clientValidatorCache) { _metadataProvider = metadataProvider; @@ -47,52 +46,85 @@ namespace Volo.Abp.AspNetCore.Mvc.ViewFeatures } public override void AddValidationAttributes( - ViewContext viewContext, - ModelExplorer modelExplorer, + ViewContext viewContext, + ModelExplorer modelExplorer, IDictionary attributes) { base.AddValidationAttributes(viewContext, modelExplorer, attributes); + AddExtraPropertyValidationsAttributes(viewContext, modelExplorer, attributes); + } + protected virtual void AddExtraPropertyValidationsAttributes(ViewContext viewContext, ModelExplorer modelExplorer, IDictionary attributes) + { var nameAttribute = attributes.GetOrDefault("name"); - var propertyName = ExtraPropertyBindingHelper.ExtractExtraPropertyName(nameAttribute); - if (propertyName == null) + if (nameAttribute == null) { return; } - //NOTE: containerName can be null on controller actions..? + var extraPropertyName = ExtraPropertyBindingHelper.ExtractExtraPropertyName(nameAttribute); + if (extraPropertyName == null) + { + return; + } + //TODO: containerName can be null on controller actions..? var containerName = ExtraPropertyBindingHelper.ExtractContainerName(nameAttribute); if (containerName == null) { return; } + if (modelExplorer.Container?.ModelType == null) + { + return; + } + var extensibleObjectType = modelExplorer.Container.ModelType .GetProperty(containerName, BindingFlags.Instance | BindingFlags.Public) - .PropertyType; + ?.PropertyType; + if (extensibleObjectType == null) + { + return; + } + + var extensionPropertyInfo = ObjectExtensionManager.Instance.GetPropertyOrNull( + extensibleObjectType, + extraPropertyName + ); - var propertyInfo = ObjectExtensionManager.Instance.GetPropertyOrNull(extensibleObjectType, propertyName); + if (extensionPropertyInfo == null) + { + return; + } - modelExplorer.Metadata.As().DisplayMetadata.DisplayName = () => propertyInfo.DisplayName.Localize(_stringLocalizerFactory); + if (modelExplorer.Metadata is DefaultModelMetadata metadata) + { + metadata.DisplayMetadata.DisplayName = + () => extensionPropertyInfo.DisplayName.Localize(_stringLocalizerFactory); + } - foreach (var validationAttribute in propertyInfo.ValidationAttributes) + foreach (var validationAttribute in extensionPropertyInfo.ValidationAttributes) { var validationContext = new ClientModelValidationContext( viewContext, modelExplorer.Metadata, _metadataProvider, - attributes); + attributes + ); + + if (validationAttribute.ErrorMessage == null) + { + ValidationAttributeHelper.SetDefaultErrorMessage(validationAttribute); + } - validationAttribute.ErrorMessage = ValidationAttributeErrorMessageStringProperty.GetValue(validationAttribute) as string; + var validationAttributeAdapter = _validationAttributeAdapterProvider.GetAttributeAdapter( + validationAttribute, + _validationStringLocalizer + ); - _validationAttributeAdapterProvider.GetAttributeAdapter(validationAttribute, _validationStringLocalizer) - .AddValidation(validationContext); + validationAttributeAdapter.AddValidation(validationContext); } } - - private static readonly PropertyInfo ValidationAttributeErrorMessageStringProperty = typeof(ValidationAttribute) - .GetProperty("ErrorMessageString", BindingFlags.Instance | BindingFlags.NonPublic); - } } From 055ba8312d88980f50617f6c14741c9e253ed870 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Tue, 28 Apr 2020 01:54:58 +0300 Subject: [PATCH 15/67] Added ObjectExtensionPropertyInfo.Attributes and marked ValidationAttributes as obsolete --- .../AbpValidationHtmlAttributeProvider.cs | 6 +- .../ObjectExtendingPropertyInfoExtensions.cs | 91 +++++++++++++++++++ .../ExtensibleObjectValidator.cs | 6 +- .../ObjectExtensionPropertyInfo.cs | 5 + .../ObjectExtensionPropertyInfoExtensions.cs | 17 ++++ .../ExtensibleObjectValidator_Tests.cs | 10 +- 6 files changed, 126 insertions(+), 9 deletions(-) create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/ObjectExtending/ObjectExtendingPropertyInfoExtensions.cs create mode 100644 framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionPropertyInfoExtensions.cs diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ViewFeatures/AbpValidationHtmlAttributeProvider.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ViewFeatures/AbpValidationHtmlAttributeProvider.cs index 0f7237ed31..f0c4c628b8 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ViewFeatures/AbpValidationHtmlAttributeProvider.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ViewFeatures/AbpValidationHtmlAttributeProvider.cs @@ -1,4 +1,6 @@ using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; using System.Reflection; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.DataAnnotations; @@ -104,7 +106,7 @@ namespace Volo.Abp.AspNetCore.Mvc.ViewFeatures () => extensionPropertyInfo.DisplayName.Localize(_stringLocalizerFactory); } - foreach (var validationAttribute in extensionPropertyInfo.ValidationAttributes) + foreach (var validationAttribute in extensionPropertyInfo.GetValidationAttributes()) { var validationContext = new ClientModelValidationContext( viewContext, @@ -123,7 +125,7 @@ namespace Volo.Abp.AspNetCore.Mvc.ViewFeatures _validationStringLocalizer ); - validationAttributeAdapter.AddValidation(validationContext); + validationAttributeAdapter?.AddValidation(validationContext); } } } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/ObjectExtending/ObjectExtendingPropertyInfoExtensions.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/ObjectExtending/ObjectExtendingPropertyInfoExtensions.cs new file mode 100644 index 0000000000..e22f83d8ce --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/ObjectExtending/ObjectExtendingPropertyInfoExtensions.cs @@ -0,0 +1,91 @@ +using System; +using System.ComponentModel.DataAnnotations; +using Microsoft.AspNetCore.Mvc; + +namespace Volo.Abp.ObjectExtending +{ + public static class ObjectExtensionPropertyInfoAspNetCoreMvcExtensions + { + public static string GetInputType(this ObjectExtensionPropertyInfo propertyInfo) + { + foreach (var attribute in propertyInfo.Attributes) + { + var inputTypeByAttribute = GetInputTypeFromAttributeOrNull(attribute); + if (inputTypeByAttribute != null) + { + return inputTypeByAttribute; + } + } + + return GetInputTypeFromTypeOrNull(propertyInfo.Type) + ?? "text"; //default + } + + private static string GetInputTypeFromAttributeOrNull(Attribute attribute) + { + if (attribute is EmailAddressAttribute) + { + return "email"; + } + + if (attribute is UrlAttribute) + { + return "url"; + } + + if (attribute is HiddenInputAttribute) + { + return "hidden"; + } + + if (attribute is PhoneAttribute) + { + return "tel"; + } + + if (attribute is DataTypeAttribute dataTypeAttribute) + { + switch (dataTypeAttribute.DataType) + { + case DataType.Password: + return "password"; + case DataType.Date: + return "date"; + case DataType.Time: + return "time"; + //TODO: Others..? + } + } + + return null; + } + + private static string GetInputTypeFromTypeOrNull(Type type) + { + if (type == typeof(bool)) + { + return "checkbox"; + } + + if (type == typeof(DateTime)) + { + return "datetime-local"; + } + + if (type == typeof(int) || + type == typeof(long) || + type == typeof(byte) || + type == typeof(sbyte) || + type == typeof(short) || + type == typeof(ushort) || + type == typeof(uint) || + type == typeof(long) || + type == typeof(ulong)) + { + return "number"; + } + + return null; + } + } +} diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ExtensibleObjectValidator.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ExtensibleObjectValidator.cs index 07d6556d10..5832b98cd3 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ExtensibleObjectValidator.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ExtensibleObjectValidator.cs @@ -123,7 +123,9 @@ namespace Volo.Abp.ObjectExtending ValidationContext objectValidationContext, ObjectExtensionPropertyInfo property) { - if (!property.ValidationAttributes.Any()) + var validationAttributes = property.GetValidationAttributes(); + + if (!validationAttributes.Any()) { return; } @@ -134,7 +136,7 @@ namespace Volo.Abp.ObjectExtending MemberName = property.Name }; - foreach (var attribute in property.ValidationAttributes) + foreach (var attribute in validationAttributes) { var result = attribute.GetValidationResult( extensibleObject.GetProperty(property.Name), diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionPropertyInfo.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionPropertyInfo.cs index 8e8c0ecc03..c0792fbe51 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionPropertyInfo.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionPropertyInfo.cs @@ -18,8 +18,12 @@ namespace Volo.Abp.ObjectExtending public Type Type { get; } [NotNull] + [Obsolete("Add validation attributes to the Attributes list instead! ValidationAttributes property will be removed in future versions.")] public List ValidationAttributes { get; } + [NotNull] + public List Attributes { get; } + [NotNull] public List> Validators { get; } @@ -65,6 +69,7 @@ namespace Volo.Abp.ObjectExtending Configuration = new Dictionary(); ValidationAttributes = new List(); + Attributes = new List(); Validators = new List>(); } } diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionPropertyInfoExtensions.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionPropertyInfoExtensions.cs new file mode 100644 index 0000000000..4eac846314 --- /dev/null +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionPropertyInfoExtensions.cs @@ -0,0 +1,17 @@ +using System.ComponentModel.DataAnnotations; +using System.Linq; + +namespace Volo.Abp.ObjectExtending +{ + public static class ObjectExtensionPropertyInfoExtensions + { + public static ValidationAttribute[] GetValidationAttributes(this ObjectExtensionPropertyInfo propertyInfo) + { + return propertyInfo + .Attributes + .OfType() + .Union(propertyInfo.ValidationAttributes) + .ToArray(); + } + } +} diff --git a/framework/test/Volo.Abp.ObjectExtending.Tests/Volo/Abp/ObjectExtending/ExtensibleObjectValidator_Tests.cs b/framework/test/Volo.Abp.ObjectExtending.Tests/Volo/Abp/ObjectExtending/ExtensibleObjectValidator_Tests.cs index 83ecc3100f..d08e3766df 100644 --- a/framework/test/Volo.Abp.ObjectExtending.Tests/Volo/Abp/ObjectExtending/ExtensibleObjectValidator_Tests.cs +++ b/framework/test/Volo.Abp.ObjectExtending.Tests/Volo/Abp/ObjectExtending/ExtensibleObjectValidator_Tests.cs @@ -19,19 +19,19 @@ namespace Volo.Abp.ObjectExtending { options.AddOrUpdateProperty("Name", propertyInfo => { - propertyInfo.ValidationAttributes.Add(new RequiredAttribute()); - propertyInfo.ValidationAttributes.Add(new StringLengthAttribute(64) { MinimumLength = 2 }); + propertyInfo.Attributes.Add(new RequiredAttribute()); + propertyInfo.Attributes.Add(new StringLengthAttribute(64) { MinimumLength = 2 }); }); options.AddOrUpdateProperty("Address", propertyInfo => { - propertyInfo.ValidationAttributes.Add(new StringLengthAttribute(255)); + propertyInfo.Attributes.Add(new StringLengthAttribute(255)); }); options.AddOrUpdateProperty("Age", propertyInfo => { - propertyInfo.ValidationAttributes.Add(new RequiredAttribute()); - propertyInfo.ValidationAttributes.Add(new RangeAttribute(18, 99)); + propertyInfo.Attributes.Add(new RequiredAttribute()); + propertyInfo.Attributes.Add(new RangeAttribute(18, 99)); }); options.AddOrUpdateProperty("IsMarried", propertyInfo => From da69be59776adffab1458b28e7d1b9e1e6270799 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Tue, 28 Apr 2020 03:00:53 +0300 Subject: [PATCH 16/67] Add InputTypeName to the AbpInputTagHelper --- .../TagHelpers/Form/AbpInputTagHelper.cs | 3 +++ .../TagHelpers/Form/AbpInputTagHelperService.cs | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpInputTagHelper.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpInputTagHelper.cs index 10ce263032..f264d21cd5 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpInputTagHelper.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpInputTagHelper.cs @@ -21,6 +21,9 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form public bool AutoFocus { get; set; } + [HtmlAttributeName("type")] + public string InputTypeName { get; set; } + public AbpFormControlSize Size { get; set; } = AbpFormControlSize.Default; [HtmlAttributeName("required-symbol")] diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpInputTagHelperService.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpInputTagHelperService.cs index 75fe4f23e7..affef51b04 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpInputTagHelperService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpInputTagHelperService.cs @@ -117,6 +117,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form return new InputTagHelper(_generator) { For = TagHelper.AspFor, + InputTypeName = TagHelper.InputTypeName, ViewContext = TagHelper.ViewContext }; } @@ -331,6 +332,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form var groupPrefix = "group-"; var tagHelperAttributes = output.Attributes.Where(a => !a.Name.StartsWith(groupPrefix)).ToList(); + var attrList = new TagHelperAttributeList(); foreach (var tagHelperAttribute in tagHelperAttributes) @@ -338,6 +340,11 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form attrList.Add(tagHelperAttribute); } + if (!TagHelper.InputTypeName.IsNullOrEmpty() && !attrList.ContainsName("type")) + { + attrList.Add("type", TagHelper.InputTypeName); + } + return attrList; } From cf8b58aa86b4e77077c737061531f25e8ed115bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Tue, 28 Apr 2020 03:03:34 +0300 Subject: [PATCH 17/67] Update document for ValidationAttributes --- docs/en/Object-Extensions.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/en/Object-Extensions.md b/docs/en/Object-Extensions.md index 6eff328c85..bee229dc27 100644 --- a/docs/en/Object-Extensions.md +++ b/docs/en/Object-Extensions.md @@ -197,8 +197,8 @@ ObjectExtensionManager.Instance "SocialSecurityNumber", options => { - options.ValidationAttributes.Add(new RequiredAttribute()); - options.ValidationAttributes.Add( + options.Attributes.Add(new RequiredAttribute()); + options.Attributes.Add( new StringLengthAttribute(32) { MinimumLength = 6 } @@ -248,12 +248,12 @@ ObjectExtensionManager.Instance objConfig.AddOrUpdateProperty("Password", propertyConfig => { - propertyConfig.ValidationAttributes.Add(new RequiredAttribute()); + propertyConfig.Attributes.Add(new RequiredAttribute()); }); objConfig.AddOrUpdateProperty("PasswordRepeat", propertyConfig => { - propertyConfig.ValidationAttributes.Add(new RequiredAttribute()); + propertyConfig.Attributes.Add(new RequiredAttribute()); }); //Write a common validation logic works on multiple properties From 9a8a97f0eaebe0edeffc1cba3d7a69049f4be6e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Tue, 28 Apr 2020 03:13:17 +0300 Subject: [PATCH 18/67] Update ObjectExtendingPropertyInfoExtensions.cs --- .../ObjectExtendingPropertyInfoExtensions.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/ObjectExtending/ObjectExtendingPropertyInfoExtensions.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/ObjectExtending/ObjectExtendingPropertyInfoExtensions.cs index e22f83d8ce..9bb6c903a9 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/ObjectExtending/ObjectExtendingPropertyInfoExtensions.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/ObjectExtending/ObjectExtendingPropertyInfoExtensions.cs @@ -53,7 +53,14 @@ namespace Volo.Abp.ObjectExtending return "date"; case DataType.Time: return "time"; - //TODO: Others..? + case DataType.EmailAddress: + return "email"; + case DataType.Url: + return "url"; + case DataType.PhoneNumber: + return "tel"; + case DataType.DateTime: + return "datetime-local"; } } From 9e498004bccae389ee3d3599857578baf06eaed8 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Tue, 28 Apr 2020 17:05:06 +0300 Subject: [PATCH 19/67] blog: Code blocks highlighed resolves https://github.com/abpframework/abp/issues/3309 --- .../Volo.Blogging.Web/BloggingWebModule.cs | 13 ++++++++ ...criptBundleContributorBloggingExtension.cs | 20 +++++++++++ ...StyleBundleContributorBloggingExtension.cs | 17 ++++++++++ .../Pages/Blogs/BloggingPage.cs | 33 ++++++++++++------- .../Pages/Blogs/Posts/Detail.cshtml | 7 ++-- .../Volo.Blogging.Web.csproj | 4 +-- npm/packs/blogging/package.json | 3 +- 7 files changed, 81 insertions(+), 16 deletions(-) create mode 100644 modules/blogging/src/Volo.Blogging.Web/Bundling/PrismjsScriptBundleContributorBloggingExtension.cs create mode 100644 modules/blogging/src/Volo.Blogging.Web/Bundling/PrismjsStyleBundleContributorBloggingExtension.cs diff --git a/modules/blogging/src/Volo.Blogging.Web/BloggingWebModule.cs b/modules/blogging/src/Volo.Blogging.Web/BloggingWebModule.cs index 00fa553902..432857686f 100644 --- a/modules/blogging/src/Volo.Blogging.Web/BloggingWebModule.cs +++ b/modules/blogging/src/Volo.Blogging.Web/BloggingWebModule.cs @@ -4,10 +4,12 @@ using Microsoft.Extensions.Options; using Volo.Abp.AspNetCore.Mvc.Localization; using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap; using Volo.Abp.AspNetCore.Mvc.UI.Bundling; +using Volo.Abp.AspNetCore.Mvc.UI.Packages.Prismjs; using Volo.Abp.AutoMapper; using Volo.Abp.Modularity; using Volo.Abp.UI.Navigation; using Volo.Abp.VirtualFileSystem; +using Volo.Blogging.Bundling; using Volo.Blogging.Localization; namespace Volo.Blogging @@ -51,6 +53,17 @@ namespace Volo.Blogging options.AddProfile(validate: true); }); + Configure(options => + { + options + .Extensions() + .Add(); + + options + .Extensions() + .Add(); + }); + Configure(options => { var urlOptions = context.Services diff --git a/modules/blogging/src/Volo.Blogging.Web/Bundling/PrismjsScriptBundleContributorBloggingExtension.cs b/modules/blogging/src/Volo.Blogging.Web/Bundling/PrismjsScriptBundleContributorBloggingExtension.cs new file mode 100644 index 0000000000..f3b2589598 --- /dev/null +++ b/modules/blogging/src/Volo.Blogging.Web/Bundling/PrismjsScriptBundleContributorBloggingExtension.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Volo.Abp.AspNetCore.Mvc.UI.Bundling; + +namespace Volo.Blogging.Bundling +{ + public class PrismjsScriptBundleContributorBloggingExtension : BundleContributor + { + public override void ConfigureBundle(BundleConfigurationContext context) + { + context.Files.AddIfNotContains("/libs/prismjs/plugins/toolbar/prism-toolbar.js"); + context.Files.AddIfNotContains("/libs/prismjs/plugins/show-language/prism-show-language.js"); + context.Files.AddIfNotContains("/libs/prismjs/plugins/copy-to-clipboard/prism-copy-to-clipboard.js"); + context.Files.AddIfNotContains("/libs/prismjs/plugins/line-highlight/prism-line-highlight.js"); + context.Files.AddIfNotContains("/libs/prismjs/components/prism-csharp.js"); + } + } +} diff --git a/modules/blogging/src/Volo.Blogging.Web/Bundling/PrismjsStyleBundleContributorBloggingExtension.cs b/modules/blogging/src/Volo.Blogging.Web/Bundling/PrismjsStyleBundleContributorBloggingExtension.cs new file mode 100644 index 0000000000..8bd3b1fafa --- /dev/null +++ b/modules/blogging/src/Volo.Blogging.Web/Bundling/PrismjsStyleBundleContributorBloggingExtension.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Volo.Abp.AspNetCore.Mvc.UI.Bundling; + +namespace Volo.Blogging.Bundling +{ + public class PrismjsStyleBundleContributorBloggingExtension : BundleContributor + { + public override void ConfigureBundle(BundleConfigurationContext context) + { + context.Files.AddIfNotContains("/libs/prismjs/plugins/line-highlight/prism-line-highlight.css"); + context.Files.AddIfNotContains("/libs/prismjs/plugins/toolbar/prism-toolbar.css"); + } + } +} diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/BloggingPage.cs b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/BloggingPage.cs index 1b525a95b3..d45a334de7 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/BloggingPage.cs +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/BloggingPage.cs @@ -2,12 +2,12 @@ using System.Linq; using System.Text; using System.Text.RegularExpressions; -using CommonMark; using Microsoft.AspNetCore.Html; using Microsoft.AspNetCore.Mvc.Localization; using Microsoft.AspNetCore.Mvc.Razor.Internal; using Volo.Abp.AspNetCore.Mvc.UI.RazorPages; using Volo.Blogging.Localization; +using Markdig; namespace Volo.Blogging.Pages.Blog { @@ -32,7 +32,7 @@ namespace Volo.Blogging.Pages.Blog public string GetShortContent(string content) { - var html = RenderMarkdownToString(content); + var html = RenderMarkdownToHtmlAsString(content); var plainText = Regex.Replace(html, "<[^>]*>", ""); if (string.IsNullOrWhiteSpace(plainText)) @@ -65,26 +65,37 @@ namespace Volo.Blogging.Pages.Blog { return new HtmlString(""); } - - byte[] bytes = Encoding.Default.GetBytes(content); - var utf8Content = Encoding.UTF8.GetString(bytes); - var html = CommonMarkConverter.Convert(utf8Content); + var html = RenderMarkdownToHtmlAsString(content); + + html = ReplaceCodeBlocksLanguage( + html, + "language-C#", + "language-csharp" + ); return new HtmlString(html); } - public string RenderMarkdownToString(string content) + protected string ReplaceCodeBlocksLanguage(string content, string currentLanguage, string newLanguage) + { + return Regex.Replace(content, "", "", RegexOptions.IgnoreCase); + } + + public string RenderMarkdownToHtmlAsString(string content) { if (content.IsNullOrWhiteSpace()) { return ""; } - byte[] bytes = Encoding.Default.GetBytes(content); - var utf8Content = Encoding.UTF8.GetString(bytes); - - return CommonMarkConverter.Convert(utf8Content); + return Markdig.Markdown.ToHtml(Encoding.UTF8.GetString(Encoding.Default.GetBytes(content)), + new MarkdownPipelineBuilder() + .UseAutoLinks() + .UseBootstrap() + .UseGridTables() + .UsePipeTables() + .Build()); } public LocalizedHtmlString ConvertDatetimeToTimeAgo(DateTime dt) diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Detail.cshtml b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Detail.cshtml index 7bed3d0d68..a6c08950ff 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Detail.cshtml +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Detail.cshtml @@ -6,6 +6,7 @@ @using Volo.Blogging @using Volo.Blogging.Pages.Blog.Posts @using Volo.Blogging.Areas.Blog.Helpers.TagHelpers +@using Volo.Abp.AspNetCore.Mvc.UI.Packages.Prismjs @inject IAuthorizationService Authorization @model DetailModel @{ @@ -15,11 +16,13 @@ } @section scripts { + } @section styles { + } @@ -85,7 +88,7 @@ - +
@@ -95,7 +98,7 @@
- +

diff --git a/modules/blogging/src/Volo.Blogging.Web/Volo.Blogging.Web.csproj b/modules/blogging/src/Volo.Blogging.Web/Volo.Blogging.Web.csproj index 7313becddb..19d156f10b 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Volo.Blogging.Web.csproj +++ b/modules/blogging/src/Volo.Blogging.Web/Volo.Blogging.Web.csproj @@ -1,4 +1,4 @@ - + @@ -19,7 +19,7 @@ - + diff --git a/npm/packs/blogging/package.json b/npm/packs/blogging/package.json index dbb0c09673..735dfdc5d5 100644 --- a/npm/packs/blogging/package.json +++ b/npm/packs/blogging/package.json @@ -7,7 +7,8 @@ "dependencies": { "@abp/aspnetcore.mvc.ui.theme.shared": "^2.6.2", "@abp/owl.carousel": "^2.6.2", - "@abp/tui-editor": "^2.6.2" + "@abp/tui-editor": "^2.6.2", + "@abp/prismjs": "^2.6.2" }, "gitHead": "eb4a0e507f492e275865b72caeb02ce28d69ae56" } From 9c2297074ff882a1dbe88f6fbb9960ab52a89883 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Tue, 28 Apr 2020 21:58:52 +0300 Subject: [PATCH 20/67] Add Configuration to ObjectExtensionManager --- .../Volo/Abp/ObjectExtending/ObjectExtensionManager.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionManager.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionManager.cs index 9f97b45261..26b692c232 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionManager.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionManager.cs @@ -10,11 +10,15 @@ namespace Volo.Abp.ObjectExtending { public static ObjectExtensionManager Instance { get; set; } = new ObjectExtensionManager(); - protected Dictionary ObjectsExtensions { get; } + [NotNull] + public Dictionary Configuration { get; } + protected Dictionary ObjectsExtensions { get; } + protected internal ObjectExtensionManager() { ObjectsExtensions = new Dictionary(); + Configuration = new Dictionary(); } [NotNull] From 676b677b1ffc186732c441ff6250c91d7198ba15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Tue, 28 Apr 2020 23:50:30 +0300 Subject: [PATCH 21/67] Added module object extension configurations. --- ...oduleEntityObjectExtensionConfiguration.cs | 59 +++++++++++++++++++ ...ityObjectPropertyExtensionConfiguration.cs | 56 ++++++++++++++++++ .../ModuleObjectExtensionConfiguration.cs | 9 +++ ...eObjectExtensionConfigurationDictionary.cs | 9 +++ ...ensionConfigurationDictionaryExtensions.cs | 28 +++++++++ ...eObjectExtensionConfigurationExtensions.cs | 24 ++++++++ .../ObjectExtending/ObjectExtensionManager.cs | 3 + ...ntityModuleObjectExtensionConfiguration.cs | 7 +++ ...eObjectExtensionConfigurationExtensions.cs | 17 ++++++ ...ObjectExtensionConfigurationsExtensions.cs | 17 ++++++ 10 files changed, 229 insertions(+) create mode 100644 framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectExtensionConfiguration.cs create mode 100644 framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionConfiguration.cs create mode 100644 framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfiguration.cs create mode 100644 framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfigurationDictionary.cs create mode 100644 framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfigurationDictionaryExtensions.cs create mode 100644 framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfigurationExtensions.cs create mode 100644 modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleObjectExtensionConfiguration.cs create mode 100644 modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleObjectExtensionConfigurationExtensions.cs create mode 100644 modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleObjectExtensionConfigurationsExtensions.cs diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectExtensionConfiguration.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectExtensionConfiguration.cs new file mode 100644 index 0000000000..c6d71149e4 --- /dev/null +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectExtensionConfiguration.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using JetBrains.Annotations; + +namespace Volo.Abp.ObjectExtending +{ + public class ModuleEntityObjectExtensionConfiguration + { + [NotNull] + protected Dictionary Properties { get; } + + [NotNull] + public List> Validators { get; } + + public ModuleEntityObjectExtensionConfiguration() + { + Properties = new Dictionary(); + Validators = new List>(); + } + + [NotNull] + public virtual ModuleEntityObjectExtensionConfiguration AddOrUpdateProperty( + [NotNull] string propertyName, + [CanBeNull] Action configureAction = null) + { + return AddOrUpdateProperty( + typeof(TProperty), + propertyName, + configureAction + ); + } + + [NotNull] + public virtual ModuleEntityObjectExtensionConfiguration AddOrUpdateProperty( + [NotNull] Type propertyType, + [NotNull] string propertyName, + [CanBeNull] Action configureAction = null) + { + Check.NotNull(propertyType, nameof(propertyType)); + Check.NotNull(propertyName, nameof(propertyName)); + + var propertyInfo = Properties.GetOrAdd( + propertyName, + () => new ModuleEntityObjectPropertyExtensionConfiguration(this, propertyType, propertyName) + ); + + configureAction?.Invoke(propertyInfo); + + return this; + } + + [NotNull] + public virtual ImmutableList GetProperties() + { + return Properties.Values.ToImmutableList(); + } + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionConfiguration.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionConfiguration.cs new file mode 100644 index 0000000000..705166e2cc --- /dev/null +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionConfiguration.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using JetBrains.Annotations; +using Volo.Abp.Localization; + +namespace Volo.Abp.ObjectExtending +{ + public class ModuleEntityObjectPropertyExtensionConfiguration + { + [NotNull] + public ModuleEntityObjectExtensionConfiguration EntityObjectExtensionConfiguration { get; } + + [NotNull] + public string Name { get; } + + [NotNull] + public Type Type { get; } + + [NotNull] + public List Attributes { get; } + + [NotNull] + public List> Validators { get; } + + [NotNull] + public ILocalizableString DisplayName + { + get => _displayName; + set + { + Check.NotNull(value, nameof(value)); + _displayName = value; + } + } + private ILocalizableString _displayName; + + [NotNull] + public Dictionary Configuration { get; } + + public ModuleEntityObjectPropertyExtensionConfiguration( + [NotNull] ModuleEntityObjectExtensionConfiguration entityObjectExtensionConfiguration, + [NotNull] Type type, + [NotNull] string name) + { + EntityObjectExtensionConfiguration = Check.NotNull(entityObjectExtensionConfiguration, nameof(entityObjectExtensionConfiguration)); + Type = Check.NotNull(type, nameof(type)); + Name = Check.NotNull(name, nameof(name)); + + DisplayName = new FixedLocalizableString(Name); + + Configuration = new Dictionary(); + Attributes = new List(); + Validators = new List>(); + } + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfiguration.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfiguration.cs new file mode 100644 index 0000000000..4972eace19 --- /dev/null +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfiguration.cs @@ -0,0 +1,9 @@ +using System.Collections.Generic; + +namespace Volo.Abp.ObjectExtending +{ + public class ModuleObjectExtensionConfiguration : Dictionary + { + + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfigurationDictionary.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfigurationDictionary.cs new file mode 100644 index 0000000000..a4ddf66473 --- /dev/null +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfigurationDictionary.cs @@ -0,0 +1,9 @@ +using System.Collections.Generic; + +namespace Volo.Abp.ObjectExtending +{ + public class ModuleObjectExtensionConfigurationDictionary : Dictionary + { + + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfigurationDictionaryExtensions.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfigurationDictionaryExtensions.cs new file mode 100644 index 0000000000..05d0670d36 --- /dev/null +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfigurationDictionaryExtensions.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using JetBrains.Annotations; + +namespace Volo.Abp.ObjectExtending +{ + public static class ModuleObjectExtensionConfigurationDictionaryExtensions + { + public static ModuleObjectExtensionConfigurationDictionary ConfigureModule( + [NotNull] this ModuleObjectExtensionConfigurationDictionary configurationDictionary, + [NotNull] string moduleName, + [NotNull] Action configureAction) + where T : ModuleObjectExtensionConfiguration, new() + { + Check.NotNull(moduleName, nameof(moduleName)); + Check.NotNull(configureAction, nameof(configureAction)); + + configureAction( + (T)configurationDictionary.GetOrAdd( + moduleName, + () => new T() + ) + ); + + return configurationDictionary; + } + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfigurationExtensions.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfigurationExtensions.cs new file mode 100644 index 0000000000..4397bfe088 --- /dev/null +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfigurationExtensions.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; + +namespace Volo.Abp.ObjectExtending +{ + public static class ModuleObjectExtensionConfigurationExtensions + { + public static T ConfigureObject( + this T objectConfiguration, + string objectName, + Action configureAction) + where T : ModuleObjectExtensionConfiguration + { + var configuration = objectConfiguration.GetOrAdd( + objectName, + () => new ModuleEntityObjectExtensionConfiguration() + ) as ModuleEntityObjectExtensionConfiguration; + + configureAction(configuration); + + return objectConfiguration; + } + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionManager.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionManager.cs index 26b692c232..684be055fe 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionManager.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionManager.cs @@ -15,10 +15,13 @@ namespace Volo.Abp.ObjectExtending protected Dictionary ObjectsExtensions { get; } + public ModuleObjectExtensionConfigurationDictionary Modules { get; } + protected internal ObjectExtensionManager() { ObjectsExtensions = new Dictionary(); Configuration = new Dictionary(); + Modules = new ModuleObjectExtensionConfigurationDictionary(); } [NotNull] diff --git a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleObjectExtensionConfiguration.cs b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleObjectExtensionConfiguration.cs new file mode 100644 index 0000000000..795c61281f --- /dev/null +++ b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleObjectExtensionConfiguration.cs @@ -0,0 +1,7 @@ +namespace Volo.Abp.ObjectExtending +{ + public class IdentityModuleObjectExtensionConfiguration : ModuleObjectExtensionConfiguration + { + + } +} \ No newline at end of file diff --git a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleObjectExtensionConfigurationExtensions.cs b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleObjectExtensionConfigurationExtensions.cs new file mode 100644 index 0000000000..8f2815ad10 --- /dev/null +++ b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleObjectExtensionConfigurationExtensions.cs @@ -0,0 +1,17 @@ +using System; + +namespace Volo.Abp.ObjectExtending +{ + public static class IdentityModuleObjectExtensionConfigurationExtensions + { + public static IdentityModuleObjectExtensionConfiguration ConfigureUser( + this IdentityModuleObjectExtensionConfiguration configurations, + Action configureAction) + { + return configurations.ConfigureEntity( + "User", + configureAction + ); + } + } +} \ No newline at end of file diff --git a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleObjectExtensionConfigurationsExtensions.cs b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleObjectExtensionConfigurationsExtensions.cs new file mode 100644 index 0000000000..3daf614f45 --- /dev/null +++ b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleObjectExtensionConfigurationsExtensions.cs @@ -0,0 +1,17 @@ +using System; + +namespace Volo.Abp.ObjectExtending +{ + public static class IdentityModuleObjectExtensionConfigurationsExtensions + { + public static ModuleObjectExtensionConfigurationDictionary ConfigureIdentity( + this ModuleObjectExtensionConfigurationDictionary modules, + Action configureAction) + { + return modules.ConfigureModule( + "Identity", + configureAction + ); + } + } +} From 911fa17f7c5d84a6d83ff8fb4412eedf45db9ba4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Wed, 29 Apr 2020 00:15:41 +0300 Subject: [PATCH 22/67] Rename to ConfigureObject --- .../IdentityModuleObjectExtensionConfigurationExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleObjectExtensionConfigurationExtensions.cs b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleObjectExtensionConfigurationExtensions.cs index 8f2815ad10..00f1b920af 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleObjectExtensionConfigurationExtensions.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleObjectExtensionConfigurationExtensions.cs @@ -8,7 +8,7 @@ namespace Volo.Abp.ObjectExtending this IdentityModuleObjectExtensionConfiguration configurations, Action configureAction) { - return configurations.ConfigureEntity( + return configurations.ConfigureObject( "User", configureAction ); From e9fc742b7e901de2b69032d95c96345f410eb145 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Wed, 29 Apr 2020 03:33:28 +0300 Subject: [PATCH 23/67] Added ObjectExtensions to ApplicationConfigurationDto --- .../ApplicationConfigurationDto.cs | 3 + .../CachedObjectExtensionsDtoService.cs | 90 +++++++++++++ .../ICachedObjectExtensionsDtoService.cs | 7 + .../LocalizedDisplayNameDto.cs | 37 +++++ .../ModuleObjectExtensionDto.cs | 11 ++ .../ModuleObjectExtraPropertyAttributeDto.cs | 36 +++++ .../ModuleObjectExtraPropertyExtensionDto.cs | 19 +++ ...ModuleObjectExtraPropertyUiExtensionDto.cs | 12 ++ ...leObjectExtraPropertyUiFormExtensionDto.cs | 10 ++ ...eObjectExtraPropertyUiTableExtensionDto.cs | 10 ++ .../ObjectExtensionConfigurationDto.cs | 12 ++ .../ObjectExtending/ObjectExtensionsDto.cs | 11 ++ .../AbpApplicationConfigurationAppService.cs | 10 +- .../AspNetCoreApiDescriptionModelProvider.cs | 2 +- .../Volo/Abp/Reflection/TypeHelper.cs | 118 ++++++++++++++++ .../MethodParameterApiDescriptionModel.cs | 5 +- .../Abp/Http/Modeling/ModelingTypeHelper.cs | 127 ------------------ .../Modeling/ParameterApiDescriptionModel.cs | 5 +- .../Modeling/PropertyApiDescriptionModel.cs | 12 +- .../ReturnValueApiDescriptionModel.cs | 5 +- .../Http/Modeling/TypeApiDescriptionModel.cs | 3 +- .../ModuleObjectExtensionConfiguration.cs | 2 +- ...eObjectExtensionConfigurationDictionary.cs | 2 +- ...eObjectExtensionConfigurationExtensions.cs | 2 +- 24 files changed, 404 insertions(+), 147 deletions(-) create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/CachedObjectExtensionsDtoService.cs create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ICachedObjectExtensionsDtoService.cs create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/LocalizedDisplayNameDto.cs create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtensionDto.cs create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyAttributeDto.cs create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyExtensionDto.cs create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyUiExtensionDto.cs create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyUiFormExtensionDto.cs create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyUiTableExtensionDto.cs create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ObjectExtensionConfigurationDto.cs create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ObjectExtensionsDto.cs delete mode 100644 framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ModelingTypeHelper.cs diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationConfigurationDto.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationConfigurationDto.cs index cc62a1e1b9..da99a3e948 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationConfigurationDto.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationConfigurationDto.cs @@ -1,4 +1,5 @@ using System; +using Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending; using Volo.Abp.AspNetCore.Mvc.MultiTenancy; namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations @@ -19,5 +20,7 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations public MultiTenancyInfoDto MultiTenancy { get; set; } public CurrentTenantDto CurrentTenant { get; set; } + + public ObjectExtensionsDto ObjectExtensions { get; set; } } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/CachedObjectExtensionsDtoService.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/CachedObjectExtensionsDtoService.cs new file mode 100644 index 0000000000..7ff5f034cb --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/CachedObjectExtensionsDtoService.cs @@ -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() + }; + + foreach (var moduleConfig in ObjectExtensionManager.Instance.Modules) + { + var moduleExtensionDto = objectExtensionsDto.Modules[moduleConfig.Key] = new ModuleExtensionDto + { + Objects = new Dictionary() + }; + + foreach (var objectConfig in moduleConfig.Value) + { + var moduleObjectExtensionDto = moduleExtensionDto.Objects[objectConfig.Key] = + new ModuleObjectExtensionDto + { + ExtraProperties = new Dictionary() + }; + + 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(), + 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; + } + } +} diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ICachedObjectExtensionsDtoService.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ICachedObjectExtensionsDtoService.cs new file mode 100644 index 0000000000..f0163c8b55 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ICachedObjectExtensionsDtoService.cs @@ -0,0 +1,7 @@ +namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending +{ + public interface ICachedObjectExtensionsDtoService + { + ObjectExtensionsDto Get(); + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/LocalizedDisplayNameDto.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/LocalizedDisplayNameDto.cs new file mode 100644 index 0000000000..748daa58b9 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/LocalizedDisplayNameDto.cs @@ -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; + } + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtensionDto.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtensionDto.cs new file mode 100644 index 0000000000..0879fc60bd --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtensionDto.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending +{ + [Serializable] + public class ModuleObjectExtensionDto + { + public Dictionary ExtraProperties { get; set; } + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyAttributeDto.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyAttributeDto.cs new file mode 100644 index 0000000000..d45bf7d8d4 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyAttributeDto.cs @@ -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 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() + }; + + if (attribute is StringLengthAttribute stringLengthAttribute) + { + dto.Configuration["MaximumLength"] = stringLengthAttribute.MaximumLength; + dto.Configuration["MinimumLength"] = stringLengthAttribute.MinimumLength; + } + + //TODO: Others! + + return dto; + } + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyExtensionDto.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyExtensionDto.cs new file mode 100644 index 0000000000..853a27e294 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyExtensionDto.cs @@ -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 Attributes { get; set; } + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyUiExtensionDto.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyUiExtensionDto.cs new file mode 100644 index 0000000000..fcb39f67c6 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyUiExtensionDto.cs @@ -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; } + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyUiFormExtensionDto.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyUiFormExtensionDto.cs new file mode 100644 index 0000000000..00411ba0f9 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyUiFormExtensionDto.cs @@ -0,0 +1,10 @@ +using System; + +namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending +{ + [Serializable] + public class ModuleObjectExtraPropertyUiFormExtensionDto + { + public bool Visible { get; set; } + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyUiTableExtensionDto.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyUiTableExtensionDto.cs new file mode 100644 index 0000000000..9c2d202da9 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyUiTableExtensionDto.cs @@ -0,0 +1,10 @@ +using System; + +namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending +{ + [Serializable] + public class ModuleObjectExtraPropertyUiTableExtensionDto + { + public bool Visible { get; set; } + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ObjectExtensionConfigurationDto.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ObjectExtensionConfigurationDto.cs new file mode 100644 index 0000000000..096c2210c0 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ObjectExtensionConfigurationDto.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; + +namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending +{ + [Serializable] + public class ModuleExtensionDto + { + public Dictionary Objects { get; set; } + } +} + diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ObjectExtensionsDto.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ObjectExtensionsDto.cs new file mode 100644 index 0000000000..fd9665eab1 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ObjectExtensionsDto.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending +{ + [Serializable] + public class ObjectExtensionsDto + { + public Dictionary Modules { get; set; } + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationAppService.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationAppService.cs index 4b4cf521c2..6271505ead 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationAppService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationAppService.cs @@ -8,6 +8,7 @@ using System.Globalization; using System.Threading.Tasks; using Microsoft.Extensions.Logging; using Volo.Abp.Application.Services; +using Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending; using Volo.Abp.AspNetCore.Mvc.MultiTenancy; using Volo.Abp.Authorization; using Volo.Abp.Features; @@ -30,6 +31,7 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations private readonly ISettingDefinitionManager _settingDefinitionManager; private readonly IFeatureDefinitionManager _featureDefinitionManager; private readonly ILanguageProvider _languageProvider; + private readonly ICachedObjectExtensionsDtoService _cachedObjectExtensionsDtoService; public AbpApplicationConfigurationAppService( IOptions localizationOptions, @@ -41,7 +43,8 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations ISettingProvider settingProvider, ISettingDefinitionManager settingDefinitionManager, IFeatureDefinitionManager featureDefinitionManager, - ILanguageProvider languageProvider) + ILanguageProvider languageProvider, + ICachedObjectExtensionsDtoService cachedObjectExtensionsDtoService) { _serviceProvider = serviceProvider; _abpAuthorizationPolicyProvider = abpAuthorizationPolicyProvider; @@ -51,6 +54,7 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations _settingDefinitionManager = settingDefinitionManager; _featureDefinitionManager = featureDefinitionManager; _languageProvider = languageProvider; + _cachedObjectExtensionsDtoService = cachedObjectExtensionsDtoService; _localizationOptions = localizationOptions.Value; _multiTenancyOptions = multiTenancyOptions.Value; } @@ -67,8 +71,8 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations CurrentUser = GetCurrentUser(), Setting = await GetSettingConfigAsync(), MultiTenancy = GetMultiTenancy(), - CurrentTenant = GetCurrentTenant() - + CurrentTenant = GetCurrentTenant(), + ObjectExtensions = _cachedObjectExtensionsDtoService.Get() }; } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AspNetCoreApiDescriptionModelProvider.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AspNetCoreApiDescriptionModelProvider.cs index f957fd894f..1042ee4d08 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AspNetCoreApiDescriptionModelProvider.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AspNetCoreApiDescriptionModelProvider.cs @@ -206,7 +206,7 @@ namespace Volo.Abp.AspNetCore.Mvc /* TODO: Add interfaces */ - var typeName = ModelingTypeHelper.GetFullNameHandlingNullableAndGenerics(type); + var typeName = TypeHelper.GetFullNameHandlingNullableAndGenerics(type); if (applicationModel.Types.ContainsKey(typeName)) { diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/Reflection/TypeHelper.cs b/framework/src/Volo.Abp.Core/Volo/Abp/Reflection/TypeHelper.cs index eeb0259321..1a31cc9f34 100644 --- a/framework/src/Volo.Abp.Core/Volo/Abp/Reflection/TypeHelper.cs +++ b/framework/src/Volo.Abp.Core/Volo/Abp/Reflection/TypeHelper.cs @@ -3,6 +3,7 @@ using System.Collections; using System.Collections.Generic; using System.Linq; using System.Reflection; +using JetBrains.Annotations; namespace Volo.Abp.Reflection { @@ -146,5 +147,122 @@ namespace Volo.Abp.Reflection return null; } + + 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; + } } } diff --git a/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/MethodParameterApiDescriptionModel.cs b/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/MethodParameterApiDescriptionModel.cs index 4199e29ec0..211359d789 100644 --- a/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/MethodParameterApiDescriptionModel.cs +++ b/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/MethodParameterApiDescriptionModel.cs @@ -1,5 +1,6 @@ using System; using System.Reflection; +using Volo.Abp.Reflection; namespace Volo.Abp.Http.Modeling { @@ -29,8 +30,8 @@ namespace Volo.Abp.Http.Modeling { Name = parameterInfo.Name, TypeAsString = parameterInfo.ParameterType.GetFullNameWithAssemblyName(), - Type = parameterInfo.ParameterType != null ? ModelingTypeHelper.GetFullNameHandlingNullableAndGenerics(parameterInfo.ParameterType) : null, - TypeSimple = parameterInfo.ParameterType != null ? ModelingTypeHelper.GetSimplifiedName(parameterInfo.ParameterType) : null, + Type = parameterInfo.ParameterType != null ? TypeHelper.GetFullNameHandlingNullableAndGenerics(parameterInfo.ParameterType) : null, + TypeSimple = parameterInfo.ParameterType != null ? TypeHelper.GetSimplifiedName(parameterInfo.ParameterType) : null, IsOptional = parameterInfo.IsOptional, DefaultValue = parameterInfo.HasDefaultValue ? parameterInfo.DefaultValue : null }; diff --git a/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ModelingTypeHelper.cs b/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ModelingTypeHelper.cs deleted file mode 100644 index 2d4b2bac85..0000000000 --- a/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ModelingTypeHelper.cs +++ /dev/null @@ -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; - } - } -} diff --git a/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ParameterApiDescriptionModel.cs b/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ParameterApiDescriptionModel.cs index 0be791053c..0450861a41 100644 --- a/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ParameterApiDescriptionModel.cs +++ b/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ParameterApiDescriptionModel.cs @@ -1,4 +1,5 @@ using System; +using Volo.Abp.Reflection; namespace Volo.Abp.Http.Modeling { @@ -34,8 +35,8 @@ namespace Volo.Abp.Http.Modeling { Name = name, NameOnMethod = nameOnMethod, - Type = type != null ? ModelingTypeHelper.GetFullNameHandlingNullableAndGenerics(type) : null, - TypeSimple = type != null ? ModelingTypeHelper.GetSimplifiedName(type) : null, + Type = type != null ? TypeHelper.GetFullNameHandlingNullableAndGenerics(type) : null, + TypeSimple = type != null ? TypeHelper.GetSimplifiedName(type) : null, IsOptional = isOptional, DefaultValue = defaultValue, ConstraintTypes = constraintTypes, diff --git a/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/PropertyApiDescriptionModel.cs b/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/PropertyApiDescriptionModel.cs index ca8af7f22a..820d9a46f9 100644 --- a/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/PropertyApiDescriptionModel.cs +++ b/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/PropertyApiDescriptionModel.cs @@ -21,18 +21,18 @@ namespace Volo.Abp.Http.Modeling if (TypeHelper.IsEnumerable(propertyInfo.PropertyType, out var itemType, includePrimitives: false)) { - typeName = $"[{ModelingTypeHelper.GetFullNameHandlingNullableAndGenerics(itemType)}]"; - simpleTypeName = $"[{ModelingTypeHelper.GetSimplifiedName(itemType)}]"; + typeName = $"[{TypeHelper.GetFullNameHandlingNullableAndGenerics(itemType)}]"; + simpleTypeName = $"[{TypeHelper.GetSimplifiedName(itemType)}]"; } else if (TypeHelper.IsDictionary(propertyInfo.PropertyType, out var keyType, out var valueType)) { - typeName = $"{{{ModelingTypeHelper.GetFullNameHandlingNullableAndGenerics(keyType)}:{ModelingTypeHelper.GetFullNameHandlingNullableAndGenerics(valueType)}}}"; - simpleTypeName = $"{{{ModelingTypeHelper.GetSimplifiedName(keyType)}:{ModelingTypeHelper.GetSimplifiedName(valueType)}}}"; + typeName = $"{{{TypeHelper.GetFullNameHandlingNullableAndGenerics(keyType)}:{TypeHelper.GetFullNameHandlingNullableAndGenerics(valueType)}}}"; + simpleTypeName = $"{{{TypeHelper.GetSimplifiedName(keyType)}:{TypeHelper.GetSimplifiedName(valueType)}}}"; } else { - typeName = ModelingTypeHelper.GetFullNameHandlingNullableAndGenerics(propertyInfo.PropertyType); - simpleTypeName = ModelingTypeHelper.GetSimplifiedName(propertyInfo.PropertyType); + typeName = TypeHelper.GetFullNameHandlingNullableAndGenerics(propertyInfo.PropertyType); + simpleTypeName = TypeHelper.GetSimplifiedName(propertyInfo.PropertyType); } return new PropertyApiDescriptionModel diff --git a/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ReturnValueApiDescriptionModel.cs b/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ReturnValueApiDescriptionModel.cs index d6532be6d4..2e0862ccce 100644 --- a/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ReturnValueApiDescriptionModel.cs +++ b/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ReturnValueApiDescriptionModel.cs @@ -1,4 +1,5 @@ using System; +using Volo.Abp.Reflection; using Volo.Abp.Threading; namespace Volo.Abp.Http.Modeling @@ -21,8 +22,8 @@ namespace Volo.Abp.Http.Modeling return new ReturnValueApiDescriptionModel { - Type = ModelingTypeHelper.GetFullNameHandlingNullableAndGenerics(unwrappedType), - TypeSimple = ModelingTypeHelper.GetSimplifiedName(unwrappedType) + Type = TypeHelper.GetFullNameHandlingNullableAndGenerics(unwrappedType), + TypeSimple = TypeHelper.GetSimplifiedName(unwrappedType) }; } } diff --git a/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/TypeApiDescriptionModel.cs b/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/TypeApiDescriptionModel.cs index fcc4b034ea..161584279b 100644 --- a/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/TypeApiDescriptionModel.cs +++ b/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/TypeApiDescriptionModel.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using Volo.Abp.Reflection; namespace Volo.Abp.Http.Modeling { @@ -32,7 +33,7 @@ namespace Volo.Abp.Http.Modeling var typeModel = new TypeApiDescriptionModel { IsEnum = type.IsEnum, - BaseType = baseType != null ? ModelingTypeHelper.GetFullNameHandlingNullableAndGenerics(baseType) : null + BaseType = baseType != null ? TypeHelper.GetFullNameHandlingNullableAndGenerics(baseType) : null }; if (typeModel.IsEnum) diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfiguration.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfiguration.cs index 4972eace19..991e31b723 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfiguration.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfiguration.cs @@ -2,7 +2,7 @@ namespace Volo.Abp.ObjectExtending { - public class ModuleObjectExtensionConfiguration : Dictionary + public class ModuleObjectExtensionConfiguration : Dictionary { } diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfigurationDictionary.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfigurationDictionary.cs index a4ddf66473..6acbedbba6 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfigurationDictionary.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfigurationDictionary.cs @@ -2,7 +2,7 @@ namespace Volo.Abp.ObjectExtending { - public class ModuleObjectExtensionConfigurationDictionary : Dictionary + public class ModuleObjectExtensionConfigurationDictionary : Dictionary { } diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfigurationExtensions.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfigurationExtensions.cs index 4397bfe088..1f3b682ffa 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfigurationExtensions.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfigurationExtensions.cs @@ -14,7 +14,7 @@ namespace Volo.Abp.ObjectExtending var configuration = objectConfiguration.GetOrAdd( objectName, () => new ModuleEntityObjectExtensionConfiguration() - ) as ModuleEntityObjectExtensionConfiguration; + ); configureAction(configuration); From ef54a6416f5d17a8e34187d76ca96abff4d3624a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Thu, 30 Apr 2020 01:57:58 +0300 Subject: [PATCH 24/67] Added UI config for extra properties --- .../CachedObjectExtensionsDtoService.cs | 8 ++++--- ...leObjectExtraPropertyUiFormExtensionDto.cs | 2 +- ...eObjectExtraPropertyUiTableExtensionDto.cs | 2 +- .../Volo/Abp/Reflection/TypeHelper.cs | 4 ++-- ...ityObjectPropertyExtensionConfiguration.cs | 5 ++++ ...yObjectPropertyExtensionUIConfiguration.cs | 23 +++++++++++++++++++ ...ectPropertyExtensionUIFormConfiguration.cs | 10 ++++++++ ...ctPropertyExtensionUITableConfiguration.cs | 10 ++++++++ .../Volo/Abp/Reflection/TypeHelper_Tests.cs | 9 ++++++++ 9 files changed, 66 insertions(+), 7 deletions(-) create mode 100644 framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionUIConfiguration.cs create mode 100644 framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionUIFormConfiguration.cs create mode 100644 framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionUITableConfiguration.cs diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/CachedObjectExtensionsDtoService.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/CachedObjectExtensionsDtoService.cs index 7ff5f034cb..946076b65b 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/CachedObjectExtensionsDtoService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/CachedObjectExtensionsDtoService.cs @@ -28,6 +28,8 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending protected virtual ObjectExtensionsDto GenerateCacheValue() { + //TODO: Obviously needs refactoring! + var objectExtensionsDto = new ObjectExtensionsDto { Modules = new Dictionary() @@ -61,15 +63,15 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending { CreateForm = new ModuleObjectExtraPropertyUiFormExtensionDto { - Visible = true + IsVisible = propertyConfig.UI.CreateForm.IsVisible }, EditForm = new ModuleObjectExtraPropertyUiFormExtensionDto { - Visible = true + IsVisible = propertyConfig.UI.EditForm.IsVisible }, Table = new ModuleObjectExtraPropertyUiTableExtensionDto { - Visible = true + IsVisible = propertyConfig.UI.Table.IsVisible } } }; diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyUiFormExtensionDto.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyUiFormExtensionDto.cs index 00411ba0f9..9d7e719f4f 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyUiFormExtensionDto.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyUiFormExtensionDto.cs @@ -5,6 +5,6 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending [Serializable] public class ModuleObjectExtraPropertyUiFormExtensionDto { - public bool Visible { get; set; } + public bool IsVisible { get; set; } } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyUiTableExtensionDto.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyUiTableExtensionDto.cs index 9c2d202da9..419b9a6430 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyUiTableExtensionDto.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyUiTableExtensionDto.cs @@ -5,6 +5,6 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending [Serializable] public class ModuleObjectExtraPropertyUiTableExtensionDto { - public bool Visible { get; set; } + public bool IsVisible { get; set; } } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/Reflection/TypeHelper.cs b/framework/src/Volo.Abp.Core/Volo/Abp/Reflection/TypeHelper.cs index 1a31cc9f34..11f43f852e 100644 --- a/framework/src/Volo.Abp.Core/Volo/Abp/Reflection/TypeHelper.cs +++ b/framework/src/Volo.Abp.Core/Volo/Abp/Reflection/TypeHelper.cs @@ -133,9 +133,9 @@ namespace Volo.Abp.Reflection type == typeof(Guid); } - public static object GetDefaultValue() + public static T GetDefaultValue() { - return GetDefaultValue(typeof(T)); + return default; } public static object GetDefaultValue(Type type) diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionConfiguration.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionConfiguration.cs index 705166e2cc..bdc8d37e1e 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionConfiguration.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionConfiguration.cs @@ -36,6 +36,9 @@ namespace Volo.Abp.ObjectExtending [NotNull] public Dictionary Configuration { get; } + + [NotNull] + public ModuleEntityObjectPropertyExtensionUIConfiguration UI { get; } public ModuleEntityObjectPropertyExtensionConfiguration( [NotNull] ModuleEntityObjectExtensionConfiguration entityObjectExtensionConfiguration, @@ -51,6 +54,8 @@ namespace Volo.Abp.ObjectExtending Configuration = new Dictionary(); Attributes = new List(); Validators = new List>(); + + UI = new ModuleEntityObjectPropertyExtensionUIConfiguration(); } } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionUIConfiguration.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionUIConfiguration.cs new file mode 100644 index 0000000000..352b714ff0 --- /dev/null +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionUIConfiguration.cs @@ -0,0 +1,23 @@ +using JetBrains.Annotations; + +namespace Volo.Abp.ObjectExtending +{ + public class ModuleEntityObjectPropertyExtensionUIConfiguration + { + [NotNull] + public ModuleEntityObjectPropertyExtensionUITableConfiguration Table { get; } + + [NotNull] + public ModuleEntityObjectPropertyExtensionUIFormConfiguration CreateForm { get; } + + [NotNull] + public ModuleEntityObjectPropertyExtensionUIFormConfiguration EditForm { get; } + + public ModuleEntityObjectPropertyExtensionUIConfiguration() + { + Table = new ModuleEntityObjectPropertyExtensionUITableConfiguration(); + CreateForm = new ModuleEntityObjectPropertyExtensionUIFormConfiguration(); + EditForm = new ModuleEntityObjectPropertyExtensionUIFormConfiguration(); + } + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionUIFormConfiguration.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionUIFormConfiguration.cs new file mode 100644 index 0000000000..28ca3d9f79 --- /dev/null +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionUIFormConfiguration.cs @@ -0,0 +1,10 @@ +namespace Volo.Abp.ObjectExtending +{ + public class ModuleEntityObjectPropertyExtensionUIFormConfiguration + { + /// + /// Default: true. + /// + public bool IsVisible { get; set; } = true; + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionUITableConfiguration.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionUITableConfiguration.cs new file mode 100644 index 0000000000..36ae59e47d --- /dev/null +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionUITableConfiguration.cs @@ -0,0 +1,10 @@ +namespace Volo.Abp.ObjectExtending +{ + public class ModuleEntityObjectPropertyExtensionUITableConfiguration + { + /// + /// Default: true. + /// + public bool IsVisible { get; set; } = true; + } +} \ No newline at end of file diff --git a/framework/test/Volo.Abp.Core.Tests/Volo/Abp/Reflection/TypeHelper_Tests.cs b/framework/test/Volo.Abp.Core.Tests/Volo/Abp/Reflection/TypeHelper_Tests.cs index e289779d2c..23eba093a6 100644 --- a/framework/test/Volo.Abp.Core.Tests/Volo/Abp/Reflection/TypeHelper_Tests.cs +++ b/framework/test/Volo.Abp.Core.Tests/Volo/Abp/Reflection/TypeHelper_Tests.cs @@ -66,6 +66,15 @@ namespace Volo.Abp.Reflection ).ShouldBeFalse(); } + [Fact] + public void GetDefaultValue() + { + TypeHelper.GetDefaultValue(typeof(bool)).ShouldBe(false); + TypeHelper.GetDefaultValue(typeof(byte)).ShouldBe(0); + TypeHelper.GetDefaultValue(typeof(int)).ShouldBe(0); + TypeHelper.GetDefaultValue(typeof(string)).ShouldBeNull(); + } + public class MyDictionary : Dictionary { From 52b6c10a550325acde5425e71284e69b7e0deb47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Thu, 30 Apr 2020 03:14:00 +0300 Subject: [PATCH 25/67] Resolved #3790: Add AbpLocalizationOptions.DefaultResourceType. --- docs/en/Localization.md | 37 ++++++++++++++++++- ...ApplicationLocalizationConfigurationDto.cs | 2 + .../AbpApplicationConfigurationAppService.cs | 3 ++ .../Localization/AbpLocalizationOptions.cs | 8 +++- .../MyProjectNameDomainSharedModule.cs | 2 + 5 files changed, 49 insertions(+), 3 deletions(-) diff --git a/docs/en/Localization.md b/docs/en/Localization.md index 11b838cf7f..53f62223cf 100644 --- a/docs/en/Localization.md +++ b/docs/en/Localization.md @@ -87,6 +87,21 @@ A JSON localization file content is shown below: * Every localization file should define the `culture` code for the file (like "en" or "en-US"). * `texts` section just contains key-value collection of the localization strings (keys may have spaces too). +### Default Resource + +`AbpLocalizationOptions.DefaultResourceType` can be set to a resource type, so it is used when the localization resource was not specified: + +````csharp +Configure(options => +{ + options.DefaultResourceType = typeof(TestResource); +}); +```` + +> The [application startup template](Startup-Templates/Application.md) sets `DefaultResourceType` to the localization resource of the application. + +See the *Client Side* section below for a use case. + ### Short Localization Resource Name Localization resources are also available in the client (JavaScript) side. So, setting a short name for the localization resource makes it easy to use localization texts. Example: @@ -180,18 +195,36 @@ Refer to the [Microsoft's localization documentation](https://docs.microsoft.com ABP provides JavaScript services to use the same localized texts in the client side. -Get a localization resource: +#### getResource + +`abp.localization.getResource` function is used to get a localization resource: ````js var testResource = abp.localization.getResource('Test'); ```` -Localize a string: +Then you can localize a string based on this resource: ````js var str = testResource('HelloWorld'); ```` +#### localize + +`abp.localization.localize` function is a shortcut where you can both specify the text name and the resource name: + +````js +var str = abp.localization.localize('HelloWorld', 'Test'); +```` + +`HelloWorld` is the text to localize, where `Test` is the localization resource name here. + +If you don't specify the localization resource name, it uses the default localization resource defined on the `AbpLocalizationOptions` (see the *Default Resource* section above). Example: + +````js +var str = abp.localization.localize('HelloWorld'); //uses the default resource +```` + ## See Also * [Localization in Angular UI](UI/Angular/Localization.md) \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationLocalizationConfigurationDto.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationLocalizationConfigurationDto.cs index a5e6574e93..8064ff99d2 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationLocalizationConfigurationDto.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationLocalizationConfigurationDto.cs @@ -14,6 +14,8 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations public CurrentCultureDto CurrentCulture { get; set; } + public string DefaultResourceName { get; set; } + public ApplicationLocalizationConfigurationDto() { Values = new Dictionary>(); diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationAppService.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationAppService.cs index 6271505ead..52af9090fa 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationAppService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationAppService.cs @@ -157,6 +157,9 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations } localizationConfig.CurrentCulture = GetCurrentCultureInfo(); + localizationConfig.DefaultResourceName = LocalizationResourceNameAttribute.GetName( + _localizationOptions.DefaultResourceType + ); Logger.LogDebug("Executed AbpApplicationConfigurationAppService.GetLocalizationConfigAsync()"); diff --git a/framework/src/Volo.Abp.Localization/Volo/Abp/Localization/AbpLocalizationOptions.cs b/framework/src/Volo.Abp.Localization/Volo/Abp/Localization/AbpLocalizationOptions.cs index ea5232bb04..aba376d773 100644 --- a/framework/src/Volo.Abp.Localization/Volo/Abp/Localization/AbpLocalizationOptions.cs +++ b/framework/src/Volo.Abp.Localization/Volo/Abp/Localization/AbpLocalizationOptions.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using Volo.Abp.Collections; namespace Volo.Abp.Localization @@ -7,6 +8,11 @@ namespace Volo.Abp.Localization { public LocalizationResourceDictionary Resources { get; } + /// + /// Used as the default resource when resource was not specified on a localization operation. + /// + public Type DefaultResourceType { get; set; } + public ITypeList GlobalContributors { get; } public List Languages { get; } diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Domain.Shared/MyProjectNameDomainSharedModule.cs b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Domain.Shared/MyProjectNameDomainSharedModule.cs index f20fb70a7e..d10c63986d 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Domain.Shared/MyProjectNameDomainSharedModule.cs +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Domain.Shared/MyProjectNameDomainSharedModule.cs @@ -39,6 +39,8 @@ namespace MyCompanyName.MyProjectName .Add("en") .AddBaseTypes(typeof(AbpValidationResource)) .AddVirtualJson("/Localization/MyProjectName"); + + options.DefaultResourceType = typeof(MyProjectNameResource); }); } } From 7e10bd92ce52bbe134295f6c8fddad7089544133 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Thu, 30 Apr 2020 05:02:07 +0300 Subject: [PATCH 26/67] Auto find the display name for a extra property (if not specified explicitly). --- .../CachedObjectExtensionsDtoService.cs | 32 ++++++++++++- .../ObjectExtending/LocalizableStringDto.cs | 14 ++++++ .../LocalizedDisplayNameDto.cs | 37 --------------- .../ModuleObjectExtraPropertyExtensionDto.cs | 4 +- .../AbpValidationHtmlAttributeProvider.cs | 2 +- .../AbpStringLocalizerFactoryExtensions.cs | 2 +- .../AbpStringLocalizerFactoryExtensions.cs | 11 +++++ ...alizerFactoryWithDefaultResourceSupport.cs | 10 ++++ .../Localization/AbpStringLocalizerFactory.cs | 47 +++++++++++-------- ...ityObjectPropertyExtensionConfiguration.cs | 15 +----- .../ObjectExtensionPropertyInfo.cs | 46 +++++++++++++----- npm/packs/core/src/abp.js | 32 ++++++++++++- 12 files changed, 165 insertions(+), 87 deletions(-) create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/LocalizableStringDto.cs delete mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/LocalizedDisplayNameDto.cs create mode 100644 framework/src/Volo.Abp.Localization.Abstractions/Microsoft/Extensions/Localization/AbpStringLocalizerFactoryExtensions.cs create mode 100644 framework/src/Volo.Abp.Localization.Abstractions/Microsoft/Extensions/Localization/IAbpStringLocalizerFactoryWithDefaultResourceSupport.cs diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/CachedObjectExtensionsDtoService.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/CachedObjectExtensionsDtoService.cs index 946076b65b..d400cc1d56 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/CachedObjectExtensionsDtoService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/CachedObjectExtensionsDtoService.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using Volo.Abp.DependencyInjection; +using Volo.Abp.Localization; using Volo.Abp.ObjectExtending; using Volo.Abp.Reflection; @@ -58,7 +59,7 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending Type = TypeHelper.GetFullNameHandlingNullableAndGenerics(propertyConfig.Type), TypeSimple = TypeHelper.GetSimplifiedName(propertyConfig.Type), Attributes = new List(), - DisplayName = LocalizedDisplayNameDto.CreateOrNull(propertyConfig.DisplayName), + DisplayName = CreateDisplayNameDto(propertyConfig), Ui = new ModuleObjectExtraPropertyUiExtensionDto { CreateForm = new ModuleObjectExtraPropertyUiFormExtensionDto @@ -88,5 +89,34 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending return objectExtensionsDto; } + + private static LocalizableStringDto CreateDisplayNameDto( + ModuleEntityObjectPropertyExtensionConfiguration propertyConfig) + { + if (propertyConfig.DisplayName == null) + { + return null; + } + + if (propertyConfig.DisplayName is LocalizableString localizableStringInstance) + { + return new LocalizableStringDto + { + Name = localizableStringInstance.Name, + Resource = LocalizationResourceNameAttribute.GetName(localizableStringInstance.ResourceType) + }; + } + + if (propertyConfig.DisplayName is FixedLocalizableString fixedLocalizableString) + { + return new LocalizableStringDto + { + Name = fixedLocalizableString.Value, + Resource = "_" + }; + } + + return null; + } } } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/LocalizableStringDto.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/LocalizableStringDto.cs new file mode 100644 index 0000000000..307831315b --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/LocalizableStringDto.cs @@ -0,0 +1,14 @@ +using System; +using JetBrains.Annotations; + +namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending +{ + [Serializable] + public class LocalizableStringDto + { + public string Name { get; set; } + + [CanBeNull] + public string Resource { get; set; } + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/LocalizedDisplayNameDto.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/LocalizedDisplayNameDto.cs deleted file mode 100644 index 748daa58b9..0000000000 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/LocalizedDisplayNameDto.cs +++ /dev/null @@ -1,37 +0,0 @@ -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; - } - } -} \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyExtensionDto.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyExtensionDto.cs index 853a27e294..661da59f60 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyExtensionDto.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyExtensionDto.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using JetBrains.Annotations; namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending { @@ -10,7 +11,8 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending public string TypeSimple { get; set; } - public LocalizedDisplayNameDto DisplayName { get; set; } + [CanBeNull] + public LocalizableStringDto DisplayName { get; set; } public ModuleObjectExtraPropertyUiExtensionDto Ui { get; set; } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ViewFeatures/AbpValidationHtmlAttributeProvider.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ViewFeatures/AbpValidationHtmlAttributeProvider.cs index f0c4c628b8..563ebe9d4a 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ViewFeatures/AbpValidationHtmlAttributeProvider.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ViewFeatures/AbpValidationHtmlAttributeProvider.cs @@ -103,7 +103,7 @@ namespace Volo.Abp.AspNetCore.Mvc.ViewFeatures if (modelExplorer.Metadata is DefaultModelMetadata metadata) { metadata.DisplayMetadata.DisplayName = - () => extensionPropertyInfo.DisplayName.Localize(_stringLocalizerFactory); + () => extensionPropertyInfo.GetDisplayName(_stringLocalizerFactory); } foreach (var validationAttribute in extensionPropertyInfo.GetValidationAttributes()) diff --git a/framework/src/Volo.Abp.Core/Microsoft/Extensions/Localization/AbpStringLocalizerFactoryExtensions.cs b/framework/src/Volo.Abp.Core/Microsoft/Extensions/Localization/AbpStringLocalizerFactoryExtensions.cs index 34931bfc95..3995bf4440 100644 --- a/framework/src/Volo.Abp.Core/Microsoft/Extensions/Localization/AbpStringLocalizerFactoryExtensions.cs +++ b/framework/src/Volo.Abp.Core/Microsoft/Extensions/Localization/AbpStringLocalizerFactoryExtensions.cs @@ -1,6 +1,6 @@ namespace Microsoft.Extensions.Localization { - public static class AbpStringLocalizerFactoryExtensions + public static class AbpCoreStringLocalizerFactoryExtensions { public static IStringLocalizer Create(this IStringLocalizerFactory localizerFactory) { diff --git a/framework/src/Volo.Abp.Localization.Abstractions/Microsoft/Extensions/Localization/AbpStringLocalizerFactoryExtensions.cs b/framework/src/Volo.Abp.Localization.Abstractions/Microsoft/Extensions/Localization/AbpStringLocalizerFactoryExtensions.cs new file mode 100644 index 0000000000..0ba8d0daed --- /dev/null +++ b/framework/src/Volo.Abp.Localization.Abstractions/Microsoft/Extensions/Localization/AbpStringLocalizerFactoryExtensions.cs @@ -0,0 +1,11 @@ +namespace Microsoft.Extensions.Localization +{ + public static class AbpStringLocalizerFactoryExtensions + { + public static IStringLocalizer CreateDefaultOrNull(this IStringLocalizerFactory localizerFactory) + { + return (localizerFactory as IAbpStringLocalizerFactoryWithDefaultResourceSupport) + ?.CreateDefaultOrNull(); + } + } +} diff --git a/framework/src/Volo.Abp.Localization.Abstractions/Microsoft/Extensions/Localization/IAbpStringLocalizerFactoryWithDefaultResourceSupport.cs b/framework/src/Volo.Abp.Localization.Abstractions/Microsoft/Extensions/Localization/IAbpStringLocalizerFactoryWithDefaultResourceSupport.cs new file mode 100644 index 0000000000..b749e454a3 --- /dev/null +++ b/framework/src/Volo.Abp.Localization.Abstractions/Microsoft/Extensions/Localization/IAbpStringLocalizerFactoryWithDefaultResourceSupport.cs @@ -0,0 +1,10 @@ +using JetBrains.Annotations; + +namespace Microsoft.Extensions.Localization +{ + public interface IAbpStringLocalizerFactoryWithDefaultResourceSupport + { + [CanBeNull] + IStringLocalizer CreateDefaultOrNull(); + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.Localization/Volo/Abp/Localization/AbpStringLocalizerFactory.cs b/framework/src/Volo.Abp.Localization/Volo/Abp/Localization/AbpStringLocalizerFactory.cs index 103567248f..cd347d8437 100644 --- a/framework/src/Volo.Abp.Localization/Volo/Abp/Localization/AbpStringLocalizerFactory.cs +++ b/framework/src/Volo.Abp.Localization/Volo/Abp/Localization/AbpStringLocalizerFactory.cs @@ -9,13 +9,12 @@ using Microsoft.Extensions.Options; namespace Volo.Abp.Localization { - public class AbpStringLocalizerFactory : IStringLocalizerFactory + public class AbpStringLocalizerFactory : IStringLocalizerFactory, IAbpStringLocalizerFactoryWithDefaultResourceSupport { - private readonly ResourceManagerStringLocalizerFactory _innerFactory; - private readonly AbpLocalizationOptions _abpLocalizationOptions; - private readonly IServiceProvider _serviceProvider; - - private readonly ConcurrentDictionary _localizerCache; + protected internal AbpLocalizationOptions AbpLocalizationOptions { get; } + protected ResourceManagerStringLocalizerFactory InnerFactory { get; } + protected IServiceProvider ServiceProvider { get; } + protected ConcurrentDictionary LocalizerCache { get; } //TODO: It's better to use decorator pattern for IStringLocalizerFactory instead of getting ResourceManagerStringLocalizerFactory as a dependency. public AbpStringLocalizerFactory( @@ -23,29 +22,29 @@ namespace Volo.Abp.Localization IOptions abpLocalizationOptions, IServiceProvider serviceProvider) { - _innerFactory = innerFactory; - _serviceProvider = serviceProvider; - _abpLocalizationOptions = abpLocalizationOptions.Value; + InnerFactory = innerFactory; + ServiceProvider = serviceProvider; + AbpLocalizationOptions = abpLocalizationOptions.Value; - _localizerCache = new ConcurrentDictionary(); + LocalizerCache = new ConcurrentDictionary(); } public virtual IStringLocalizer Create(Type resourceType) { - var resource = _abpLocalizationOptions.Resources.GetOrDefault(resourceType); + var resource = AbpLocalizationOptions.Resources.GetOrDefault(resourceType); if (resource == null) { - return _innerFactory.Create(resourceType); + return InnerFactory.Create(resourceType); } - if (_localizerCache.TryGetValue(resourceType, out var cacheItem)) + if (LocalizerCache.TryGetValue(resourceType, out var cacheItem)) { return cacheItem.Localizer; } - lock (_localizerCache) + lock (LocalizerCache) { - return _localizerCache.GetOrAdd( + return LocalizerCache.GetOrAdd( resourceType, _ => CreateStringLocalizerCacheItem(resource) ).Localizer; @@ -54,12 +53,12 @@ namespace Volo.Abp.Localization private StringLocalizerCacheItem CreateStringLocalizerCacheItem(LocalizationResource resource) { - foreach (var globalContributor in _abpLocalizationOptions.GlobalContributors) + foreach (var globalContributor in AbpLocalizationOptions.GlobalContributors) { resource.Contributors.Add((ILocalizationResourceContributor) Activator.CreateInstance(globalContributor)); } - using (var scope = _serviceProvider.CreateScope()) + using (var scope = ServiceProvider.CreateScope()) { var context = new LocalizationResourceInitializationContext(resource, scope.ServiceProvider); @@ -81,7 +80,7 @@ namespace Volo.Abp.Localization { //TODO: Investigate when this is called? - return _innerFactory.Create(baseName, location); + return InnerFactory.Create(baseName, location); } internal static void Replace(IServiceCollection services) @@ -90,7 +89,7 @@ namespace Volo.Abp.Localization services.AddSingleton(); } - private class StringLocalizerCacheItem + protected class StringLocalizerCacheItem { public AbpDictionaryBasedStringLocalizer Localizer { get; } @@ -99,5 +98,15 @@ namespace Volo.Abp.Localization Localizer = localizer; } } + + public IStringLocalizer CreateDefaultOrNull() + { + if (AbpLocalizationOptions.DefaultResourceType == null) + { + return null; + } + + return Create(AbpLocalizationOptions.DefaultResourceType); + } } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionConfiguration.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionConfiguration.cs index bdc8d37e1e..bf965ba955 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionConfiguration.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionConfiguration.cs @@ -22,17 +22,8 @@ namespace Volo.Abp.ObjectExtending [NotNull] public List> Validators { get; } - [NotNull] - public ILocalizableString DisplayName - { - get => _displayName; - set - { - Check.NotNull(value, nameof(value)); - _displayName = value; - } - } - private ILocalizableString _displayName; + [CanBeNull] + public ILocalizableString DisplayName { get; set; } [NotNull] public Dictionary Configuration { get; } @@ -49,8 +40,6 @@ namespace Volo.Abp.ObjectExtending Type = Check.NotNull(type, nameof(type)); Name = Check.NotNull(name, nameof(name)); - DisplayName = new FixedLocalizableString(Name); - Configuration = new Dictionary(); Attributes = new List(); Validators = new List>(); diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionPropertyInfo.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionPropertyInfo.cs index c0792fbe51..59f42b1494 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionPropertyInfo.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionPropertyInfo.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using JetBrains.Annotations; +using Microsoft.Extensions.Localization; using Volo.Abp.Localization; namespace Volo.Abp.ObjectExtending @@ -27,17 +28,8 @@ namespace Volo.Abp.ObjectExtending [NotNull] public List> Validators { get; } - [NotNull] - public ILocalizableString DisplayName - { - get => _displayName; - set - { - Check.NotNull(value, nameof(value)); - _displayName = value; - } - } - private ILocalizableString _displayName; + [CanBeNull] + public ILocalizableString DisplayName { get; set; } /// /// Indicates whether to check the other side of the object mapping @@ -65,12 +57,40 @@ namespace Volo.Abp.ObjectExtending Type = Check.NotNull(type, nameof(type)); Name = Check.NotNull(name, nameof(name)); - DisplayName = new FixedLocalizableString(Name); - Configuration = new Dictionary(); ValidationAttributes = new List(); Attributes = new List(); Validators = new List>(); } + + [NotNull] + public string GetDisplayName( + [NotNull] IStringLocalizerFactory stringLocalizerFactory) + { + if (DisplayName != null) + { + return DisplayName.Localize(stringLocalizerFactory); + } + + var defaultStringLocalizer = stringLocalizerFactory.CreateDefaultOrNull(); + if (defaultStringLocalizer == null) + { + return Name; + } + + var localizedString = defaultStringLocalizer[$"DisplayName:{Name}"]; + if (!localizedString.ResourceNotFound) + { + return localizedString; + } + + localizedString = defaultStringLocalizer[Name]; + if (!localizedString.ResourceNotFound) + { + return localizedString; + } + + return Name; + } } } diff --git a/npm/packs/core/src/abp.js b/npm/packs/core/src/abp.js index 730db8bc97..fa42828306 100644 --- a/npm/packs/core/src/abp.js +++ b/npm/packs/core/src/abp.js @@ -76,10 +76,17 @@ var abp = abp || {}; abp.localization.values = {}; abp.localization.localize = function (key, sourceName) { + if (sourceName === '_') { //A convention to suppress the localization + return key; + } + sourceName = sourceName || abp.localization.defaultResourceName; + if (!sourceName) { + abp.log.warn('Localization source name is not specified and the defaultResourceName was not defined!'); + return key; + } var source = abp.localization.values[sourceName]; - if (!source) { abp.log.warn('Could not find localization source: ' + sourceName); return key; @@ -97,6 +104,29 @@ var abp = abp || {}; return abp.utils.formatString.apply(this, copiedArguments); }; + abp.localization.isLocalized = function (key, sourceName) { + if (sourceName === '_') { //A convention to suppress the localization + return true; + } + + sourceName = sourceName || abp.localization.defaultResourceName; + if (!sourceName) { + return false; + } + + var source = abp.localization.values[sourceName]; + if (!source) { + return false; + } + + var value = source[key]; + if (value === undefined) { + return false; + } + + return true; + }; + abp.localization.getResource = function (name) { return function () { var copiedArguments = Array.prototype.slice.call(arguments, 0); From 9f732f5b969b48809a0b51b093effe98ed170319 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ak=C4=B1n=20Sabri=20=C3=87am?= Date: Fri, 1 May 2020 21:43:13 +0300 Subject: [PATCH 27/67] updated a few abpioadmin localization keys --- .../Admin/Localization/Resources/en.json | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/abp_io/AbpIoLocalization/AbpIoLocalization/Admin/Localization/Resources/en.json b/abp_io/AbpIoLocalization/AbpIoLocalization/Admin/Localization/Resources/en.json index 07aa50adf2..67fddef8c7 100644 --- a/abp_io/AbpIoLocalization/AbpIoLocalization/Admin/Localization/Resources/en.json +++ b/abp_io/AbpIoLocalization/AbpIoLocalization/Admin/Localization/Resources/en.json @@ -13,8 +13,8 @@ "Permission:Edit": "Edit", "Permission:Delete": "Delete", "Permission:Create": "Create", - "Permission:Accounting": "Accounting", - "Permission:Accounting:Quotation": "Quotation", + "Permission:Accounting": "Accounting", + "Permission:Accounting:Quotation": "Quotation", "Menu:Organizations": "Organizations", "Menu:Accounting": "Accounting", "Menu:Packages": "Packages", @@ -101,13 +101,10 @@ "CompanyName": "Company name", "CompanyAddress": "Company address", "Price": "Price", -<<<<<<< Updated upstream "DiscountText": "Discount text", "DiscountQuantity": "Discount quantity", - "DiscountPrice": "Discount price", + "DiscountPrice": "Discount price", "Quotation": "Quotation", - "Generate": "Generate" -======= "ExtraText": "Extra Text", "ExtraAmount": "Extra Amount", "DownloadQuotation": "Download Quotation", @@ -119,7 +116,6 @@ "AddProduct": "Add Product", "NeedToAddProduct": "Need to add product to generate invoice !", "TotalPrice": "Total Price", - "Generate": "Generate" ->>>>>>> Stashed changes + "Generate": "Generate" } } \ No newline at end of file From 10b9ce3410b40c96094f976afd7069eb3e020716 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Fri, 1 May 2020 22:07:53 +0300 Subject: [PATCH 28/67] Add Format Arguments section --- docs/en/Localization.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/en/Localization.md b/docs/en/Localization.md index 53f62223cf..954fe8620f 100644 --- a/docs/en/Localization.md +++ b/docs/en/Localization.md @@ -181,6 +181,10 @@ public class MyService } ```` +##### Format Arguments + +Format arguments can be passed after the localization key. If your message is `Hello {0}, welcome!`, then you can pass the `{0}` argument to the localizer like `_localizer["HelloMessage", "John"]` + #### Simplest Usage In A Razor View/Page ````c# @@ -225,6 +229,17 @@ If you don't specify the localization resource name, it uses the default localiz var str = abp.localization.localize('HelloWorld'); //uses the default resource ```` +##### Format Arguments + +If your localized string contains arguments, like `Hello {0}, welcome!`, you can pass arguments to the localization methods. Examples: + +````js +var str1 = abp.localization.getResource('Test')('HelloWelcomeMessage', 'John'); +var str2 = abp.localization.localize('HelloWorld', 'Test', 'John'); +```` + +Both of the samples above produce the output `Hello John, welcome!`. + ## See Also * [Localization in Angular UI](UI/Angular/Localization.md) \ No newline at end of file From 06e665b755adf1fe8694da833dc382416cb969f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Fri, 1 May 2020 23:08:57 +0300 Subject: [PATCH 29/67] Use default localization resource. Introduce IHasNameWithLocalizableDisplayName. --- .../AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs | 14 ++++++-- .../AbpApplicationConfigurationAppService.cs | 12 ++++--- .../AbpValidationHtmlAttributeProvider.cs | 4 +-- ...ameWithLocalizableDisplayNameExtensions.cs | 36 +++++++++++++++++++ .../IHasNameWithLocalizableDisplayName.cs | 13 +++++++ .../ObjectExtensionPropertyInfo.cs | 32 +---------------- .../Abp/TextTemplating/TemplateDefinition.cs | 2 +- .../Abp/TextTemplating/TemplateRenderer.cs | 15 ++++++-- 8 files changed, 86 insertions(+), 42 deletions(-) create mode 100644 framework/src/Volo.Abp.Localization.Abstractions/Volo/Abp/Localization/HasNameWithLocalizableDisplayNameExtensions.cs create mode 100644 framework/src/Volo.Abp.Localization.Abstractions/Volo/Abp/Localization/IHasNameWithLocalizableDisplayName.cs diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs index d49e2c15e6..00ba8423b3 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs @@ -18,6 +18,7 @@ using Microsoft.AspNetCore.Mvc.Razor; using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure; using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Localization; using Volo.Abp.ApiVersioning; using Volo.Abp.AspNetCore.Mvc.ApiExploring; using Volo.Abp.AspNetCore.Mvc.Conventions; @@ -114,8 +115,17 @@ namespace Volo.Abp.AspNetCore.Mvc { options.DataAnnotationLocalizerProvider = (type, factory) => { - var resourceType = abpMvcDataAnnotationsLocalizationOptions.AssemblyResources.GetOrDefault(type.Assembly); - return factory.Create(resourceType ?? type); + var resourceType = abpMvcDataAnnotationsLocalizationOptions + .AssemblyResources + .GetOrDefault(type.Assembly); + + if (resourceType != null) + { + return factory.Create(resourceType); + } + + return factory.CreateDefaultOrNull() ?? + factory.Create(type); }; }) .AddViewLocalization(); //TODO: How to configure from the application? Also, consider to move to a UI module since APIs does not care about it. diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationAppService.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationAppService.cs index 52af9090fa..187823b663 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationAppService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationAppService.cs @@ -76,7 +76,7 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations }; } - protected virtual CurrentTenantDto GetCurrentTenant() + protected virtual CurrentTenantDto GetCurrentTenant() { return new CurrentTenantDto() { @@ -157,9 +157,13 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations } localizationConfig.CurrentCulture = GetCurrentCultureInfo(); - localizationConfig.DefaultResourceName = LocalizationResourceNameAttribute.GetName( - _localizationOptions.DefaultResourceType - ); + + if (_localizationOptions.DefaultResourceType != null) + { + localizationConfig.DefaultResourceName = LocalizationResourceNameAttribute.GetName( + _localizationOptions.DefaultResourceType + ); + } Logger.LogDebug("Executed AbpApplicationConfigurationAppService.GetLocalizationConfigAsync()"); diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ViewFeatures/AbpValidationHtmlAttributeProvider.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ViewFeatures/AbpValidationHtmlAttributeProvider.cs index 563ebe9d4a..84a3d05e25 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ViewFeatures/AbpValidationHtmlAttributeProvider.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ViewFeatures/AbpValidationHtmlAttributeProvider.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; -using System.Linq; using System.Reflection; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.DataAnnotations; @@ -14,6 +13,7 @@ using Microsoft.Extensions.Options; using Volo.Abp.AspNetCore.Mvc.ModelBinding; using Volo.Abp.AspNetCore.Mvc.Validation; using Volo.Abp.DependencyInjection; +using Volo.Abp.Localization; using Volo.Abp.ObjectExtending; using Volo.Abp.Validation.Localization; @@ -103,7 +103,7 @@ namespace Volo.Abp.AspNetCore.Mvc.ViewFeatures if (modelExplorer.Metadata is DefaultModelMetadata metadata) { metadata.DisplayMetadata.DisplayName = - () => extensionPropertyInfo.GetDisplayName(_stringLocalizerFactory); + () => extensionPropertyInfo.GetLocalizedDisplayName(_stringLocalizerFactory); } foreach (var validationAttribute in extensionPropertyInfo.GetValidationAttributes()) diff --git a/framework/src/Volo.Abp.Localization.Abstractions/Volo/Abp/Localization/HasNameWithLocalizableDisplayNameExtensions.cs b/framework/src/Volo.Abp.Localization.Abstractions/Volo/Abp/Localization/HasNameWithLocalizableDisplayNameExtensions.cs new file mode 100644 index 0000000000..4d42b73537 --- /dev/null +++ b/framework/src/Volo.Abp.Localization.Abstractions/Volo/Abp/Localization/HasNameWithLocalizableDisplayNameExtensions.cs @@ -0,0 +1,36 @@ +using System; +using JetBrains.Annotations; +using Microsoft.Extensions.Localization; + +namespace Volo.Abp.Localization +{ + public static class HasNameWithLocalizableDisplayNameExtensions + { + [NotNull] + public static string GetLocalizedDisplayName( + [NotNull] this IHasNameWithLocalizableDisplayName source, + [NotNull] IStringLocalizerFactory stringLocalizerFactory, + [CanBeNull] string localizationNamePrefix = "DisplayName:") + { + if (source.DisplayName != null) + { + return source.DisplayName.Localize(stringLocalizerFactory); + } + + var defaultStringLocalizer = stringLocalizerFactory.CreateDefaultOrNull(); + if (defaultStringLocalizer == null) + { + return source.Name; + } + + var localizedString = defaultStringLocalizer[$"{localizationNamePrefix}{source.Name}"]; + if (!localizedString.ResourceNotFound || + localizationNamePrefix.IsNullOrEmpty()) + { + return localizedString; + } + + return defaultStringLocalizer[source.Name]; + } + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.Localization.Abstractions/Volo/Abp/Localization/IHasNameWithLocalizableDisplayName.cs b/framework/src/Volo.Abp.Localization.Abstractions/Volo/Abp/Localization/IHasNameWithLocalizableDisplayName.cs new file mode 100644 index 0000000000..8be0d7d2de --- /dev/null +++ b/framework/src/Volo.Abp.Localization.Abstractions/Volo/Abp/Localization/IHasNameWithLocalizableDisplayName.cs @@ -0,0 +1,13 @@ +using JetBrains.Annotations; + +namespace Volo.Abp.Localization +{ + public interface IHasNameWithLocalizableDisplayName + { + [NotNull] + public string Name { get; } + + [CanBeNull] + public ILocalizableString DisplayName { get; } + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionPropertyInfo.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionPropertyInfo.cs index 59f42b1494..5d55325477 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionPropertyInfo.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionPropertyInfo.cs @@ -7,7 +7,7 @@ using Volo.Abp.Localization; namespace Volo.Abp.ObjectExtending { - public class ObjectExtensionPropertyInfo + public class ObjectExtensionPropertyInfo : IHasNameWithLocalizableDisplayName { [NotNull] public ObjectExtensionInfo ObjectExtension { get; } @@ -62,35 +62,5 @@ namespace Volo.Abp.ObjectExtending Attributes = new List(); Validators = new List>(); } - - [NotNull] - public string GetDisplayName( - [NotNull] IStringLocalizerFactory stringLocalizerFactory) - { - if (DisplayName != null) - { - return DisplayName.Localize(stringLocalizerFactory); - } - - var defaultStringLocalizer = stringLocalizerFactory.CreateDefaultOrNull(); - if (defaultStringLocalizer == null) - { - return Name; - } - - var localizedString = defaultStringLocalizer[$"DisplayName:{Name}"]; - if (!localizedString.ResourceNotFound) - { - return localizedString; - } - - localizedString = defaultStringLocalizer[Name]; - if (!localizedString.ResourceNotFound) - { - return localizedString; - } - - return Name; - } } } diff --git a/framework/src/Volo.Abp.TextTemplating/Volo/Abp/TextTemplating/TemplateDefinition.cs b/framework/src/Volo.Abp.TextTemplating/Volo/Abp/TextTemplating/TemplateDefinition.cs index db2ccf6f63..948c1712db 100644 --- a/framework/src/Volo.Abp.TextTemplating/Volo/Abp/TextTemplating/TemplateDefinition.cs +++ b/framework/src/Volo.Abp.TextTemplating/Volo/Abp/TextTemplating/TemplateDefinition.cs @@ -5,7 +5,7 @@ using Volo.Abp.Localization; namespace Volo.Abp.TextTemplating { - public class TemplateDefinition + public class TemplateDefinition : IHasNameWithLocalizableDisplayName { public const int MaxNameLength = 128; diff --git a/framework/src/Volo.Abp.TextTemplating/Volo/Abp/TextTemplating/TemplateRenderer.cs b/framework/src/Volo.Abp.TextTemplating/Volo/Abp/TextTemplating/TemplateRenderer.cs index f51e8447b0..86eb684f52 100644 --- a/framework/src/Volo.Abp.TextTemplating/Volo/Abp/TextTemplating/TemplateRenderer.cs +++ b/framework/src/Volo.Abp.TextTemplating/Volo/Abp/TextTemplating/TemplateRenderer.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Threading.Tasks; using JetBrains.Annotations; using Microsoft.Extensions.Localization; +using Microsoft.Extensions.Options; using Scriban; using Scriban.Runtime; using Volo.Abp.DependencyInjection; @@ -136,9 +137,9 @@ namespace Volo.Abp.TextTemplating scriptObject["model"] = model; } - if (templateDefinition.LocalizationResource != null) + var localizer = GetLocalizerOrNull(templateDefinition); + if (localizer != null) { - var localizer = _stringLocalizerFactory.Create(templateDefinition.LocalizationResource); scriptObject.Import( "L", new Func( @@ -151,5 +152,15 @@ namespace Volo.Abp.TextTemplating return context; } + + private IStringLocalizer GetLocalizerOrNull(TemplateDefinition templateDefinition) + { + if (templateDefinition.LocalizationResource != null) + { + return _stringLocalizerFactory.Create(templateDefinition.LocalizationResource); + } + + return _stringLocalizerFactory.CreateDefaultOrNull(); + } } } \ No newline at end of file From 407807fe971c0396b8b26461d18e5e5596c9eafa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Sat, 2 May 2020 00:02:51 +0300 Subject: [PATCH 30/67] Add ModuleObjectExtensionConfigurationHelper --- ...ityObjectPropertyExtensionConfiguration.cs | 2 +- ...oduleObjectExtensionConfigurationHelper.cs | 70 +++++++++++++++++++ 2 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfigurationHelper.cs diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionConfiguration.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionConfiguration.cs index bf965ba955..ac4d7ad73f 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionConfiguration.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionConfiguration.cs @@ -5,7 +5,7 @@ using Volo.Abp.Localization; namespace Volo.Abp.ObjectExtending { - public class ModuleEntityObjectPropertyExtensionConfiguration + public class ModuleEntityObjectPropertyExtensionConfiguration : IHasNameWithLocalizableDisplayName { [NotNull] public ModuleEntityObjectExtensionConfiguration EntityObjectExtensionConfiguration { get; } diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfigurationHelper.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfigurationHelper.cs new file mode 100644 index 0000000000..b8ab6b5516 --- /dev/null +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfigurationHelper.cs @@ -0,0 +1,70 @@ +using System; +using System.Collections.Generic; +using JetBrains.Annotations; + +namespace Volo.Abp.ObjectExtending +{ + public static class ModuleObjectExtensionConfigurationHelper + { + public static void ApplyModuleObjectExtensionConfigurations( + string moduleName, + string objectName, + Type[] createFormTypes = null, + Type[] editFormTypes = null + ) + { + foreach (var propertyConfig in GetPropertyConfigurations(moduleName, objectName)) + { + if (propertyConfig.UI.CreateForm.IsVisible && + createFormTypes != null) + { + ApplyPropertyConfigurationToTypes(propertyConfig, createFormTypes); + } + + if (propertyConfig.UI.EditForm.IsVisible && + editFormTypes != null) + { + ApplyPropertyConfigurationToTypes(propertyConfig, editFormTypes); + } + } + } + + [NotNull] + public static IEnumerable GetPropertyConfigurations( + string moduleName, + string objectName) + { + var moduleConfig = ObjectExtensionManager.Instance.Modules.GetOrDefault(moduleName); + if (moduleConfig == null) + { + return Array.Empty(); + } + + var objectConfig = moduleConfig.GetOrDefault(objectName); + if (objectConfig == null) + { + return Array.Empty(); + } + + return objectConfig.GetProperties(); + } + + public static void ApplyPropertyConfigurationToTypes( + ModuleEntityObjectPropertyExtensionConfiguration propertyConfig, + Type[] types) + { + ObjectExtensionManager.Instance + .AddOrUpdateProperty( + types, + propertyConfig.Type, + propertyConfig.Name, + property => + { + property.Attributes.AddRange(propertyConfig.Attributes); + property.DisplayName = propertyConfig.DisplayName; + property.Validators.AddRange(propertyConfig.Validators); + } + ); + } + } +} From d319fe2525f6b2fea98e2678c73a661ba23bcc46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Sat, 2 May 2020 00:48:56 +0300 Subject: [PATCH 31/67] Added API config for extra properties. --- .../CachedObjectExtensionsDtoService.cs | 29 ++++++++++++++----- ...ObjectPropertyExtensionApiConfiguration.cs | 23 +++++++++++++++ ...PropertyExtensionApiCreateConfiguration.cs | 13 +++++++++ ...ectPropertyExtensionApiGetConfiguration.cs | 13 +++++++++ ...PropertyExtensionApiUpdateConfiguration.cs | 13 +++++++++ .../ModuleObjectExtraPropertyExtensionDto.cs | 2 ++ ...ModuleObjectExtraPropertyUiExtensionDto.cs | 6 ++-- ...ObjectPropertyExtensionApiConfiguration.cs | 23 +++++++++++++++ ...PropertyExtensionApiCreateConfiguration.cs | 10 +++++++ ...ectPropertyExtensionApiGetConfiguration.cs | 10 +++++++ ...PropertyExtensionApiUpdateConfiguration.cs | 10 +++++++ ...ityObjectPropertyExtensionConfiguration.cs | 4 +++ ...yObjectPropertyExtensionUIConfiguration.cs | 12 ++++---- ...oduleObjectExtensionConfigurationHelper.cs | 27 +++++++++++++++-- 14 files changed, 176 insertions(+), 19 deletions(-) create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleEntityObjectPropertyExtensionApiConfiguration.cs create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleEntityObjectPropertyExtensionApiCreateConfiguration.cs create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleEntityObjectPropertyExtensionApiGetConfiguration.cs create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleEntityObjectPropertyExtensionApiUpdateConfiguration.cs create mode 100644 framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionApiConfiguration.cs create mode 100644 framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionApiCreateConfiguration.cs create mode 100644 framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionApiGetConfiguration.cs create mode 100644 framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionApiUpdateConfiguration.cs diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/CachedObjectExtensionsDtoService.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/CachedObjectExtensionsDtoService.cs index d400cc1d56..d59c458eb0 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/CachedObjectExtensionsDtoService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/CachedObjectExtensionsDtoService.cs @@ -58,21 +58,36 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending { Type = TypeHelper.GetFullNameHandlingNullableAndGenerics(propertyConfig.Type), TypeSimple = TypeHelper.GetSimplifiedName(propertyConfig.Type), - Attributes = new List(), + Attributes = new List(), DisplayName = CreateDisplayNameDto(propertyConfig), + Api = new ModuleEntityObjectPropertyExtensionApiConfigurationDto + { + OnGet = new ModuleEntityObjectPropertyExtensionApiGetConfigurationDto + { + IsAvailable = propertyConfig.Api.OnGet.IsAvailable + }, + OnCreate = new ModuleEntityObjectPropertyExtensionApiCreateConfigurationDto + { + IsAvailable = propertyConfig.Api.OnCreate.IsAvailable + }, + OnUpdate = new ModuleEntityObjectPropertyExtensionApiUpdateConfigurationDto + { + IsAvailable = propertyConfig.Api.OnUpdate.IsAvailable + } + }, Ui = new ModuleObjectExtraPropertyUiExtensionDto { - CreateForm = new ModuleObjectExtraPropertyUiFormExtensionDto + OnCreateForm = new ModuleObjectExtraPropertyUiFormExtensionDto { - IsVisible = propertyConfig.UI.CreateForm.IsVisible + IsVisible = propertyConfig.UI.OnCreateForm.IsVisible }, - EditForm = new ModuleObjectExtraPropertyUiFormExtensionDto + OnEditForm = new ModuleObjectExtraPropertyUiFormExtensionDto { - IsVisible = propertyConfig.UI.EditForm.IsVisible + IsVisible = propertyConfig.UI.OnEditForm.IsVisible }, - Table = new ModuleObjectExtraPropertyUiTableExtensionDto + OnTable = new ModuleObjectExtraPropertyUiTableExtensionDto { - IsVisible = propertyConfig.UI.Table.IsVisible + IsVisible = propertyConfig.UI.OnTable.IsVisible } } }; diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleEntityObjectPropertyExtensionApiConfiguration.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleEntityObjectPropertyExtensionApiConfiguration.cs new file mode 100644 index 0000000000..9f4d1db42c --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleEntityObjectPropertyExtensionApiConfiguration.cs @@ -0,0 +1,23 @@ +using JetBrains.Annotations; + +namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending +{ + public class ModuleEntityObjectPropertyExtensionApiConfigurationDto + { + [NotNull] + public ModuleEntityObjectPropertyExtensionApiGetConfigurationDto OnGet { get; set; } + + [NotNull] + public ModuleEntityObjectPropertyExtensionApiCreateConfigurationDto OnCreate { get; set; } + + [NotNull] + public ModuleEntityObjectPropertyExtensionApiUpdateConfigurationDto OnUpdate { get; set; } + + public ModuleEntityObjectPropertyExtensionApiConfigurationDto() + { + OnGet = new ModuleEntityObjectPropertyExtensionApiGetConfigurationDto(); + OnCreate = new ModuleEntityObjectPropertyExtensionApiCreateConfigurationDto(); + OnUpdate = new ModuleEntityObjectPropertyExtensionApiUpdateConfigurationDto(); + } + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleEntityObjectPropertyExtensionApiCreateConfiguration.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleEntityObjectPropertyExtensionApiCreateConfiguration.cs new file mode 100644 index 0000000000..7cfa9959b0 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleEntityObjectPropertyExtensionApiCreateConfiguration.cs @@ -0,0 +1,13 @@ +using System; + +namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending +{ + [Serializable] + public class ModuleEntityObjectPropertyExtensionApiCreateConfigurationDto + { + /// + /// Default: true. + /// + public bool IsAvailable { get; set; } = true; + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleEntityObjectPropertyExtensionApiGetConfiguration.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleEntityObjectPropertyExtensionApiGetConfiguration.cs new file mode 100644 index 0000000000..20bf7682c3 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleEntityObjectPropertyExtensionApiGetConfiguration.cs @@ -0,0 +1,13 @@ +using System; + +namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending +{ + [Serializable] + public class ModuleEntityObjectPropertyExtensionApiGetConfigurationDto + { + /// + /// Default: true. + /// + public bool IsAvailable { get; set; } = true; + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleEntityObjectPropertyExtensionApiUpdateConfiguration.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleEntityObjectPropertyExtensionApiUpdateConfiguration.cs new file mode 100644 index 0000000000..3000965957 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleEntityObjectPropertyExtensionApiUpdateConfiguration.cs @@ -0,0 +1,13 @@ +using System; + +namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending +{ + [Serializable] + public class ModuleEntityObjectPropertyExtensionApiUpdateConfigurationDto + { + /// + /// Default: true. + /// + public bool IsAvailable { get; set; } = true; + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyExtensionDto.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyExtensionDto.cs index 661da59f60..d61c49d327 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyExtensionDto.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyExtensionDto.cs @@ -14,6 +14,8 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending [CanBeNull] public LocalizableStringDto DisplayName { get; set; } + public ModuleEntityObjectPropertyExtensionApiConfigurationDto Api { get; set; } + public ModuleObjectExtraPropertyUiExtensionDto Ui { get; set; } public List Attributes { get; set; } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyUiExtensionDto.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyUiExtensionDto.cs index fcb39f67c6..8a24a3895c 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyUiExtensionDto.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyUiExtensionDto.cs @@ -5,8 +5,8 @@ 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; } + public ModuleObjectExtraPropertyUiTableExtensionDto OnTable { get; set; } + public ModuleObjectExtraPropertyUiFormExtensionDto OnCreateForm { get; set; } + public ModuleObjectExtraPropertyUiFormExtensionDto OnEditForm { get; set; } } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionApiConfiguration.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionApiConfiguration.cs new file mode 100644 index 0000000000..6fdce01246 --- /dev/null +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionApiConfiguration.cs @@ -0,0 +1,23 @@ +using JetBrains.Annotations; + +namespace Volo.Abp.ObjectExtending +{ + public class ModuleEntityObjectPropertyExtensionApiConfiguration + { + [NotNull] + public ModuleEntityObjectPropertyExtensionApiGetConfiguration OnGet { get; } + + [NotNull] + public ModuleEntityObjectPropertyExtensionApiCreateConfiguration OnCreate { get; } + + [NotNull] + public ModuleEntityObjectPropertyExtensionApiUpdateConfiguration OnUpdate { get; } + + public ModuleEntityObjectPropertyExtensionApiConfiguration() + { + OnGet = new ModuleEntityObjectPropertyExtensionApiGetConfiguration(); + OnCreate = new ModuleEntityObjectPropertyExtensionApiCreateConfiguration(); + OnUpdate = new ModuleEntityObjectPropertyExtensionApiUpdateConfiguration(); + } + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionApiCreateConfiguration.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionApiCreateConfiguration.cs new file mode 100644 index 0000000000..9d4c976ce2 --- /dev/null +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionApiCreateConfiguration.cs @@ -0,0 +1,10 @@ +namespace Volo.Abp.ObjectExtending +{ + public class ModuleEntityObjectPropertyExtensionApiCreateConfiguration + { + /// + /// Default: true. + /// + public bool IsAvailable { get; set; } = true; + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionApiGetConfiguration.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionApiGetConfiguration.cs new file mode 100644 index 0000000000..bb5ec447d8 --- /dev/null +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionApiGetConfiguration.cs @@ -0,0 +1,10 @@ +namespace Volo.Abp.ObjectExtending +{ + public class ModuleEntityObjectPropertyExtensionApiGetConfiguration + { + /// + /// Default: true. + /// + public bool IsAvailable { get; set; } = true; + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionApiUpdateConfiguration.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionApiUpdateConfiguration.cs new file mode 100644 index 0000000000..88b2b5b744 --- /dev/null +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionApiUpdateConfiguration.cs @@ -0,0 +1,10 @@ +namespace Volo.Abp.ObjectExtending +{ + public class ModuleEntityObjectPropertyExtensionApiUpdateConfiguration + { + /// + /// Default: true. + /// + public bool IsAvailable { get; set; } = true; + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionConfiguration.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionConfiguration.cs index ac4d7ad73f..0259dce5d0 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionConfiguration.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionConfiguration.cs @@ -30,6 +30,9 @@ namespace Volo.Abp.ObjectExtending [NotNull] public ModuleEntityObjectPropertyExtensionUIConfiguration UI { get; } + + [NotNull] + public ModuleEntityObjectPropertyExtensionApiConfiguration Api { get; } public ModuleEntityObjectPropertyExtensionConfiguration( [NotNull] ModuleEntityObjectExtensionConfiguration entityObjectExtensionConfiguration, @@ -45,6 +48,7 @@ namespace Volo.Abp.ObjectExtending Validators = new List>(); UI = new ModuleEntityObjectPropertyExtensionUIConfiguration(); + Api = new ModuleEntityObjectPropertyExtensionApiConfiguration(); } } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionUIConfiguration.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionUIConfiguration.cs index 352b714ff0..64270be7fa 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionUIConfiguration.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionUIConfiguration.cs @@ -5,19 +5,19 @@ namespace Volo.Abp.ObjectExtending public class ModuleEntityObjectPropertyExtensionUIConfiguration { [NotNull] - public ModuleEntityObjectPropertyExtensionUITableConfiguration Table { get; } + public ModuleEntityObjectPropertyExtensionUITableConfiguration OnTable { get; } [NotNull] - public ModuleEntityObjectPropertyExtensionUIFormConfiguration CreateForm { get; } + public ModuleEntityObjectPropertyExtensionUIFormConfiguration OnCreateForm { get; } [NotNull] - public ModuleEntityObjectPropertyExtensionUIFormConfiguration EditForm { get; } + public ModuleEntityObjectPropertyExtensionUIFormConfiguration OnEditForm { get; } public ModuleEntityObjectPropertyExtensionUIConfiguration() { - Table = new ModuleEntityObjectPropertyExtensionUITableConfiguration(); - CreateForm = new ModuleEntityObjectPropertyExtensionUIFormConfiguration(); - EditForm = new ModuleEntityObjectPropertyExtensionUIFormConfiguration(); + OnTable = new ModuleEntityObjectPropertyExtensionUITableConfiguration(); + OnCreateForm = new ModuleEntityObjectPropertyExtensionUIFormConfiguration(); + OnEditForm = new ModuleEntityObjectPropertyExtensionUIFormConfiguration(); } } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfigurationHelper.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfigurationHelper.cs index b8ab6b5516..91a329d984 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfigurationHelper.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfigurationHelper.cs @@ -10,22 +10,43 @@ namespace Volo.Abp.ObjectExtending string moduleName, string objectName, Type[] createFormTypes = null, - Type[] editFormTypes = null + Type[] editFormTypes = null, + Type[] getApiTypes = null, + Type[] createApiTypes = null, + Type[] updateApiTypes = null ) { foreach (var propertyConfig in GetPropertyConfigurations(moduleName, objectName)) { - if (propertyConfig.UI.CreateForm.IsVisible && + if (propertyConfig.UI.OnCreateForm.IsVisible && createFormTypes != null) { ApplyPropertyConfigurationToTypes(propertyConfig, createFormTypes); } - if (propertyConfig.UI.EditForm.IsVisible && + if (propertyConfig.UI.OnEditForm.IsVisible && editFormTypes != null) { ApplyPropertyConfigurationToTypes(propertyConfig, editFormTypes); } + + if (propertyConfig.Api.OnGet.IsAvailable && + getApiTypes != null) + { + ApplyPropertyConfigurationToTypes(propertyConfig, getApiTypes); + } + + if (propertyConfig.Api.OnCreate.IsAvailable && + createApiTypes != null) + { + ApplyPropertyConfigurationToTypes(propertyConfig, createApiTypes); + } + + if (propertyConfig.Api.OnUpdate.IsAvailable && + updateApiTypes != null) + { + ApplyPropertyConfigurationToTypes(propertyConfig, updateApiTypes); + } } } From c00233278160de3457aa0fc1843c7f17d8fb4375 Mon Sep 17 00:00:00 2001 From: Alper Ebicoglu Date: Sat, 2 May 2020 01:02:09 +0300 Subject: [PATCH 32/67] add invoice --- .../AbpIoLocalization/Admin/Localization/Resources/en.json | 1 + 1 file changed, 1 insertion(+) diff --git a/abp_io/AbpIoLocalization/AbpIoLocalization/Admin/Localization/Resources/en.json b/abp_io/AbpIoLocalization/AbpIoLocalization/Admin/Localization/Resources/en.json index 67fddef8c7..eedc323adc 100644 --- a/abp_io/AbpIoLocalization/AbpIoLocalization/Admin/Localization/Resources/en.json +++ b/abp_io/AbpIoLocalization/AbpIoLocalization/Admin/Localization/Resources/en.json @@ -15,6 +15,7 @@ "Permission:Create": "Create", "Permission:Accounting": "Accounting", "Permission:Accounting:Quotation": "Quotation", + "Permission:Accounting:Invoice": "Invoice", "Menu:Organizations": "Organizations", "Menu:Accounting": "Accounting", "Menu:Packages": "Packages", From e75005ceeda995c95dd670389dbd0d181a0296ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Sat, 2 May 2020 01:09:33 +0300 Subject: [PATCH 33/67] Added Entity configuration for object extensions --- ...ityObjectPropertyExtensionConfiguration.cs | 6 +- ...ectPropertyExtensionEntityConfiguration.cs | 10 ++ ...oduleObjectExtensionConfigurationHelper.cs | 91 +++++++++++++++---- .../Abp/Identity/AbpIdentityDomainModule.cs | 10 ++ 4 files changed, 99 insertions(+), 18 deletions(-) create mode 100644 framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionEntityConfiguration.cs diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionConfiguration.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionConfiguration.cs index 0259dce5d0..e4450d4dfd 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionConfiguration.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionConfiguration.cs @@ -27,7 +27,10 @@ namespace Volo.Abp.ObjectExtending [NotNull] public Dictionary Configuration { get; } - + + [NotNull] + public ModuleEntityObjectPropertyExtensionEntityConfiguration Entity { get; } + [NotNull] public ModuleEntityObjectPropertyExtensionUIConfiguration UI { get; } @@ -47,6 +50,7 @@ namespace Volo.Abp.ObjectExtending Attributes = new List(); Validators = new List>(); + Entity = new ModuleEntityObjectPropertyExtensionEntityConfiguration(); UI = new ModuleEntityObjectPropertyExtensionUIConfiguration(); Api = new ModuleEntityObjectPropertyExtensionApiConfiguration(); } diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionEntityConfiguration.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionEntityConfiguration.cs new file mode 100644 index 0000000000..8a683ab81e --- /dev/null +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionEntityConfiguration.cs @@ -0,0 +1,10 @@ +namespace Volo.Abp.ObjectExtending +{ + public class ModuleEntityObjectPropertyExtensionEntityConfiguration + { + /// + /// Default: true. + /// + public bool IsAvailable { get; set; } = true; + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfigurationHelper.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfigurationHelper.cs index 91a329d984..94056f3251 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfigurationHelper.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfigurationHelper.cs @@ -6,30 +6,30 @@ namespace Volo.Abp.ObjectExtending { public static class ModuleObjectExtensionConfigurationHelper { - public static void ApplyModuleObjectExtensionConfigurations( + public static void ApplyModuleObjectExtensionConfigurationToEntity( string moduleName, string objectName, - Type[] createFormTypes = null, - Type[] editFormTypes = null, - Type[] getApiTypes = null, - Type[] createApiTypes = null, - Type[] updateApiTypes = null - ) + Type entityType) { foreach (var propertyConfig in GetPropertyConfigurations(moduleName, objectName)) { - if (propertyConfig.UI.OnCreateForm.IsVisible && - createFormTypes != null) + if (propertyConfig.Entity.IsAvailable && + entityType != null) { - ApplyPropertyConfigurationToTypes(propertyConfig, createFormTypes); - } - - if (propertyConfig.UI.OnEditForm.IsVisible && - editFormTypes != null) - { - ApplyPropertyConfigurationToTypes(propertyConfig, editFormTypes); + ApplyPropertyConfigurationToTypes(propertyConfig, new[] { entityType }); } + } + } + public static void ApplyModuleObjectExtensionConfigurationToApi( + string moduleName, + string objectName, + Type[] getApiTypes = null, + Type[] createApiTypes = null, + Type[] updateApiTypes = null) + { + foreach (var propertyConfig in GetPropertyConfigurations(moduleName, objectName)) + { if (propertyConfig.Api.OnGet.IsAvailable && getApiTypes != null) { @@ -50,9 +50,66 @@ namespace Volo.Abp.ObjectExtending } } + public static void ApplyModuleObjectExtensionConfigurationToUI( + string moduleName, + string objectName, + Type[] createFormTypes = null, + Type[] editFormTypes = null) + { + foreach (var propertyConfig in GetPropertyConfigurations(moduleName, objectName)) + { + if (propertyConfig.UI.OnCreateForm.IsVisible && + createFormTypes != null) + { + ApplyPropertyConfigurationToTypes(propertyConfig, createFormTypes); + } + + if (propertyConfig.UI.OnEditForm.IsVisible && + editFormTypes != null) + { + ApplyPropertyConfigurationToTypes(propertyConfig, editFormTypes); + } + } + } + + public static void ApplyModuleObjectExtensionConfigurations( + string moduleName, + string objectName, + Type entityType = null, + Type[] createFormTypes = null, + Type[] editFormTypes = null, + Type[] getApiTypes = null, + Type[] createApiTypes = null, + Type[] updateApiTypes = null) + { + if (entityType != null) + { + ApplyModuleObjectExtensionConfigurationToEntity( + moduleName, + objectName, + entityType + ); + } + + ApplyModuleObjectExtensionConfigurationToApi( + moduleName, + objectName, + getApiTypes: getApiTypes, + createApiTypes: createApiTypes, + updateApiTypes: updateApiTypes + ); + + ApplyModuleObjectExtensionConfigurationToUI( + moduleName, + objectName, + createFormTypes: createFormTypes, + editFormTypes: editFormTypes + ); + } + [NotNull] public static IEnumerable GetPropertyConfigurations( - string moduleName, + string moduleName, string objectName) { var moduleConfig = ObjectExtensionManager.Instance.Modules.GetOrDefault(moduleName); diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/AbpIdentityDomainModule.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/AbpIdentityDomainModule.cs index 12af875bab..d1413d4cb8 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/AbpIdentityDomainModule.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/AbpIdentityDomainModule.cs @@ -6,6 +6,7 @@ using Volo.Abp.AutoMapper; using Volo.Abp.Domain; using Volo.Abp.EventBus.Distributed; using Volo.Abp.Modularity; +using Volo.Abp.ObjectExtending; using Volo.Abp.Users; namespace Volo.Abp.Identity @@ -45,6 +46,15 @@ namespace Volo.Abp.Identity AddAbpIdentityOptionsFactory(context.Services); } + public override void PostConfigureServices(ServiceConfigurationContext context) + { + ModuleObjectExtensionConfigurationHelper.ApplyModuleObjectExtensionConfigurationToEntity( + "Identity", + "User", + typeof(IdentityUser) + ); + } + private static void AddAbpIdentityOptionsFactory(IServiceCollection services) { services.Replace(ServiceDescriptor.Transient, AbpIdentityOptionsFactory>()); From 3ca475804d56a504840363747f228ce328013fa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Sat, 2 May 2020 01:17:12 +0300 Subject: [PATCH 34/67] Move related classes to the Volo.Abp.ObjectExtending.Modularity namespace --- .../ObjectExtending/CachedObjectExtensionsDtoService.cs | 1 + .../ModuleEntityObjectExtensionConfiguration.cs | 2 +- .../ModuleEntityObjectPropertyExtensionApiConfiguration.cs | 2 +- ...duleEntityObjectPropertyExtensionApiCreateConfiguration.cs | 2 +- .../ModuleEntityObjectPropertyExtensionApiGetConfiguration.cs | 2 +- ...duleEntityObjectPropertyExtensionApiUpdateConfiguration.cs | 2 +- .../ModuleEntityObjectPropertyExtensionConfiguration.cs | 2 +- .../ModuleEntityObjectPropertyExtensionEntityConfiguration.cs | 2 +- .../ModuleEntityObjectPropertyExtensionUIConfiguration.cs | 2 +- .../ModuleEntityObjectPropertyExtensionUIFormConfiguration.cs | 2 +- ...ModuleEntityObjectPropertyExtensionUITableConfiguration.cs | 2 +- .../{ => Modularity}/ModuleObjectExtensionConfiguration.cs | 2 +- .../ModuleObjectExtensionConfigurationDictionary.cs | 2 +- .../ModuleObjectExtensionConfigurationDictionaryExtensions.cs | 2 +- .../ModuleObjectExtensionConfigurationExtensions.cs | 2 +- .../ModuleObjectExtensionConfigurationHelper.cs | 2 +- .../Volo/Abp/ObjectExtending/ObjectExtensionManager.cs | 1 + .../IdentityModuleObjectExtensionConfiguration.cs | 4 +++- .../IdentityModuleObjectExtensionConfigurationExtensions.cs | 1 + .../IdentityModuleObjectExtensionConfigurationsExtensions.cs | 1 + .../Volo/Abp/Identity/AbpIdentityDomainModule.cs | 2 +- 21 files changed, 23 insertions(+), 17 deletions(-) rename framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/{ => Modularity}/ModuleEntityObjectExtensionConfiguration.cs (97%) rename framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/{ => Modularity}/ModuleEntityObjectPropertyExtensionApiConfiguration.cs (94%) rename framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/{ => Modularity}/ModuleEntityObjectPropertyExtensionApiCreateConfiguration.cs (81%) rename framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/{ => Modularity}/ModuleEntityObjectPropertyExtensionApiGetConfiguration.cs (80%) rename framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/{ => Modularity}/ModuleEntityObjectPropertyExtensionApiUpdateConfiguration.cs (81%) rename framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/{ => Modularity}/ModuleEntityObjectPropertyExtensionConfiguration.cs (97%) rename framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/{ => Modularity}/ModuleEntityObjectPropertyExtensionEntityConfiguration.cs (80%) rename framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/{ => Modularity}/ModuleEntityObjectPropertyExtensionUIConfiguration.cs (94%) rename framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/{ => Modularity}/ModuleEntityObjectPropertyExtensionUIFormConfiguration.cs (80%) rename framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/{ => Modularity}/ModuleEntityObjectPropertyExtensionUITableConfiguration.cs (80%) rename framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/{ => Modularity}/ModuleObjectExtensionConfiguration.cs (78%) rename framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/{ => Modularity}/ModuleObjectExtensionConfigurationDictionary.cs (78%) rename framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/{ => Modularity}/ModuleObjectExtensionConfigurationDictionaryExtensions.cs (94%) rename framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/{ => Modularity}/ModuleObjectExtensionConfigurationExtensions.cs (93%) rename framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/{ => Modularity}/ModuleObjectExtensionConfigurationHelper.cs (99%) diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/CachedObjectExtensionsDtoService.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/CachedObjectExtensionsDtoService.cs index d59c458eb0..65d23eea06 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/CachedObjectExtensionsDtoService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/CachedObjectExtensionsDtoService.cs @@ -2,6 +2,7 @@ using Volo.Abp.DependencyInjection; using Volo.Abp.Localization; using Volo.Abp.ObjectExtending; +using Volo.Abp.ObjectExtending.Modularity; using Volo.Abp.Reflection; namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectExtensionConfiguration.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectExtensionConfiguration.cs similarity index 97% rename from framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectExtensionConfiguration.cs rename to framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectExtensionConfiguration.cs index c6d71149e4..3e1c3ef136 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectExtensionConfiguration.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectExtensionConfiguration.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Collections.Immutable; using JetBrains.Annotations; -namespace Volo.Abp.ObjectExtending +namespace Volo.Abp.ObjectExtending.Modularity { public class ModuleEntityObjectExtensionConfiguration { diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionApiConfiguration.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionApiConfiguration.cs similarity index 94% rename from framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionApiConfiguration.cs rename to framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionApiConfiguration.cs index 6fdce01246..ff195d2653 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionApiConfiguration.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionApiConfiguration.cs @@ -1,6 +1,6 @@ using JetBrains.Annotations; -namespace Volo.Abp.ObjectExtending +namespace Volo.Abp.ObjectExtending.Modularity { public class ModuleEntityObjectPropertyExtensionApiConfiguration { diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionApiCreateConfiguration.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionApiCreateConfiguration.cs similarity index 81% rename from framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionApiCreateConfiguration.cs rename to framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionApiCreateConfiguration.cs index 9d4c976ce2..2c8c812f8c 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionApiCreateConfiguration.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionApiCreateConfiguration.cs @@ -1,4 +1,4 @@ -namespace Volo.Abp.ObjectExtending +namespace Volo.Abp.ObjectExtending.Modularity { public class ModuleEntityObjectPropertyExtensionApiCreateConfiguration { diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionApiGetConfiguration.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionApiGetConfiguration.cs similarity index 80% rename from framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionApiGetConfiguration.cs rename to framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionApiGetConfiguration.cs index bb5ec447d8..5c43e8397c 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionApiGetConfiguration.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionApiGetConfiguration.cs @@ -1,4 +1,4 @@ -namespace Volo.Abp.ObjectExtending +namespace Volo.Abp.ObjectExtending.Modularity { public class ModuleEntityObjectPropertyExtensionApiGetConfiguration { diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionApiUpdateConfiguration.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionApiUpdateConfiguration.cs similarity index 81% rename from framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionApiUpdateConfiguration.cs rename to framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionApiUpdateConfiguration.cs index 88b2b5b744..58355f44fa 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionApiUpdateConfiguration.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionApiUpdateConfiguration.cs @@ -1,4 +1,4 @@ -namespace Volo.Abp.ObjectExtending +namespace Volo.Abp.ObjectExtending.Modularity { public class ModuleEntityObjectPropertyExtensionApiUpdateConfiguration { diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionConfiguration.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionConfiguration.cs similarity index 97% rename from framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionConfiguration.cs rename to framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionConfiguration.cs index e4450d4dfd..52d88c8e26 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionConfiguration.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionConfiguration.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using JetBrains.Annotations; using Volo.Abp.Localization; -namespace Volo.Abp.ObjectExtending +namespace Volo.Abp.ObjectExtending.Modularity { public class ModuleEntityObjectPropertyExtensionConfiguration : IHasNameWithLocalizableDisplayName { diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionEntityConfiguration.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionEntityConfiguration.cs similarity index 80% rename from framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionEntityConfiguration.cs rename to framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionEntityConfiguration.cs index 8a683ab81e..8ca9fc7cf5 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionEntityConfiguration.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionEntityConfiguration.cs @@ -1,4 +1,4 @@ -namespace Volo.Abp.ObjectExtending +namespace Volo.Abp.ObjectExtending.Modularity { public class ModuleEntityObjectPropertyExtensionEntityConfiguration { diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionUIConfiguration.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionUIConfiguration.cs similarity index 94% rename from framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionUIConfiguration.cs rename to framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionUIConfiguration.cs index 64270be7fa..6465497ee6 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionUIConfiguration.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionUIConfiguration.cs @@ -1,6 +1,6 @@ using JetBrains.Annotations; -namespace Volo.Abp.ObjectExtending +namespace Volo.Abp.ObjectExtending.Modularity { public class ModuleEntityObjectPropertyExtensionUIConfiguration { diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionUIFormConfiguration.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionUIFormConfiguration.cs similarity index 80% rename from framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionUIFormConfiguration.cs rename to framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionUIFormConfiguration.cs index 28ca3d9f79..48de16ab49 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionUIFormConfiguration.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionUIFormConfiguration.cs @@ -1,4 +1,4 @@ -namespace Volo.Abp.ObjectExtending +namespace Volo.Abp.ObjectExtending.Modularity { public class ModuleEntityObjectPropertyExtensionUIFormConfiguration { diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionUITableConfiguration.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionUITableConfiguration.cs similarity index 80% rename from framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionUITableConfiguration.cs rename to framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionUITableConfiguration.cs index 36ae59e47d..f42bbac1a3 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleEntityObjectPropertyExtensionUITableConfiguration.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionUITableConfiguration.cs @@ -1,4 +1,4 @@ -namespace Volo.Abp.ObjectExtending +namespace Volo.Abp.ObjectExtending.Modularity { public class ModuleEntityObjectPropertyExtensionUITableConfiguration { diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfiguration.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleObjectExtensionConfiguration.cs similarity index 78% rename from framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfiguration.cs rename to framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleObjectExtensionConfiguration.cs index 991e31b723..67453f8188 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfiguration.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleObjectExtensionConfiguration.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace Volo.Abp.ObjectExtending +namespace Volo.Abp.ObjectExtending.Modularity { public class ModuleObjectExtensionConfiguration : Dictionary { diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfigurationDictionary.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleObjectExtensionConfigurationDictionary.cs similarity index 78% rename from framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfigurationDictionary.cs rename to framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleObjectExtensionConfigurationDictionary.cs index 6acbedbba6..656de2e947 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfigurationDictionary.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleObjectExtensionConfigurationDictionary.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace Volo.Abp.ObjectExtending +namespace Volo.Abp.ObjectExtending.Modularity { public class ModuleObjectExtensionConfigurationDictionary : Dictionary { diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfigurationDictionaryExtensions.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleObjectExtensionConfigurationDictionaryExtensions.cs similarity index 94% rename from framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfigurationDictionaryExtensions.cs rename to framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleObjectExtensionConfigurationDictionaryExtensions.cs index 05d0670d36..927c05fa15 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfigurationDictionaryExtensions.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleObjectExtensionConfigurationDictionaryExtensions.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using JetBrains.Annotations; -namespace Volo.Abp.ObjectExtending +namespace Volo.Abp.ObjectExtending.Modularity { public static class ModuleObjectExtensionConfigurationDictionaryExtensions { diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfigurationExtensions.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleObjectExtensionConfigurationExtensions.cs similarity index 93% rename from framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfigurationExtensions.cs rename to framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleObjectExtensionConfigurationExtensions.cs index 1f3b682ffa..218c66344e 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfigurationExtensions.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleObjectExtensionConfigurationExtensions.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; -namespace Volo.Abp.ObjectExtending +namespace Volo.Abp.ObjectExtending.Modularity { public static class ModuleObjectExtensionConfigurationExtensions { diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfigurationHelper.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleObjectExtensionConfigurationHelper.cs similarity index 99% rename from framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfigurationHelper.cs rename to framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleObjectExtensionConfigurationHelper.cs index 94056f3251..375fdfe1f2 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfigurationHelper.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleObjectExtensionConfigurationHelper.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using JetBrains.Annotations; -namespace Volo.Abp.ObjectExtending +namespace Volo.Abp.ObjectExtending.Modularity { public static class ModuleObjectExtensionConfigurationHelper { diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionManager.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionManager.cs index 684be055fe..45a4be8847 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionManager.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionManager.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Collections.Immutable; using JetBrains.Annotations; using Volo.Abp.Data; +using Volo.Abp.ObjectExtending.Modularity; namespace Volo.Abp.ObjectExtending { diff --git a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleObjectExtensionConfiguration.cs b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleObjectExtensionConfiguration.cs index 795c61281f..4d80ed897e 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleObjectExtensionConfiguration.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleObjectExtensionConfiguration.cs @@ -1,4 +1,6 @@ -namespace Volo.Abp.ObjectExtending +using Volo.Abp.ObjectExtending.Modularity; + +namespace Volo.Abp.ObjectExtending { public class IdentityModuleObjectExtensionConfiguration : ModuleObjectExtensionConfiguration { diff --git a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleObjectExtensionConfigurationExtensions.cs b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleObjectExtensionConfigurationExtensions.cs index 00f1b920af..31d24d242b 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleObjectExtensionConfigurationExtensions.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleObjectExtensionConfigurationExtensions.cs @@ -1,4 +1,5 @@ using System; +using Volo.Abp.ObjectExtending.Modularity; namespace Volo.Abp.ObjectExtending { diff --git a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleObjectExtensionConfigurationsExtensions.cs b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleObjectExtensionConfigurationsExtensions.cs index 3daf614f45..8ef25a5eb4 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleObjectExtensionConfigurationsExtensions.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleObjectExtensionConfigurationsExtensions.cs @@ -1,4 +1,5 @@ using System; +using Volo.Abp.ObjectExtending.Modularity; namespace Volo.Abp.ObjectExtending { diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/AbpIdentityDomainModule.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/AbpIdentityDomainModule.cs index d1413d4cb8..6657184803 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/AbpIdentityDomainModule.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/AbpIdentityDomainModule.cs @@ -6,7 +6,7 @@ using Volo.Abp.AutoMapper; using Volo.Abp.Domain; using Volo.Abp.EventBus.Distributed; using Volo.Abp.Modularity; -using Volo.Abp.ObjectExtending; +using Volo.Abp.ObjectExtending.Modularity; using Volo.Abp.Users; namespace Volo.Abp.Identity From 6120c9c8ff9ccef3875226e5b58e18740c88118e Mon Sep 17 00:00:00 2001 From: Alper Ebicoglu Date: Sat, 2 May 2020 01:26:18 +0300 Subject: [PATCH 35/67] invoice generation localizations. volosoft/volo#1996 --- .../AbpIoLocalization/Admin/Localization/Resources/en.json | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/abp_io/AbpIoLocalization/AbpIoLocalization/Admin/Localization/Resources/en.json b/abp_io/AbpIoLocalization/AbpIoLocalization/Admin/Localization/Resources/en.json index eedc323adc..d0d829bbf3 100644 --- a/abp_io/AbpIoLocalization/AbpIoLocalization/Admin/Localization/Resources/en.json +++ b/abp_io/AbpIoLocalization/AbpIoLocalization/Admin/Localization/Resources/en.json @@ -115,8 +115,10 @@ "InvoiceDate": "Invoice Date", "Quantity": "Quantity", "AddProduct": "Add Product", - "NeedToAddProduct": "Need to add product to generate invoice !", + "AddProductWarning": "You need to add product!", "TotalPrice": "Total Price", - "Generate": "Generate" + "Generate": "Generate", + "MissingQuantityField": "The quantity field is required!", + "MissingPriceField": "The Price field is required!" } } \ No newline at end of file From fa02cd7a1982c5bd6949dabb8f48007bdcb8b667 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Sat, 2 May 2020 01:40:48 +0300 Subject: [PATCH 36/67] Added IsAvailableToClients. --- .../CachedObjectExtensionsDtoService.cs | 5 +++++ ...ModuleEntityObjectPropertyExtensionConfiguration.cs | 10 +++++++++- .../ModuleObjectExtensionConfigurationHelper.cs | 10 ++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/CachedObjectExtensionsDtoService.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/CachedObjectExtensionsDtoService.cs index 65d23eea06..21cb11e318 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/CachedObjectExtensionsDtoService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/CachedObjectExtensionsDtoService.cs @@ -54,6 +54,11 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending foreach (var propertyConfig in objectConfig.Value.GetProperties()) { + if (!propertyConfig.IsAvailableToClients) + { + continue; + } + var propertyExtensionDto = moduleObjectExtensionDto.ExtraProperties[propertyConfig.Name] = new ModuleObjectExtraPropertyExtensionDto { diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionConfiguration.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionConfiguration.cs index 52d88c8e26..99b790aa82 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionConfiguration.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionConfiguration.cs @@ -27,10 +27,18 @@ namespace Volo.Abp.ObjectExtending.Modularity [NotNull] public Dictionary Configuration { get; } - + [NotNull] public ModuleEntityObjectPropertyExtensionEntityConfiguration Entity { get; } + /// + /// Single point to enable/disable this property for the clients (UI and API). + /// If this is false, the configuration made in the and the + /// properties are not used. + /// Default: true. + /// + public bool IsAvailableToClients { get; set; } = true; + [NotNull] public ModuleEntityObjectPropertyExtensionUIConfiguration UI { get; } diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleObjectExtensionConfigurationHelper.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleObjectExtensionConfigurationHelper.cs index 375fdfe1f2..8bff5e8f05 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleObjectExtensionConfigurationHelper.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleObjectExtensionConfigurationHelper.cs @@ -30,6 +30,11 @@ namespace Volo.Abp.ObjectExtending.Modularity { foreach (var propertyConfig in GetPropertyConfigurations(moduleName, objectName)) { + if (!propertyConfig.IsAvailableToClients) + { + continue; + } + if (propertyConfig.Api.OnGet.IsAvailable && getApiTypes != null) { @@ -58,6 +63,11 @@ namespace Volo.Abp.ObjectExtending.Modularity { foreach (var propertyConfig in GetPropertyConfigurations(moduleName, objectName)) { + if (!propertyConfig.IsAvailableToClients) + { + continue; + } + if (propertyConfig.UI.OnCreateForm.IsVisible && createFormTypes != null) { From ba9fb4b6eb5f8e06beff1c8abd442adf5e08a10c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Sat, 2 May 2020 01:44:45 +0300 Subject: [PATCH 37/67] Update AbpDbContext.cs --- .../Volo/Abp/EntityFrameworkCore/AbpDbContext.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs index 80482a886f..7f914fb1a0 100644 --- a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs +++ b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs @@ -204,7 +204,7 @@ namespace Volo.Abp.EntityFrameworkCore var currentValue = e.Entry.CurrentValues[property.Name]; if (currentValue != null) { - entity.SetProperty(property.Name, currentValue); + entity.ExtraProperties[property.Name] = currentValue; } } } From 50d416dd25e0788cd96913c6fbfb5237078bd26d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Sat, 2 May 2020 02:44:54 +0300 Subject: [PATCH 38/67] Check validation on SetProperty. --- framework/Volo.Abp.sln | 11 +- .../Volo.Abp.ObjectExtending.csproj | 3 +- .../Abp/Data/HasExtraPropertiesExtensions.cs | 13 +- .../AbpObjectExtendingModule.cs | 8 +- .../ExtensibleObjectValidator.cs | 143 +++++++++++++++--- ...bjectExtensionPropertyValidationContext.cs | 1 + .../FodyWeavers.xml | 3 + .../FodyWeavers.xsd | 30 ++++ .../Volo.Abp.Validation.Abstractions.csproj | 21 +++ .../AbpValidationAbstractionsModule.cs | 9 ++ .../Abp/Validation/AbpValidationException.cs | 0 .../Abp/Validation/IHasValidationErrors.cs | 0 .../Volo.Abp.Validation.csproj | 1 + .../Abp/Validation/AbpValidationModule.cs | 1 + .../ExtensibleObjectValidator_Tests.cs | 35 +++-- nupkg/common.ps1 | 1 + 16 files changed, 243 insertions(+), 37 deletions(-) create mode 100644 framework/src/Volo.Abp.Validation.Abstractions/FodyWeavers.xml create mode 100644 framework/src/Volo.Abp.Validation.Abstractions/FodyWeavers.xsd create mode 100644 framework/src/Volo.Abp.Validation.Abstractions/Volo.Abp.Validation.Abstractions.csproj create mode 100644 framework/src/Volo.Abp.Validation.Abstractions/Volo/Abp/Validation/AbpValidationAbstractionsModule.cs rename framework/src/{Volo.Abp.Validation => Volo.Abp.Validation.Abstractions}/Volo/Abp/Validation/AbpValidationException.cs (100%) rename framework/src/{Volo.Abp.Validation => Volo.Abp.Validation.Abstractions}/Volo/Abp/Validation/IHasValidationErrors.cs (100%) diff --git a/framework/Volo.Abp.sln b/framework/Volo.Abp.sln index 5159f0a86e..5d6f3e99a2 100644 --- a/framework/Volo.Abp.sln +++ b/framework/Volo.Abp.sln @@ -279,9 +279,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.ObjectExtending", EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.ObjectExtending.Tests", "test\Volo.Abp.ObjectExtending.Tests\Volo.Abp.ObjectExtending.Tests.csproj", "{17F8CA89-D9A2-4863-A5BD-B8E4D2901FD5}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.TextTemplating", "src\Volo.Abp.TextTemplating\Volo.Abp.TextTemplating.csproj", "{9E53F91F-EACD-4191-A487-E727741F1311}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.TextTemplating", "src\Volo.Abp.TextTemplating\Volo.Abp.TextTemplating.csproj", "{9E53F91F-EACD-4191-A487-E727741F1311}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.TextTemplating.Tests", "test\Volo.Abp.TextTemplating.Tests\Volo.Abp.TextTemplating.Tests.csproj", "{251C7FD3-D313-4BCE-8068-352EC7EEA275}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.TextTemplating.Tests", "test\Volo.Abp.TextTemplating.Tests\Volo.Abp.TextTemplating.Tests.csproj", "{251C7FD3-D313-4BCE-8068-352EC7EEA275}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.Validation.Abstractions", "src\Volo.Abp.Validation.Abstractions\Volo.Abp.Validation.Abstractions.csproj", "{FA5D1D6A-2A05-4A3D-99C1-2B6C1D1F99A3}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -841,6 +843,10 @@ Global {251C7FD3-D313-4BCE-8068-352EC7EEA275}.Debug|Any CPU.Build.0 = Debug|Any CPU {251C7FD3-D313-4BCE-8068-352EC7EEA275}.Release|Any CPU.ActiveCfg = Release|Any CPU {251C7FD3-D313-4BCE-8068-352EC7EEA275}.Release|Any CPU.Build.0 = Release|Any CPU + {FA5D1D6A-2A05-4A3D-99C1-2B6C1D1F99A3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FA5D1D6A-2A05-4A3D-99C1-2B6C1D1F99A3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FA5D1D6A-2A05-4A3D-99C1-2B6C1D1F99A3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FA5D1D6A-2A05-4A3D-99C1-2B6C1D1F99A3}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -984,6 +990,7 @@ Global {17F8CA89-D9A2-4863-A5BD-B8E4D2901FD5} = {447C8A77-E5F0-4538-8687-7383196D04EA} {9E53F91F-EACD-4191-A487-E727741F1311} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6} {251C7FD3-D313-4BCE-8068-352EC7EEA275} = {447C8A77-E5F0-4538-8687-7383196D04EA} + {FA5D1D6A-2A05-4A3D-99C1-2B6C1D1F99A3} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {BB97ECF4-9A84-433F-A80B-2A3285BDD1D5} diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo.Abp.ObjectExtending.csproj b/framework/src/Volo.Abp.ObjectExtending/Volo.Abp.ObjectExtending.csproj index e50ff26d5f..4b8542101a 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo.Abp.ObjectExtending.csproj +++ b/framework/src/Volo.Abp.ObjectExtending/Volo.Abp.ObjectExtending.csproj @@ -1,4 +1,4 @@ - + @@ -15,6 +15,7 @@ + diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/Data/HasExtraPropertiesExtensions.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/Data/HasExtraPropertiesExtensions.cs index febf95bd22..ca9cc0a4c1 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/Data/HasExtraPropertiesExtensions.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/Data/HasExtraPropertiesExtensions.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Globalization; +using Volo.Abp.DynamicProxy; using Volo.Abp.ObjectExtending; using Volo.Abp.Reflection; @@ -37,10 +38,20 @@ namespace Volo.Abp.Data throw new AbpException("GetProperty does not support non-primitive types. Use non-generic GetProperty method and handle type casting manually."); } - public static TSource SetProperty(this TSource source, string name, object value) + public static TSource SetProperty( + this TSource source, + string name, + object value, + bool validate = true) where TSource : IHasExtraProperties { + if (validate) + { + ExtensibleObjectValidator.CheckValue(source, name, value); + } + source.ExtraProperties[name] = value; + return source; } diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/AbpObjectExtendingModule.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/AbpObjectExtendingModule.cs index f8b585594e..310e1feb23 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/AbpObjectExtendingModule.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/AbpObjectExtendingModule.cs @@ -1,10 +1,12 @@ -using Volo.Abp.Localization; -using Volo.Abp.Modularity; +using Volo.Abp.Modularity; +using Volo.Abp.Validation; +using Volo.Abp.Localization; namespace Volo.Abp.ObjectExtending { [DependsOn( - typeof(AbpLocalizationAbstractionsModule) + typeof(AbpLocalizationAbstractionsModule), + typeof(AbpValidationAbstractionsModule) )] public class AbpObjectExtendingModule : AbpModule { diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ExtensibleObjectValidator.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ExtensibleObjectValidator.cs index 5832b98cd3..d3fabc8c8e 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ExtensibleObjectValidator.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ExtensibleObjectValidator.cs @@ -4,18 +4,49 @@ using System.Linq; using JetBrains.Annotations; using Volo.Abp.Data; using Volo.Abp.DynamicProxy; +using Volo.Abp.Validation; namespace Volo.Abp.ObjectExtending { public static class ExtensibleObjectValidator { - [NotNull] + public static void CheckValue( + [NotNull] IHasExtraProperties extensibleObject, + [NotNull] string propertyName, + [CanBeNull] object value) + { + var validationErrors = GetValidationErrors( + extensibleObject, + propertyName, + value + ); + + if (validationErrors.Any()) + { + throw new AbpValidationException(validationErrors); + } + } + + public static bool IsValid( + [NotNull] IHasExtraProperties extensibleObject, + [CanBeNull] ValidationContext objectValidationContext = null) + { + return GetValidationErrors( + extensibleObject, + objectValidationContext + ).Any(); + } + public static bool IsValid( [NotNull] IHasExtraProperties extensibleObject, + [NotNull] string propertyName, + [CanBeNull] object value, [CanBeNull] ValidationContext objectValidationContext = null) { return GetValidationErrors( extensibleObject, + propertyName, + value, objectValidationContext ).Any(); } @@ -26,10 +57,30 @@ namespace Volo.Abp.ObjectExtending [CanBeNull] ValidationContext objectValidationContext = null) { var validationErrors = new List(); - + + AddValidationErrors( + extensibleObject, + validationErrors, + objectValidationContext + ); + + return validationErrors; + } + + [NotNull] + public static List GetValidationErrors( + [NotNull] IHasExtraProperties extensibleObject, + [NotNull] string propertyName, + [CanBeNull] object value, + [CanBeNull] ValidationContext objectValidationContext = null) + { + var validationErrors = new List(); + AddValidationErrors( extensibleObject, validationErrors, + propertyName, + value, objectValidationContext ); @@ -78,10 +129,55 @@ namespace Volo.Abp.ObjectExtending ); } + public static void AddValidationErrors( + [NotNull] IHasExtraProperties extensibleObject, + [NotNull] List validationErrors, + [NotNull] string propertyName, + [CanBeNull] object value, + [CanBeNull] ValidationContext objectValidationContext = null) + { + Check.NotNull(extensibleObject, nameof(extensibleObject)); + Check.NotNull(validationErrors, nameof(validationErrors)); + Check.NotNullOrWhiteSpace(propertyName, nameof(propertyName)); + + if (objectValidationContext == null) + { + objectValidationContext = new ValidationContext( + extensibleObject, + null, + new Dictionary() + ); + } + + var objectType = ProxyHelper.UnProxy(extensibleObject).GetType(); + + var objectExtensionInfo = ObjectExtensionManager.Instance + .GetOrNull(objectType); + + if (objectExtensionInfo == null) + { + return; + } + + var property = objectExtensionInfo.GetPropertyOrNull(propertyName); + if (property == null) + { + return; + } + + AddPropertyValidationErrors( + extensibleObject, + validationErrors, + objectValidationContext, + property, + value + ); + } + private static void AddPropertyValidationErrors( - IHasExtraProperties extensibleObject, + IHasExtraProperties extensibleObject, List validationErrors, - ValidationContext objectValidationContext, + ValidationContext objectValidationContext, ObjectExtensionInfo objectExtensionInfo) { var properties = objectExtensionInfo.GetProperties(); @@ -92,36 +188,46 @@ namespace Volo.Abp.ObjectExtending foreach (var property in properties) { - AddPropertyValidationErrors(extensibleObject, validationErrors, objectValidationContext, property); + AddPropertyValidationErrors( + extensibleObject, + validationErrors, + objectValidationContext, + property, + extensibleObject.GetProperty(property.Name) + ); } } private static void AddPropertyValidationErrors( - IHasExtraProperties extensibleObject, + IHasExtraProperties extensibleObject, List validationErrors, - ValidationContext objectValidationContext, - ObjectExtensionPropertyInfo property) + ValidationContext objectValidationContext, + ObjectExtensionPropertyInfo property, + object value) { AddPropertyValidationAttributeErrors( extensibleObject, validationErrors, objectValidationContext, - property + property, + value ); ExecuteCustomPropertyValidationActions( extensibleObject, validationErrors, objectValidationContext, - property + property, + value ); } private static void AddPropertyValidationAttributeErrors( - IHasExtraProperties extensibleObject, + IHasExtraProperties extensibleObject, List validationErrors, - ValidationContext objectValidationContext, - ObjectExtensionPropertyInfo property) + ValidationContext objectValidationContext, + ObjectExtensionPropertyInfo property, + object value) { var validationAttributes = property.GetValidationAttributes(); @@ -139,7 +245,7 @@ namespace Volo.Abp.ObjectExtending foreach (var attribute in validationAttributes) { var result = attribute.GetValidationResult( - extensibleObject.GetProperty(property.Name), + value, propertyValidationContext ); @@ -154,7 +260,8 @@ namespace Volo.Abp.ObjectExtending IHasExtraProperties extensibleObject, List validationErrors, ValidationContext objectValidationContext, - ObjectExtensionPropertyInfo property) + ObjectExtensionPropertyInfo property, + object value) { if (!property.Validators.Any()) { @@ -166,7 +273,7 @@ namespace Volo.Abp.ObjectExtending extensibleObject, validationErrors, objectValidationContext, - extensibleObject.GetProperty(property.Name) + value ); foreach (var validator in property.Validators) @@ -176,9 +283,9 @@ namespace Volo.Abp.ObjectExtending } private static void ExecuteCustomObjectValidationActions( - IHasExtraProperties extensibleObject, + IHasExtraProperties extensibleObject, List validationErrors, - ValidationContext objectValidationContext, + ValidationContext objectValidationContext, ObjectExtensionInfo objectExtensionInfo) { if (!objectExtensionInfo.Validators.Any()) diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionPropertyValidationContext.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionPropertyValidationContext.cs index ab2a7ccb38..81b6edbed8 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionPropertyValidationContext.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionPropertyValidationContext.cs @@ -40,6 +40,7 @@ namespace Volo.Abp.ObjectExtending /// /// Can be used to resolve services from the dependency injection container. + /// This can be null when SetProperty method is used on the object. /// [CanBeNull] public IServiceProvider ServiceProvider => ValidationContext; diff --git a/framework/src/Volo.Abp.Validation.Abstractions/FodyWeavers.xml b/framework/src/Volo.Abp.Validation.Abstractions/FodyWeavers.xml new file mode 100644 index 0000000000..be0de3a908 --- /dev/null +++ b/framework/src/Volo.Abp.Validation.Abstractions/FodyWeavers.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/framework/src/Volo.Abp.Validation.Abstractions/FodyWeavers.xsd b/framework/src/Volo.Abp.Validation.Abstractions/FodyWeavers.xsd new file mode 100644 index 0000000000..3f3946e282 --- /dev/null +++ b/framework/src/Volo.Abp.Validation.Abstractions/FodyWeavers.xsd @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + 'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed. + + + + + A comma-separated list of error codes that can be safely ignored in assembly verification. + + + + + 'false' to turn off automatic generation of the XML Schema file. + + + + + \ No newline at end of file diff --git a/framework/src/Volo.Abp.Validation.Abstractions/Volo.Abp.Validation.Abstractions.csproj b/framework/src/Volo.Abp.Validation.Abstractions/Volo.Abp.Validation.Abstractions.csproj new file mode 100644 index 0000000000..2ed6955187 --- /dev/null +++ b/framework/src/Volo.Abp.Validation.Abstractions/Volo.Abp.Validation.Abstractions.csproj @@ -0,0 +1,21 @@ + + + + + + + netstandard2.0 + Volo.Abp.Validation.Abstractions + Volo.Abp.Validation.Abstractions + $(AssetTargetFallback);portable-net45+win8+wp8+wpa81; + false + false + false + + + + + + + + \ No newline at end of file diff --git a/framework/src/Volo.Abp.Validation.Abstractions/Volo/Abp/Validation/AbpValidationAbstractionsModule.cs b/framework/src/Volo.Abp.Validation.Abstractions/Volo/Abp/Validation/AbpValidationAbstractionsModule.cs new file mode 100644 index 0000000000..433ad86a4f --- /dev/null +++ b/framework/src/Volo.Abp.Validation.Abstractions/Volo/Abp/Validation/AbpValidationAbstractionsModule.cs @@ -0,0 +1,9 @@ +using Volo.Abp.Modularity; + +namespace Volo.Abp.Validation +{ + public class AbpValidationAbstractionsModule : AbpModule + { + + } +} diff --git a/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/AbpValidationException.cs b/framework/src/Volo.Abp.Validation.Abstractions/Volo/Abp/Validation/AbpValidationException.cs similarity index 100% rename from framework/src/Volo.Abp.Validation/Volo/Abp/Validation/AbpValidationException.cs rename to framework/src/Volo.Abp.Validation.Abstractions/Volo/Abp/Validation/AbpValidationException.cs diff --git a/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/IHasValidationErrors.cs b/framework/src/Volo.Abp.Validation.Abstractions/Volo/Abp/Validation/IHasValidationErrors.cs similarity index 100% rename from framework/src/Volo.Abp.Validation/Volo/Abp/Validation/IHasValidationErrors.cs rename to framework/src/Volo.Abp.Validation.Abstractions/Volo/Abp/Validation/IHasValidationErrors.cs diff --git a/framework/src/Volo.Abp.Validation/Volo.Abp.Validation.csproj b/framework/src/Volo.Abp.Validation/Volo.Abp.Validation.csproj index edbcf2f04d..10daff842e 100644 --- a/framework/src/Volo.Abp.Validation/Volo.Abp.Validation.csproj +++ b/framework/src/Volo.Abp.Validation/Volo.Abp.Validation.csproj @@ -21,6 +21,7 @@ + diff --git a/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/AbpValidationModule.cs b/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/AbpValidationModule.cs index 9da6766a5d..3fb027cba7 100644 --- a/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/AbpValidationModule.cs +++ b/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/AbpValidationModule.cs @@ -9,6 +9,7 @@ using Volo.Abp.VirtualFileSystem; namespace Volo.Abp.Validation { [DependsOn( + typeof(AbpValidationAbstractionsModule), typeof(AbpLocalizationModule) )] public class AbpValidationModule : AbpModule diff --git a/framework/test/Volo.Abp.ObjectExtending.Tests/Volo/Abp/ObjectExtending/ExtensibleObjectValidator_Tests.cs b/framework/test/Volo.Abp.ObjectExtending.Tests/Volo/Abp/ObjectExtending/ExtensibleObjectValidator_Tests.cs index d08e3766df..c41ffead56 100644 --- a/framework/test/Volo.Abp.ObjectExtending.Tests/Volo/Abp/ObjectExtending/ExtensibleObjectValidator_Tests.cs +++ b/framework/test/Volo.Abp.ObjectExtending.Tests/Volo/Abp/ObjectExtending/ExtensibleObjectValidator_Tests.cs @@ -2,6 +2,7 @@ using Shouldly; using Volo.Abp.Data; using Volo.Abp.Threading; +using Volo.Abp.Validation; using Xunit; namespace Volo.Abp.ObjectExtending @@ -85,8 +86,8 @@ namespace Volo.Abp.ObjectExtending ExtensibleObjectValidator .GetValidationErrors( new ExtensiblePersonObject() - .SetProperty("Name", "John") - .SetProperty("Age", 42) + .SetProperty("Name", "John", validate: false) + .SetProperty("Age", 42, validate: false) ).Count.ShouldBe(0); //All Valid } @@ -101,39 +102,49 @@ namespace Volo.Abp.ObjectExtending ExtensibleObjectValidator .GetValidationErrors( new ExtensiblePersonObject() - .SetProperty("Address", new string('x', 256)) + .SetProperty("Address", new string('x', 256), validate: false) ).Count.ShouldBe(3); // Name, Age & Address ExtensibleObjectValidator .GetValidationErrors( new ExtensiblePersonObject() - .SetProperty("Age", 42) + .SetProperty("Age", 42, validate: false) ).Count.ShouldBe(1); // Name ExtensibleObjectValidator .GetValidationErrors( new ExtensiblePersonObject() - .SetProperty("Address", new string('x', 256)) - .SetProperty("Age", 100) + .SetProperty("Address", new string('x', 256), validate: false) + .SetProperty("Age", 100, validate: false) ).Count.ShouldBe(3); // Name, Age & Address ExtensibleObjectValidator .GetValidationErrors( new ExtensiblePersonObject() - .SetProperty("Name", "John") - .SetProperty("Age", 42) - .SetProperty("Password", "123") - .SetProperty("PasswordRepeat", "1256") + .SetProperty("Name", "John", validate: false) + .SetProperty("Age", 42, validate: false) + .SetProperty("Password", "123", validate: false) + .SetProperty("PasswordRepeat", "1256", validate: false) ).Count.ShouldBe(1); // PasswordRepeat != Password ExtensibleObjectValidator .GetValidationErrors( new ExtensiblePersonObject() - .SetProperty("Name", "BadValue") - .SetProperty("Age", 42) + .SetProperty("Name", "BadValue", validate: false) + .SetProperty("Age", 42, validate: false) ).Count.ShouldBe(1); //Name is 'BadValue'! } + [Fact] + public void Should_Check_Validation_On_SetProperty() + { + Assert.Throws(() => + { + new ExtensiblePersonObject() + .SetProperty("Address", new string('x', 256)); + }); + } + private class ExtensiblePersonObject : ExtensibleObject { diff --git a/nupkg/common.ps1 b/nupkg/common.ps1 index 9c77b05eef..6dfe0041aa 100644 --- a/nupkg/common.ps1 +++ b/nupkg/common.ps1 @@ -107,6 +107,7 @@ $projects = ( "framework/src/Volo.Abp.UI", "framework/src/Volo.Abp.UI.Navigation", "framework/src/Volo.Abp.Uow", + "framework/src/Volo.Abp.Validation.Abstractions", "framework/src/Volo.Abp.Validation", "framework/src/Volo.Abp.VirtualFileSystem", From 0e4edc8e271757740c6dc4fa76743148048d06a0 Mon Sep 17 00:00:00 2001 From: Alper Ebicoglu Date: Sat, 2 May 2020 04:34:39 +0300 Subject: [PATCH 39/67] refactor nuget package version updater --- .../VoloNugetPackagesVersionUpdater.cs | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/VoloNugetPackagesVersionUpdater.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/VoloNugetPackagesVersionUpdater.cs index 587492804b..cb3ccfdef5 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/VoloNugetPackagesVersionUpdater.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/VoloNugetPackagesVersionUpdater.cs @@ -42,8 +42,9 @@ namespace Volo.Abp.Cli.ProjectModification protected virtual async Task UpdateInternalAsync(string projectPath, bool includePreviews = false, bool switchToStable = false) { var fileContent = File.ReadAllText(projectPath); + var updatedContent = await UpdateVoloPackagesAsync(fileContent, includePreviews, switchToStable); - File.WriteAllText(projectPath, await UpdateVoloPackagesAsync(fileContent, includePreviews, switchToStable)); + File.WriteAllText(projectPath, updatedContent); } private async Task UpdateVoloPackagesAsync(string content, bool includePreviews = false, bool switchToStable = false) @@ -74,16 +75,13 @@ namespace Volo.Abp.Cli.ProjectModification var versionAttribute = package.Attributes["Version"]; var currentVersion = versionAttribute.Value; - var packageVersion = SemanticVersion.Parse(currentVersion); - - Logger.LogDebug("Checking package: \"{0}\" - Current version: {1}", packageId, packageVersion); + var currentSemanticVersion = SemanticVersion.Parse(currentVersion); + Logger.LogDebug("Checking package: \"{0}\" - Current version: {1}", packageId, currentSemanticVersion); if (includePreviews || (currentVersion.Contains("-preview") && !switchToStable)) { - var latestVersion = (await _myGetPackageListFinder.GetPackages()).Packages - .FirstOrDefault(p => p.Id == packageId) - ?.Versions.LastOrDefault(); + var latestVersion = await GetLatestVersionFromMyGet(packageId); if (currentVersion != latestVersion) { @@ -99,14 +97,14 @@ namespace Volo.Abp.Cli.ProjectModification { var latestVersion = await _nuGetService.GetLatestVersionOrNullAsync(packageId); - if (latestVersion != null && (currentVersion.Contains("-preview") || packageVersion < latestVersion)) + if (latestVersion != null && (currentVersion.Contains("-preview") || currentSemanticVersion < latestVersion)) { - Logger.LogInformation("Updating package \"{0}\" from v{1} to v{2}.", packageId, packageVersion.ToString(), latestVersion.ToString()); + Logger.LogInformation("Updating package \"{0}\" from v{1} to v{2}.", packageId, currentSemanticVersion.ToString(), latestVersion.ToString()); versionAttribute.Value = latestVersion.ToString(); } else { - Logger.LogInformation("Package: \"{0}-v{1}\" is up to date.", packageId, packageVersion); + Logger.LogInformation("Package: \"{0}-v{1}\" is up to date.", packageId, currentSemanticVersion); } } } @@ -116,11 +114,18 @@ namespace Volo.Abp.Cli.ProjectModification } catch (Exception ex) { - Logger.LogError("Cannot update volo packages! An error occured while updating the package \"{0}\". Error: {1}", packageId, ex.Message); + Logger.LogError("Cannot update Volo.* packages! An error occured while updating the package \"{0}\". Error: {1}", packageId, ex.Message); Logger.LogException(ex); } return await Task.FromResult(content); } + + private async Task GetLatestVersionFromMyGet(string packageId) + { + var myGetPack = await _myGetPackageListFinder.GetPackages(); + + return myGetPack.Packages.FirstOrDefault(p => p.Id == packageId)?.Versions.LastOrDefault(); + } } } From 89361480edf238649c6294f571d1517c999911be Mon Sep 17 00:00:00 2001 From: Alper Ebicoglu Date: Sat, 2 May 2020 05:12:12 +0300 Subject: [PATCH 40/67] closes #3811 --- .../Volo/Abp/Cli/Http/CliHttpClient.cs | 56 +++++++++++ .../Abp/Cli/Licensing/AbpIoApiKeyService.cs | 39 +++----- .../Volo/Abp/Cli/NuGet/NuGetService.cs | 97 +++++++------------ 3 files changed, 104 insertions(+), 88 deletions(-) diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Http/CliHttpClient.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Http/CliHttpClient.cs index ca1a23fcfc..bd3037d830 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Http/CliHttpClient.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Http/CliHttpClient.cs @@ -1,9 +1,15 @@ using System; +using System.Collections.Generic; using System.IO; using System.Net.Http; using System.Text; +using System.Threading; +using System.Threading.Tasks; using IdentityModel.Client; +using Polly; +using Polly.Extensions.Http; using Volo.Abp.Cli.Auth; +using Microsoft.Extensions.Logging; namespace Volo.Abp.Cli.Http { @@ -41,5 +47,55 @@ namespace Volo.Abp.Cli.Http client.SetBearerToken(accessToken); } } + + public async Task GetHttpResponseMessageWithRetryAsync + ( + string url, + CancellationToken? cancellationToken = null, + ILogger logger = null, + IEnumerable sleepDurations = null + ) + { + if (sleepDurations == null) + { + sleepDurations = new[] + { + TimeSpan.FromSeconds(2), + TimeSpan.FromSeconds(4), + TimeSpan.FromSeconds(7) + }; + } + + if (!cancellationToken.HasValue) + { + cancellationToken = CancellationToken.None; + } + + return await HttpPolicyExtensions + .HandleTransientHttpError() + .OrResult(msg => !msg.IsSuccessStatusCode) + .WaitAndRetryAsync(sleepDurations, + (responseMessage, timeSpan, retryCount, context) => + { + if (responseMessage.Exception != null) + { + string httpErrorCode = responseMessage.Result == null ? + httpErrorCode = string.Empty : + "HTTP-" + (int)responseMessage.Result.StatusCode + ", "; + + logger?.LogWarning( + $"{retryCount}. HTTP request attempt failed to {url} with an error: {httpErrorCode}{responseMessage.Exception.Message}. " + + $"Waiting {timeSpan.TotalSeconds} secs for the next try..."); + } + else if (responseMessage.Result != null) + { + logger?.LogWarning( + $"{retryCount}. HTTP request attempt failed to {url} with an error: {(int)responseMessage.Result.StatusCode}-{responseMessage.Result.ReasonPhrase}. " + + $"Waiting {timeSpan.TotalSeconds} secs for the next try..."); + } + }) + .ExecuteAsync(async () => await this.GetAsync(url, cancellationToken.Value)); + } + } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Licensing/AbpIoApiKeyService.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Licensing/AbpIoApiKeyService.cs index cddead548f..33a2e10fdf 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Licensing/AbpIoApiKeyService.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Licensing/AbpIoApiKeyService.cs @@ -13,6 +13,7 @@ using Volo.Abp.Cli.Http; using Volo.Abp.Cli.ProjectBuilding; using Volo.Abp.DependencyInjection; using Volo.Abp.Json; +using Volo.Abp.Threading; namespace Volo.Abp.Cli.Licensing { @@ -20,14 +21,21 @@ namespace Volo.Abp.Cli.Licensing { protected IJsonSerializer JsonSerializer { get; } protected IRemoteServiceExceptionHandler RemoteServiceExceptionHandler { get; } + protected ICancellationTokenProvider CancellationTokenProvider { get; } + private readonly ILogger _logger; private DeveloperApiKeyResult _apiKeyResult = null; - public AbpIoApiKeyService(IJsonSerializer jsonSerializer, IRemoteServiceExceptionHandler remoteServiceExceptionHandler, ILogger logger) + public AbpIoApiKeyService( + IJsonSerializer jsonSerializer, + ICancellationTokenProvider cancellationTokenProvider, + IRemoteServiceExceptionHandler remoteServiceExceptionHandler, + ILogger logger) { JsonSerializer = jsonSerializer; RemoteServiceExceptionHandler = remoteServiceExceptionHandler; _logger = logger; + CancellationTokenProvider = cancellationTokenProvider; } public async Task GetApiKeyOrNullAsync(bool invalidateCache = false) @@ -51,31 +59,10 @@ namespace Volo.Abp.Cli.Licensing using (var client = new CliHttpClient()) { - var response = await HttpPolicyExtensions - .HandleTransientHttpError() - .OrResult(msg => !msg.IsSuccessStatusCode) - .WaitAndRetryAsync(new[] - { - TimeSpan.FromSeconds(1), - TimeSpan.FromSeconds(3), - TimeSpan.FromSeconds(7) - }, - (responseMessage, timeSpan, retryCount, context) => - { - if (responseMessage.Exception != null) - { - _logger.LogWarning( - $"{retryCount}. request attempt failed to {url} with an error: \"{responseMessage.Exception.Message}\". " + - $"Waiting {timeSpan.TotalSeconds} secs for the next try..."); - } - else if (responseMessage.Result != null) - { - _logger.LogWarning( - $"{retryCount}. request attempt failed {url} with {(int)responseMessage.Result.StatusCode}-{responseMessage.Result.ReasonPhrase}. " + - $"Waiting {timeSpan.TotalSeconds} secs for the next try..."); - } - }) - .ExecuteAsync(async () => await client.GetAsync(url)); + var response = await client.GetHttpResponseMessageWithRetryAsync( + url: url, + cancellationToken: CancellationTokenProvider.Token, + logger: _logger); if (!response.IsSuccessStatusCode) { diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/NuGet/NuGetService.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/NuGet/NuGetService.cs index c0eb6fd209..0fd35582bf 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/NuGet/NuGetService.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/NuGet/NuGetService.cs @@ -1,16 +1,10 @@ using Newtonsoft.Json; using NuGet.Versioning; -using System; using System.Collections.Generic; -using System.IO; using System.Linq; -using System.Net; -using System.Net.Http; using System.Threading.Tasks; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; -using Polly; -using Polly.Extensions.Http; using Volo.Abp.Cli.Auth; using Volo.Abp.Cli.Http; using Volo.Abp.Cli.Licensing; @@ -29,6 +23,8 @@ namespace Volo.Abp.Cli.NuGet protected ICancellationTokenProvider CancellationTokenProvider { get; } protected IRemoteServiceExceptionHandler RemoteServiceExceptionHandler { get; } private readonly IApiKeyService _apiKeyService; + private List _proPackageList; + private DeveloperApiKeyResult _apiKeyResult; public NuGetService( IJsonSerializer jsonSerializer, @@ -45,20 +41,20 @@ namespace Volo.Abp.Cli.NuGet public async Task GetLatestVersionOrNullAsync(string packageId, bool includePreviews = false, bool includeNightly = false) { - List proPackageList = null; - if (AuthService.IsLoggedIn()) { - proPackageList = await GetProPackageListAsync(); + if (_proPackageList == null) + { + _proPackageList = await GetProPackageListAsync(); + } } string url; if (includeNightly) { - url = - $"https://www.myget.org/F/abp-nightly/api/v3/flatcontainer/{packageId.ToLowerInvariant()}/index.json"; + url = $"https://www.myget.org/F/abp-nightly/api/v3/flatcontainer/{packageId.ToLowerInvariant()}/index.json"; } - else if (proPackageList?.Contains(packageId) ?? false) + else if (_proPackageList?.Contains(packageId) ?? false) { url = await GetNuGetUrlForCommercialPackage(packageId); } @@ -67,15 +63,13 @@ namespace Volo.Abp.Cli.NuGet url = $"https://api.nuget.org/v3-flatcontainer/{packageId.ToLowerInvariant()}/index.json"; } - using (var client = new CliHttpClient(setBearerToken: false)) { - var responseMessage = await GetHttpResponseMessageWithRetryAsync(client, url); - - if (!responseMessage.IsSuccessStatusCode) - { - throw new Exception($"ERROR: Remote server returns '{responseMessage.StatusCode}'"); - } + var responseMessage = await client.GetHttpResponseMessageWithRetryAsync( + url, + cancellationToken: CancellationTokenProvider.Token, + logger: Logger + ); await RemoteServiceExceptionHandler.EnsureSuccessfulHttpResponseAsync(responseMessage); @@ -98,62 +92,41 @@ namespace Volo.Abp.Cli.NuGet private async Task GetNuGetUrlForCommercialPackage(string packageId) { - var apiKeyResult = await _apiKeyService.GetApiKeyOrNullAsync(); - return CliUrls.GetNuGetPackageInfoUrl(apiKeyResult.ApiKey, packageId); - } + if (_apiKeyResult == null) + { + _apiKeyResult = await _apiKeyService.GetApiKeyOrNullAsync(); + } - private async Task GetHttpResponseMessageWithRetryAsync(HttpClient client, string url) - { - return await HttpPolicyExtensions - .HandleTransientHttpError() - .OrResult(msg => !msg.IsSuccessStatusCode) - .WaitAndRetryAsync(new[] - { - TimeSpan.FromSeconds(2), - TimeSpan.FromSeconds(4), - TimeSpan.FromSeconds(7) - }, - (responseMessage, timeSpan, retryCount, context) => - { - if (responseMessage.Exception != null) - { - Logger.LogWarning( - $"{retryCount}. HTTP request attempt failed to {url} with an error: HTTP {(int)responseMessage.Result.StatusCode}-{responseMessage.Exception.Message}. " + - $"Waiting {timeSpan.TotalSeconds} secs for the next try..."); - } - else if (responseMessage.Result != null) - { - Logger.LogWarning( - $"{retryCount}. HTTP request attempt failed to {url} with an error: {(int)responseMessage.Result.StatusCode}-{responseMessage.Result.ReasonPhrase}. " + - $"Waiting {timeSpan.TotalSeconds} secs for the next try..."); - } - }) - .ExecuteAsync(async () => await client.GetAsync(url, CancellationTokenProvider.Token)); + return CliUrls.GetNuGetPackageInfoUrl(_apiKeyResult.ApiKey, packageId); } private async Task> GetProPackageListAsync() { using var client = new CliHttpClient(); - var responseMessage = await client.GetAsync( - $"{CliUrls.WwwAbpIo}api/app/nugetPackage/proPackageNames", - CancellationTokenProvider.Token + var url = $"{CliUrls.WwwAbpIo}api/app/nugetPackage/proPackageNames"; + + var responseMessage = await client.GetHttpResponseMessageWithRetryAsync( + url: url, + cancellationToken: CancellationTokenProvider.Token, + logger: Logger ); - if (!responseMessage.IsSuccessStatusCode) + if (responseMessage.IsSuccessStatusCode) { - var exceptionMessage = "Remote server returns '" + (int)responseMessage.StatusCode + "-" + responseMessage.ReasonPhrase + "'. "; - var remoteServiceErrorMessage = await RemoteServiceExceptionHandler.GetAbpRemoteServiceErrorAsync(responseMessage); + return JsonSerializer.Deserialize>(await responseMessage.Content.ReadAsStringAsync()); + } - if (remoteServiceErrorMessage != null) - { - exceptionMessage += remoteServiceErrorMessage; - } - Logger.LogInformation(exceptionMessage); - return null; + var exceptionMessage = "Remote server returns '" + (int)responseMessage.StatusCode + "-" + responseMessage.ReasonPhrase + "'. "; + var remoteServiceErrorMessage = await RemoteServiceExceptionHandler.GetAbpRemoteServiceErrorAsync(responseMessage); + + if (remoteServiceErrorMessage != null) + { + exceptionMessage += remoteServiceErrorMessage; } - return JsonSerializer.Deserialize>(await responseMessage.Content.ReadAsStringAsync()); + Logger.LogError(exceptionMessage); + return null; } public class NuGetVersionResultDto From d8591bdaa6f353d4c4e2d397e9d8a3ecba3186fa Mon Sep 17 00:00:00 2001 From: Alper Ebicoglu Date: Sat, 2 May 2020 05:23:57 +0300 Subject: [PATCH 41/67] closes #3811 --- .../MyGetPackageListFinder.cs | 2 +- .../ProjectModification/NpmPackagesUpdater.cs | 62 ++++++++++++------- .../VoloNugetPackagesVersionUpdater.cs | 2 +- 3 files changed, 42 insertions(+), 24 deletions(-) diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/MyGetPackageListFinder.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/MyGetPackageListFinder.cs index 41907276f4..75e9156ce0 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/MyGetPackageListFinder.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/MyGetPackageListFinder.cs @@ -20,7 +20,7 @@ namespace Volo.Abp.Cli.ProjectModification Logger = NullLogger.Instance; } - public async Task GetPackages() + public async Task GetPackagesAsync() { if (_response != null) { diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/NpmPackagesUpdater.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/NpmPackagesUpdater.cs index a5a2e506cc..1a279fafc7 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/NpmPackagesUpdater.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/NpmPackagesUpdater.cs @@ -13,25 +13,31 @@ using Volo.Abp.Cli.Http; using Volo.Abp.Cli.Utils; using Volo.Abp.DependencyInjection; using Volo.Abp.IO; +using Volo.Abp.Threading; namespace Volo.Abp.Cli.ProjectModification { public class NpmPackagesUpdater : ITransientDependency { public ILogger Logger { get; set; } + protected ICancellationTokenProvider CancellationTokenProvider { get; } private readonly PackageJsonFileFinder _packageJsonFileFinder; private readonly NpmGlobalPackagesChecker _npmGlobalPackagesChecker; private readonly MyGetPackageListFinder _myGetPackageListFinder; - private readonly Dictionary _fileVersionStorage = new Dictionary(); + private MyGetApiResponse _myGetApiResponse; - public NpmPackagesUpdater(PackageJsonFileFinder packageJsonFileFinder, NpmGlobalPackagesChecker npmGlobalPackagesChecker, MyGetPackageListFinder myGetPackageListFinder) + public NpmPackagesUpdater( + PackageJsonFileFinder packageJsonFileFinder, + NpmGlobalPackagesChecker npmGlobalPackagesChecker, + MyGetPackageListFinder myGetPackageListFinder, + ICancellationTokenProvider cancellationTokenProvider) { _packageJsonFileFinder = packageJsonFileFinder; _npmGlobalPackagesChecker = npmGlobalPackagesChecker; _myGetPackageListFinder = myGetPackageListFinder; - + CancellationTokenProvider = cancellationTokenProvider; Logger = NullLogger.Instance; } @@ -77,7 +83,7 @@ namespace Volo.Abp.Cli.ProjectModification } } - private async Task DeleteNpmrcFileAsync(string directoryName) + private static async Task DeleteNpmrcFileAsync(string directoryName) { FileHelper.DeleteIfExists(Path.Combine(directoryName, ".npmrc")); @@ -135,11 +141,13 @@ namespace Volo.Abp.Cli.ProjectModification { using (var client = new CliHttpClient(TimeSpan.FromMinutes(1))) { - var responseMessage = await client.GetAsync( - $"{CliUrls.WwwAbpIo}api/myget/apikey/" + var response = await client.GetHttpResponseMessageWithRetryAsync( + url: $"{CliUrls.WwwAbpIo}api/myget/apikey/", + cancellationToken: CancellationTokenProvider.Token, + logger: Logger ); - return Encoding.Default.GetString(await responseMessage.Content.ReadAsByteArrayAsync()); + return Encoding.Default.GetString(await response.Content.ReadAsByteArrayAsync()); } } catch (Exception) @@ -148,26 +156,26 @@ namespace Volo.Abp.Cli.ProjectModification } } - private bool IsAngularProject(string fileDirectory) + private static bool IsAngularProject(string fileDirectory) { return File.Exists(Path.Combine(fileDirectory, "angular.json")); } - protected virtual async Task UpdatePackagesInFile(string file, bool includePreviews = false, bool switchToStable = false) + protected virtual async Task UpdatePackagesInFile(string filePath, bool includePreviews = false, bool switchToStable = false) { var packagesUpdated = false; - var fileContent = File.ReadAllText(file); + var fileContent = File.ReadAllText(filePath); var packageJson = JObject.Parse(fileContent); var abpPackages = GetAbpPackagesFromPackageJson(packageJson); if (!abpPackages.Any()) { - return packagesUpdated; + return false; } foreach (var abpPackage in abpPackages) { - var updated = await TryUpdatePackage(file, abpPackage, includePreviews, switchToStable); + var updated = await TryUpdatingPackage(filePath, abpPackage, includePreviews, switchToStable); if (updated) { @@ -175,15 +183,18 @@ namespace Volo.Abp.Cli.ProjectModification } } - var modifiedFileContent = packageJson.ToString(Formatting.Indented); + var updatedContent = packageJson.ToString(Formatting.Indented); - File.WriteAllText(file, modifiedFileContent); + File.WriteAllText(filePath, updatedContent); return packagesUpdated; } - protected virtual async Task TryUpdatePackage(string file, JProperty package, - bool includePreviews = false, bool switchToStable = false) + protected virtual async Task TryUpdatingPackage( + string filePath, + JProperty package, + bool includePreviews = false, + bool switchToStable = false) { var currentVersion = (string)package.Value; @@ -198,23 +209,31 @@ namespace Volo.Abp.Cli.ProjectModification package.Value.Replace(versionWithPrefix); - Logger.LogInformation($"Updated {package.Name} to {version} in {file.Replace(Directory.GetCurrentDirectory(), "")}."); + Logger.LogInformation($"Updated {package.Name} to {version} in {filePath.Replace(Directory.GetCurrentDirectory(), "")}."); return true; } - protected virtual async Task GetLatestVersion(JProperty package, string currentVersion, - bool includePreviews = false, bool switchToStable = false) + protected virtual async Task GetLatestVersion( + JProperty package, + string currentVersion, + bool includePreviews = false, + bool switchToStable = false) { if (_fileVersionStorage.ContainsKey(package.Name)) { return _fileVersionStorage[package.Name]; } - string newVersion = currentVersion; + var newVersion = currentVersion; if (includePreviews || (!switchToStable && currentVersion.Contains("-preview"))) { - var mygetPackage = (await _myGetPackageListFinder.GetPackages()).Packages.FirstOrDefault(p => p.Id == package.Name); + if (_myGetApiResponse == null) + { + _myGetApiResponse = await _myGetPackageListFinder.GetPackagesAsync(); + } + + var mygetPackage = _myGetApiResponse.Packages.FirstOrDefault(p => p.Id == package.Name); if (mygetPackage != null) { newVersion = mygetPackage.Versions.Last(); @@ -225,7 +244,6 @@ namespace Volo.Abp.Cli.ProjectModification newVersion = CmdHelper.RunCmdAndGetOutput($"npm show {package.Name} version"); } - _fileVersionStorage[package.Name] = newVersion; return newVersion; diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/VoloNugetPackagesVersionUpdater.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/VoloNugetPackagesVersionUpdater.cs index cb3ccfdef5..fb2a386ef9 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/VoloNugetPackagesVersionUpdater.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/VoloNugetPackagesVersionUpdater.cs @@ -123,7 +123,7 @@ namespace Volo.Abp.Cli.ProjectModification private async Task GetLatestVersionFromMyGet(string packageId) { - var myGetPack = await _myGetPackageListFinder.GetPackages(); + var myGetPack = await _myGetPackageListFinder.GetPackagesAsync(); return myGetPack.Packages.FirstOrDefault(p => p.Id == packageId)?.Versions.LastOrDefault(); } From 3317b7809524e8ec4f21260213b9ae2d1ea53e96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Sun, 3 May 2020 00:41:28 +0300 Subject: [PATCH 42/67] Move Module property to an extension method. --- .../CachedObjectExtensionsDtoService.cs | 2 +- ...oduleObjectExtensionConfigurationHelper.cs | 2 +- .../ModuleObjectExtensionManagerExtensions.cs | 22 +++++++++++++++++++ .../ObjectExtending/ObjectExtensionManager.cs | 4 ---- 4 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionManagerExtensions.cs diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/CachedObjectExtensionsDtoService.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/CachedObjectExtensionsDtoService.cs index 21cb11e318..197ae6d07d 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/CachedObjectExtensionsDtoService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/CachedObjectExtensionsDtoService.cs @@ -37,7 +37,7 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending Modules = new Dictionary() }; - foreach (var moduleConfig in ObjectExtensionManager.Instance.Modules) + foreach (var moduleConfig in ObjectExtensionManager.Instance.Modules()) { var moduleExtensionDto = objectExtensionsDto.Modules[moduleConfig.Key] = new ModuleExtensionDto { diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleObjectExtensionConfigurationHelper.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleObjectExtensionConfigurationHelper.cs index 8bff5e8f05..6df0e58fb0 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleObjectExtensionConfigurationHelper.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleObjectExtensionConfigurationHelper.cs @@ -122,7 +122,7 @@ namespace Volo.Abp.ObjectExtending.Modularity string moduleName, string objectName) { - var moduleConfig = ObjectExtensionManager.Instance.Modules.GetOrDefault(moduleName); + var moduleConfig = ObjectExtensionManager.Instance.Modules().GetOrDefault(moduleName); if (moduleConfig == null) { return Array.Empty(); diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionManagerExtensions.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionManagerExtensions.cs new file mode 100644 index 0000000000..7a1422f2f6 --- /dev/null +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionManagerExtensions.cs @@ -0,0 +1,22 @@ +using System.Collections.Generic; +using JetBrains.Annotations; +using Volo.Abp.ObjectExtending.Modularity; + +namespace Volo.Abp.ObjectExtending +{ + public static class ModuleObjectExtensionManagerExtensions + { + private const string ObjectExtensionManagerConfigurationKey = "_Modules"; + + public static ModuleObjectExtensionConfigurationDictionary Modules( + [NotNull]this ObjectExtensionManager objectExtensionManager) + { + Check.NotNull(objectExtensionManager, nameof(objectExtensionManager)); + + return objectExtensionManager.Configuration.GetOrAdd( + ObjectExtensionManagerConfigurationKey, + () => new ModuleObjectExtensionConfigurationDictionary() + ) as ModuleObjectExtensionConfigurationDictionary; + } + } +} diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionManager.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionManager.cs index 45a4be8847..26b692c232 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionManager.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionManager.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Collections.Immutable; using JetBrains.Annotations; using Volo.Abp.Data; -using Volo.Abp.ObjectExtending.Modularity; namespace Volo.Abp.ObjectExtending { @@ -16,13 +15,10 @@ namespace Volo.Abp.ObjectExtending protected Dictionary ObjectsExtensions { get; } - public ModuleObjectExtensionConfigurationDictionary Modules { get; } - protected internal ObjectExtensionManager() { ObjectsExtensions = new Dictionary(); Configuration = new Dictionary(); - Modules = new ModuleObjectExtensionConfigurationDictionary(); } [NotNull] From e26d693ca309c52211e167dd6af1f465c7d76b7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Sun, 3 May 2020 00:55:05 +0300 Subject: [PATCH 43/67] Refactor module entity extensions --- .../CachedObjectExtensionsDtoService.cs | 2 +- .../ModuleEntityObjectExtensionConfiguration.cs | 4 ++-- ...uleEntityObjectExtensionConfigurationDictionary.cs | 9 +++++++++ ...yObjectPropertyExtensionConfigurationDictionary.cs | 9 +++++++++ .../Modularity/ModuleObjectExtensionConfiguration.cs | 11 +++++++---- .../ModuleObjectExtensionConfigurationExtensions.cs | 2 +- .../ModuleObjectExtensionConfigurationHelper.cs | 2 +- 7 files changed, 30 insertions(+), 9 deletions(-) create mode 100644 framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectExtensionConfigurationDictionary.cs create mode 100644 framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionConfigurationDictionary.cs diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/CachedObjectExtensionsDtoService.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/CachedObjectExtensionsDtoService.cs index 197ae6d07d..766be2e42b 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/CachedObjectExtensionsDtoService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/CachedObjectExtensionsDtoService.cs @@ -44,7 +44,7 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending Objects = new Dictionary() }; - foreach (var objectConfig in moduleConfig.Value) + foreach (var objectConfig in moduleConfig.Value.Entities) { var moduleObjectExtensionDto = moduleExtensionDto.Objects[objectConfig.Key] = new ModuleObjectExtensionDto diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectExtensionConfiguration.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectExtensionConfiguration.cs index 3e1c3ef136..2c7beaa0e4 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectExtensionConfiguration.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectExtensionConfiguration.cs @@ -8,14 +8,14 @@ namespace Volo.Abp.ObjectExtending.Modularity public class ModuleEntityObjectExtensionConfiguration { [NotNull] - protected Dictionary Properties { get; } + protected ModuleEntityObjectPropertyExtensionConfigurationDictionary Properties { get; } [NotNull] public List> Validators { get; } public ModuleEntityObjectExtensionConfiguration() { - Properties = new Dictionary(); + Properties = new ModuleEntityObjectPropertyExtensionConfigurationDictionary(); Validators = new List>(); } diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectExtensionConfigurationDictionary.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectExtensionConfigurationDictionary.cs new file mode 100644 index 0000000000..73d78b808e --- /dev/null +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectExtensionConfigurationDictionary.cs @@ -0,0 +1,9 @@ +using System.Collections.Generic; + +namespace Volo.Abp.ObjectExtending.Modularity +{ + public class ModuleEntityObjectExtensionConfigurationDictionary : Dictionary + { + + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionConfigurationDictionary.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionConfigurationDictionary.cs new file mode 100644 index 0000000000..4b7e7e3ddb --- /dev/null +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionConfigurationDictionary.cs @@ -0,0 +1,9 @@ +using System.Collections.Generic; + +namespace Volo.Abp.ObjectExtending.Modularity +{ + public class ModuleEntityObjectPropertyExtensionConfigurationDictionary : Dictionary + { + + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleObjectExtensionConfiguration.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleObjectExtensionConfiguration.cs index 67453f8188..14470d1a17 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleObjectExtensionConfiguration.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleObjectExtensionConfiguration.cs @@ -1,9 +1,12 @@ -using System.Collections.Generic; - -namespace Volo.Abp.ObjectExtending.Modularity +namespace Volo.Abp.ObjectExtending.Modularity { - public class ModuleObjectExtensionConfiguration : Dictionary + public class ModuleObjectExtensionConfiguration { + public ModuleEntityObjectExtensionConfigurationDictionary Entities { get; set; } + public ModuleObjectExtensionConfiguration() + { + Entities = new ModuleEntityObjectExtensionConfigurationDictionary(); + } } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleObjectExtensionConfigurationExtensions.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleObjectExtensionConfigurationExtensions.cs index 218c66344e..137002418a 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleObjectExtensionConfigurationExtensions.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleObjectExtensionConfigurationExtensions.cs @@ -11,7 +11,7 @@ namespace Volo.Abp.ObjectExtending.Modularity Action configureAction) where T : ModuleObjectExtensionConfiguration { - var configuration = objectConfiguration.GetOrAdd( + var configuration = objectConfiguration.Entities.GetOrAdd( objectName, () => new ModuleEntityObjectExtensionConfiguration() ); diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleObjectExtensionConfigurationHelper.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleObjectExtensionConfigurationHelper.cs index 6df0e58fb0..a975f00102 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleObjectExtensionConfigurationHelper.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleObjectExtensionConfigurationHelper.cs @@ -128,7 +128,7 @@ namespace Volo.Abp.ObjectExtending.Modularity return Array.Empty(); } - var objectConfig = moduleConfig.GetOrDefault(objectName); + var objectConfig = moduleConfig.Entities.GetOrDefault(objectName); if (objectConfig == null) { return Array.Empty(); From c4955719b16dfb45d4ea2dade79db9108b0f0d05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Sun, 3 May 2020 02:00:28 +0300 Subject: [PATCH 44/67] Rename and refactor module extensions. --- .../CachedObjectExtensionsDtoService.cs | 187 +++++++++++------- .../ObjectExtending/EntityExtensionDto.cs | 14 ++ ...on.cs => ExtensionPropertyApiCreateDto.cs} | 2 +- .../ExtensionPropertyApiDto.cs | 23 +++ ...ation.cs => ExtensionPropertyApiGetDto.cs} | 2 +- ...on.cs => ExtensionPropertyApiUpdateDto.cs} | 2 +- ...to.cs => ExtensionPropertyAttributeDto.cs} | 6 +- ...xtensionDto.cs => ExtensionPropertyDto.cs} | 10 +- .../ObjectExtending/ExtensionPropertyUiDto.cs | 12 ++ ...onDto.cs => ExtensionPropertyUiFormDto.cs} | 2 +- ...nDto.cs => ExtensionPropertyUiTableDto.cs} | 2 +- .../ObjectExtending/LocalizableStringDto.cs | 9 +- ...ObjectPropertyExtensionApiConfiguration.cs | 23 --- .../ModuleObjectExtensionDto.cs | 11 -- ...ModuleObjectExtraPropertyUiExtensionDto.cs | 12 -- .../ObjectExtensionConfigurationDto.cs | 7 +- .../Abp/Localization/LocalizableString.cs | 9 +- ...ion.cs => EntityExtensionConfiguration.cs} | 23 ++- .../EntityExtensionConfigurationDictionary.cs | 9 + .../ExtensionPropertyApiConfiguration.cs | 23 +++ ...xtensionPropertyApiCreateConfiguration.cs} | 2 +- ...> ExtensionPropertyApiGetConfiguration.cs} | 2 +- ...xtensionPropertyApiUpdateConfiguration.cs} | 2 +- ...n.cs => ExtensionPropertyConfiguration.cs} | 30 +-- ...xtensionPropertyConfigurationDictionary.cs | 9 + ...> ExtensionPropertyEntityConfiguration.cs} | 2 +- .../ExtensionPropertyUiConfiguration.cs | 23 +++ ...> ExtensionPropertyUiFormConfiguration.cs} | 2 +- ... ExtensionPropertyUiTableConfiguration.cs} | 2 +- ...yObjectExtensionConfigurationDictionary.cs | 9 - ...ObjectPropertyExtensionApiConfiguration.cs | 23 --- ...ropertyExtensionConfigurationDictionary.cs | 9 - ...yObjectPropertyExtensionUIConfiguration.cs | 23 --- .../ModuleExtensionConfiguration.cs | 20 ++ .../ModuleExtensionConfigurationDictionary.cs | 9 + ...nsionConfigurationDictionaryExtensions.cs} | 8 +- ...ModuleExtensionConfigurationExtensions.cs} | 10 +- ... => ModuleExtensionConfigurationHelper.cs} | 44 ++--- .../ModuleObjectExtensionConfiguration.cs | 12 -- ...eObjectExtensionConfigurationDictionary.cs | 9 - .../ModuleObjectExtensionManagerExtensions.cs | 6 +- .../IdentityModuleExtensionConfiguration.cs | 9 + ...yModuleExtensionConfigurationExtensions.cs | 18 ++ ...ntityModuleObjectExtensionConfiguration.cs | 9 - ...eObjectExtensionConfigurationExtensions.cs | 18 -- ...ObjectExtensionConfigurationsExtensions.cs | 6 +- .../Abp/Identity/AbpIdentityDomainModule.cs | 2 +- 47 files changed, 384 insertions(+), 322 deletions(-) create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/EntityExtensionDto.cs rename framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/{ModuleEntityObjectPropertyExtensionApiGetConfiguration.cs => ExtensionPropertyApiCreateDto.cs} (76%) create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ExtensionPropertyApiDto.cs rename framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/{ModuleEntityObjectPropertyExtensionApiCreateConfiguration.cs => ExtensionPropertyApiGetDto.cs} (76%) rename framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/{ModuleEntityObjectPropertyExtensionApiUpdateConfiguration.cs => ExtensionPropertyApiUpdateDto.cs} (76%) rename framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/{ModuleObjectExtraPropertyAttributeDto.cs => ExtensionPropertyAttributeDto.cs} (83%) rename framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/{ModuleObjectExtraPropertyExtensionDto.cs => ExtensionPropertyDto.cs} (55%) create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ExtensionPropertyUiDto.cs rename framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/{ModuleObjectExtraPropertyUiFormExtensionDto.cs => ExtensionPropertyUiFormDto.cs} (73%) rename framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/{ModuleObjectExtraPropertyUiTableExtensionDto.cs => ExtensionPropertyUiTableDto.cs} (73%) delete mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleEntityObjectPropertyExtensionApiConfiguration.cs delete mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtensionDto.cs delete mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyUiExtensionDto.cs rename framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/{ModuleEntityObjectExtensionConfiguration.cs => EntityExtensionConfiguration.cs} (55%) create mode 100644 framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/EntityExtensionConfigurationDictionary.cs create mode 100644 framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ExtensionPropertyApiConfiguration.cs rename framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/{ModuleEntityObjectPropertyExtensionApiGetConfiguration.cs => ExtensionPropertyApiCreateConfiguration.cs} (72%) rename framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/{ModuleEntityObjectPropertyExtensionEntityConfiguration.cs => ExtensionPropertyApiGetConfiguration.cs} (72%) rename framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/{ModuleEntityObjectPropertyExtensionApiCreateConfiguration.cs => ExtensionPropertyApiUpdateConfiguration.cs} (71%) rename framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/{ModuleEntityObjectPropertyExtensionConfiguration.cs => ExtensionPropertyConfiguration.cs} (54%) create mode 100644 framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ExtensionPropertyConfigurationDictionary.cs rename framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/{ModuleEntityObjectPropertyExtensionApiUpdateConfiguration.cs => ExtensionPropertyEntityConfiguration.cs} (71%) create mode 100644 framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ExtensionPropertyUiConfiguration.cs rename framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/{ModuleEntityObjectPropertyExtensionUIFormConfiguration.cs => ExtensionPropertyUiFormConfiguration.cs} (71%) rename framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/{ModuleEntityObjectPropertyExtensionUITableConfiguration.cs => ExtensionPropertyUiTableConfiguration.cs} (71%) delete mode 100644 framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectExtensionConfigurationDictionary.cs delete mode 100644 framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionApiConfiguration.cs delete mode 100644 framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionConfigurationDictionary.cs delete mode 100644 framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionUIConfiguration.cs create mode 100644 framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleExtensionConfiguration.cs create mode 100644 framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleExtensionConfigurationDictionary.cs rename framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/{ModuleObjectExtensionConfigurationDictionaryExtensions.cs => ModuleExtensionConfigurationDictionaryExtensions.cs} (64%) rename framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/{ModuleObjectExtensionConfigurationExtensions.cs => ModuleExtensionConfigurationExtensions.cs} (55%) rename framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/{ModuleObjectExtensionConfigurationHelper.cs => ModuleExtensionConfigurationHelper.cs} (78%) delete mode 100644 framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleObjectExtensionConfiguration.cs delete mode 100644 framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleObjectExtensionConfigurationDictionary.cs create mode 100644 modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleExtensionConfiguration.cs create mode 100644 modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleExtensionConfigurationExtensions.cs delete mode 100644 modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleObjectExtensionConfiguration.cs delete mode 100644 modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleObjectExtensionConfigurationExtensions.cs diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/CachedObjectExtensionsDtoService.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/CachedObjectExtensionsDtoService.cs index 766be2e42b..f87fef31aa 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/CachedObjectExtensionsDtoService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/CachedObjectExtensionsDtoService.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; using Volo.Abp.DependencyInjection; using Volo.Abp.Localization; using Volo.Abp.ObjectExtending; @@ -30,8 +31,6 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending protected virtual ObjectExtensionsDto GenerateCacheValue() { - //TODO: Obviously needs refactoring! - var objectExtensionsDto = new ObjectExtensionsDto { Modules = new Dictionary() @@ -39,80 +38,118 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending foreach (var moduleConfig in ObjectExtensionManager.Instance.Modules()) { - var moduleExtensionDto = objectExtensionsDto.Modules[moduleConfig.Key] = new ModuleExtensionDto - { - Objects = new Dictionary() - }; + objectExtensionsDto.Modules[moduleConfig.Key] = CreateModuleExtensionDto(moduleConfig.Value); + } + + return objectExtensionsDto; + } + + protected virtual ModuleExtensionDto CreateModuleExtensionDto( + ModuleExtensionConfiguration moduleConfig) + { + var moduleExtensionDto = new ModuleExtensionDto + { + Entities = new Dictionary() + }; + + foreach (var objectConfig in moduleConfig.Entities) + { + moduleExtensionDto.Entities[objectConfig.Key] = GetEntityExtensionDto(objectConfig.Value); + } - foreach (var objectConfig in moduleConfig.Value.Entities) + foreach (var customConfig in moduleConfig.Configuration.Where(c => !c.Key.StartsWith("_"))) + { + moduleExtensionDto.Configuration[customConfig.Key] = customConfig.Value; + } + + return moduleExtensionDto; + } + + protected virtual EntityExtensionDto GetEntityExtensionDto( + EntityExtensionConfiguration entityConfig) + { + var entityExtensionDto = new EntityExtensionDto + { + Properties = new Dictionary(), + Configuration = new Dictionary() + }; + + foreach (var propertyConfig in entityConfig.GetProperties()) + { + if (!propertyConfig.IsAvailableToClients) { - var moduleObjectExtensionDto = moduleExtensionDto.Objects[objectConfig.Key] = - new ModuleObjectExtensionDto - { - ExtraProperties = new Dictionary() - }; + continue; + } + + entityExtensionDto.Properties[propertyConfig.Name] = CreateExtensionPropertyDto(propertyConfig); + } + + foreach (var customConfig in entityConfig.Configuration.Where(c => !c.Key.StartsWith("_"))) + { + entityExtensionDto.Configuration[customConfig.Key] = customConfig.Value; + } - foreach (var propertyConfig in objectConfig.Value.GetProperties()) + return entityExtensionDto; + } + + protected virtual ExtensionPropertyDto CreateExtensionPropertyDto( + ExtensionPropertyConfiguration propertyConfig) + { + var extensionPropertyDto = new ExtensionPropertyDto + { + Type = TypeHelper.GetFullNameHandlingNullableAndGenerics(propertyConfig.Type), + TypeSimple = TypeHelper.GetSimplifiedName(propertyConfig.Type), + Attributes = new List(), + DisplayName = CreateDisplayNameDto(propertyConfig), + Configuration = new Dictionary(), + Api = new ExtensionPropertyApiDto + { + OnGet = new ExtensionPropertyApiGetDto + { + IsAvailable = propertyConfig.Api.OnGet.IsAvailable + }, + OnCreate = new ExtensionPropertyApiCreateDto { - if (!propertyConfig.IsAvailableToClients) - { - continue; - } - - var propertyExtensionDto = moduleObjectExtensionDto.ExtraProperties[propertyConfig.Name] = - new ModuleObjectExtraPropertyExtensionDto - { - Type = TypeHelper.GetFullNameHandlingNullableAndGenerics(propertyConfig.Type), - TypeSimple = TypeHelper.GetSimplifiedName(propertyConfig.Type), - Attributes = new List(), - DisplayName = CreateDisplayNameDto(propertyConfig), - Api = new ModuleEntityObjectPropertyExtensionApiConfigurationDto - { - OnGet = new ModuleEntityObjectPropertyExtensionApiGetConfigurationDto - { - IsAvailable = propertyConfig.Api.OnGet.IsAvailable - }, - OnCreate = new ModuleEntityObjectPropertyExtensionApiCreateConfigurationDto - { - IsAvailable = propertyConfig.Api.OnCreate.IsAvailable - }, - OnUpdate = new ModuleEntityObjectPropertyExtensionApiUpdateConfigurationDto - { - IsAvailable = propertyConfig.Api.OnUpdate.IsAvailable - } - }, - Ui = new ModuleObjectExtraPropertyUiExtensionDto - { - OnCreateForm = new ModuleObjectExtraPropertyUiFormExtensionDto - { - IsVisible = propertyConfig.UI.OnCreateForm.IsVisible - }, - OnEditForm = new ModuleObjectExtraPropertyUiFormExtensionDto - { - IsVisible = propertyConfig.UI.OnEditForm.IsVisible - }, - OnTable = new ModuleObjectExtraPropertyUiTableExtensionDto - { - IsVisible = propertyConfig.UI.OnTable.IsVisible - } - } - }; - - foreach (var attribute in propertyConfig.Attributes) - { - propertyExtensionDto.Attributes.Add( - ModuleObjectExtraPropertyAttributeDto.Create(attribute) - ); - } + IsAvailable = propertyConfig.Api.OnCreate.IsAvailable + }, + OnUpdate = new ExtensionPropertyApiUpdateDto + { + IsAvailable = propertyConfig.Api.OnUpdate.IsAvailable + } + }, + Ui = new ExtensionPropertyUiDto + { + OnCreateForm = new ExtensionPropertyUiFormDto + { + IsVisible = propertyConfig.UI.OnCreateForm.IsVisible + }, + OnEditForm = new ExtensionPropertyUiFormDto + { + IsVisible = propertyConfig.UI.OnEditForm.IsVisible + }, + OnTable = new ExtensionPropertyUiTableDto + { + IsVisible = propertyConfig.UI.OnTable.IsVisible } } + }; + + foreach (var attribute in propertyConfig.Attributes) + { + extensionPropertyDto.Attributes.Add( + ExtensionPropertyAttributeDto.Create(attribute) + ); } - return objectExtensionsDto; + foreach (var customConfig in propertyConfig.Configuration.Where(c => !c.Key.StartsWith("_"))) + { + extensionPropertyDto.Configuration[customConfig.Key] = customConfig.Value; + } + + return extensionPropertyDto; } - private static LocalizableStringDto CreateDisplayNameDto( - ModuleEntityObjectPropertyExtensionConfiguration propertyConfig) + protected virtual LocalizableStringDto CreateDisplayNameDto(ExtensionPropertyConfiguration propertyConfig) { if (propertyConfig.DisplayName == null) { @@ -121,20 +158,18 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending if (propertyConfig.DisplayName is LocalizableString localizableStringInstance) { - return new LocalizableStringDto - { - Name = localizableStringInstance.Name, - Resource = LocalizationResourceNameAttribute.GetName(localizableStringInstance.ResourceType) - }; + return new LocalizableStringDto( + localizableStringInstance.Name, + localizableStringInstance.ResourceType != null + ? LocalizationResourceNameAttribute.GetName(localizableStringInstance.ResourceType) + : null + ); } if (propertyConfig.DisplayName is FixedLocalizableString fixedLocalizableString) { - return new LocalizableStringDto - { - Name = fixedLocalizableString.Value, - Resource = "_" - }; + // "_" means don't use the default resource, but directly use the name. + return new LocalizableStringDto(fixedLocalizableString.Value, "_"); } return null; diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/EntityExtensionDto.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/EntityExtensionDto.cs new file mode 100644 index 0000000000..83093e0370 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/EntityExtensionDto.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending +{ + [Serializable] + public class EntityExtensionDto + { + public Dictionary Properties { get; set; } + + public Dictionary Configuration { get; set; } + + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleEntityObjectPropertyExtensionApiGetConfiguration.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ExtensionPropertyApiCreateDto.cs similarity index 76% rename from framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleEntityObjectPropertyExtensionApiGetConfiguration.cs rename to framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ExtensionPropertyApiCreateDto.cs index 20bf7682c3..a2a588a358 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleEntityObjectPropertyExtensionApiGetConfiguration.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ExtensionPropertyApiCreateDto.cs @@ -3,7 +3,7 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending { [Serializable] - public class ModuleEntityObjectPropertyExtensionApiGetConfigurationDto + public class ExtensionPropertyApiCreateDto { /// /// Default: true. diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ExtensionPropertyApiDto.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ExtensionPropertyApiDto.cs new file mode 100644 index 0000000000..a9b4ec5b24 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ExtensionPropertyApiDto.cs @@ -0,0 +1,23 @@ +using JetBrains.Annotations; + +namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending +{ + public class ExtensionPropertyApiDto + { + [NotNull] + public ExtensionPropertyApiGetDto OnGet { get; set; } + + [NotNull] + public ExtensionPropertyApiCreateDto OnCreate { get; set; } + + [NotNull] + public ExtensionPropertyApiUpdateDto OnUpdate { get; set; } + + public ExtensionPropertyApiDto() + { + OnGet = new ExtensionPropertyApiGetDto(); + OnCreate = new ExtensionPropertyApiCreateDto(); + OnUpdate = new ExtensionPropertyApiUpdateDto(); + } + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleEntityObjectPropertyExtensionApiCreateConfiguration.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ExtensionPropertyApiGetDto.cs similarity index 76% rename from framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleEntityObjectPropertyExtensionApiCreateConfiguration.cs rename to framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ExtensionPropertyApiGetDto.cs index 7cfa9959b0..e50a45d15a 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleEntityObjectPropertyExtensionApiCreateConfiguration.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ExtensionPropertyApiGetDto.cs @@ -3,7 +3,7 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending { [Serializable] - public class ModuleEntityObjectPropertyExtensionApiCreateConfigurationDto + public class ExtensionPropertyApiGetDto { /// /// Default: true. diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleEntityObjectPropertyExtensionApiUpdateConfiguration.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ExtensionPropertyApiUpdateDto.cs similarity index 76% rename from framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleEntityObjectPropertyExtensionApiUpdateConfiguration.cs rename to framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ExtensionPropertyApiUpdateDto.cs index 3000965957..a517b258da 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleEntityObjectPropertyExtensionApiUpdateConfiguration.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ExtensionPropertyApiUpdateDto.cs @@ -3,7 +3,7 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending { [Serializable] - public class ModuleEntityObjectPropertyExtensionApiUpdateConfigurationDto + public class ExtensionPropertyApiUpdateDto { /// /// Default: true. diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyAttributeDto.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ExtensionPropertyAttributeDto.cs similarity index 83% rename from framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyAttributeDto.cs rename to framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ExtensionPropertyAttributeDto.cs index d45bf7d8d4..c1c19350c2 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyAttributeDto.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ExtensionPropertyAttributeDto.cs @@ -6,16 +6,16 @@ using Volo.Abp.Reflection; namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending { [Serializable] - public class ModuleObjectExtraPropertyAttributeDto + public class ExtensionPropertyAttributeDto { public string Type { get; set; } public string TypeSimple { get; set; } public Dictionary Configuration { get; set; } - public static ModuleObjectExtraPropertyAttributeDto Create(Attribute attribute) + public static ExtensionPropertyAttributeDto Create(Attribute attribute) { var attributeType = attribute.GetType(); - var dto = new ModuleObjectExtraPropertyAttributeDto + var dto = new ExtensionPropertyAttributeDto { Type = TypeHelper.GetFullNameHandlingNullableAndGenerics(attributeType), TypeSimple = TypeHelper.GetSimplifiedName(attributeType), diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyExtensionDto.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ExtensionPropertyDto.cs similarity index 55% rename from framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyExtensionDto.cs rename to framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ExtensionPropertyDto.cs index d61c49d327..74214914b9 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyExtensionDto.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ExtensionPropertyDto.cs @@ -5,7 +5,7 @@ using JetBrains.Annotations; namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending { [Serializable] - public class ModuleObjectExtraPropertyExtensionDto + public class ExtensionPropertyDto { public string Type { get; set; } @@ -14,10 +14,12 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending [CanBeNull] public LocalizableStringDto DisplayName { get; set; } - public ModuleEntityObjectPropertyExtensionApiConfigurationDto Api { get; set; } + public ExtensionPropertyApiDto Api { get; set; } - public ModuleObjectExtraPropertyUiExtensionDto Ui { get; set; } + public ExtensionPropertyUiDto Ui { get; set; } - public List Attributes { get; set; } + public List Attributes { get; set; } + + public Dictionary Configuration { get; set; } } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ExtensionPropertyUiDto.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ExtensionPropertyUiDto.cs new file mode 100644 index 0000000000..2fb841ec5a --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ExtensionPropertyUiDto.cs @@ -0,0 +1,12 @@ +using System; + +namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending +{ + [Serializable] + public class ExtensionPropertyUiDto + { + public ExtensionPropertyUiTableDto OnTable { get; set; } + public ExtensionPropertyUiFormDto OnCreateForm { get; set; } + public ExtensionPropertyUiFormDto OnEditForm { get; set; } + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyUiFormExtensionDto.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ExtensionPropertyUiFormDto.cs similarity index 73% rename from framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyUiFormExtensionDto.cs rename to framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ExtensionPropertyUiFormDto.cs index 9d7e719f4f..c4f6f5211c 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyUiFormExtensionDto.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ExtensionPropertyUiFormDto.cs @@ -3,7 +3,7 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending { [Serializable] - public class ModuleObjectExtraPropertyUiFormExtensionDto + public class ExtensionPropertyUiFormDto { public bool IsVisible { get; set; } } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyUiTableExtensionDto.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ExtensionPropertyUiTableDto.cs similarity index 73% rename from framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyUiTableExtensionDto.cs rename to framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ExtensionPropertyUiTableDto.cs index 419b9a6430..4c9e4a7ce0 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyUiTableExtensionDto.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ExtensionPropertyUiTableDto.cs @@ -3,7 +3,7 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending { [Serializable] - public class ModuleObjectExtraPropertyUiTableExtensionDto + public class ExtensionPropertyUiTableDto { public bool IsVisible { get; set; } } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/LocalizableStringDto.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/LocalizableStringDto.cs index 307831315b..b80352d791 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/LocalizableStringDto.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/LocalizableStringDto.cs @@ -6,9 +6,16 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending [Serializable] public class LocalizableStringDto { - public string Name { get; set; } + [NotNull] + public string Name { get; private set; } [CanBeNull] public string Resource { get; set; } + + public LocalizableStringDto([NotNull] string name, string resource = null) + { + Name = Check.NotNullOrEmpty(name, nameof(name)); + Resource = resource; + } } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleEntityObjectPropertyExtensionApiConfiguration.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleEntityObjectPropertyExtensionApiConfiguration.cs deleted file mode 100644 index 9f4d1db42c..0000000000 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleEntityObjectPropertyExtensionApiConfiguration.cs +++ /dev/null @@ -1,23 +0,0 @@ -using JetBrains.Annotations; - -namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending -{ - public class ModuleEntityObjectPropertyExtensionApiConfigurationDto - { - [NotNull] - public ModuleEntityObjectPropertyExtensionApiGetConfigurationDto OnGet { get; set; } - - [NotNull] - public ModuleEntityObjectPropertyExtensionApiCreateConfigurationDto OnCreate { get; set; } - - [NotNull] - public ModuleEntityObjectPropertyExtensionApiUpdateConfigurationDto OnUpdate { get; set; } - - public ModuleEntityObjectPropertyExtensionApiConfigurationDto() - { - OnGet = new ModuleEntityObjectPropertyExtensionApiGetConfigurationDto(); - OnCreate = new ModuleEntityObjectPropertyExtensionApiCreateConfigurationDto(); - OnUpdate = new ModuleEntityObjectPropertyExtensionApiUpdateConfigurationDto(); - } - } -} \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtensionDto.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtensionDto.cs deleted file mode 100644 index 0879fc60bd..0000000000 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtensionDto.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending -{ - [Serializable] - public class ModuleObjectExtensionDto - { - public Dictionary ExtraProperties { get; set; } - } -} \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyUiExtensionDto.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyUiExtensionDto.cs deleted file mode 100644 index 8a24a3895c..0000000000 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyUiExtensionDto.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; - -namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending -{ - [Serializable] - public class ModuleObjectExtraPropertyUiExtensionDto - { - public ModuleObjectExtraPropertyUiTableExtensionDto OnTable { get; set; } - public ModuleObjectExtraPropertyUiFormExtensionDto OnCreateForm { get; set; } - public ModuleObjectExtraPropertyUiFormExtensionDto OnEditForm { get; set; } - } -} \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ObjectExtensionConfigurationDto.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ObjectExtensionConfigurationDto.cs index 096c2210c0..e077596f59 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ObjectExtensionConfigurationDto.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ObjectExtensionConfigurationDto.cs @@ -6,7 +6,8 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending [Serializable] public class ModuleExtensionDto { - public Dictionary Objects { get; set; } - } -} + public Dictionary Entities { get; set; } + public Dictionary Configuration { get; set; } + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.Localization/Volo/Abp/Localization/LocalizableString.cs b/framework/src/Volo.Abp.Localization/Volo/Abp/Localization/LocalizableString.cs index 6698ba4645..40edff18e7 100644 --- a/framework/src/Volo.Abp.Localization/Volo/Abp/Localization/LocalizableString.cs +++ b/framework/src/Volo.Abp.Localization/Volo/Abp/Localization/LocalizableString.cs @@ -1,18 +1,21 @@ using System; +using JetBrains.Annotations; using Microsoft.Extensions.Localization; namespace Volo.Abp.Localization { public class LocalizableString : ILocalizableString { + [CanBeNull] public Type ResourceType { get; } + [NotNull] public string Name { get; } - public LocalizableString(Type resourceType, string name) + public LocalizableString(Type resourceType, [NotNull] string name) { + Name = Check.NotNullOrEmpty(name, nameof(name)); ResourceType = resourceType; - Name = name; } public LocalizedString Localize(IStringLocalizerFactory stringLocalizerFactory) @@ -20,7 +23,7 @@ namespace Volo.Abp.Localization return stringLocalizerFactory.Create(ResourceType)[Name]; } - public static LocalizableString Create(string name) + public static LocalizableString Create([NotNull] string name) { return new LocalizableString(typeof(TResource), name); } diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectExtensionConfiguration.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/EntityExtensionConfiguration.cs similarity index 55% rename from framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectExtensionConfiguration.cs rename to framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/EntityExtensionConfiguration.cs index 2c7beaa0e4..ce84cb19e5 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectExtensionConfiguration.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/EntityExtensionConfiguration.cs @@ -5,24 +5,27 @@ using JetBrains.Annotations; namespace Volo.Abp.ObjectExtending.Modularity { - public class ModuleEntityObjectExtensionConfiguration + public class EntityExtensionConfiguration { [NotNull] - protected ModuleEntityObjectPropertyExtensionConfigurationDictionary Properties { get; } + protected ExtensionPropertyConfigurationDictionary Properties { get; } [NotNull] public List> Validators { get; } - public ModuleEntityObjectExtensionConfiguration() + public Dictionary Configuration { get; } + + public EntityExtensionConfiguration() { - Properties = new ModuleEntityObjectPropertyExtensionConfigurationDictionary(); + Properties = new ExtensionPropertyConfigurationDictionary(); Validators = new List>(); + Configuration = new Dictionary(); } [NotNull] - public virtual ModuleEntityObjectExtensionConfiguration AddOrUpdateProperty( + public virtual EntityExtensionConfiguration AddOrUpdateProperty( [NotNull] string propertyName, - [CanBeNull] Action configureAction = null) + [CanBeNull] Action configureAction = null) { return AddOrUpdateProperty( typeof(TProperty), @@ -32,17 +35,17 @@ namespace Volo.Abp.ObjectExtending.Modularity } [NotNull] - public virtual ModuleEntityObjectExtensionConfiguration AddOrUpdateProperty( + public virtual EntityExtensionConfiguration AddOrUpdateProperty( [NotNull] Type propertyType, [NotNull] string propertyName, - [CanBeNull] Action configureAction = null) + [CanBeNull] Action configureAction = null) { Check.NotNull(propertyType, nameof(propertyType)); Check.NotNull(propertyName, nameof(propertyName)); var propertyInfo = Properties.GetOrAdd( propertyName, - () => new ModuleEntityObjectPropertyExtensionConfiguration(this, propertyType, propertyName) + () => new ExtensionPropertyConfiguration(this, propertyType, propertyName) ); configureAction?.Invoke(propertyInfo); @@ -51,7 +54,7 @@ namespace Volo.Abp.ObjectExtending.Modularity } [NotNull] - public virtual ImmutableList GetProperties() + public virtual ImmutableList GetProperties() { return Properties.Values.ToImmutableList(); } diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/EntityExtensionConfigurationDictionary.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/EntityExtensionConfigurationDictionary.cs new file mode 100644 index 0000000000..4cc43c2932 --- /dev/null +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/EntityExtensionConfigurationDictionary.cs @@ -0,0 +1,9 @@ +using System.Collections.Generic; + +namespace Volo.Abp.ObjectExtending.Modularity +{ + public class EntityExtensionConfigurationDictionary : Dictionary + { + + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ExtensionPropertyApiConfiguration.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ExtensionPropertyApiConfiguration.cs new file mode 100644 index 0000000000..507c8636b4 --- /dev/null +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ExtensionPropertyApiConfiguration.cs @@ -0,0 +1,23 @@ +using JetBrains.Annotations; + +namespace Volo.Abp.ObjectExtending.Modularity +{ + public class ExtensionPropertyApiConfiguration + { + [NotNull] + public ExtensionPropertyApiGetConfiguration OnGet { get; } + + [NotNull] + public ExtensionPropertyApiCreateConfiguration OnCreate { get; } + + [NotNull] + public ExtensionPropertyApiUpdateConfiguration OnUpdate { get; } + + public ExtensionPropertyApiConfiguration() + { + OnGet = new ExtensionPropertyApiGetConfiguration(); + OnCreate = new ExtensionPropertyApiCreateConfiguration(); + OnUpdate = new ExtensionPropertyApiUpdateConfiguration(); + } + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionApiGetConfiguration.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ExtensionPropertyApiCreateConfiguration.cs similarity index 72% rename from framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionApiGetConfiguration.cs rename to framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ExtensionPropertyApiCreateConfiguration.cs index 5c43e8397c..235390b9be 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionApiGetConfiguration.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ExtensionPropertyApiCreateConfiguration.cs @@ -1,6 +1,6 @@ namespace Volo.Abp.ObjectExtending.Modularity { - public class ModuleEntityObjectPropertyExtensionApiGetConfiguration + public class ExtensionPropertyApiCreateConfiguration { /// /// Default: true. diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionEntityConfiguration.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ExtensionPropertyApiGetConfiguration.cs similarity index 72% rename from framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionEntityConfiguration.cs rename to framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ExtensionPropertyApiGetConfiguration.cs index 8ca9fc7cf5..caf7957a02 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionEntityConfiguration.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ExtensionPropertyApiGetConfiguration.cs @@ -1,6 +1,6 @@ namespace Volo.Abp.ObjectExtending.Modularity { - public class ModuleEntityObjectPropertyExtensionEntityConfiguration + public class ExtensionPropertyApiGetConfiguration { /// /// Default: true. diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionApiCreateConfiguration.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ExtensionPropertyApiUpdateConfiguration.cs similarity index 71% rename from framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionApiCreateConfiguration.cs rename to framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ExtensionPropertyApiUpdateConfiguration.cs index 2c8c812f8c..897a261a83 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionApiCreateConfiguration.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ExtensionPropertyApiUpdateConfiguration.cs @@ -1,6 +1,6 @@ namespace Volo.Abp.ObjectExtending.Modularity { - public class ModuleEntityObjectPropertyExtensionApiCreateConfiguration + public class ExtensionPropertyApiUpdateConfiguration { /// /// Default: true. diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionConfiguration.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ExtensionPropertyConfiguration.cs similarity index 54% rename from framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionConfiguration.cs rename to framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ExtensionPropertyConfiguration.cs index 99b790aa82..0ff3941f4e 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionConfiguration.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ExtensionPropertyConfiguration.cs @@ -5,10 +5,10 @@ using Volo.Abp.Localization; namespace Volo.Abp.ObjectExtending.Modularity { - public class ModuleEntityObjectPropertyExtensionConfiguration : IHasNameWithLocalizableDisplayName + public class ExtensionPropertyConfiguration : IHasNameWithLocalizableDisplayName { [NotNull] - public ModuleEntityObjectExtensionConfiguration EntityObjectExtensionConfiguration { get; } + public EntityExtensionConfiguration EntityExtensionConfiguration { get; } [NotNull] public string Name { get; } @@ -26,11 +26,8 @@ namespace Volo.Abp.ObjectExtending.Modularity public ILocalizableString DisplayName { get; set; } [NotNull] - public Dictionary Configuration { get; } + public Dictionary Configuration { get; } - [NotNull] - public ModuleEntityObjectPropertyExtensionEntityConfiguration Entity { get; } - /// /// Single point to enable/disable this property for the clients (UI and API). /// If this is false, the configuration made in the and the @@ -40,27 +37,30 @@ namespace Volo.Abp.ObjectExtending.Modularity public bool IsAvailableToClients { get; set; } = true; [NotNull] - public ModuleEntityObjectPropertyExtensionUIConfiguration UI { get; } + public ExtensionPropertyEntityConfiguration Entity { get; } + + [NotNull] + public ExtensionPropertyUiConfiguration UI { get; } [NotNull] - public ModuleEntityObjectPropertyExtensionApiConfiguration Api { get; } + public ExtensionPropertyApiConfiguration Api { get; } - public ModuleEntityObjectPropertyExtensionConfiguration( - [NotNull] ModuleEntityObjectExtensionConfiguration entityObjectExtensionConfiguration, + public ExtensionPropertyConfiguration( + [NotNull] EntityExtensionConfiguration entityExtensionConfiguration, [NotNull] Type type, [NotNull] string name) { - EntityObjectExtensionConfiguration = Check.NotNull(entityObjectExtensionConfiguration, nameof(entityObjectExtensionConfiguration)); + EntityExtensionConfiguration = Check.NotNull(entityExtensionConfiguration, nameof(entityExtensionConfiguration)); Type = Check.NotNull(type, nameof(type)); Name = Check.NotNull(name, nameof(name)); - Configuration = new Dictionary(); + Configuration = new Dictionary(); Attributes = new List(); Validators = new List>(); - Entity = new ModuleEntityObjectPropertyExtensionEntityConfiguration(); - UI = new ModuleEntityObjectPropertyExtensionUIConfiguration(); - Api = new ModuleEntityObjectPropertyExtensionApiConfiguration(); + Entity = new ExtensionPropertyEntityConfiguration(); + UI = new ExtensionPropertyUiConfiguration(); + Api = new ExtensionPropertyApiConfiguration(); } } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ExtensionPropertyConfigurationDictionary.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ExtensionPropertyConfigurationDictionary.cs new file mode 100644 index 0000000000..b21e659a38 --- /dev/null +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ExtensionPropertyConfigurationDictionary.cs @@ -0,0 +1,9 @@ +using System.Collections.Generic; + +namespace Volo.Abp.ObjectExtending.Modularity +{ + public class ExtensionPropertyConfigurationDictionary : Dictionary + { + + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionApiUpdateConfiguration.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ExtensionPropertyEntityConfiguration.cs similarity index 71% rename from framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionApiUpdateConfiguration.cs rename to framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ExtensionPropertyEntityConfiguration.cs index 58355f44fa..3380d11658 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionApiUpdateConfiguration.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ExtensionPropertyEntityConfiguration.cs @@ -1,6 +1,6 @@ namespace Volo.Abp.ObjectExtending.Modularity { - public class ModuleEntityObjectPropertyExtensionApiUpdateConfiguration + public class ExtensionPropertyEntityConfiguration { /// /// Default: true. diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ExtensionPropertyUiConfiguration.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ExtensionPropertyUiConfiguration.cs new file mode 100644 index 0000000000..aa581228bd --- /dev/null +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ExtensionPropertyUiConfiguration.cs @@ -0,0 +1,23 @@ +using JetBrains.Annotations; + +namespace Volo.Abp.ObjectExtending.Modularity +{ + public class ExtensionPropertyUiConfiguration + { + [NotNull] + public ExtensionPropertyUiTableConfiguration OnTable { get; } + + [NotNull] + public ExtensionPropertyUiFormConfiguration OnCreateForm { get; } + + [NotNull] + public ExtensionPropertyUiFormConfiguration OnEditForm { get; } + + public ExtensionPropertyUiConfiguration() + { + OnTable = new ExtensionPropertyUiTableConfiguration(); + OnCreateForm = new ExtensionPropertyUiFormConfiguration(); + OnEditForm = new ExtensionPropertyUiFormConfiguration(); + } + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionUIFormConfiguration.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ExtensionPropertyUiFormConfiguration.cs similarity index 71% rename from framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionUIFormConfiguration.cs rename to framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ExtensionPropertyUiFormConfiguration.cs index 48de16ab49..77434d4c03 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionUIFormConfiguration.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ExtensionPropertyUiFormConfiguration.cs @@ -1,6 +1,6 @@ namespace Volo.Abp.ObjectExtending.Modularity { - public class ModuleEntityObjectPropertyExtensionUIFormConfiguration + public class ExtensionPropertyUiFormConfiguration { /// /// Default: true. diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionUITableConfiguration.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ExtensionPropertyUiTableConfiguration.cs similarity index 71% rename from framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionUITableConfiguration.cs rename to framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ExtensionPropertyUiTableConfiguration.cs index f42bbac1a3..4c95e1a02f 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionUITableConfiguration.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ExtensionPropertyUiTableConfiguration.cs @@ -1,6 +1,6 @@ namespace Volo.Abp.ObjectExtending.Modularity { - public class ModuleEntityObjectPropertyExtensionUITableConfiguration + public class ExtensionPropertyUiTableConfiguration { /// /// Default: true. diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectExtensionConfigurationDictionary.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectExtensionConfigurationDictionary.cs deleted file mode 100644 index 73d78b808e..0000000000 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectExtensionConfigurationDictionary.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System.Collections.Generic; - -namespace Volo.Abp.ObjectExtending.Modularity -{ - public class ModuleEntityObjectExtensionConfigurationDictionary : Dictionary - { - - } -} \ No newline at end of file diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionApiConfiguration.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionApiConfiguration.cs deleted file mode 100644 index ff195d2653..0000000000 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionApiConfiguration.cs +++ /dev/null @@ -1,23 +0,0 @@ -using JetBrains.Annotations; - -namespace Volo.Abp.ObjectExtending.Modularity -{ - public class ModuleEntityObjectPropertyExtensionApiConfiguration - { - [NotNull] - public ModuleEntityObjectPropertyExtensionApiGetConfiguration OnGet { get; } - - [NotNull] - public ModuleEntityObjectPropertyExtensionApiCreateConfiguration OnCreate { get; } - - [NotNull] - public ModuleEntityObjectPropertyExtensionApiUpdateConfiguration OnUpdate { get; } - - public ModuleEntityObjectPropertyExtensionApiConfiguration() - { - OnGet = new ModuleEntityObjectPropertyExtensionApiGetConfiguration(); - OnCreate = new ModuleEntityObjectPropertyExtensionApiCreateConfiguration(); - OnUpdate = new ModuleEntityObjectPropertyExtensionApiUpdateConfiguration(); - } - } -} \ No newline at end of file diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionConfigurationDictionary.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionConfigurationDictionary.cs deleted file mode 100644 index 4b7e7e3ddb..0000000000 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionConfigurationDictionary.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System.Collections.Generic; - -namespace Volo.Abp.ObjectExtending.Modularity -{ - public class ModuleEntityObjectPropertyExtensionConfigurationDictionary : Dictionary - { - - } -} \ No newline at end of file diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionUIConfiguration.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionUIConfiguration.cs deleted file mode 100644 index 6465497ee6..0000000000 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleEntityObjectPropertyExtensionUIConfiguration.cs +++ /dev/null @@ -1,23 +0,0 @@ -using JetBrains.Annotations; - -namespace Volo.Abp.ObjectExtending.Modularity -{ - public class ModuleEntityObjectPropertyExtensionUIConfiguration - { - [NotNull] - public ModuleEntityObjectPropertyExtensionUITableConfiguration OnTable { get; } - - [NotNull] - public ModuleEntityObjectPropertyExtensionUIFormConfiguration OnCreateForm { get; } - - [NotNull] - public ModuleEntityObjectPropertyExtensionUIFormConfiguration OnEditForm { get; } - - public ModuleEntityObjectPropertyExtensionUIConfiguration() - { - OnTable = new ModuleEntityObjectPropertyExtensionUITableConfiguration(); - OnCreateForm = new ModuleEntityObjectPropertyExtensionUIFormConfiguration(); - OnEditForm = new ModuleEntityObjectPropertyExtensionUIFormConfiguration(); - } - } -} \ No newline at end of file diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleExtensionConfiguration.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleExtensionConfiguration.cs new file mode 100644 index 0000000000..cc09d1bad9 --- /dev/null +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleExtensionConfiguration.cs @@ -0,0 +1,20 @@ +using System.Collections.Generic; +using JetBrains.Annotations; + +namespace Volo.Abp.ObjectExtending.Modularity +{ + public class ModuleExtensionConfiguration + { + [NotNull] + public EntityExtensionConfigurationDictionary Entities { get; } + + [NotNull] + public Dictionary Configuration { get; } + + public ModuleExtensionConfiguration() + { + Entities = new EntityExtensionConfigurationDictionary(); + Configuration = new Dictionary(); + } + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleExtensionConfigurationDictionary.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleExtensionConfigurationDictionary.cs new file mode 100644 index 0000000000..a5713ed62d --- /dev/null +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleExtensionConfigurationDictionary.cs @@ -0,0 +1,9 @@ +using System.Collections.Generic; + +namespace Volo.Abp.ObjectExtending.Modularity +{ + public class ModuleExtensionConfigurationDictionary : Dictionary + { + + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleObjectExtensionConfigurationDictionaryExtensions.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleExtensionConfigurationDictionaryExtensions.cs similarity index 64% rename from framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleObjectExtensionConfigurationDictionaryExtensions.cs rename to framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleExtensionConfigurationDictionaryExtensions.cs index 927c05fa15..5eab8e38b9 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleObjectExtensionConfigurationDictionaryExtensions.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleExtensionConfigurationDictionaryExtensions.cs @@ -4,13 +4,13 @@ using JetBrains.Annotations; namespace Volo.Abp.ObjectExtending.Modularity { - public static class ModuleObjectExtensionConfigurationDictionaryExtensions + public static class ModuleExtensionConfigurationDictionaryExtensions { - public static ModuleObjectExtensionConfigurationDictionary ConfigureModule( - [NotNull] this ModuleObjectExtensionConfigurationDictionary configurationDictionary, + public static ModuleExtensionConfigurationDictionary ConfigureModule( + [NotNull] this ModuleExtensionConfigurationDictionary configurationDictionary, [NotNull] string moduleName, [NotNull] Action configureAction) - where T : ModuleObjectExtensionConfiguration, new() + where T : ModuleExtensionConfiguration, new() { Check.NotNull(moduleName, nameof(moduleName)); Check.NotNull(configureAction, nameof(configureAction)); diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleObjectExtensionConfigurationExtensions.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleExtensionConfigurationExtensions.cs similarity index 55% rename from framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleObjectExtensionConfigurationExtensions.cs rename to framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleExtensionConfigurationExtensions.cs index 137002418a..9dbe3a743f 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleObjectExtensionConfigurationExtensions.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleExtensionConfigurationExtensions.cs @@ -3,17 +3,17 @@ using System.Collections.Generic; namespace Volo.Abp.ObjectExtending.Modularity { - public static class ModuleObjectExtensionConfigurationExtensions + public static class ModuleExtensionConfigurationExtensions { - public static T ConfigureObject( + public static T ConfigureEntity( this T objectConfiguration, string objectName, - Action configureAction) - where T : ModuleObjectExtensionConfiguration + Action configureAction) + where T : ModuleExtensionConfiguration { var configuration = objectConfiguration.Entities.GetOrAdd( objectName, - () => new ModuleEntityObjectExtensionConfiguration() + () => new EntityExtensionConfiguration() ); configureAction(configuration); diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleObjectExtensionConfigurationHelper.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleExtensionConfigurationHelper.cs similarity index 78% rename from framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleObjectExtensionConfigurationHelper.cs rename to framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleExtensionConfigurationHelper.cs index a975f00102..1f1edd757e 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleObjectExtensionConfigurationHelper.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleExtensionConfigurationHelper.cs @@ -4,14 +4,14 @@ using JetBrains.Annotations; namespace Volo.Abp.ObjectExtending.Modularity { - public static class ModuleObjectExtensionConfigurationHelper + public static class ModuleExtensionConfigurationHelper { - public static void ApplyModuleObjectExtensionConfigurationToEntity( + public static void ApplyEntityConfigurationToEntity( string moduleName, - string objectName, + string entityName, Type entityType) { - foreach (var propertyConfig in GetPropertyConfigurations(moduleName, objectName)) + foreach (var propertyConfig in GetPropertyConfigurations(moduleName, entityName)) { if (propertyConfig.Entity.IsAvailable && entityType != null) @@ -21,7 +21,7 @@ namespace Volo.Abp.ObjectExtending.Modularity } } - public static void ApplyModuleObjectExtensionConfigurationToApi( + public static void ApplyEntityConfigurationToApi( string moduleName, string objectName, Type[] getApiTypes = null, @@ -55,13 +55,13 @@ namespace Volo.Abp.ObjectExtending.Modularity } } - public static void ApplyModuleObjectExtensionConfigurationToUI( + public static void ApplyEntityConfigurationToUi( string moduleName, - string objectName, + string entityName, Type[] createFormTypes = null, Type[] editFormTypes = null) { - foreach (var propertyConfig in GetPropertyConfigurations(moduleName, objectName)) + foreach (var propertyConfig in GetPropertyConfigurations(moduleName, entityName)) { if (!propertyConfig.IsAvailableToClients) { @@ -82,9 +82,9 @@ namespace Volo.Abp.ObjectExtending.Modularity } } - public static void ApplyModuleObjectExtensionConfigurations( + public static void ApplyEntityConfigurations( string moduleName, - string objectName, + string entityName, Type entityType = null, Type[] createFormTypes = null, Type[] editFormTypes = null, @@ -94,51 +94,51 @@ namespace Volo.Abp.ObjectExtending.Modularity { if (entityType != null) { - ApplyModuleObjectExtensionConfigurationToEntity( + ApplyEntityConfigurationToEntity( moduleName, - objectName, + entityName, entityType ); } - ApplyModuleObjectExtensionConfigurationToApi( + ApplyEntityConfigurationToApi( moduleName, - objectName, + entityName, getApiTypes: getApiTypes, createApiTypes: createApiTypes, updateApiTypes: updateApiTypes ); - ApplyModuleObjectExtensionConfigurationToUI( + ApplyEntityConfigurationToUi( moduleName, - objectName, + entityName, createFormTypes: createFormTypes, editFormTypes: editFormTypes ); } [NotNull] - public static IEnumerable GetPropertyConfigurations( + public static IEnumerable GetPropertyConfigurations( string moduleName, - string objectName) + string entityName) { var moduleConfig = ObjectExtensionManager.Instance.Modules().GetOrDefault(moduleName); if (moduleConfig == null) { - return Array.Empty(); + return Array.Empty(); } - var objectConfig = moduleConfig.Entities.GetOrDefault(objectName); + var objectConfig = moduleConfig.Entities.GetOrDefault(entityName); if (objectConfig == null) { - return Array.Empty(); + return Array.Empty(); } return objectConfig.GetProperties(); } public static void ApplyPropertyConfigurationToTypes( - ModuleEntityObjectPropertyExtensionConfiguration propertyConfig, + ExtensionPropertyConfiguration propertyConfig, Type[] types) { ObjectExtensionManager.Instance diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleObjectExtensionConfiguration.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleObjectExtensionConfiguration.cs deleted file mode 100644 index 14470d1a17..0000000000 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleObjectExtensionConfiguration.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace Volo.Abp.ObjectExtending.Modularity -{ - public class ModuleObjectExtensionConfiguration - { - public ModuleEntityObjectExtensionConfigurationDictionary Entities { get; set; } - - public ModuleObjectExtensionConfiguration() - { - Entities = new ModuleEntityObjectExtensionConfigurationDictionary(); - } - } -} \ No newline at end of file diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleObjectExtensionConfigurationDictionary.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleObjectExtensionConfigurationDictionary.cs deleted file mode 100644 index 656de2e947..0000000000 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleObjectExtensionConfigurationDictionary.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System.Collections.Generic; - -namespace Volo.Abp.ObjectExtending.Modularity -{ - public class ModuleObjectExtensionConfigurationDictionary : Dictionary - { - - } -} \ No newline at end of file diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionManagerExtensions.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionManagerExtensions.cs index 7a1422f2f6..71339f725f 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionManagerExtensions.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionManagerExtensions.cs @@ -8,15 +8,15 @@ namespace Volo.Abp.ObjectExtending { private const string ObjectExtensionManagerConfigurationKey = "_Modules"; - public static ModuleObjectExtensionConfigurationDictionary Modules( + public static ModuleExtensionConfigurationDictionary Modules( [NotNull]this ObjectExtensionManager objectExtensionManager) { Check.NotNull(objectExtensionManager, nameof(objectExtensionManager)); return objectExtensionManager.Configuration.GetOrAdd( ObjectExtensionManagerConfigurationKey, - () => new ModuleObjectExtensionConfigurationDictionary() - ) as ModuleObjectExtensionConfigurationDictionary; + () => new ModuleExtensionConfigurationDictionary() + ) as ModuleExtensionConfigurationDictionary; } } } diff --git a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleExtensionConfiguration.cs b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleExtensionConfiguration.cs new file mode 100644 index 0000000000..fc057eccce --- /dev/null +++ b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleExtensionConfiguration.cs @@ -0,0 +1,9 @@ +using Volo.Abp.ObjectExtending.Modularity; + +namespace Volo.Abp.ObjectExtending +{ + public class IdentityModuleExtensionConfiguration : ModuleExtensionConfiguration + { + + } +} \ No newline at end of file diff --git a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleExtensionConfigurationExtensions.cs b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleExtensionConfigurationExtensions.cs new file mode 100644 index 0000000000..b7a8877034 --- /dev/null +++ b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleExtensionConfigurationExtensions.cs @@ -0,0 +1,18 @@ +using System; +using Volo.Abp.ObjectExtending.Modularity; + +namespace Volo.Abp.ObjectExtending +{ + public static class IdentityModuleExtensionConfigurationExtensions + { + public static IdentityModuleExtensionConfiguration ConfigureUser( + this IdentityModuleExtensionConfiguration configurations, + Action configureAction) + { + return configurations.ConfigureEntity( + "User", + configureAction + ); + } + } +} \ No newline at end of file diff --git a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleObjectExtensionConfiguration.cs b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleObjectExtensionConfiguration.cs deleted file mode 100644 index 4d80ed897e..0000000000 --- a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleObjectExtensionConfiguration.cs +++ /dev/null @@ -1,9 +0,0 @@ -using Volo.Abp.ObjectExtending.Modularity; - -namespace Volo.Abp.ObjectExtending -{ - public class IdentityModuleObjectExtensionConfiguration : ModuleObjectExtensionConfiguration - { - - } -} \ No newline at end of file diff --git a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleObjectExtensionConfigurationExtensions.cs b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleObjectExtensionConfigurationExtensions.cs deleted file mode 100644 index 31d24d242b..0000000000 --- a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleObjectExtensionConfigurationExtensions.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; -using Volo.Abp.ObjectExtending.Modularity; - -namespace Volo.Abp.ObjectExtending -{ - public static class IdentityModuleObjectExtensionConfigurationExtensions - { - public static IdentityModuleObjectExtensionConfiguration ConfigureUser( - this IdentityModuleObjectExtensionConfiguration configurations, - Action configureAction) - { - return configurations.ConfigureObject( - "User", - configureAction - ); - } - } -} \ No newline at end of file diff --git a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleObjectExtensionConfigurationsExtensions.cs b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleObjectExtensionConfigurationsExtensions.cs index 8ef25a5eb4..a8422314ae 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleObjectExtensionConfigurationsExtensions.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleObjectExtensionConfigurationsExtensions.cs @@ -5,9 +5,9 @@ namespace Volo.Abp.ObjectExtending { public static class IdentityModuleObjectExtensionConfigurationsExtensions { - public static ModuleObjectExtensionConfigurationDictionary ConfigureIdentity( - this ModuleObjectExtensionConfigurationDictionary modules, - Action configureAction) + public static ModuleExtensionConfigurationDictionary ConfigureIdentity( + this ModuleExtensionConfigurationDictionary modules, + Action configureAction) { return modules.ConfigureModule( "Identity", diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/AbpIdentityDomainModule.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/AbpIdentityDomainModule.cs index 6657184803..f7eea9fb5c 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/AbpIdentityDomainModule.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/AbpIdentityDomainModule.cs @@ -48,7 +48,7 @@ namespace Volo.Abp.Identity public override void PostConfigureServices(ServiceConfigurationContext context) { - ModuleObjectExtensionConfigurationHelper.ApplyModuleObjectExtensionConfigurationToEntity( + ModuleExtensionConfigurationHelper.ApplyEntityConfigurationToEntity( "Identity", "User", typeof(IdentityUser) From c43838c786bdc9cea97bdfd07a4327043699d012 Mon Sep 17 00:00:00 2001 From: Alper Ebicoglu Date: Sun, 3 May 2020 02:25:43 +0300 Subject: [PATCH 45/67] fixes #3816 --- .../Volo/Abp/Validation/Localization/cs.json | 2 +- .../Volo/Abp/Validation/Localization/en.json | 2 +- .../Volo/Abp/Validation/Localization/es.json | 2 +- .../Volo/Abp/Validation/Localization/pl-PL.json | 2 +- .../Volo/Abp/Validation/Localization/pt-BR.json | 2 +- .../Volo/Abp/Validation/Localization/ru.json | 2 +- .../Volo/Abp/Validation/Localization/tr.json | 2 +- .../Volo/Abp/Validation/Localization/vi.json | 2 +- .../Volo/Abp/Validation/Localization/zh-Hans.json | 2 +- .../Volo/Abp/Validation/Localization/zh-Hant.json | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/Localization/cs.json b/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/Localization/cs.json index 2be5ff3b15..d202abe1eb 100644 --- a/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/Localization/cs.json +++ b/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/Localization/cs.json @@ -10,7 +10,7 @@ "The field {0} must be a string or array type with a minimum length of '{1}'.": "V poli {0} musí být řežezec nebo řada o minimální délce '{1}'.", "The {0} field is not a valid phone number.": "V poli {0} není platné telefonní číslo.", "The field {0} must be between {1} and {2}.": "Pole {0} musí být mezi {1} a {2}.", - "The field {0} must match the regular expression '{1}'.": "Pole {0} musí odpovídat regulérnímu výrazu '{1}'.", + "The field {0} must match the regular expression '{1}'.": "Pole {0} neodpovídá požadovanému formátu.", "The {0} field is required.": "Pole {0} je povinné.", "The field {0} must be a string with a maximum length of {1}.": "Pole {0} musí být řetězec o maximální délce {1}.", "The field {0} must be a string with a minimum length of {2} and a maximum length of {1}.": "Pole {0} musí být řetězec o minimální délce {2} a maximální délce {1} znaků.", diff --git a/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/Localization/en.json b/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/Localization/en.json index b6ff1bb26c..74c6670e55 100644 --- a/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/Localization/en.json +++ b/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/Localization/en.json @@ -10,7 +10,7 @@ "The field {0} must be a string or array type with a minimum length of '{1}'.": "The field {0} must be a string or array type with a minimum length of '{1}'.", "The {0} field is not a valid phone number.": "The {0} field is not a valid phone number.", "The field {0} must be between {1} and {2}.": "The field {0} must be between {1} and {2}.", - "The field {0} must match the regular expression '{1}'.": "The field {0} must match the regular expression '{1}'.", + "The field {0} must match the regular expression '{1}'.": "The field {0} does not match the requested format.", "The {0} field is required.": "The {0} field is required.", "The field {0} must be a string with a maximum length of {1}.": "The field {0} must be a string with a maximum length of {1}.", "The field {0} must be a string with a minimum length of {2} and a maximum length of {1}.": "The field {0} must be a string with a minimum length of {2} and a maximum length of {1}.", diff --git a/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/Localization/es.json b/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/Localization/es.json index 25ed44d7ad..1615d7db42 100644 --- a/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/Localization/es.json +++ b/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/Localization/es.json @@ -10,7 +10,7 @@ "The field {0} must be a string or array type with a minimum length of '{1}'.": "El campo {0} debe ser una cadena o un array con una longitud mínima de '{1}'.", "The {0} field is not a valid phone number.": "{0} no es un número de teléfono válido.", "The field {0} must be between {1} and {2}.": "El campo {0} debe ser entre {1} y {2}.", - "The field {0} must match the regular expression '{1}'.": "El campo {0} debe coincidir con la expresión regular '{1}'.", + "The field {0} must match the regular expression '{1}'.": "El campo {0} no coincide con el formato solicitado.", "The {0} field is required.": "La {0} campo es obligatorio.", "The field {0} must be a string with a maximum length of {1}.": "El campo {0} debe ser una cadena con una longitud máxima de {1}.", "The field {0} must be a string with a minimum length of {2} and a maximum length of {1}.": "El campo {0} debe ser una cadena con una longitud mínima de {2} y una longitud máxima de {1}.", diff --git a/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/Localization/pl-PL.json b/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/Localization/pl-PL.json index 93145f0a3a..80dc72212d 100644 --- a/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/Localization/pl-PL.json +++ b/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/Localization/pl-PL.json @@ -10,7 +10,7 @@ "The field {0} must be a string or array type with a minimum length of '{1}'.": "Pole {0} musi być łańcuchem znaków lub talicą o minimalnej długości '{1}'.", "The {0} field is not a valid phone number.": "Pole {0} nie jest poprawnym numerem telefonu.", "The field {0} must be between {1} and {2}.": "Pole {0} musi być pomiędzy {1} i {2}.", - "The field {0} must match the regular expression '{1}'.": "Pole {0} musi pasować do wyrażenia regularnego '{1}'.", + "The field {0} must match the regular expression '{1}'.": "Pole {0} nie pasuje do żądanego formatu.", "The {0} field is required.": "Pole {0} jest wymagane.", "The field {0} must be a string with a maximum length of {1}.": "Pole {0} musi być łańcuchem znaków o maksymalnej długości {1}.", "The field {0} must be a string with a minimum length of {2} and a maximum length of {1}.": "Pole {0} musi być łańcuchem znaków o minimalnej długości {2} i maksymalnej długości {1}.", diff --git a/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/Localization/pt-BR.json b/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/Localization/pt-BR.json index b0852a3f5f..8d799a7730 100644 --- a/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/Localization/pt-BR.json +++ b/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/Localization/pt-BR.json @@ -10,7 +10,7 @@ "The field {0} must be a string or array type with a minimum length of '{1}'.": "O campo {0} deve ser uma palavra ou matriz com o tamanho mínimo de '{1}'.", "The {0} field is not a valid phone number.": "O campo {0} não é um telefone válido.", "The field {0} must be between {1} and {2}.": "O campo {0} deve estar entre {1} e {2}.", - "The field {0} must match the regular expression '{1}'.": "O campo {0} deve ser compatível com a expressão regular '{1}'.", + "The field {0} must match the regular expression '{1}'.": "O campo {0} não corresponde ao formato solicitado.", "The {0} field is required.": "O Campo {0} é obrigatório.", "The field {0} must be a string with a maximum length of {1}.": "O campo {0} deve ser uma palavra com o tamanho máximo de {1}.", "The field {0} must be a string with a minimum length of {2} and a maximum length of {1}.": "O campo {0} deve ser uma palavra com o tamanho mínimo de {2} e tamanho máximo de {1}.", diff --git a/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/Localization/ru.json b/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/Localization/ru.json index 6272fdf534..d718dbbed8 100644 --- a/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/Localization/ru.json +++ b/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/Localization/ru.json @@ -10,7 +10,7 @@ "The field {0} must be a string or array type with a minimum length of '{1}'.": "Поле {0} должно иметь тип строки или массива с минимальной длиной '{1}'.", "The {0} field is not a valid phone number.": "Поле {0} не содержит действительный номер телефона.", "The field {0} must be between {1} and {2}.": "Поле {0} должно находиться между {1} и {2}.", - "The field {0} must match the regular expression '{1}'.": "Поле {0} должно соответствовать регулярному выражению '{1}'.", + "The field {0} must match the regular expression '{1}'.": "Поле {0} не соответствует запрошенному формату.", "The {0} field is required.": "Поле {0} необходимо заполнить.", "The field {0} must be a string with a maximum length of {1}.": "Поле {0} должно быть строкой с максимальной длиной {1}.", "The field {0} must be a string with a minimum length of {2} and a maximum length of {1}.": "Поле {0} должно быть строкой с минимальной длиной {2} и максимальной длиной {1}.", diff --git a/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/Localization/tr.json b/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/Localization/tr.json index 447495e236..a70a3cd329 100644 --- a/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/Localization/tr.json +++ b/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/Localization/tr.json @@ -10,7 +10,7 @@ "The field {0} must be a string or array type with a minimum length of '{1}'.": "{0} alanı en az '{1}' uzunluğunda bir metin ya da dizi olmalıdır.", "The {0} field is not a valid phone number.": "{0} alanı geçerli bir telefon numarası olmalıdır.", "The field {0} must be between {1} and {2}.": "{0} değeri {1} ile {2} arasında olmalıdır.", - "The field {0} must match the regular expression '{1}'.": "{0} alanı şu düzenli ifadeye uymalıdır: '{1}'.", + "The field {0} must match the regular expression '{1}'.": "{0} alanı istenilen biçimde değil.", "The {0} field is required.": "{0} alanı zorunludur.", "The field {0} must be a string with a maximum length of {1}.": "{0} alanı en fazla {1} uzunluğunda bir metin olmalıdır.", "The field {0} must be a string with a minimum length of {2} and a maximum length of {1}.": "{0} alanı en az {2}, en fazla {1} uzunluğunda bir metin olmalıdır.", diff --git a/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/Localization/vi.json b/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/Localization/vi.json index 2d9c0c55f5..9f8e3e30ee 100644 --- a/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/Localization/vi.json +++ b/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/Localization/vi.json @@ -9,7 +9,7 @@ "The field {0} must be a string or array type with a maximum length of '{1}'.": "Trường {0} phải là một chuỗi hoặc một mảng với độ dài tối đa là '{1}'.", "The {0} field is not a valid phone number.": "Trường {0} không phải là một số điện thoại hợp lệ", "The field {0} must be between {1} and {2}.": "Trường {0} phải ở giữa {1} and {2}.", - "The field {0} must match the regular expression '{1}'.": "Trường {0} phải khớp với biểu thức chính quy '{1}'.", + "The field {0} must match the regular expression '{1}'.": "Trường {0} không khớp với định dạng được yêu cầu.", "The {0} field is required.": "Trường {0} là bắt buộc.", "The field {0} must be a string with a maximum length of {1}.": "Trường {0} phải là một chuỗi với độ dài tối đa là {1}.", "The field {0} must be a string with a minimum length of {2} and a maximum length of {1}.": "Trường {0} phải là một chuỗi với độ dài tối thiểu {2} và tối đa là {1}.", diff --git a/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/Localization/zh-Hans.json b/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/Localization/zh-Hans.json index 282423a44a..88a6e93acf 100644 --- a/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/Localization/zh-Hans.json +++ b/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/Localization/zh-Hans.json @@ -10,7 +10,7 @@ "The field {0} must be a string or array type with a minimum length of '{1}'.": "字段{0}必须是最小长度为'{1}'的字符串或数组.", "The {0} field is not a valid phone number.": "字段{0}不是有效的手机号码.", "The field {0} must be between {1} and {2}.": "字段{0}值必须在{1}和{2}范围内.", - "The field {0} must match the regular expression '{1}'.": "字段{0}必须匹配正则表达式'{1}'.", + "The field {0} must match the regular expression '{1}'.": "字段{0}与请求的格式不匹配。", "The {0} field is required.": "字段{0}不可为空.", "The field {0} must be a string with a maximum length of {1}.": "字段{0}必须是长度为{1}的字符串.", "The field {0} must be a string with a minimum length of {2} and a maximum length of {1}.": "字段{0}必须是最小长度为{2}并且最大长度{1}的字符串.", diff --git a/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/Localization/zh-Hant.json b/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/Localization/zh-Hant.json index 1e7e419625..2cd200151c 100644 --- a/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/Localization/zh-Hant.json +++ b/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/Localization/zh-Hant.json @@ -10,7 +10,7 @@ "The field {0} must be a string or array type with a minimum length of '{1}'.": "欄位{0}必須是最小長度為'{1}'的字串或陣列.", "The {0} field is not a valid phone number.": "欄位{0}不是有效的電話號碼.", "The field {0} must be between {1} and {2}.": "欄位{0}值必須在{1}和{2}範圍內.", - "The field {0} must match the regular expression '{1}'.": "欄位{0}必須匹配正規表示式'{1}'.", + "The field {0} must match the regular expression '{1}'.": "字段{0}与请求的格式不匹配。", "The {0} field is required.": "欄位{0}不可為空.", "The field {0} must be a string with a maximum length of {1}.": "欄位{0}必須是長度為{1}的字串.", "The field {0} must be a string with a minimum length of {2} and a maximum length of {1}.": "欄位{0}必須是最小長度為{2}並且最大長度{1}的字串.", From 0282c461009ee9dda50d67bdacbf12926a102c26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Sun, 3 May 2020 03:15:00 +0300 Subject: [PATCH 46/67] Use ConcurrentDictionary for the configuration. --- .../ModuleObjectExtensionManagerExtensions.cs | 5 ++--- .../Volo/Abp/ObjectExtending/ObjectExtensionManager.cs | 5 +++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionManagerExtensions.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionManagerExtensions.cs index 71339f725f..eeb7095068 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionManagerExtensions.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionManagerExtensions.cs @@ -1,5 +1,4 @@ -using System.Collections.Generic; -using JetBrains.Annotations; +using JetBrains.Annotations; using Volo.Abp.ObjectExtending.Modularity; namespace Volo.Abp.ObjectExtending @@ -15,7 +14,7 @@ namespace Volo.Abp.ObjectExtending return objectExtensionManager.Configuration.GetOrAdd( ObjectExtensionManagerConfigurationKey, - () => new ModuleExtensionConfigurationDictionary() + _ => new ModuleExtensionConfigurationDictionary() ) as ModuleExtensionConfigurationDictionary; } } diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionManager.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionManager.cs index 26b692c232..2b0ce8977d 100644 --- a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionManager.cs +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionManager.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Concurrent; using System.Collections.Generic; using System.Collections.Immutable; using JetBrains.Annotations; @@ -11,14 +12,14 @@ namespace Volo.Abp.ObjectExtending public static ObjectExtensionManager Instance { get; set; } = new ObjectExtensionManager(); [NotNull] - public Dictionary Configuration { get; } + public ConcurrentDictionary Configuration { get; } protected Dictionary ObjectsExtensions { get; } protected internal ObjectExtensionManager() { ObjectsExtensions = new Dictionary(); - Configuration = new Dictionary(); + Configuration = new ConcurrentDictionary(); } [NotNull] From 1fc1c1b28d8d29aa6fd04d7697ff50f40f76cfe7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Sun, 3 May 2020 03:19:29 +0300 Subject: [PATCH 47/67] Add Role for extensibility and refactor related classes. --- .../IdentityModuleExtensionConfiguration.cs | 19 ++++++++++++++++++- ...yModuleExtensionConfigurationExtensions.cs | 2 +- .../IdentityModuleExtensionConsts.cs | 14 ++++++++++++++ ...nsionConfigurationDictionaryExtensions.cs} | 4 ++-- .../Abp/Identity/AbpIdentityDomainModule.cs | 11 +++++++++-- 5 files changed, 44 insertions(+), 6 deletions(-) create mode 100644 modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleExtensionConsts.cs rename modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/{IdentityModuleObjectExtensionConfigurationsExtensions.cs => ModuleExtensionConfigurationDictionaryExtensions.cs} (77%) diff --git a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleExtensionConfiguration.cs b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleExtensionConfiguration.cs index fc057eccce..c2fc9b7a13 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleExtensionConfiguration.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleExtensionConfiguration.cs @@ -1,9 +1,26 @@ -using Volo.Abp.ObjectExtending.Modularity; +using System; +using Volo.Abp.ObjectExtending.Modularity; namespace Volo.Abp.ObjectExtending { public class IdentityModuleExtensionConfiguration : ModuleExtensionConfiguration { + public IdentityModuleExtensionConfiguration ConfigureUser( + Action configureAction) + { + return this.ConfigureEntity( + IdentityModuleExtensionConsts.EntityNames.User, + configureAction + ); + } + public IdentityModuleExtensionConfiguration ConfigureRole( + Action configureAction) + { + return this.ConfigureEntity( + IdentityModuleExtensionConsts.EntityNames.Role, + configureAction + ); + } } } \ No newline at end of file diff --git a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleExtensionConfigurationExtensions.cs b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleExtensionConfigurationExtensions.cs index b7a8877034..7b07d1f9ed 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleExtensionConfigurationExtensions.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleExtensionConfigurationExtensions.cs @@ -10,7 +10,7 @@ namespace Volo.Abp.ObjectExtending Action configureAction) { return configurations.ConfigureEntity( - "User", + IdentityModuleExtensionConsts.EntityNames.User, configureAction ); } diff --git a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleExtensionConsts.cs b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleExtensionConsts.cs new file mode 100644 index 0000000000..b7cc311965 --- /dev/null +++ b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleExtensionConsts.cs @@ -0,0 +1,14 @@ +namespace Volo.Abp.ObjectExtending +{ + public static class IdentityModuleExtensionConsts + { + public const string ModuleName = "Identity"; + + public static class EntityNames + { + public const string User = "User"; + + public const string Role = "Role"; + } + } +} \ No newline at end of file diff --git a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleObjectExtensionConfigurationsExtensions.cs b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/ModuleExtensionConfigurationDictionaryExtensions.cs similarity index 77% rename from modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleObjectExtensionConfigurationsExtensions.cs rename to modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/ModuleExtensionConfigurationDictionaryExtensions.cs index a8422314ae..af94966a10 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleObjectExtensionConfigurationsExtensions.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/ModuleExtensionConfigurationDictionaryExtensions.cs @@ -3,14 +3,14 @@ using Volo.Abp.ObjectExtending.Modularity; namespace Volo.Abp.ObjectExtending { - public static class IdentityModuleObjectExtensionConfigurationsExtensions + public static class ModuleExtensionConfigurationDictionaryExtensions { public static ModuleExtensionConfigurationDictionary ConfigureIdentity( this ModuleExtensionConfigurationDictionary modules, Action configureAction) { return modules.ConfigureModule( - "Identity", + IdentityModuleExtensionConsts.ModuleName, configureAction ); } diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/AbpIdentityDomainModule.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/AbpIdentityDomainModule.cs index f7eea9fb5c..373fa2b637 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/AbpIdentityDomainModule.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/AbpIdentityDomainModule.cs @@ -6,6 +6,7 @@ using Volo.Abp.AutoMapper; using Volo.Abp.Domain; using Volo.Abp.EventBus.Distributed; using Volo.Abp.Modularity; +using Volo.Abp.ObjectExtending; using Volo.Abp.ObjectExtending.Modularity; using Volo.Abp.Users; @@ -49,10 +50,16 @@ namespace Volo.Abp.Identity public override void PostConfigureServices(ServiceConfigurationContext context) { ModuleExtensionConfigurationHelper.ApplyEntityConfigurationToEntity( - "Identity", - "User", + IdentityModuleExtensionConsts.ModuleName, + IdentityModuleExtensionConsts.EntityNames.User, typeof(IdentityUser) ); + + ModuleExtensionConfigurationHelper.ApplyEntityConfigurationToEntity( + IdentityModuleExtensionConsts.ModuleName, + IdentityModuleExtensionConsts.EntityNames.Role, + typeof(IdentityRole) + ); } private static void AddAbpIdentityOptionsFactory(IServiceCollection services) From 819b0b61fee02f33f287e6b94b69a2ecbcf09ab2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Mon, 4 May 2020 00:10:59 +0300 Subject: [PATCH 48/67] remove unused class --- ...tyModuleExtensionConfigurationExtensions.cs | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleExtensionConfigurationExtensions.cs diff --git a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleExtensionConfigurationExtensions.cs b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleExtensionConfigurationExtensions.cs deleted file mode 100644 index 7b07d1f9ed..0000000000 --- a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleExtensionConfigurationExtensions.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; -using Volo.Abp.ObjectExtending.Modularity; - -namespace Volo.Abp.ObjectExtending -{ - public static class IdentityModuleExtensionConfigurationExtensions - { - public static IdentityModuleExtensionConfiguration ConfigureUser( - this IdentityModuleExtensionConfiguration configurations, - Action configureAction) - { - return configurations.ConfigureEntity( - IdentityModuleExtensionConsts.EntityNames.User, - configureAction - ); - } - } -} \ No newline at end of file From e8116111434477ad97ab5d222a11f897465e02de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Mon, 4 May 2020 00:11:07 +0300 Subject: [PATCH 49/67] delete empty line --- .../TagHelpers/Form/AbpDynamicformTagHelperService.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpDynamicformTagHelperService.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpDynamicformTagHelperService.cs index a1601378d9..4504906566 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpDynamicformTagHelperService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpDynamicformTagHelperService.cs @@ -144,8 +144,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form } } } - - + protected virtual void RemoveFormGroupItemsNotInModel(TagHelperContext context, TagHelperOutput output, List items) { var models = GetModels(context, output); From a51d8fb782e78d885c0bd433ad2a54e3b9495e97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Mon, 4 May 2020 00:11:24 +0300 Subject: [PATCH 50/67] Allow to extend the ClaimType --- .../IdentityModuleExtensionConfiguration.cs | 9 +++++++++ .../Abp/ObjectExtending/IdentityModuleExtensionConsts.cs | 2 ++ .../Volo/Abp/Identity/AbpIdentityDomainModule.cs | 6 ++++++ 3 files changed, 17 insertions(+) diff --git a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleExtensionConfiguration.cs b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleExtensionConfiguration.cs index c2fc9b7a13..3892fb00f6 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleExtensionConfiguration.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleExtensionConfiguration.cs @@ -22,5 +22,14 @@ namespace Volo.Abp.ObjectExtending configureAction ); } + + public IdentityModuleExtensionConfiguration ConfigureClaimType( + Action configureAction) + { + return this.ConfigureEntity( + IdentityModuleExtensionConsts.EntityNames.ClaimType, + configureAction + ); + } } } \ No newline at end of file diff --git a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleExtensionConsts.cs b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleExtensionConsts.cs index b7cc311965..6d2b4c0653 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleExtensionConsts.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleExtensionConsts.cs @@ -9,6 +9,8 @@ public const string User = "User"; public const string Role = "Role"; + + public const string ClaimType = "ClaimType"; } } } \ No newline at end of file diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/AbpIdentityDomainModule.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/AbpIdentityDomainModule.cs index 373fa2b637..f757c56f1e 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/AbpIdentityDomainModule.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/AbpIdentityDomainModule.cs @@ -60,6 +60,12 @@ namespace Volo.Abp.Identity IdentityModuleExtensionConsts.EntityNames.Role, typeof(IdentityRole) ); + + ModuleExtensionConfigurationHelper.ApplyEntityConfigurationToEntity( + IdentityModuleExtensionConsts.ModuleName, + IdentityModuleExtensionConsts.EntityNames.ClaimType, + typeof(IdentityClaimType) + ); } private static void AddAbpIdentityOptionsFactory(IServiceCollection services) From 9c9d7c59b695b249101ad9e70d716d9494542d24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Mon, 4 May 2020 00:32:15 +0300 Subject: [PATCH 51/67] rename to IdentityModuleExtensionConfigurationDictionaryExtensions --- ...IdentityModuleExtensionConfigurationDictionaryExtensions.cs} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/{ModuleExtensionConfigurationDictionaryExtensions.cs => IdentityModuleExtensionConfigurationDictionaryExtensions.cs} (86%) diff --git a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/ModuleExtensionConfigurationDictionaryExtensions.cs b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleExtensionConfigurationDictionaryExtensions.cs similarity index 86% rename from modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/ModuleExtensionConfigurationDictionaryExtensions.cs rename to modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleExtensionConfigurationDictionaryExtensions.cs index af94966a10..40fbb3b594 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/ModuleExtensionConfigurationDictionaryExtensions.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleExtensionConfigurationDictionaryExtensions.cs @@ -3,7 +3,7 @@ using Volo.Abp.ObjectExtending.Modularity; namespace Volo.Abp.ObjectExtending { - public static class ModuleExtensionConfigurationDictionaryExtensions + public static class IdentityModuleExtensionConfigurationDictionaryExtensions { public static ModuleExtensionConfigurationDictionary ConfigureIdentity( this ModuleExtensionConfigurationDictionary modules, From 304fa36149644505f866e9265ee3e9c73f39c52f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Mon, 4 May 2020 03:12:10 +0300 Subject: [PATCH 52/67] Apply entity extensions to the identity server module --- ...ntityServerModuleExtensionConfiguration.cs | 35 +++++++++++++++++++ ...ensionConfigurationDictionaryExtensions.cs | 18 ++++++++++ .../IdentityServerModuleExtensionConsts.cs | 16 +++++++++ .../AbpIdentityServerDomainModule.cs | 24 ++++++++++++- 4 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/ObjectExtending/IdentityServerModuleExtensionConfiguration.cs create mode 100644 modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/ObjectExtending/IdentityServerModuleExtensionConfigurationDictionaryExtensions.cs create mode 100644 modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/ObjectExtending/IdentityServerModuleExtensionConsts.cs diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/ObjectExtending/IdentityServerModuleExtensionConfiguration.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/ObjectExtending/IdentityServerModuleExtensionConfiguration.cs new file mode 100644 index 0000000000..78a26900c9 --- /dev/null +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/ObjectExtending/IdentityServerModuleExtensionConfiguration.cs @@ -0,0 +1,35 @@ +using System; +using Volo.Abp.ObjectExtending.Modularity; + +namespace Volo.Abp.ObjectExtending +{ + public class IdentityServerModuleExtensionConfiguration : ModuleExtensionConfiguration + { + public IdentityServerModuleExtensionConfiguration ConfigureClient( + Action configureAction) + { + return this.ConfigureEntity( + IdentityServerModuleExtensionConsts.EntityNames.Client, + configureAction + ); + } + + public IdentityServerModuleExtensionConfiguration ConfigureApiResource( + Action configureAction) + { + return this.ConfigureEntity( + IdentityServerModuleExtensionConsts.EntityNames.ApiResource, + configureAction + ); + } + + public IdentityServerModuleExtensionConfiguration ConfigureIdentityResource( + Action configureAction) + { + return this.ConfigureEntity( + IdentityServerModuleExtensionConsts.EntityNames.IdentityResource, + configureAction + ); + } + } +} diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/ObjectExtending/IdentityServerModuleExtensionConfigurationDictionaryExtensions.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/ObjectExtending/IdentityServerModuleExtensionConfigurationDictionaryExtensions.cs new file mode 100644 index 0000000000..a943ca1839 --- /dev/null +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/ObjectExtending/IdentityServerModuleExtensionConfigurationDictionaryExtensions.cs @@ -0,0 +1,18 @@ +using System; +using Volo.Abp.ObjectExtending.Modularity; + +namespace Volo.Abp.ObjectExtending +{ + public static class IdentityServerModuleExtensionConfigurationDictionaryExtensions + { + public static ModuleExtensionConfigurationDictionary ConfigureIdentityServer( + this ModuleExtensionConfigurationDictionary modules, + Action configureAction) + { + return modules.ConfigureModule( + IdentityServerModuleExtensionConsts.ModuleName, + configureAction + ); + } + } +} \ No newline at end of file diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/ObjectExtending/IdentityServerModuleExtensionConsts.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/ObjectExtending/IdentityServerModuleExtensionConsts.cs new file mode 100644 index 0000000000..8623b8830a --- /dev/null +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/ObjectExtending/IdentityServerModuleExtensionConsts.cs @@ -0,0 +1,16 @@ +namespace Volo.Abp.ObjectExtending +{ + public static class IdentityServerModuleExtensionConsts + { + public const string ModuleName = "IdentityServer"; + + public static class EntityNames + { + public const string Client = "Client"; + + public const string IdentityResource = "IdentityResource"; + + public const string ApiResource = "ApiResource"; + } + } +} \ No newline at end of file diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpIdentityServerDomainModule.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpIdentityServerDomainModule.cs index ef1969fe24..95c8eec537 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpIdentityServerDomainModule.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpIdentityServerDomainModule.cs @@ -11,10 +11,11 @@ using Volo.Abp.Identity; using Volo.Abp.IdentityServer.ApiResources; using Volo.Abp.IdentityServer.Clients; using Volo.Abp.IdentityServer.Devices; -using Volo.Abp.IdentityServer.Grants; using Volo.Abp.IdentityServer.IdentityResources; using Volo.Abp.IdentityServer.Tokens; using Volo.Abp.Modularity; +using Volo.Abp.ObjectExtending; +using Volo.Abp.ObjectExtending.Modularity; using Volo.Abp.Security; using Volo.Abp.Validation; @@ -95,6 +96,27 @@ namespace Volo.Abp.IdentityServer } } + public override void PostConfigureServices(ServiceConfigurationContext context) + { + ModuleExtensionConfigurationHelper.ApplyEntityConfigurationToEntity( + IdentityServerModuleExtensionConsts.ModuleName, + IdentityServerModuleExtensionConsts.EntityNames.Client, + typeof(Client) + ); + + ModuleExtensionConfigurationHelper.ApplyEntityConfigurationToEntity( + IdentityServerModuleExtensionConsts.ModuleName, + IdentityServerModuleExtensionConsts.EntityNames.IdentityResource, + typeof(IdentityResource) + ); + + ModuleExtensionConfigurationHelper.ApplyEntityConfigurationToEntity( + IdentityServerModuleExtensionConsts.ModuleName, + IdentityServerModuleExtensionConsts.EntityNames.ApiResource, + typeof(ApiResource) + ); + } + public override void OnApplicationInitialization(ApplicationInitializationContext context) { var options = context.ServiceProvider.GetRequiredService>().Value; From 43e9cd2977b037de6cd3180ca120a8ee288ae520 Mon Sep 17 00:00:00 2001 From: mehmet-erim Date: Mon, 4 May 2020 03:12:26 +0300 Subject: [PATCH 53/67] fix: circular dependency warnings --- .../src/lib/services/localization.service.ts | 12 +++- .../core/src/lib/states/config.state.ts | 56 +++++++++++-------- .../core/src/lib/states/session.state.ts | 29 ++++------ .../confirmation/confirmation.component.html | 4 +- .../confirmation/confirmation.component.ts | 16 ++++-- .../toast-container.component.ts | 10 ++-- .../src/lib/services/confirmation.service.ts | 17 +++--- .../src/lib/services/toaster.service.ts | 2 +- .../src/lib/theme-shared.module.ts | 8 ++- 9 files changed, 86 insertions(+), 68 deletions(-) diff --git a/npm/ng-packs/packages/core/src/lib/services/localization.service.ts b/npm/ng-packs/packages/core/src/lib/services/localization.service.ts index b12b517156..0e89732e56 100644 --- a/npm/ng-packs/packages/core/src/lib/services/localization.service.ts +++ b/npm/ng-packs/packages/core/src/lib/services/localization.service.ts @@ -1,10 +1,11 @@ import { Injectable, NgZone, Optional, SkipSelf } from '@angular/core'; import { ActivatedRouteSnapshot, Router } from '@angular/router'; -import { Store } from '@ngxs/store'; +import { Store, Actions, ofActionSuccessful } from '@ngxs/store'; import { noop, Observable } from 'rxjs'; import { ConfigState } from '../states/config.state'; import { registerLocale } from '../utils/initial-utils'; import { Config } from '../models/config'; +import { SetLanguage } from '../actions/session.actions'; type ShouldReuseRoute = (future: ActivatedRouteSnapshot, curr: ActivatedRouteSnapshot) => boolean; @@ -18,6 +19,7 @@ export class LocalizationService { } constructor( + private actions: Actions, private store: Store, private router: Router, private ngZone: NgZone, @@ -26,6 +28,14 @@ export class LocalizationService { otherInstance: LocalizationService, ) { if (otherInstance) throw new Error('LocalizationService should have only one instance.'); + + this.listenToSetLanguage(); + } + + private listenToSetLanguage() { + this.actions + .pipe(ofActionSuccessful(SetLanguage)) + .subscribe(({ payload }) => this.registerLocale(payload)); } setRouteReuse(reuse: ShouldReuseRoute) { diff --git a/npm/ng-packs/packages/core/src/lib/states/config.state.ts b/npm/ng-packs/packages/core/src/lib/states/config.state.ts index 01a181229f..af706586bb 100644 --- a/npm/ng-packs/packages/core/src/lib/states/config.state.ts +++ b/npm/ng-packs/packages/core/src/lib/states/config.state.ts @@ -1,7 +1,8 @@ +import { HttpClient, HttpErrorResponse } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Action, createSelector, Selector, State, StateContext, Store } from '@ngxs/store'; -import { of } from 'rxjs'; -import { switchMap, tap } from 'rxjs/operators'; +import { of, throwError } from 'rxjs'; +import { catchError, switchMap, tap } from 'rxjs/operators'; import snq from 'snq'; import { AddRoute, @@ -9,10 +10,11 @@ import { PatchRouteByName, SetEnvironment, } from '../actions/config.actions'; +import { RestOccurError } from '../actions/rest.actions'; import { SetLanguage } from '../actions/session.actions'; +import { ApplicationConfiguration } from '../models/application-configuration'; import { ABP } from '../models/common'; import { Config } from '../models/config'; -import { ApplicationConfigurationService } from '../services/application-configuration.service'; import { organizeRoutes } from '../utils/route-utils'; import { SessionState } from './session.state'; @@ -195,31 +197,37 @@ export class ConfigState { return selector; } - constructor( - private appConfigurationService: ApplicationConfigurationService, - private store: Store, - ) {} + constructor(private http: HttpClient, private store: Store) {} @Action(GetAppConfiguration) addData({ patchState, dispatch }: StateContext) { - return this.appConfigurationService.getConfiguration().pipe( - tap(configuration => - patchState({ - ...configuration, + const apiName = this.store.selectSnapshot(ConfigState.getDeep('environment.application.name')); + const api = this.store.selectSnapshot(ConfigState.getApiUrl(apiName)); + return this.http + .get(`${api}/api/abp/application-configuration`) + .pipe( + tap(configuration => + patchState({ + ...configuration, + }), + ), + switchMap(configuration => { + let defaultLang: string = + configuration.setting.values['Abp.Localization.DefaultLanguage']; + + if (defaultLang.includes(';')) { + defaultLang = defaultLang.split(';')[0]; + } + + return this.store.selectSnapshot(SessionState.getLanguage) + ? of(null) + : dispatch(new SetLanguage(defaultLang)); }), - ), - switchMap(configuration => { - let defaultLang: string = configuration.setting.values['Abp.Localization.DefaultLanguage']; - - if (defaultLang.includes(';')) { - defaultLang = defaultLang.split(';')[0]; - } - - return this.store.selectSnapshot(SessionState.getLanguage) - ? of(null) - : dispatch(new SetLanguage(defaultLang)); - }), - ); + catchError(err => { + dispatch(new RestOccurError(new HttpErrorResponse({ status: 0, error: err }))); + return throwError(err); + }), + ); } @Action(PatchRouteByName) diff --git a/npm/ng-packs/packages/core/src/lib/states/session.state.ts b/npm/ng-packs/packages/core/src/lib/states/session.state.ts index 9342bacd62..6acbf1d60d 100644 --- a/npm/ng-packs/packages/core/src/lib/states/session.state.ts +++ b/npm/ng-packs/packages/core/src/lib/states/session.state.ts @@ -1,26 +1,24 @@ +import { Injectable } from '@angular/core'; import { Action, + Actions, + ofActionSuccessful, Selector, State, StateContext, Store, - NgxsOnInit, - Actions, - ofActionSuccessful, } from '@ngxs/store'; -import { from, fromEvent } from 'rxjs'; -import { switchMap, take } from 'rxjs/operators'; +import { OAuthService } from 'angular-oauth2-oidc'; +import { fromEvent } from 'rxjs'; +import { take } from 'rxjs/operators'; import { GetAppConfiguration } from '../actions/config.actions'; import { - SetLanguage, - SetTenant, ModifyOpenedTabCount, + SetLanguage, SetRemember, + SetTenant, } from '../actions/session.actions'; import { ABP, Session } from '../models'; -import { LocalizationService } from '../services/localization.service'; -import { OAuthService } from 'angular-oauth2-oidc'; -import { Injectable } from '@angular/core'; @State({ name: 'SessionState', @@ -43,12 +41,7 @@ export class SessionState { return sessionDetail; } - constructor( - private localizationService: LocalizationService, - private oAuthService: OAuthService, - private store: Store, - private actions: Actions, - ) { + constructor(private oAuthService: OAuthService, private store: Store, private actions: Actions) { actions .pipe(ofActionSuccessful(GetAppConfiguration)) .pipe(take(1)) @@ -81,9 +74,7 @@ export class SessionState { language: payload, }); - return dispatch(new GetAppConfiguration()).pipe( - switchMap(() => from(this.localizationService.registerLocale(payload))), - ); + return dispatch(new GetAppConfiguration()); } @Action(SetTenant) diff --git a/npm/ng-packs/packages/theme-shared/src/lib/components/confirmation/confirmation.component.html b/npm/ng-packs/packages/theme-shared/src/lib/components/confirmation/confirmation.component.html index a40d72adf4..8b0d8591c4 100644 --- a/npm/ng-packs/packages/theme-shared/src/lib/components/confirmation/confirmation.component.html +++ b/npm/ng-packs/packages/theme-shared/src/lib/components/confirmation/confirmation.component.html @@ -20,14 +20,14 @@ diff --git a/npm/ng-packs/packages/theme-shared/src/lib/components/confirmation/confirmation.component.ts b/npm/ng-packs/packages/theme-shared/src/lib/components/confirmation/confirmation.component.ts index a73382678a..a68789044c 100644 --- a/npm/ng-packs/packages/theme-shared/src/lib/components/confirmation/confirmation.component.ts +++ b/npm/ng-packs/packages/theme-shared/src/lib/components/confirmation/confirmation.component.ts @@ -1,13 +1,13 @@ -import { Component } from '@angular/core'; +import { Component, OnInit } from '@angular/core'; +import { ReplaySubject } from 'rxjs'; import { Confirmation } from '../../models/confirmation'; -import { ConfirmationService } from '../../services/confirmation.service'; @Component({ selector: 'abp-confirmation', templateUrl: './confirmation.component.html', styleUrls: ['./confirmation.component.scss'], }) -export class ConfirmationComponent { +export class ConfirmationComponent implements OnInit { confirm = Confirmation.Status.confirm; reject = Confirmation.Status.reject; dismiss = Confirmation.Status.dismiss; @@ -16,6 +16,10 @@ export class ConfirmationComponent { data: Confirmation.DialogData; + confirmation$: ReplaySubject; + + clear: (status: Confirmation.Status) => void; + get iconClass(): string { switch (this.data.severity) { case 'info': @@ -31,14 +35,14 @@ export class ConfirmationComponent { } } - constructor(private confirmationService: ConfirmationService) { - this.confirmationService.confirmation$.subscribe(confirmation => { + ngOnInit() { + this.confirmation$.subscribe(confirmation => { this.data = confirmation; this.visible = !!confirmation; }); } close(status: Confirmation.Status) { - this.confirmationService.clear(status); + this.clear(status); } } diff --git a/npm/ng-packs/packages/theme-shared/src/lib/components/toast-container/toast-container.component.ts b/npm/ng-packs/packages/theme-shared/src/lib/components/toast-container/toast-container.component.ts index 124dcc5185..28d66123a9 100644 --- a/npm/ng-packs/packages/theme-shared/src/lib/components/toast-container/toast-container.component.ts +++ b/npm/ng-packs/packages/theme-shared/src/lib/components/toast-container/toast-container.component.ts @@ -1,7 +1,7 @@ import { Component, Input, OnInit } from '@angular/core'; -import { Toaster } from '../../models/toaster'; import { toastInOut } from '../../animations/toast.animations'; -import { ToasterService } from '../../services/toaster.service'; +import { Toaster } from '../../models/toaster'; +import { ReplaySubject } from 'rxjs'; @Component({ selector: 'abp-toast-container', @@ -10,6 +10,8 @@ import { ToasterService } from '../../services/toaster.service'; animations: [toastInOut], }) export class ToastContainerComponent implements OnInit { + toasts$: ReplaySubject; + toasts = [] as Toaster.Toast[]; @Input() @@ -27,10 +29,8 @@ export class ToastContainerComponent implements OnInit { @Input() toastKey: string; - constructor(private toastService: ToasterService) {} - ngOnInit() { - this.toastService.toasts$.subscribe(toasts => { + this.toasts$.subscribe(toasts => { this.toasts = this.toastKey ? toasts.filter(t => { return t.options && t.options.containerKey !== this.toastKey; diff --git a/npm/ng-packs/packages/theme-shared/src/lib/services/confirmation.service.ts b/npm/ng-packs/packages/theme-shared/src/lib/services/confirmation.service.ts index bfd5b32230..d254449894 100644 --- a/npm/ng-packs/packages/theme-shared/src/lib/services/confirmation.service.ts +++ b/npm/ng-packs/packages/theme-shared/src/lib/services/confirmation.service.ts @@ -15,13 +15,14 @@ export class ConfirmationService { constructor(private contentProjectionService: ContentProjectionService) {} private setContainer() { - setTimeout(() => { - this.containerComponentRef = this.contentProjectionService.projectContent( - PROJECTION_STRATEGY.AppendComponentToBody(ConfirmationComponent), - ); + this.containerComponentRef = this.contentProjectionService.projectContent( + PROJECTION_STRATEGY.AppendComponentToBody(ConfirmationComponent, { + confirmation$: this.confirmation$, + clear: this.clear, + }), + ); - this.containerComponentRef.changeDetectorRef.detectChanges(); - }, 0); + this.containerComponentRef.changeDetectorRef.detectChanges(); } info( @@ -75,10 +76,10 @@ export class ConfirmationService { return this.status$; } - clear(status: Confirmation.Status = Confirmation.Status.dismiss) { + clear = (status: Confirmation.Status = Confirmation.Status.dismiss) => { this.confirmation$.next(); this.status$.next(status); - } + }; private listenToEscape() { fromEvent(document, 'keyup') diff --git a/npm/ng-packs/packages/theme-shared/src/lib/services/toaster.service.ts b/npm/ng-packs/packages/theme-shared/src/lib/services/toaster.service.ts index 4d178c0ad2..295647309d 100644 --- a/npm/ng-packs/packages/theme-shared/src/lib/services/toaster.service.ts +++ b/npm/ng-packs/packages/theme-shared/src/lib/services/toaster.service.ts @@ -21,7 +21,7 @@ export class ToasterService { private setContainer() { this.containerComponentRef = this.contentProjectionService.projectContent( - PROJECTION_STRATEGY.AppendComponentToBody(ToastContainerComponent), + PROJECTION_STRATEGY.AppendComponentToBody(ToastContainerComponent, { toasts$: this.toasts$ }), ); this.containerComponentRef.changeDetectorRef.detectChanges(); diff --git a/npm/ng-packs/packages/theme-shared/src/lib/theme-shared.module.ts b/npm/ng-packs/packages/theme-shared/src/lib/theme-shared.module.ts index 5d53ed2124..8134a44be4 100644 --- a/npm/ng-packs/packages/theme-shared/src/lib/theme-shared.module.ts +++ b/npm/ng-packs/packages/theme-shared/src/lib/theme-shared.module.ts @@ -92,8 +92,6 @@ export function appendScript(injector: Injector) { ], }) export class ThemeSharedModule { - constructor(private errorHandler: ErrorHandler) {} - static forRoot(options = {} as RootParams): ModuleWithProviders { return { ngModule: ThemeSharedModule, @@ -104,6 +102,12 @@ export class ThemeSharedModule { deps: [THEME_SHARED_APPEND_CONTENT], useFactory: noop, }, + { + provide: APP_INITIALIZER, + multi: true, + deps: [ErrorHandler], + useFactory: noop, + }, { provide: HTTP_ERROR_CONFIG, useValue: options.httpErrorConfig }, { provide: 'HTTP_ERROR_CONFIG', From 8b7d5600f5166cdef5b5830ff8e7311bf0346cd2 Mon Sep 17 00:00:00 2001 From: mehmet-erim Date: Mon, 4 May 2020 03:13:25 +0300 Subject: [PATCH 54/67] refactor(core): add partial to context types in projection.strategy --- .../src/lib/strategies/projection.strategy.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/npm/ng-packs/packages/core/src/lib/strategies/projection.strategy.ts b/npm/ng-packs/packages/core/src/lib/strategies/projection.strategy.ts index e7a62383a2..bc7c9201fd 100644 --- a/npm/ng-packs/packages/core/src/lib/strategies/projection.strategy.ts +++ b/npm/ng-packs/packages/core/src/lib/strategies/projection.strategy.ts @@ -95,7 +95,10 @@ export class TemplateProjectionStrategy> extends Proj } export const PROJECTION_STRATEGY = { - AppendComponentToBody>(component: T, context?: InferredInstanceOf) { + AppendComponentToBody>( + component: T, + context?: Partial>, + ) { return new RootComponentProjectionStrategy( component, context && CONTEXT_STRATEGY.Component(context), @@ -104,7 +107,7 @@ export const PROJECTION_STRATEGY = { AppendComponentToContainer>( component: T, containerRef: ViewContainerRef, - context?: InferredInstanceOf, + context?: Partial>, ) { return new ComponentProjectionStrategy( component, @@ -115,7 +118,7 @@ export const PROJECTION_STRATEGY = { AppendTemplateToContainer>( templateRef: T, containerRef: ViewContainerRef, - context?: InferredContextOf, + context?: Partial>, ) { return new TemplateProjectionStrategy( templateRef, @@ -126,7 +129,7 @@ export const PROJECTION_STRATEGY = { PrependComponentToContainer>( component: T, containerRef: ViewContainerRef, - context?: InferredInstanceOf, + context?: Partial>, ) { return new ComponentProjectionStrategy( component, @@ -137,7 +140,7 @@ export const PROJECTION_STRATEGY = { PrependTemplateToContainer>( templateRef: T, containerRef: ViewContainerRef, - context?: InferredContextOf, + context?: Partial>, ) { return new TemplateProjectionStrategy( templateRef, @@ -148,7 +151,7 @@ export const PROJECTION_STRATEGY = { ProjectComponentToContainer>( component: T, containerRef: ViewContainerRef, - context?: InferredInstanceOf, + context?: Partial>, ) { return new ComponentProjectionStrategy( component, @@ -159,7 +162,7 @@ export const PROJECTION_STRATEGY = { ProjectTemplateToContainer>( templateRef: T, containerRef: ViewContainerRef, - context?: InferredContextOf, + context?: Partial>, ) { return new TemplateProjectionStrategy( templateRef, From 91f1b6982b610f87389e741f591078806e9d00a2 Mon Sep 17 00:00:00 2001 From: mehmet-erim Date: Mon, 4 May 2020 03:13:49 +0300 Subject: [PATCH 55/67] test(core): fix testing errors --- .../packages/core/src/lib/tests/config.state.spec.ts | 12 ++++++------ .../src/lib/tests/dynamic-layout.component.spec.ts | 3 ++- .../core/src/lib/tests/localization.service.spec.ts | 7 ++++--- .../core/src/lib/tests/session.state.spec.ts | 4 +--- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/npm/ng-packs/packages/core/src/lib/tests/config.state.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/config.state.spec.ts index 1ff9ad817e..ae98855913 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/config.state.spec.ts +++ b/npm/ng-packs/packages/core/src/lib/tests/config.state.spec.ts @@ -7,6 +7,7 @@ import { ABP } from '../models'; import { Config } from '../models/config'; import { ApplicationConfigurationService, ConfigStateService } from '../services'; import { ConfigState } from '../states'; +import { HttpClient } from '@angular/common/http'; export const CONFIG_STATE_DATA = { environment: { @@ -136,19 +137,17 @@ describe('ConfigState', () => { let store: SpyObject; let service: ConfigStateService; let state: ConfigState; - let appConfigService: SpyObject; const createService = createServiceFactory({ service: ConfigStateService, - mocks: [ApplicationConfigurationService, Store], + mocks: [ApplicationConfigurationService, Store, HttpClient], }); beforeEach(() => { spectator = createService(); store = spectator.get(Store); service = spectator.service; - appConfigService = spectator.get(ApplicationConfigurationService); - state = new ConfigState(spectator.get(ApplicationConfigurationService), store); + state = new ConfigState(spectator.get(HttpClient), store); }); describe('#getAll', () => { @@ -283,7 +282,7 @@ describe('ConfigState', () => { }); describe('#GetAppConfiguration', () => { - it('should call the getConfiguration of ApplicationConfigurationService and patch the state', done => { + it('should call the app-configuration API and patch the state', done => { let patchStateArg; let dispatchArg; @@ -299,7 +298,8 @@ describe('ConfigState', () => { dispatchArg = a; return of(a); }); - appConfigService.getConfiguration.andReturn(res$); + const httpClient = spectator.get(HttpClient); + httpClient.get.andReturn(res$); state.addData({ patchState, dispatch } as any).subscribe(); diff --git a/npm/ng-packs/packages/core/src/lib/tests/dynamic-layout.component.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/dynamic-layout.component.spec.ts index 0a123b6a4f..e1a678a19f 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/dynamic-layout.component.spec.ts +++ b/npm/ng-packs/packages/core/src/lib/tests/dynamic-layout.component.spec.ts @@ -7,6 +7,7 @@ import { eLayoutType } from '../enums'; import { ABP } from '../models'; import { ConfigState, ReplaceableComponentsState } from '../states'; import { ApplicationConfigurationService } from '../services'; +import { HttpClient } from '@angular/common/http'; @Component({ selector: 'abp-layout-application', @@ -92,7 +93,7 @@ describe('DynamicLayoutComponent', () => { component: RouterOutletComponent, stubsEnabled: false, declarations: [DummyComponent, DynamicLayoutComponent], - mocks: [ApplicationConfigurationService], + mocks: [ApplicationConfigurationService, HttpClient], imports: [ RouterModule, DummyLayoutModule, diff --git a/npm/ng-packs/packages/core/src/lib/tests/localization.service.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/localization.service.spec.ts index bfd8948318..5600e3aa39 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/localization.service.spec.ts +++ b/npm/ng-packs/packages/core/src/lib/tests/localization.service.spec.ts @@ -1,7 +1,7 @@ import { Router } from '@angular/router'; import { createServiceFactory, SpectatorService, SpyObject } from '@ngneat/spectator/jest'; -import { Store } from '@ngxs/store'; -import { Observable, of } from 'rxjs'; +import { Store, Actions } from '@ngxs/store'; +import { Observable, of, Subject } from 'rxjs'; import { LocalizationService } from '../services/localization.service'; describe('LocalizationService', () => { @@ -13,6 +13,7 @@ describe('LocalizationService', () => { service: LocalizationService, entryComponents: [], mocks: [Store, Router], + providers: [{ provide: Actions, useValue: new Subject() }], }); beforeEach(() => { @@ -74,7 +75,7 @@ describe('LocalizationService', () => { it('should throw an error message when service have an otherInstance', async () => { try { - const instance = new LocalizationService(null, null, null, {} as any); + const instance = new LocalizationService(new Subject(), null, null, null, {} as any); } catch (error) { expect((error as Error).message).toBe('LocalizationService should have only one instance.'); } diff --git a/npm/ng-packs/packages/core/src/lib/tests/session.state.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/session.state.spec.ts index cdf616e5d2..8a7953dd16 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/session.state.spec.ts +++ b/npm/ng-packs/packages/core/src/lib/tests/session.state.spec.ts @@ -25,7 +25,7 @@ describe('SessionState', () => { beforeEach(() => { spectator = createService(); - state = new SessionState(spectator.get(LocalizationService), null, null, new Subject()); + state = new SessionState(null, null, new Subject()); }); describe('#getLanguage', () => { @@ -49,13 +49,11 @@ describe('SessionState', () => { dispatchedData = action; return of({}); }); - const spy = jest.spyOn(spectator.get(LocalizationService), 'registerLocale'); state.setLanguage({ patchState, dispatch } as any, { payload: 'en' }).subscribe(); expect(patchedData).toEqual({ language: 'en' }); expect(dispatchedData instanceof GetAppConfiguration).toBeTruthy(); - expect(spy).toHaveBeenCalledWith('en'); }); }); From bdb0d6b6c155ada0e90c96d4dc45a1fe122668a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Levent=20Arman=20=C3=96zak?= Date: Mon, 4 May 2020 11:53:10 +0300 Subject: [PATCH 56/67] Update confirmation.service.ts --- .../src/lib/services/confirmation.service.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/npm/ng-packs/packages/theme-shared/src/lib/services/confirmation.service.ts b/npm/ng-packs/packages/theme-shared/src/lib/services/confirmation.service.ts index d254449894..4c69d0cc37 100644 --- a/npm/ng-packs/packages/theme-shared/src/lib/services/confirmation.service.ts +++ b/npm/ng-packs/packages/theme-shared/src/lib/services/confirmation.service.ts @@ -12,6 +12,11 @@ export class ConfirmationService { private containerComponentRef: ComponentRef; + clear = (status: Confirmation.Status = Confirmation.Status.dismiss) => { + this.confirmation$.next(); + this.status$.next(status); + }; + constructor(private contentProjectionService: ContentProjectionService) {} private setContainer() { @@ -76,11 +81,6 @@ export class ConfirmationService { return this.status$; } - clear = (status: Confirmation.Status = Confirmation.Status.dismiss) => { - this.confirmation$.next(); - this.status$.next(status); - }; - private listenToEscape() { fromEvent(document, 'keyup') .pipe( From 9fea8104206f627c4fb6c4c24a3bbcd1bedb5706 Mon Sep 17 00:00:00 2001 From: Arman Ozak Date: Mon, 4 May 2020 13:02:36 +0300 Subject: [PATCH 57/67] refactor: use async pipe instead of subscription --- .../confirmation/confirmation.component.html | 4 +-- .../confirmation/confirmation.component.ts | 27 ++++++------------- 2 files changed, 10 insertions(+), 21 deletions(-) diff --git a/npm/ng-packs/packages/theme-shared/src/lib/components/confirmation/confirmation.component.html b/npm/ng-packs/packages/theme-shared/src/lib/components/confirmation/confirmation.component.html index 8b0d8591c4..8987cda2f9 100644 --- a/npm/ng-packs/packages/theme-shared/src/lib/components/confirmation/confirmation.component.html +++ b/npm/ng-packs/packages/theme-shared/src/lib/components/confirmation/confirmation.component.html @@ -1,8 +1,8 @@ -
+
- +

; clear: (status: Confirmation.Status) => void; - get iconClass(): string { - switch (this.data.severity) { + close(status: Confirmation.Status) { + this.clear(status); + } + + getIconClass({ severity }: Confirmation.DialogData): string { + switch (severity) { case 'info': return 'fa-info-circle'; case 'success': @@ -34,15 +34,4 @@ export class ConfirmationComponent implements OnInit { return 'fa-question-circle'; } } - - ngOnInit() { - this.confirmation$.subscribe(confirmation => { - this.data = confirmation; - this.visible = !!confirmation; - }); - } - - close(status: Confirmation.Status) { - this.clear(status); - } } From b41a9dc3667e36ba6447127c169f6d8d25a74cc7 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Mon, 4 May 2020 15:56:28 +0300 Subject: [PATCH 58/67] datatables scrollX default true --- .../datatables/datatables-extensions.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore-mvc-ui-theme-shared/datatables/datatables-extensions.js b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore-mvc-ui-theme-shared/datatables/datatables-extensions.js index 77cae54b67..a5a8d2c077 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore-mvc-ui-theme-shared/datatables/datatables-extensions.js +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore-mvc-ui-theme-shared/datatables/datatables-extensions.js @@ -336,6 +336,9 @@ }; datatables.normalizeConfiguration = function (configuration) { + + configuration.scrollX = true; + for (var i = 0; i < configuration.columnDefs.length; i++) { var column = configuration.columnDefs[i]; if (!column.targets) { From a114f711ec06a80d4129722b609d75f648d311bc Mon Sep 17 00:00:00 2001 From: Arman Ozak Date: Mon, 4 May 2020 17:15:08 +0300 Subject: [PATCH 59/67] fix: add zero delay timeout before change detection call --- .../src/lib/services/confirmation.service.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/npm/ng-packs/packages/theme-shared/src/lib/services/confirmation.service.ts b/npm/ng-packs/packages/theme-shared/src/lib/services/confirmation.service.ts index 4c69d0cc37..2672a93a2a 100644 --- a/npm/ng-packs/packages/theme-shared/src/lib/services/confirmation.service.ts +++ b/npm/ng-packs/packages/theme-shared/src/lib/services/confirmation.service.ts @@ -1,9 +1,9 @@ -import { Injectable, ComponentRef } from '@angular/core'; -import { Confirmation } from '../models/confirmation'; -import { fromEvent, Observable, Subject, ReplaySubject } from 'rxjs'; -import { takeUntil, debounceTime, filter } from 'rxjs/operators'; import { Config, ContentProjectionService, PROJECTION_STRATEGY } from '@abp/ng.core'; +import { ComponentRef, Injectable } from '@angular/core'; +import { fromEvent, Observable, ReplaySubject, Subject } from 'rxjs'; +import { debounceTime, filter, takeUntil } from 'rxjs/operators'; import { ConfirmationComponent } from '../components/confirmation/confirmation.component'; +import { Confirmation } from '../models/confirmation'; @Injectable({ providedIn: 'root' }) export class ConfirmationService { @@ -27,7 +27,9 @@ export class ConfirmationService { }), ); - this.containerComponentRef.changeDetectorRef.detectChanges(); + setTimeout(() => { + this.containerComponentRef.changeDetectorRef.detectChanges(); + }, 0); } info( From aea81e4fd9a048801b7c040ca5f9f8b2cdce738e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Mon, 4 May 2020 18:35:49 +0300 Subject: [PATCH 60/67] Enable audit log extensions --- ...uditLoggingModuleExtensionConfiguration.cs | 35 +++++++++++++++++++ ...ensionConfigurationDictionaryExtensions.cs | 18 ++++++++++ .../AuditLoggingModuleExtensionConsts.cs | 16 +++++++++ .../AbpAuditLoggingDomainModule.cs | 21 +++++++++++ 4 files changed, 90 insertions(+) create mode 100644 modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/ObjectExtending/AuditLoggingModuleExtensionConfiguration.cs create mode 100644 modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/ObjectExtending/AuditLoggingModuleExtensionConfigurationDictionaryExtensions.cs create mode 100644 modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/ObjectExtending/AuditLoggingModuleExtensionConsts.cs diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/ObjectExtending/AuditLoggingModuleExtensionConfiguration.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/ObjectExtending/AuditLoggingModuleExtensionConfiguration.cs new file mode 100644 index 0000000000..24c54e4b55 --- /dev/null +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/ObjectExtending/AuditLoggingModuleExtensionConfiguration.cs @@ -0,0 +1,35 @@ +using System; +using Volo.Abp.ObjectExtending.Modularity; + +namespace Volo.Abp.ObjectExtending +{ + public class AuditLoggingModuleExtensionConfiguration : ModuleExtensionConfiguration + { + public AuditLoggingModuleExtensionConfiguration ConfigureAuditLog( + Action configureAction) + { + return this.ConfigureEntity( + AuditLoggingModuleExtensionConsts.EntityNames.AuditLog, + configureAction + ); + } + + public AuditLoggingModuleExtensionConfiguration ConfigureAuditLogAction( + Action configureAction) + { + return this.ConfigureEntity( + AuditLoggingModuleExtensionConsts.EntityNames.AuditLogAction, + configureAction + ); + } + + public AuditLoggingModuleExtensionConfiguration ConfigureEntityChange( + Action configureAction) + { + return this.ConfigureEntity( + AuditLoggingModuleExtensionConsts.EntityNames.EntityChange, + configureAction + ); + } + } +} diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/ObjectExtending/AuditLoggingModuleExtensionConfigurationDictionaryExtensions.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/ObjectExtending/AuditLoggingModuleExtensionConfigurationDictionaryExtensions.cs new file mode 100644 index 0000000000..3de08783e1 --- /dev/null +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/ObjectExtending/AuditLoggingModuleExtensionConfigurationDictionaryExtensions.cs @@ -0,0 +1,18 @@ +using System; +using Volo.Abp.ObjectExtending.Modularity; + +namespace Volo.Abp.ObjectExtending +{ + public static class AuditLoggingModuleExtensionConfigurationDictionaryExtensions + { + public static ModuleExtensionConfigurationDictionary ConfigureAuditLogging( + this ModuleExtensionConfigurationDictionary modules, + Action configureAction) + { + return modules.ConfigureModule( + AuditLoggingModuleExtensionConsts.ModuleName, + configureAction + ); + } + } +} \ No newline at end of file diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/ObjectExtending/AuditLoggingModuleExtensionConsts.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/ObjectExtending/AuditLoggingModuleExtensionConsts.cs new file mode 100644 index 0000000000..ec8be4914b --- /dev/null +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/ObjectExtending/AuditLoggingModuleExtensionConsts.cs @@ -0,0 +1,16 @@ +namespace Volo.Abp.ObjectExtending +{ + public static class AuditLoggingModuleExtensionConsts + { + public const string ModuleName = "AuditLogging"; + + public static class EntityNames + { + public const string AuditLog = "AuditLog"; + + public const string AuditLogAction = "AuditLogAction"; + + public const string EntityChange = "EntityChange"; + } + } +} \ No newline at end of file diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AbpAuditLoggingDomainModule.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AbpAuditLoggingDomainModule.cs index 376dea99f3..b2d2505004 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AbpAuditLoggingDomainModule.cs +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AbpAuditLoggingDomainModule.cs @@ -1,6 +1,8 @@ using Volo.Abp.Auditing; using Volo.Abp.Domain; using Volo.Abp.Modularity; +using Volo.Abp.ObjectExtending; +using Volo.Abp.ObjectExtending.Modularity; namespace Volo.Abp.AuditLogging { @@ -9,6 +11,25 @@ namespace Volo.Abp.AuditLogging [DependsOn(typeof(AbpAuditLoggingDomainSharedModule))] public class AbpAuditLoggingDomainModule : AbpModule { + public override void PostConfigureServices(ServiceConfigurationContext context) + { + ModuleExtensionConfigurationHelper.ApplyEntityConfigurationToEntity( + AuditLoggingModuleExtensionConsts.ModuleName, + AuditLoggingModuleExtensionConsts.EntityNames.AuditLog, + typeof(AuditLog) + ); + ModuleExtensionConfigurationHelper.ApplyEntityConfigurationToEntity( + AuditLoggingModuleExtensionConsts.ModuleName, + AuditLoggingModuleExtensionConsts.EntityNames.AuditLogAction, + typeof(AuditLogAction) + ); + + ModuleExtensionConfigurationHelper.ApplyEntityConfigurationToEntity( + AuditLoggingModuleExtensionConsts.ModuleName, + AuditLoggingModuleExtensionConsts.EntityNames.EntityChange, + typeof(EntityChange) + ); + } } } From b8216daeb5693837b8c8fbec0b4c2b85df66d89c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Mon, 4 May 2020 22:20:02 +0300 Subject: [PATCH 61/67] Refactor datatables-extensions.js --- .../datatables/datatables-extensions.js | 71 ++++--------------- 1 file changed, 13 insertions(+), 58 deletions(-) diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore-mvc-ui-theme-shared/datatables/datatables-extensions.js b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore-mvc-ui-theme-shared/datatables/datatables-extensions.js index a5a8d2c077..36f864e201 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore-mvc-ui-theme-shared/datatables/datatables-extensions.js +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore-mvc-ui-theme-shared/datatables/datatables-extensions.js @@ -2,59 +2,16 @@ (function ($) { - /************************************************************************ - * RECORD-ACTIONS extension for datatables - --------------------------------------------------------------- - * SINGLE BUTTON USAGE (creates the given JQuery element) - { - targets: 0, //optional - rowAction: - { - element: $("