Browse Source

Rename DeclaringFrom to ImplementFrom and Support methods with the same name

pull/9905/head
liangshiwei 5 years ago
parent
commit
8ce9cdb070
  1. 8
      framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AspNetCoreApiDescriptionModelProvider.cs
  2. 15
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ServiceProxy/CSharp/CSharpServiceProxyGenerator.cs
  3. 4
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ServiceProxy/JavaScript/JavaScriptServiceProxyGenerator.cs
  4. 13
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ServiceProxy/ServiceProxyGeneratorBase.cs
  5. 15
      framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/ClientProxying/ClientProxyApiDescriptionFinder.cs
  6. 19
      framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/ClientProxying/ClientProxyBase.cs
  7. 6
      framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ActionApiDescriptionModel.cs

8
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
)
);

15
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<string> usingNamespaceList)
{
methodBuilder.AppendLine($"public {returnTypeName} {action.Name}(<args>)");
methodBuilder.AppendLine($"public virtual {returnTypeName} {action.Name}(<args>)");
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}(<args>)");
methodBuilder.AppendLine($"public virtual async {returnSign} {action.Name}(<args>)");
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
};

4
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)

13
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<ApplicationApiDescriptionModel>(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);
}
}
}

15
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);
}
}
}

19
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<HttpProxyExecuterContext> 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();
}
}
}

6
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<string> 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<string> 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
};
}

Loading…
Cancel
Save