Browse Source

Add `service type` parameter to `ServiceProxyGenerator`.

pull/14288/head
maliming 4 years ago
parent
commit
585945529f
  1. 17
      framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApiDescriptionExtensions.cs
  2. 1
      framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AspNetCoreApiDescriptionModelProvider.cs
  3. 19
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/ProxyCommandBase.cs
  4. 7
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ServiceProxying/Angular/AngularServiceProxyGenerator.cs
  5. 5
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ServiceProxying/CSharp/CSharpServiceProxyGenerator.cs
  6. 4
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ServiceProxying/GenerateProxyArgs.cs
  7. 7
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ServiceProxying/JavaScript/JavaScriptServiceProxyGenerator.cs
  8. 16
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ServiceProxying/ServiceProxyGeneratorBase.cs
  9. 8
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ServiceProxying/ServiceType.cs
  10. 5
      framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ControllerApiDescriptionModel.cs
  11. 4
      framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ModuleApiDescriptionModel.cs

17
framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApiDescriptionExtensions.cs

@ -1,5 +1,4 @@
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.ApiExplorer;
using Microsoft.AspNetCore.Mvc.ApiExplorer;
using Microsoft.AspNetCore.Mvc.Controllers;
using Volo.Abp.Reflection;
@ -7,9 +6,9 @@ namespace Volo.Abp.AspNetCore.Mvc;
public static class ApiDescriptionExtensions
{
public static bool IsRemoteService(this ApiDescription actionDescriptor)
public static bool IsRemoteService(this ApiDescription apiDescriptor)
{
if (actionDescriptor.ActionDescriptor is ControllerActionDescriptor controllerActionDescriptor)
if (apiDescriptor.ActionDescriptor is ControllerActionDescriptor controllerActionDescriptor)
{
var remoteServiceAttr = ReflectionHelper.GetSingleAttributeOfMemberOrDeclaringTypeOrDefault<RemoteServiceAttribute>(controllerActionDescriptor.MethodInfo);
if (remoteServiceAttr != null && remoteServiceAttr.IsEnabled)
@ -31,4 +30,14 @@ public static class ApiDescriptionExtensions
return false;
}
public static bool IsIntegrationService(this ApiDescription apiDescriptor)
{
if (apiDescriptor.ActionDescriptor is ControllerActionDescriptor controllerActionDescriptor)
{
return IntegrationServiceAttribute.IsDefinedOrInherited(controllerActionDescriptor.ControllerTypeInfo);
}
return false;
}
}

1
framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AspNetCoreApiDescriptionModelProvider.cs

@ -103,6 +103,7 @@ public class AspNetCoreApiDescriptionModelProvider : IApiDescriptionModelProvide
_options.ControllerNameGenerator(controllerType, setting),
FindGroupName(controllerType) ?? apiDescription.GroupName,
apiDescription.IsRemoteService(),
apiDescription.IsIntegrationService(),
apiDescription.GetProperty<ApiVersion>()?.ToString(),
controllerType,
_modelOptions.IgnoredInterfaces

19
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/ProxyCommandBase.cs

@ -68,8 +68,19 @@ public abstract class ProxyCommandBase<T> : IConsoleCommand, ITransientDependenc
var source = commandLineArgs.Options.GetOrNull(Options.Source.Short, Options.Source.Long);
var workDirectory = commandLineArgs.Options.GetOrNull(Options.WorkDirectory.Short, Options.WorkDirectory.Long) ?? Directory.GetCurrentDirectory();
var folder = commandLineArgs.Options.GetOrNull(Options.Folder.Long);
var serviceTypeArg = commandLineArgs.Options.GetOrNull(Options.Module.Short, Options.ServiceType.Long);
return new GenerateProxyArgs(CommandName, workDirectory, module, url, output, target, apiName, source, folder, commandLineArgs.Options);
ServiceType? serviceType = null;
if (!serviceTypeArg.IsNullOrWhiteSpace())
{
serviceType = serviceTypeArg.ToLower() == "application"
? ServiceType.Application
: serviceTypeArg.ToLower() == "integration"
? ServiceType.Integration
: null;
}
return new GenerateProxyArgs(CommandName, workDirectory, module, url, output, target, apiName, source, folder, serviceType, commandLineArgs.Options);
}
public virtual string GetUsageInfo()
@ -162,5 +173,11 @@ public abstract class ProxyCommandBase<T> : IConsoleCommand, ITransientDependenc
public const string Short = "wd";
public const string Long = "working-directory";
}
public static class ServiceType
{
public const string Short = "st";
public const string Long = "service-type";
}
}
}

7
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ServiceProxying/Angular/AngularServiceProxyGenerator.cs

@ -30,7 +30,7 @@ public class AngularServiceProxyGenerator : ServiceProxyGeneratorBase<AngularSer
_cliService = cliService;
}
public override async Task GenerateProxyAsync(GenerateProxyArgs args)
public async override Task GenerateProxyAsync(GenerateProxyArgs args)
{
CheckAngularJsonFile();
await CheckNgSchematicsAsync();
@ -79,6 +79,11 @@ public class AngularServiceProxyGenerator : ServiceProxyGeneratorBase<AngularSer
_cmdhelper.RunCmd(commandBuilder.ToString());
}
protected override ServiceType? GetDefaultServiceType(GenerateProxyArgs args)
{
return ServiceType.Application;
}
private async Task CheckNgSchematicsAsync()
{
var packageJsonPath = $"package.json";

5
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ServiceProxying/CSharp/CSharpServiceProxyGenerator.cs

@ -88,6 +88,11 @@ public class CSharpServiceProxyGenerator : ServiceProxyGeneratorBase<CSharpServi
await CreateGenerateProxyJsonFile(args, applicationApiDescriptionModel);
}
protected override ServiceType? GetDefaultServiceType(GenerateProxyArgs args)
{
return ServiceType.All;
}
private async Task CreateGenerateProxyJsonFile(GenerateProxyArgs args, ApplicationApiDescriptionModel applicationApiDescriptionModel)
{
var folder = args.Folder.IsNullOrWhiteSpace() ? DefaultNamespace : args.Folder;

4
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ServiceProxying/GenerateProxyArgs.cs

@ -25,6 +25,8 @@ public class GenerateProxyArgs
public string Folder { get; }
public ServiceType? ServiceType { get; }
[NotNull]
public Dictionary<string, string> ExtraProperties { get; set; }
@ -38,6 +40,7 @@ public class GenerateProxyArgs
string apiName,
string source,
string folder,
ServiceType? serviceType,
Dictionary<string, string> extraProperties = null)
{
CommandName = Check.NotNullOrWhiteSpace(commandName, nameof(commandName));
@ -49,6 +52,7 @@ public class GenerateProxyArgs
ApiName = apiName;
Source = source;
Folder = folder;
ServiceType = serviceType;
ExtraProperties = extraProperties ?? new Dictionary<string, string>();
}
}

7
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ServiceProxying/JavaScript/JavaScriptServiceProxyGenerator.cs

@ -28,7 +28,7 @@ public class JavaScriptServiceProxyGenerator : ServiceProxyGeneratorBase<JavaScr
_jQueryProxyScriptGenerator = jQueryProxyScriptGenerator;
}
public override async Task GenerateProxyAsync(GenerateProxyArgs args)
public async override Task GenerateProxyAsync(GenerateProxyArgs args)
{
CheckWorkDirectory(args.WorkDirectory);
@ -57,6 +57,11 @@ public class JavaScriptServiceProxyGenerator : ServiceProxyGeneratorBase<JavaScr
Logger.LogInformation($"Create {GetLoggerOutputPath(output, args.WorkDirectory)}");
}
protected override ServiceType? GetDefaultServiceType(GenerateProxyArgs args)
{
return ServiceType.Application;
}
private void RemoveProxy(GenerateProxyArgs args, string filePath)
{
if (File.Exists(filePath))

16
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ServiceProxying/ServiceProxyGeneratorBase.cs

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
@ -42,12 +43,25 @@ public abstract class ServiceProxyGeneratorBase<T> : IServiceProxyGenerator wher
throw new CliUsageException($"Module name: {args.Module} is invalid");
}
var serviceType = args.ServiceType ?? GetDefaultServiceType(args);
switch (serviceType)
{
case ServiceType.Application:
moduleDefinition.Controllers.RemoveAll(x => !x.Value.IsRemoteService);
break;
case ServiceType.Integration:
moduleDefinition.Controllers.RemoveAll(x => !x.Value.IsIntegrationService);
break;
}
var apiDescriptionModel = ApplicationApiDescriptionModel.Create();
apiDescriptionModel.AddModule(moduleDefinition);
return apiDescriptionModel;
}
protected abstract ServiceType? GetDefaultServiceType(GenerateProxyArgs args);
protected string GetLoggerOutputPath(string path, string workDirectory)
{
return path.Replace(workDirectory, string.Empty).TrimStart(Path.DirectorySeparatorChar);

8
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ServiceProxying/ServiceType.cs

@ -0,0 +1,8 @@
namespace Volo.Abp.Cli.ServiceProxying;
public enum ServiceType : byte
{
All = 0,
Application = 1,
Integration = 2
}

5
framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ControllerApiDescriptionModel.cs

@ -14,6 +14,8 @@ public class ControllerApiDescriptionModel
public bool IsRemoteService { get; set; }
public bool IsIntegrationService { get; set; }
public string ApiVersion { get; set; }
public string Type { get; set; }
@ -27,13 +29,14 @@ public class ControllerApiDescriptionModel
}
public static ControllerApiDescriptionModel Create(string controllerName, string groupName, bool isRemoteService, string apiVersion, Type type, [CanBeNull] HashSet<Type> ignoredInterfaces = null)
public static ControllerApiDescriptionModel Create(string controllerName, string groupName, bool isRemoteService, bool isIntegrationService, string apiVersion, Type type, [CanBeNull] HashSet<Type> ignoredInterfaces = null)
{
return new ControllerApiDescriptionModel
{
ControllerName = controllerName,
ControllerGroupName = groupName,
IsRemoteService = isRemoteService,
IsIntegrationService = isIntegrationService,
ApiVersion = apiVersion,
Type = type.FullName,
Actions = new Dictionary<string, ActionApiDescriptionModel>(),

4
framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ModuleApiDescriptionModel.cs

@ -49,10 +49,10 @@ public class ModuleApiDescriptionModel
return Controllers[controller.Type] = controller;
}
public ControllerApiDescriptionModel GetOrAddController(string name, string groupName, bool isRemoteService, string apiVersion, Type type, [CanBeNull] HashSet<Type> ignoredInterfaces = null)
public ControllerApiDescriptionModel GetOrAddController(string name, string groupName, bool isRemoteService, bool isIntegrationService, string apiVersion, Type type, [CanBeNull] HashSet<Type> ignoredInterfaces = null)
{
var key = apiVersion.IsNullOrWhiteSpace() ? type.FullName : $"{apiVersion + "."}{type.FullName}";
return Controllers.GetOrAdd(key, () => ControllerApiDescriptionModel.Create(name, groupName, isRemoteService, apiVersion, type, ignoredInterfaces));
return Controllers.GetOrAdd(key, () => ControllerApiDescriptionModel.Create(name, groupName, isRemoteService, isIntegrationService, apiVersion, type, ignoredInterfaces));
}
public ModuleApiDescriptionModel CreateSubModel(string[] controllers, string[] actions)

Loading…
Cancel
Save