From 8ce9cdb0708b9d4a1e39337b26bd4a04e7e8d6d2 Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Tue, 31 Aug 2021 16:25:16 +0800 Subject: [PATCH] Rename DeclaringFrom to ImplementFrom and Support methods with the same name --- .../AspNetCoreApiDescriptionModelProvider.cs | 8 ++++---- .../CSharp/CSharpServiceProxyGenerator.cs | 15 ++++++++------- .../JavaScriptServiceProxyGenerator.cs | 4 ++-- .../ServiceProxy/ServiceProxyGeneratorBase.cs | 13 +++++++++++-- .../ClientProxyApiDescriptionFinder.cs | 15 +++++++++++++-- .../Client/ClientProxying/ClientProxyBase.cs | 19 +++++++++++++++++-- .../Modeling/ActionApiDescriptionModel.cs | 6 +++--- 7 files changed, 58 insertions(+), 22 deletions(-) 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 64132608aa..67900fc5bd 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 @@ -113,11 +113,11 @@ namespace Volo.Abp.AspNetCore.Mvc allowAnonymous = false; } - var declaringFrom = controllerType.FullName; + var implementFrom = controllerType.FullName; var interfaces = controllerType.GetInterfaces().ToList(); - foreach (var interfaceType in interfaces.Where(interfaceType => interfaceType.GetMethods().Any(x => x.Name == method.Name))) + foreach (var interfaceType in interfaces.Where(interfaceType => interfaceType.GetMethods().Any(x => x.ToString() == method.ToString()))) { - declaringFrom = TypeHelper.GetFullNameHandlingNullableAndGenerics(interfaceType); + implementFrom = TypeHelper.GetFullNameHandlingNullableAndGenerics(interfaceType); break; } @@ -130,7 +130,7 @@ namespace Volo.Abp.AspNetCore.Mvc apiDescription.HttpMethod, GetSupportedVersions(controllerType, method, setting), allowAnonymous, - declaringFrom + implementFrom ) ); diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ServiceProxy/CSharp/CSharpServiceProxyGenerator.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ServiceProxy/CSharp/CSharpServiceProxyGenerator.cs index c26ed8f376..85198ae31d 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ServiceProxy/CSharp/CSharpServiceProxyGenerator.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ServiceProxy/CSharp/CSharpServiceProxyGenerator.cs @@ -82,7 +82,7 @@ namespace Volo.Abp.Cli.ServiceProxy.CSharp var applicationApiDescriptionModel = await GetApplicationApiDescriptionModelAsync(args); - foreach (var controller in applicationApiDescriptionModel.Modules[args.Module].Controllers) + foreach (var controller in applicationApiDescriptionModel.Modules.Values.SelectMany(x => x.Controllers)) { if (ShouldGenerateProxy(controller.Value)) { @@ -114,7 +114,7 @@ namespace Volo.Abp.Cli.ServiceProxy.CSharp Directory.Delete(folderPath, true); } - Logger.LogInformation($"Delete {folderPath.Replace(args.WorkDirectory, string.Empty).TrimStart('\\')}"); + Logger.LogInformation($"Delete {GetLoggerOutputPath(folderPath, args.WorkDirectory)}"); } private async Task GenerateClientProxyFileAsync( @@ -161,7 +161,7 @@ namespace Volo.Abp.Cli.ServiceProxy.CSharp using (var writer = new StreamWriter(filePath)) { await writer.WriteAsync(clientProxyBuilder.ToString()); - Logger.LogInformation($"Create {filePath.Replace(args.WorkDirectory, string.Empty).TrimStart('\\')}"); + Logger.LogInformation($"Create {GetLoggerOutputPath(filePath, args.WorkDirectory)}"); } await GenerateClientProxyPartialFileAsync(args, clientProxyName, fileNamespace, filePath); @@ -186,7 +186,7 @@ namespace Volo.Abp.Cli.ServiceProxy.CSharp await writer.WriteAsync(clientProxyBuilder.ToString()); } - Logger.LogInformation($"Create {filePath.Replace(args.WorkDirectory, string.Empty).TrimStart('\\')}"); + Logger.LogInformation($"Create {GetLoggerOutputPath(filePath, args.WorkDirectory)}"); } } @@ -212,7 +212,7 @@ namespace Volo.Abp.Cli.ServiceProxy.CSharp private void GenerateSynchronizationMethod(ActionApiDescriptionModel action, string returnTypeName, StringBuilder methodBuilder, List usingNamespaceList) { - methodBuilder.AppendLine($"public {returnTypeName} {action.Name}()"); + methodBuilder.AppendLine($"public virtual {returnTypeName} {action.Name}()"); foreach (var parameter in action.Parameters.GroupBy(x => x.Name).Select( x=> x.First())) { @@ -236,7 +236,7 @@ namespace Volo.Abp.Cli.ServiceProxy.CSharp { var returnSign = returnTypeName == "void" ? "Task": $"Task<{returnTypeName}>"; - methodBuilder.AppendLine($"public async {returnSign} {action.Name}()"); + methodBuilder.AppendLine($"public virtual async {returnSign} {action.Name}()"); foreach (var parameter in action.ParametersOnMethod) { @@ -280,7 +280,7 @@ namespace Volo.Abp.Cli.ServiceProxy.CSharp private static bool ShouldGenerateMethod(string appServiceTypeName, ActionApiDescriptionModel action) { - return action.DeclaringFrom.StartsWith(AppServicePrefix) || action.DeclaringFrom.StartsWith(appServiceTypeName); + return action.ImplementFrom.StartsWith(AppServicePrefix) || action.ImplementFrom.StartsWith(appServiceTypeName); } private static string GetTypeNamespace(string typeFullName) @@ -347,6 +347,7 @@ namespace Volo.Abp.Cli.ServiceProxy.CSharp "Boolean" => "bool", "String" => "string", "Int32" => "int", + "Int64" => "long", _ => typeName }; diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ServiceProxy/JavaScript/JavaScriptServiceProxyGenerator.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ServiceProxy/JavaScript/JavaScriptServiceProxyGenerator.cs index 485c5b7f0a..b8046cdc3e 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ServiceProxy/JavaScript/JavaScriptServiceProxyGenerator.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ServiceProxy/JavaScript/JavaScriptServiceProxyGenerator.cs @@ -54,7 +54,7 @@ namespace Volo.Abp.Cli.ServiceProxy.JavaScript await writer.WriteAsync(script); } - Logger.LogInformation($"Create {output.Replace(args.WorkDirectory, string.Empty).TrimStart('\\')}"); + Logger.LogInformation($"Create {GetLoggerOutputPath(output, args.WorkDirectory)}"); } private void RemoveProxy(GenerateProxyArgs args, string filePath) @@ -64,7 +64,7 @@ namespace Volo.Abp.Cli.ServiceProxy.JavaScript File.Delete(filePath); } - Logger.LogInformation($"Delete {filePath.Replace(args.WorkDirectory, string.Empty).TrimStart('\\')}"); + Logger.LogInformation($"Delete {GetLoggerOutputPath(filePath, args.WorkDirectory)}"); } private static void CheckWorkDirectory(string directory) diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ServiceProxy/ServiceProxyGeneratorBase.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ServiceProxy/ServiceProxyGeneratorBase.cs index a183efa35b..f3e402a719 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ServiceProxy/ServiceProxyGeneratorBase.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ServiceProxy/ServiceProxyGeneratorBase.cs @@ -1,4 +1,7 @@ -using System.Threading.Tasks; +using System; +using System.IO; +using System.Linq; +using System.Threading.Tasks; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Volo.Abp.Cli.Http; @@ -33,7 +36,8 @@ namespace Volo.Abp.Cli.ServiceProxy var apiDefinitionResult = await client.GetStringAsync(CliUrls.GetApiDefinitionUrl(args.Url)); var apiDefinition = JsonSerializer.Deserialize(apiDefinitionResult); - if (!apiDefinition.Modules.TryGetValue(args.Module, out var moduleDefinition)) + var moduleDefinition = apiDefinition.Modules.FirstOrDefault(x => string.Equals(x.Key, args.Module, StringComparison.CurrentCultureIgnoreCase)).Value; + if (moduleDefinition == null) { throw new CliUsageException($"Module name: {args.Module} is invalid"); } @@ -43,5 +47,10 @@ namespace Volo.Abp.Cli.ServiceProxy return apiDescriptionModel; } + + protected string GetLoggerOutputPath(string path, string workDirectory) + { + return path.Replace(workDirectory, string.Empty).TrimStart(Path.DirectorySeparatorChar); + } } } diff --git a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/ClientProxying/ClientProxyApiDescriptionFinder.cs b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/ClientProxying/ClientProxyApiDescriptionFinder.cs index c12a74f013..982a1d6f22 100644 --- a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/ClientProxying/ClientProxyApiDescriptionFinder.cs +++ b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/ClientProxying/ClientProxyApiDescriptionFinder.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Text; using System.Threading.Tasks; using Microsoft.Extensions.FileProviders; using Volo.Abp.DependencyInjection; @@ -49,9 +50,19 @@ namespace Volo.Abp.Http.Client.ClientProxying foreach (var actionItem in controller.Actions.Values) { - if (!ActionApiDescriptionModels.ContainsKey($"{appServiceType}.{actionItem.Name}")) + var stringBuilder = new StringBuilder($"{appServiceType}.{actionItem.Name}("); + stringBuilder.Append("("); + foreach (var parameter in actionItem.ParametersOnMethod) { - ActionApiDescriptionModels.Add($"{appServiceType}.{actionItem.Name}", actionItem); + stringBuilder.Append($"{parameter.Type},"); + } + stringBuilder.Append(")"); + stringBuilder.Replace(",)", ")"); + + var actionKey = stringBuilder.ToString(); + if (!ActionApiDescriptionModels.ContainsKey(actionKey)) + { + ActionApiDescriptionModels.Add(actionKey, actionItem); } } } diff --git a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/ClientProxying/ClientProxyBase.cs b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/ClientProxying/ClientProxyBase.cs index 85d8242ad1..c6eb3a74fe 100644 --- a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/ClientProxying/ClientProxyBase.cs +++ b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/ClientProxying/ClientProxyBase.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Linq; +using System.Text; using System.Threading.Tasks; using Volo.Abp.DependencyInjection; using Volo.Abp.Http.Modeling; @@ -25,8 +26,8 @@ namespace Volo.Abp.Http.Client.ClientProxying protected virtual async Task BuildHttpProxyExecuterContext(string methodName, params object[] arguments) { - var actionDescriptionKey = $"{typeof(TService).FullName}.{methodName}"; - var action = await ClientProxyApiDescriptionFinder.FindActionAsync(actionDescriptionKey); + var actionKey = GetActionKey(typeof(TService).FullName, methodName, arguments); + var action = await ClientProxyApiDescriptionFinder.FindActionAsync(actionKey); return new HttpProxyExecuterContext(action, BuildArguments(action, arguments), typeof(TService)); } @@ -43,5 +44,19 @@ namespace Volo.Abp.Http.Client.ClientProxying return dict; } + + private static string GetActionKey(string serviceTypeFullName, string methodName, params object[] arguments) + { + var stringBuilder = new StringBuilder($"{serviceTypeFullName}.{methodName}("); + stringBuilder.Append("("); + foreach (var parameter in arguments) + { + stringBuilder.Append($"{parameter.GetType().FullName},"); + } + stringBuilder.Append(")"); + stringBuilder.Replace(",)", ")"); + + return stringBuilder.ToString(); + } } } diff --git a/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ActionApiDescriptionModel.cs b/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ActionApiDescriptionModel.cs index a83d4c4c87..c23f722c30 100644 --- a/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ActionApiDescriptionModel.cs +++ b/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ActionApiDescriptionModel.cs @@ -28,14 +28,14 @@ namespace Volo.Abp.Http.Modeling public bool? AllowAnonymous { get; set; } - public string DeclaringFrom { get; set; } + public string ImplementFrom { get; set; } public ActionApiDescriptionModel() { } - public static ActionApiDescriptionModel Create([NotNull] string uniqueName, [NotNull] MethodInfo method, [NotNull] string url, [CanBeNull] string httpMethod, [NotNull] IList supportedVersions, bool? allowAnonymous = null, string declaringFrom = null) + public static ActionApiDescriptionModel Create([NotNull] string uniqueName, [NotNull] MethodInfo method, [NotNull] string url, [CanBeNull] string httpMethod, [NotNull] IList supportedVersions, bool? allowAnonymous = null, string implementFrom = null) { Check.NotNull(uniqueName, nameof(uniqueName)); Check.NotNull(method, nameof(method)); @@ -56,7 +56,7 @@ namespace Volo.Abp.Http.Modeling .ToList(), SupportedVersions = supportedVersions, AllowAnonymous = allowAnonymous, - DeclaringFrom = declaringFrom + ImplementFrom = implementFrom }; }