From 044ede1e152b31f82bfd2c414ee15cb79b50ab1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20=C3=87otur?= Date: Sun, 21 Nov 2021 23:45:52 +0300 Subject: [PATCH] use file-scoped namespacing for studioOpen module --- .../AbpStudioAnalyzingAbstractionsModule.cs | 11 +- .../Application/ApplicationServiceModel.cs | 29 +- .../Models/Authorization/PermissionModel.cs | 37 ++- .../Database/DatabaseCollectionModel.cs | 23 +- .../Models/Database/DatabaseTableModel.cs | 23 +- .../Models/Database/EfCoreDbContextModel.cs | 29 +- .../Models/Database/IDbContextModel.cs | 11 +- .../Models/Database/MongoDbContextModel.cs | 29 +- .../Models/Domain/AggregateRootModel.cs | 17 +- .../Models/Domain/DomainServiceModel.cs | 25 +- .../Analyzing/Models/Domain/EntityModel.cs | 39 ++- .../Models/Domain/RepositoryInterfaceModel.cs | 29 +- .../Analyzing/Models/Feature/FeatureModel.cs | 69 +++-- .../Analyzing/Models/Module/AbpModuleModel.cs | 21 +- .../Models/PackageContentItemModel.cs | 21 +- .../Models/PackageContentItemNameAttribute.cs | 31 +- .../Analyzing/Models/PackageContentList.cs | 11 +- .../Studio/Analyzing/Models/PackageModel.cs | 27 +- .../Analyzing/Models/Setting/SettingModel.cs | 31 +- .../AbpStudioDomainCommonServicesModule.cs | 17 +- .../Volo/Abp/Studio/AbpStudioException.cs | 37 ++- .../Volo/Abp/Studio/Helpers/PathHelper.cs | 43 ++- .../Studio/Modifying/AbpModuleFileManager.cs | 103 ++++--- .../Abp/Studio/Modifying/CsprojFileManager.cs | 265 ++++++++-------- .../Studio/Modifying/IAbpModuleFileManager.cs | 11 +- .../Studio/Modifying/ICsprojFileManager.cs | 17 +- .../Abp/Studio/Nuget/INugetSourceCodeStore.cs | 25 +- .../Studio/Nuget/NugetPackageCacheManager.cs | 39 ++- .../Abp/Studio/Nuget/NugetSourceCodeStore.cs | 223 +++++++------- .../Nuget/TemplateNugetPackageInfoProvider.cs | 19 +- .../Abp/Studio/Package/PackageDependency.cs | 37 ++- .../Volo/Abp/Studio/Package/PackageTypes.cs | 287 +++++++++--------- .../Volo/Abp/Studio/Package/ReferenceType.cs | 13 +- .../Solution/DotnetSlnFileModifierService.cs | 171 ++++++----- .../Solution/IDotnetSlnFileModifierService.cs | 9 +- .../Solution/ISolutionFileModuleAdder.cs | 9 +- .../Solution/SolutionFileModuleAdder.cs | 51 ++-- .../Volo/Abp/Studio/Xml/XmlFileManagerBase.cs | 63 ++-- .../Abp/Studio/AbpStudioDomainSharedModule.cs | 13 +- .../Volo/Abp/Studio/AbpStudioErrorCodes.cs | 59 ++-- .../Volo/Abp/Studio/Modules/ModuleConsts.cs | 27 +- .../Package/PackageReferenceCompatibility.cs | 21 +- ...StudioModuleInstallerAbstractionsModule.cs | 13 +- .../Abp/Studio/Analyzing/AnalyzingOptions.cs | 75 +++-- .../EfCoreConfigurationMethodDeclaration.cs | 21 +- .../IModuleInstallingPipelineBuilder.cs | 9 +- .../ModuleInstallingContext.cs | 113 ++++--- .../ModuleInstallingPipeline.cs | 69 +++-- .../ModuleInstallingPipelineStep.cs | 9 +- .../IModuleInstallingOptionProvider.cs | 9 +- .../Options/ModuleInstallingOption.cs | 37 ++- .../Options/ModuleInstallingOptionType.cs | 17 +- .../Volo/Abp/Studio/Package/PackageConsts.cs | 11 +- .../Volo/Abp/Studio/Package/PackageHelper.cs | 17 +- .../Volo/Abp/Studio/Package/PackageInfo.cs | 41 ++- .../Studio/Package/PackageInfoWithAnalyze.cs | 35 ++- .../Studio/AbpStudioModuleInstallerModule.cs | 17 +- .../ModuleInstallingPipelineBuilderBase.cs | 35 ++- .../Steps/AddEfCoreConfigurationMethodStep.cs | 41 ++- .../Steps/AddToSolutionFileStep.cs | 13 +- .../Steps/PackageReferencingStep.cs | 131 ++++---- .../Steps/SourceCodeDownloadStep.cs | 41 ++- 62 files changed, 1382 insertions(+), 1444 deletions(-) diff --git a/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/AbpStudioAnalyzingAbstractionsModule.cs b/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/AbpStudioAnalyzingAbstractionsModule.cs index 6935ae3755..a8d5ea5918 100644 --- a/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/AbpStudioAnalyzingAbstractionsModule.cs +++ b/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/AbpStudioAnalyzingAbstractionsModule.cs @@ -1,9 +1,8 @@ using Volo.Abp.Modularity; -namespace Volo.Abp.Studio.Analyzing +namespace Volo.Abp.Studio.Analyzing; + +public class AbpStudioAnalyzingAbstractionsModule : AbpModule { - public class AbpStudioAnalyzingAbstractionsModule : AbpModule - { - - } -} \ No newline at end of file + +} diff --git a/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/Application/ApplicationServiceModel.cs b/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/Application/ApplicationServiceModel.cs index 3618b58711..469f6d4e89 100644 --- a/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/Application/ApplicationServiceModel.cs +++ b/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/Application/ApplicationServiceModel.cs @@ -1,21 +1,20 @@ using System.Collections.Generic; using JetBrains.Annotations; -namespace Volo.Abp.Studio.Analyzing.Models.Application +namespace Volo.Abp.Studio.Analyzing.Models.Application; + +[PackageContentItemName(ContentTypeName)] +public class ApplicationServiceModel : PackageContentItemModel { - [PackageContentItemName(ContentTypeName)] - public class ApplicationServiceModel : PackageContentItemModel + public const string ContentTypeName = "applicationService"; + + public string Namespace { get; set; } + + public string Summary { get; set; } + + public List ImplementingInterfaces { get; set; } + + public ApplicationServiceModel([NotNull] string name) : base(name) { - public const string ContentTypeName = "applicationService"; - - public string Namespace { get; set; } - - public string Summary { get; set; } - - public List ImplementingInterfaces { get; set; } - - public ApplicationServiceModel([NotNull] string name) : base(name) - { - } } -} \ No newline at end of file +} diff --git a/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/Authorization/PermissionModel.cs b/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/Authorization/PermissionModel.cs index a386f5c4d5..c711879e48 100644 --- a/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/Authorization/PermissionModel.cs +++ b/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/Authorization/PermissionModel.cs @@ -1,24 +1,23 @@ using JetBrains.Annotations; -namespace Volo.Abp.Studio.Analyzing.Models.Authorization +namespace Volo.Abp.Studio.Analyzing.Models.Authorization; + +[PackageContentItemName(ContentTypeName)] +public class PermissionModel : PackageContentItemModel { - [PackageContentItemName(ContentTypeName)] - public class PermissionModel : PackageContentItemModel - { - public const string ContentTypeName = "permission"; + public const string ContentTypeName = "permission"; + + public string DisplayName { get; } - public string DisplayName { get; } - - public bool IsEnabled { get; } - - public PermissionModel( - [NotNull] string name, - string displayName, - bool isEnabled) - : base(name) - { - DisplayName = displayName; - IsEnabled = isEnabled; - } + public bool IsEnabled { get; } + + public PermissionModel( + [NotNull] string name, + string displayName, + bool isEnabled) + : base(name) + { + DisplayName = displayName; + IsEnabled = isEnabled; } -} \ No newline at end of file +} diff --git a/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/Database/DatabaseCollectionModel.cs b/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/Database/DatabaseCollectionModel.cs index 5e78f54f87..b089f8c2c7 100644 --- a/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/Database/DatabaseCollectionModel.cs +++ b/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/Database/DatabaseCollectionModel.cs @@ -1,17 +1,16 @@ using JetBrains.Annotations; -namespace Volo.Abp.Studio.Analyzing.Models.Database +namespace Volo.Abp.Studio.Analyzing.Models.Database; + +[PackageContentItemName(ContentTypeName)] +public class DatabaseCollectionModel : PackageContentItemModel { - [PackageContentItemName(ContentTypeName)] - public class DatabaseCollectionModel : PackageContentItemModel - { - public const string ContentTypeName = "databaseCollection"; - - public string EntityFullName { get; private set; } + public const string ContentTypeName = "databaseCollection"; - public DatabaseCollectionModel([NotNull] string name, string entityFullName) : base(name) - { - EntityFullName = Check.NotNullOrWhiteSpace(entityFullName, nameof(entityFullName)); - } + public string EntityFullName { get; private set; } + + public DatabaseCollectionModel([NotNull] string name, string entityFullName) : base(name) + { + EntityFullName = Check.NotNullOrWhiteSpace(entityFullName, nameof(entityFullName)); } -} \ No newline at end of file +} diff --git a/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/Database/DatabaseTableModel.cs b/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/Database/DatabaseTableModel.cs index a2af1acdbb..b210fefa78 100644 --- a/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/Database/DatabaseTableModel.cs +++ b/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/Database/DatabaseTableModel.cs @@ -1,17 +1,16 @@ using JetBrains.Annotations; -namespace Volo.Abp.Studio.Analyzing.Models.Database +namespace Volo.Abp.Studio.Analyzing.Models.Database; + +[PackageContentItemName(ContentTypeName)] +public class DatabaseTableModel : PackageContentItemModel { - [PackageContentItemName(ContentTypeName)] - public class DatabaseTableModel : PackageContentItemModel - { - public const string ContentTypeName = "databaseTable"; - - public string EntityFullName { get; private set; } + public const string ContentTypeName = "databaseTable"; - public DatabaseTableModel([NotNull] string name, string entityFullName) : base(name) - { - EntityFullName = Check.NotNullOrWhiteSpace(entityFullName, nameof(entityFullName)); - } + public string EntityFullName { get; private set; } + + public DatabaseTableModel([NotNull] string name, string entityFullName) : base(name) + { + EntityFullName = Check.NotNullOrWhiteSpace(entityFullName, nameof(entityFullName)); } -} \ No newline at end of file +} diff --git a/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/Database/EfCoreDbContextModel.cs b/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/Database/EfCoreDbContextModel.cs index 292b58e65f..d780e8363b 100644 --- a/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/Database/EfCoreDbContextModel.cs +++ b/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/Database/EfCoreDbContextModel.cs @@ -1,25 +1,24 @@ using System.Collections.Generic; using JetBrains.Annotations; -namespace Volo.Abp.Studio.Analyzing.Models.Database +namespace Volo.Abp.Studio.Analyzing.Models.Database; + +[PackageContentItemName(ContentTypeName)] +public class EfCoreDbContextModel : PackageContentItemModel, IDbContextModel { - [PackageContentItemName(ContentTypeName)] - public class EfCoreDbContextModel : PackageContentItemModel, IDbContextModel - { - public const string ContentTypeName = "efCoreDbContext"; + public const string ContentTypeName = "efCoreDbContext"; - public string Namespace { get; private set; } + public string Namespace { get; private set; } - public string ConnectionStringName { get; set; } + public string ConnectionStringName { get; set; } - public List DatabaseTables { get; set; } + public List DatabaseTables { get; set; } - public EfCoreDbContextModel( - [NotNull] string name, - [NotNull] string @namespace - ) : base(name) - { - Namespace = Check.NotNullOrWhiteSpace(@namespace, nameof(@namespace)); - } + public EfCoreDbContextModel( + [NotNull] string name, + [NotNull] string @namespace + ) : base(name) + { + Namespace = Check.NotNullOrWhiteSpace(@namespace, nameof(@namespace)); } } diff --git a/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/Database/IDbContextModel.cs b/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/Database/IDbContextModel.cs index 08c00162f5..e2daad00aa 100644 --- a/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/Database/IDbContextModel.cs +++ b/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/Database/IDbContextModel.cs @@ -1,7 +1,6 @@ -namespace Volo.Abp.Studio.Analyzing.Models.Database +namespace Volo.Abp.Studio.Analyzing.Models.Database; + +public interface IDbContextModel { - public interface IDbContextModel - { - string ConnectionStringName { get; set; } - } -} \ No newline at end of file + string ConnectionStringName { get; set; } +} diff --git a/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/Database/MongoDbContextModel.cs b/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/Database/MongoDbContextModel.cs index 6fa6c80f79..66af6ce1ab 100644 --- a/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/Database/MongoDbContextModel.cs +++ b/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/Database/MongoDbContextModel.cs @@ -1,25 +1,24 @@ using System.Collections.Generic; using JetBrains.Annotations; -namespace Volo.Abp.Studio.Analyzing.Models.Database +namespace Volo.Abp.Studio.Analyzing.Models.Database; + +[PackageContentItemName(ContentTypeName)] +public class MongoDbContextModel : PackageContentItemModel, IDbContextModel { - [PackageContentItemName(ContentTypeName)] - public class MongoDbContextModel : PackageContentItemModel, IDbContextModel - { - public const string ContentTypeName = "mongoDbContext"; + public const string ContentTypeName = "mongoDbContext"; - public string Namespace { get; private set; } + public string Namespace { get; private set; } - public string ConnectionStringName { get; set; } + public string ConnectionStringName { get; set; } - public List DatabaseCollections { get; set; } + public List DatabaseCollections { get; set; } - public MongoDbContextModel( - [NotNull] string name, - [NotNull] string @namespace - ) : base(name) - { - Namespace = Check.NotNullOrWhiteSpace(@namespace, nameof(@namespace)); - } + public MongoDbContextModel( + [NotNull] string name, + [NotNull] string @namespace + ) : base(name) + { + Namespace = Check.NotNullOrWhiteSpace(@namespace, nameof(@namespace)); } } diff --git a/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/Domain/AggregateRootModel.cs b/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/Domain/AggregateRootModel.cs index f31e07d8b1..2778d9f6b0 100644 --- a/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/Domain/AggregateRootModel.cs +++ b/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/Domain/AggregateRootModel.cs @@ -1,12 +1,11 @@ -namespace Volo.Abp.Studio.Analyzing.Models.Domain +namespace Volo.Abp.Studio.Analyzing.Models.Domain; + +[PackageContentItemName(ContentTypeName)] +public class AggregateRootModel : EntityModel { - [PackageContentItemName(ContentTypeName)] - public class AggregateRootModel : EntityModel - { - public new const string ContentTypeName = "aggregateRoot"; + public new const string ContentTypeName = "aggregateRoot"; - public AggregateRootModel(string name) : base(name) - { - } + public AggregateRootModel(string name) : base(name) + { } -} \ No newline at end of file +} diff --git a/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/Domain/DomainServiceModel.cs b/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/Domain/DomainServiceModel.cs index 6b4a648bcd..a06935c145 100644 --- a/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/Domain/DomainServiceModel.cs +++ b/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/Domain/DomainServiceModel.cs @@ -1,18 +1,17 @@ using JetBrains.Annotations; -namespace Volo.Abp.Studio.Analyzing.Models.Domain +namespace Volo.Abp.Studio.Analyzing.Models.Domain; + +[PackageContentItemName(ContentTypeName)] +public class DomainServiceModel : PackageContentItemModel { - [PackageContentItemName(ContentTypeName)] - public class DomainServiceModel : PackageContentItemModel - { - public const string ContentTypeName = "domainService"; - - public string Namespace { get; set; } - - public string Summary { get; set; } + public const string ContentTypeName = "domainService"; + + public string Namespace { get; set; } - public DomainServiceModel([NotNull] string name) : base(name) - { - } + public string Summary { get; set; } + + public DomainServiceModel([NotNull] string name) : base(name) + { } -} \ No newline at end of file +} diff --git a/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/Domain/EntityModel.cs b/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/Domain/EntityModel.cs index 0b3e5a5708..4df5392d61 100644 --- a/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/Domain/EntityModel.cs +++ b/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/Domain/EntityModel.cs @@ -1,25 +1,24 @@ using System.Collections.Generic; -namespace Volo.Abp.Studio.Analyzing.Models.Domain +namespace Volo.Abp.Studio.Analyzing.Models.Domain; + +[PackageContentItemName(ContentTypeName)] +public class EntityModel : PackageContentItemModel { - [PackageContentItemName(ContentTypeName)] - public class EntityModel : PackageContentItemModel - { - public const string ContentTypeName = "entity"; - - public string Namespace { get; set; } - - public string PrimaryKeyType { get; set; } - - public string Summary { get; set; } - - public List CollectionProperties { get; set; } - public List NavigationProperties { get; set; } + public const string ContentTypeName = "entity"; + + public string Namespace { get; set; } + + public string PrimaryKeyType { get; set; } - public EntityModel(string name) : base(name) - { - CollectionProperties = new List(); - NavigationProperties = new List(); - } + public string Summary { get; set; } + + public List CollectionProperties { get; set; } + public List NavigationProperties { get; set; } + + public EntityModel(string name) : base(name) + { + CollectionProperties = new List(); + NavigationProperties = new List(); } -} \ No newline at end of file +} diff --git a/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/Domain/RepositoryInterfaceModel.cs b/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/Domain/RepositoryInterfaceModel.cs index a44613b335..8eac804536 100644 --- a/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/Domain/RepositoryInterfaceModel.cs +++ b/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/Domain/RepositoryInterfaceModel.cs @@ -1,20 +1,19 @@ using JetBrains.Annotations; -namespace Volo.Abp.Studio.Analyzing.Models.Domain +namespace Volo.Abp.Studio.Analyzing.Models.Domain; + +[PackageContentItemName(ContentTypeName)] +public class RepositoryInterfaceModel : PackageContentItemModel { - [PackageContentItemName(ContentTypeName)] - public class RepositoryInterfaceModel : PackageContentItemModel - { - public const string ContentTypeName = "repositoryInterface"; + public const string ContentTypeName = "repositoryInterface"; + + public string Namespace { get; set; } - public string Namespace { get; set; } - - public string Summary { get; set; } - - public EntityModel EntityModel { get; set; } - - public RepositoryInterfaceModel([NotNull] string name) : base(name) - { - } + public string Summary { get; set; } + + public EntityModel EntityModel { get; set; } + + public RepositoryInterfaceModel([NotNull] string name) : base(name) + { } -} \ No newline at end of file +} diff --git a/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/Feature/FeatureModel.cs b/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/Feature/FeatureModel.cs index ee2b7ef48b..70e42d4d58 100644 --- a/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/Feature/FeatureModel.cs +++ b/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/Feature/FeatureModel.cs @@ -1,40 +1,39 @@ using JetBrains.Annotations; -namespace Volo.Abp.Studio.Analyzing.Models.Feature +namespace Volo.Abp.Studio.Analyzing.Models.Feature; + +[PackageContentItemName(ContentTypeName)] +public class FeatureModel : PackageContentItemModel { - [PackageContentItemName(ContentTypeName)] - public class FeatureModel : PackageContentItemModel + public const string ContentTypeName = "feature"; + + public string ValueType { get; } + + public string DefaultValue { get; } + + public string DisplayName { get; } + + public string Description { get; } + + public bool IsAvailableToHost { get; } + + public bool IsVisibleToClients { get; } + + public FeatureModel( + [NotNull] string name, + [NotNull] string valueType, + string defaultValue, + string displayName, + string description, + bool isAvailableToHost, + bool isVisibleToClients + ) : base(name) { - public const string ContentTypeName = "feature"; - - public string ValueType { get; } - - public string DefaultValue { get; } - - public string DisplayName { get; } - - public string Description { get; } - - public bool IsAvailableToHost { get; } - - public bool IsVisibleToClients { get; } - - public FeatureModel( - [NotNull] string name, - [NotNull] string valueType, - string defaultValue, - string displayName, - string description, - bool isAvailableToHost, - bool isVisibleToClients - ) : base(name) - { - ValueType = valueType; - DefaultValue = defaultValue; - DisplayName = displayName; - Description = description; - IsAvailableToHost = isAvailableToHost; - IsVisibleToClients = isVisibleToClients; - } + ValueType = valueType; + DefaultValue = defaultValue; + DisplayName = displayName; + Description = description; + IsAvailableToHost = isAvailableToHost; + IsVisibleToClients = isVisibleToClients; } -} \ No newline at end of file +} diff --git a/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/Module/AbpModuleModel.cs b/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/Module/AbpModuleModel.cs index 9094d7d0b8..4bdfffb5d4 100644 --- a/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/Module/AbpModuleModel.cs +++ b/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/Module/AbpModuleModel.cs @@ -1,16 +1,15 @@ using JetBrains.Annotations; -namespace Volo.Abp.Studio.Analyzing.Models.Module +namespace Volo.Abp.Studio.Analyzing.Models.Module; + +[PackageContentItemName(ContentTypeName)] +public class AbpModuleModel : PackageContentItemModel { - [PackageContentItemName(ContentTypeName)] - public class AbpModuleModel : PackageContentItemModel + public const string ContentTypeName = "abpModule"; + + public string Namespace { get; set; } + + public AbpModuleModel([NotNull] string name) : base(name) { - public const string ContentTypeName = "abpModule"; - - public string Namespace { get; set; } - - public AbpModuleModel([NotNull] string name) : base(name) - { - } } -} \ No newline at end of file +} diff --git a/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/PackageContentItemModel.cs b/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/PackageContentItemModel.cs index 749ecd8fa9..5c57e7bf6f 100644 --- a/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/PackageContentItemModel.cs +++ b/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/PackageContentItemModel.cs @@ -1,16 +1,15 @@ using JetBrains.Annotations; -namespace Volo.Abp.Studio.Analyzing.Models +namespace Volo.Abp.Studio.Analyzing.Models; + +public abstract class PackageContentItemModel { - public abstract class PackageContentItemModel + public string ContentType { get; } + public string Name { get; } + + public PackageContentItemModel([NotNull] string name) { - public string ContentType { get; } - public string Name { get; } - - public PackageContentItemModel([NotNull] string name) - { - Name = Check.NotNullOrWhiteSpace(name, nameof(name)); - ContentType = PackageContentItemNameAttribute.GetName(GetType()); - } + Name = Check.NotNullOrWhiteSpace(name, nameof(name)); + ContentType = PackageContentItemNameAttribute.GetName(GetType()); } -} \ No newline at end of file +} diff --git a/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/PackageContentItemNameAttribute.cs b/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/PackageContentItemNameAttribute.cs index 9a04fa274b..9427c813ae 100644 --- a/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/PackageContentItemNameAttribute.cs +++ b/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/PackageContentItemNameAttribute.cs @@ -1,26 +1,25 @@ using System; using Volo.Abp.Reflection; -namespace Volo.Abp.Studio.Analyzing.Models +namespace Volo.Abp.Studio.Analyzing.Models; + +public class PackageContentItemNameAttribute : Attribute { - public class PackageContentItemNameAttribute : Attribute + public string Name { get; } + + public PackageContentItemNameAttribute(string name) { - public string Name { get; } + Name = name; + } - public PackageContentItemNameAttribute(string name) + public static string GetName(Type type) + { + var attribute = ReflectionHelper.GetSingleAttributeOrDefault(type); + if (attribute == null) { - Name = name; + throw new ApplicationException($"Given type {type.FullName} must have an {nameof(PackageContentItemNameAttribute)}, but not defined!"); } - - public static string GetName(Type type) - { - var attribute = ReflectionHelper.GetSingleAttributeOrDefault(type); - if (attribute == null) - { - throw new ApplicationException($"Given type {type.FullName} must have an {nameof(PackageContentItemNameAttribute)}, but not defined!"); - } - return attribute.Name; - } + return attribute.Name; } -} \ No newline at end of file +} diff --git a/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/PackageContentList.cs b/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/PackageContentList.cs index ab519cb264..c1805e4112 100644 --- a/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/PackageContentList.cs +++ b/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/PackageContentList.cs @@ -1,9 +1,8 @@ using System.Collections.Generic; -namespace Volo.Abp.Studio.Analyzing.Models +namespace Volo.Abp.Studio.Analyzing.Models; + +public class PackageContentList : List { - public class PackageContentList : List - { - - } -} \ No newline at end of file + +} diff --git a/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/PackageModel.cs b/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/PackageModel.cs index 74bcaac9cf..d5a991c76d 100644 --- a/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/PackageModel.cs +++ b/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/PackageModel.cs @@ -1,20 +1,19 @@ using JetBrains.Annotations; -namespace Volo.Abp.Studio.Analyzing.Models +namespace Volo.Abp.Studio.Analyzing.Models; + +public class PackageModel { - public class PackageModel - { - public string Name { get; } + public string Name { get; } - public string Hash { get; } - - public PackageContentList Contents { get; } + public string Hash { get; } - public PackageModel([NotNull] string name, [NotNull] string hash) - { - Name = Check.NotNullOrWhiteSpace(name, nameof(name)); - Contents = new PackageContentList(); - Hash = hash; - } + public PackageContentList Contents { get; } + + public PackageModel([NotNull] string name, [NotNull] string hash) + { + Name = Check.NotNullOrWhiteSpace(name, nameof(name)); + Contents = new PackageContentList(); + Hash = hash; } -} \ No newline at end of file +} diff --git a/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/Setting/SettingModel.cs b/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/Setting/SettingModel.cs index 910f81099f..06c9548bbb 100644 --- a/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/Setting/SettingModel.cs +++ b/studio/src/Volo.Abp.Studio.Analyzing.Abstractions/Volo/Abp/Studio/Analyzing/Models/Setting/SettingModel.cs @@ -1,26 +1,25 @@ using JetBrains.Annotations; -namespace Volo.Abp.Studio.Analyzing.Models.Setting +namespace Volo.Abp.Studio.Analyzing.Models.Setting; + +[PackageContentItemName(ContentTypeName)] +public class SettingModel : PackageContentItemModel { - [PackageContentItemName(ContentTypeName)] - public class SettingModel : PackageContentItemModel - { - public const string ContentTypeName = "setting"; + public const string ContentTypeName = "setting"; - public string DefaultValue { get; set; } + public string DefaultValue { get; set; } - public string DisplayName { get; set; } + public string DisplayName { get; set; } - public string Description { get; set; } + public string Description { get; set; } - public bool IsVisibleToClient { get; set; } + public bool IsVisibleToClient { get; set; } - public bool IsInherited { get; set; } + public bool IsInherited { get; set; } - public bool IsEncrypted { get; set; } - - public SettingModel([NotNull] string name) : base(name) - { - } + public bool IsEncrypted { get; set; } + + public SettingModel([NotNull] string name) : base(name) + { } -} \ No newline at end of file +} diff --git a/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/AbpStudioDomainCommonServicesModule.cs b/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/AbpStudioDomainCommonServicesModule.cs index 84b2dba930..54d2ea09f2 100644 --- a/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/AbpStudioDomainCommonServicesModule.cs +++ b/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/AbpStudioDomainCommonServicesModule.cs @@ -2,16 +2,15 @@ using Microsoft.Extensions.DependencyInjection; using Volo.Abp.Modularity; -namespace Volo.Abp.Studio +namespace Volo.Abp.Studio; + +[DependsOn( + typeof(AbpStudioDomainSharedModule) + )] +public class AbpStudioDomainCommonServicesModule : AbpModule { - [DependsOn( - typeof(AbpStudioDomainSharedModule) - )] - public class AbpStudioDomainCommonServicesModule : AbpModule + public override void ConfigureServices(ServiceConfigurationContext context) { - public override void ConfigureServices(ServiceConfigurationContext context) - { - context.Services.AddSingleton(new FileSystem()); - } + context.Services.AddSingleton(new FileSystem()); } } diff --git a/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/AbpStudioException.cs b/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/AbpStudioException.cs index 418e6067b9..7e851f38cf 100644 --- a/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/AbpStudioException.cs +++ b/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/AbpStudioException.cs @@ -2,27 +2,26 @@ using System.Runtime.Serialization; using Microsoft.Extensions.Logging; -namespace Volo.Abp.Studio +namespace Volo.Abp.Studio; + +public class AbpStudioException : BusinessException { - public class AbpStudioException : BusinessException + public AbpStudioException( + string code = null, + string message = null, + string details = null, + Exception innerException = null, + LogLevel logLevel = LogLevel.Warning) + : base(code, message, details, innerException, logLevel) { - public AbpStudioException( - string code = null, - string message = null, - string details = null, - Exception innerException = null, - LogLevel logLevel = LogLevel.Warning) - : base(code, message, details, innerException, logLevel) - { - Code = code; - Details = details; - LogLevel = logLevel; - } + Code = code; + Details = details; + LogLevel = logLevel; + } - public AbpStudioException(SerializationInfo serializationInfo, StreamingContext context) - : base(serializationInfo, context) - { + public AbpStudioException(SerializationInfo serializationInfo, StreamingContext context) + : base(serializationInfo, context) + { - } } -} \ No newline at end of file +} diff --git a/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Helpers/PathHelper.cs b/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Helpers/PathHelper.cs index b741e37cf8..2fd608c0b1 100644 --- a/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Helpers/PathHelper.cs +++ b/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Helpers/PathHelper.cs @@ -2,36 +2,35 @@ using System.Runtime.InteropServices; using JetBrains.Annotations; -namespace Volo.Abp.Studio.Helpers +namespace Volo.Abp.Studio.Helpers; + +public static class PathHelper { - public static class PathHelper + public static string GetRelativePath([NotNull] string basePath, [NotNull] string targetPath) { - public static string GetRelativePath([NotNull] string basePath, [NotNull] string targetPath) - { - Check.NotNull(basePath, nameof(basePath)); - Check.NotNull(targetPath, nameof(targetPath)); + Check.NotNull(basePath, nameof(basePath)); + Check.NotNull(targetPath, nameof(targetPath)); - return new Uri(basePath).MakeRelativeUri(new Uri(targetPath)).ToString(); - } + return new Uri(basePath).MakeRelativeUri(new Uri(targetPath)).ToString(); + } - public static string EnsureForwardSlash(string path) + public static string EnsureForwardSlash(string path) + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - return path.Replace("\\", "/"); - } - - return path; + return path.Replace("\\", "/"); } - public static string Normalize(string path) - { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - return path.Replace("/", "\\"); - } + return path; + } - return path; + public static string Normalize(string path) + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + return path.Replace("/", "\\"); } + + return path; } } diff --git a/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Modifying/AbpModuleFileManager.cs b/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Modifying/AbpModuleFileManager.cs index ccb90ad2e4..84b3d944cb 100644 --- a/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Modifying/AbpModuleFileManager.cs +++ b/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Modifying/AbpModuleFileManager.cs @@ -5,73 +5,72 @@ using System.Linq; using System.Threading.Tasks; using Volo.Abp.DependencyInjection; -namespace Volo.Abp.Studio.Packages.Modifying +namespace Volo.Abp.Studio.Packages.Modifying; + +public class AbpModuleFileManager : IAbpModuleFileManager, ITransientDependency { - public class AbpModuleFileManager : IAbpModuleFileManager, ITransientDependency + public IFileSystem FileSystem { get; } + + public AbpModuleFileManager(IFileSystem fileSystem) + { + FileSystem = fileSystem; + } + + public async Task AddDependency(string filePath, string moduleToAdd) { - public IFileSystem FileSystem { get; } + var fileContent = await FileSystem.File.ReadAllTextAsync(filePath); + var moduleName = moduleToAdd.Split(".").Last(); + var moduleNamespace = moduleToAdd.RemovePostFix("." + moduleName); + var usingStatement = $"using {moduleNamespace};"; + var dependsOnStart = $"DependsOn("; - public AbpModuleFileManager(IFileSystem fileSystem) + if (fileContent.Contains($"typeof({moduleName})")) { - FileSystem = fileSystem; + // module already added + return; } - public async Task AddDependency(string filePath, string moduleToAdd) + if (!fileContent.NormalizeLineEndings().SplitToLines().Any(l => l.Trim().StartsWith("namespace ") && l.Contains(moduleNamespace)) && + !fileContent.Contains(usingStatement) + ) { - var fileContent = await FileSystem.File.ReadAllTextAsync(filePath); - var moduleName = moduleToAdd.Split(".").Last(); - var moduleNamespace = moduleToAdd.RemovePostFix("." + moduleName); - var usingStatement = $"using {moduleNamespace};"; - var dependsOnStart = $"DependsOn("; - - if (fileContent.Contains($"typeof({moduleName})")) - { - // module already added - return; - } - - if (!fileContent.NormalizeLineEndings().SplitToLines().Any(l=> l.Trim().StartsWith("namespace ") && l.Contains(moduleNamespace)) && - !fileContent.Contains(usingStatement) - ) - { - fileContent = usingStatement + Environment.NewLine + fileContent; - } - - if (!fileContent.Contains(dependsOnStart)) - { - var fileLines = fileContent.NormalizeLineEndings().SplitToLines().ToList(); - fileLines.InsertBefore(l=> l.Contains("public") && l.Contains("class"), $" [DependsOn(typeof({moduleName}))]"); - fileContent = fileLines.JoinAsString(Environment.NewLine); - } - else - { - var fileLines = fileContent.NormalizeLineEndings().SplitToLines().ToList(); - var dependsOnStartLine = fileLines.First(l=> l.Contains(dependsOnStart)); - var dependsOnStartLineModified = dependsOnStartLine.Replace(dependsOnStart, - dependsOnStart + Environment.NewLine + - $" typeof({moduleName})," - ); - fileContent = fileContent.Replace(dependsOnStartLine, dependsOnStartLineModified); - } - - FileSystem.File.WriteAllTextAsync(filePath, fileContent); + fileContent = usingStatement + Environment.NewLine + fileContent; } - public async Task ExtractModuleNameWithNamespace(string filePath) + if (!fileContent.Contains(dependsOnStart)) { - var fileContent = await FileSystem.File.ReadAllTextAsync(filePath); + var fileLines = fileContent.NormalizeLineEndings().SplitToLines().ToList(); + fileLines.InsertBefore(l => l.Contains("public") && l.Contains("class"), $" [DependsOn(typeof({moduleName}))]"); + fileContent = fileLines.JoinAsString(Environment.NewLine); + } + else + { + var fileLines = fileContent.NormalizeLineEndings().SplitToLines().ToList(); + var dependsOnStartLine = fileLines.First(l => l.Contains(dependsOnStart)); + var dependsOnStartLineModified = dependsOnStartLine.Replace(dependsOnStart, + dependsOnStart + Environment.NewLine + + $" typeof({moduleName})," + ); + fileContent = fileContent.Replace(dependsOnStartLine, dependsOnStartLineModified); + } + + FileSystem.File.WriteAllTextAsync(filePath, fileContent); + } + + public async Task ExtractModuleNameWithNamespace(string filePath) + { + var fileContent = await FileSystem.File.ReadAllTextAsync(filePath); - var fileLines = fileContent.NormalizeLineEndings().SplitToLines(); + var fileLines = fileContent.NormalizeLineEndings().SplitToLines(); - var lineOfClassName = fileLines.First(l=> l.Contains("public") && l.Contains("class")); + var lineOfClassName = fileLines.First(l => l.Contains("public") && l.Contains("class")); - var moduleName = lineOfClassName.Split(":")[0].Trim().Split(" ").Last(); + var moduleName = lineOfClassName.Split(":")[0].Trim().Split(" ").Last(); - var lineOfNamespace = fileLines.First(l=> l.Trim().StartsWith("namespace")); + var lineOfNamespace = fileLines.First(l => l.Trim().StartsWith("namespace")); - var moduleNamespace = lineOfNamespace.Split(" ").Skip(1).First(); + var moduleNamespace = lineOfNamespace.Split(" ").Skip(1).First(); - return moduleNamespace + "." + moduleName; - } + return moduleNamespace + "." + moduleName; } } diff --git a/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Modifying/CsprojFileManager.cs b/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Modifying/CsprojFileManager.cs index e1bf7bccd2..fb7ace820e 100644 --- a/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Modifying/CsprojFileManager.cs +++ b/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Modifying/CsprojFileManager.cs @@ -8,197 +8,196 @@ using Volo.Abp.Studio.Helpers; using Volo.Abp.Studio.Package; using Volo.Abp.Studio.Xml; -namespace Volo.Abp.Studio.Packages.Modifying +namespace Volo.Abp.Studio.Packages.Modifying; + +public class CsprojFileManager : XmlFileManagerBase, ICsprojFileManager, ITransientDependency { - public class CsprojFileManager: XmlFileManagerBase, ICsprojFileManager, ITransientDependency + public async Task AddProjectReferenceAsync(string filePath, string projectToReference) { - public async Task AddProjectReferenceAsync(string filePath, string projectToReference) + var document = await GetXmlDocumentAsync(filePath); + + /*if (document.SelectNodes($"/Project/ItemGroup/ProjectReference[ends-with(@Include, '{Path.GetFileName(projectToReference)}')]").Count > 0) { - var document = await GetXmlDocumentAsync(filePath); + return; + }*/ - /*if (document.SelectNodes($"/Project/ItemGroup/ProjectReference[ends-with(@Include, '{Path.GetFileName(projectToReference)}')]").Count > 0) - { - return; - }*/ + var packageReferenceToSameProject = + document.SelectNodes( + $"/Project/ItemGroup/PackageReference[starts-with(@Include, '{Path.GetFileName(projectToReference).RemovePostFix(".csproj")}')]" + ); - var packageReferenceToSameProject = - document.SelectNodes( - $"/Project/ItemGroup/PackageReference[starts-with(@Include, '{Path.GetFileName(projectToReference).RemovePostFix(".csproj")}')]" - ); + if (packageReferenceToSameProject.Count > 0) + { + packageReferenceToSameProject[0].ParentNode.RemoveChild(packageReferenceToSameProject[0]); + } - if (packageReferenceToSameProject.Count > 0) - { - packageReferenceToSameProject[0].ParentNode.RemoveChild(packageReferenceToSameProject[0]); - } + var relativePath = PathHelper.GetRelativePath(filePath, projectToReference); - var relativePath = PathHelper.GetRelativePath(filePath, projectToReference); + var itemGroupNode = GetOrCreateItemGroupNode(document); - var itemGroupNode = GetOrCreateItemGroupNode(document); + var newNode = document.CreateElement("ProjectReference"); - var newNode = document.CreateElement("ProjectReference"); + var includeAttr = document.CreateAttribute("Include"); + includeAttr.Value = relativePath; + newNode.Attributes.Append(includeAttr); - var includeAttr = document.CreateAttribute("Include"); - includeAttr.Value = relativePath; - newNode.Attributes.Append(includeAttr); + itemGroupNode.AppendChild(newNode); - itemGroupNode.AppendChild(newNode); + await SaveXmlDocumentAsync(filePath, document); + } - await SaveXmlDocumentAsync(filePath, document); - } + public async Task AddPackageReferenceAsync(string filePath, string packageName, string version) + { + var document = await GetXmlDocumentAsync(filePath); - public async Task AddPackageReferenceAsync(string filePath, string packageName, string version) + if (document.SelectNodes($"/Project/ItemGroup/PackageReference[starts-with(@Include, '{packageName}')]").Count > 0) { - var document = await GetXmlDocumentAsync(filePath); - - if (document.SelectNodes($"/Project/ItemGroup/PackageReference[starts-with(@Include, '{packageName}')]").Count > 0) - { - // Package reference is already added. - return; - } + // Package reference is already added. + return; + } - var itemGroupNode = GetOrCreateItemGroupNode(document); + var itemGroupNode = GetOrCreateItemGroupNode(document); - var newNode = document.CreateElement("PackageReference"); + var newNode = document.CreateElement("PackageReference"); - var includeAttr = document.CreateAttribute("Include"); - includeAttr.Value = packageName; - newNode.Attributes.Append(includeAttr); + var includeAttr = document.CreateAttribute("Include"); + includeAttr.Value = packageName; + newNode.Attributes.Append(includeAttr); - var versionAttr = document.CreateAttribute("Version"); - versionAttr.Value = version; - newNode.Attributes.Append(versionAttr); + var versionAttr = document.CreateAttribute("Version"); + versionAttr.Value = version; + newNode.Attributes.Append(versionAttr); - itemGroupNode.AppendChild(newNode); - itemGroupNode.AppendChild(document.CreateWhitespace(Environment.NewLine + " ")); + itemGroupNode.AppendChild(newNode); + itemGroupNode.AppendChild(document.CreateWhitespace(Environment.NewLine + " ")); - await SaveXmlDocumentAsync(filePath, document); - } + await SaveXmlDocumentAsync(filePath, document); + } - public async Task ConvertPackageReferenceToProjectReferenceAsync(string filePath, string projectToReference) - { - var document = await GetXmlDocumentAsync(filePath); + public async Task ConvertPackageReferenceToProjectReferenceAsync(string filePath, string projectToReference) + { + var document = await GetXmlDocumentAsync(filePath); - var packageName = Path.GetFileName(projectToReference).RemovePostFix(".csproj"); + var packageName = Path.GetFileName(projectToReference).RemovePostFix(".csproj"); - var matchedNodes = document.SelectNodes($"/Project/ItemGroup/PackageReference[starts-with(@Include, '{packageName}')]"); + var matchedNodes = document.SelectNodes($"/Project/ItemGroup/PackageReference[starts-with(@Include, '{packageName}')]"); - if (matchedNodes.Count == 0) - { - return; - } + if (matchedNodes.Count == 0) + { + return; + } - XmlNode targetNode = null; + XmlNode targetNode = null; - foreach (XmlNode matchedNode in matchedNodes) + foreach (XmlNode matchedNode in matchedNodes) + { + if (matchedNode.Attributes["Include"].Value == packageName) { - if (matchedNode.Attributes["Include"].Value == packageName) - { - targetNode = matchedNode; - break; - } + targetNode = matchedNode; + break; } + } - if (targetNode == null) - { - return; - } + if (targetNode == null) + { + return; + } - var targetNodeParent = targetNode.ParentNode; + var targetNodeParent = targetNode.ParentNode; - targetNodeParent.RemoveChild(targetNode); + targetNodeParent.RemoveChild(targetNode); - var relativePath = PathHelper.GetRelativePath(filePath, projectToReference); + var relativePath = PathHelper.GetRelativePath(filePath, projectToReference); - var newNode = document.CreateElement("ProjectReference"); + var newNode = document.CreateElement("ProjectReference"); - var includeAttr = document.CreateAttribute("Include"); - includeAttr.Value = relativePath; - newNode.Attributes.Append(includeAttr); + var includeAttr = document.CreateAttribute("Include"); + includeAttr.Value = relativePath; + newNode.Attributes.Append(includeAttr); - targetNodeParent.AppendChild(newNode); + targetNodeParent.AppendChild(newNode); - await SaveXmlDocumentAsync(filePath, document); - } + await SaveXmlDocumentAsync(filePath, document); + } - public async Task GetTargetFrameworkAsync(string filePath) - { - var document = await GetXmlDocumentAsync(filePath); + public async Task GetTargetFrameworkAsync(string filePath) + { + var document = await GetXmlDocumentAsync(filePath); - var nodes = document["Project"]?["PropertyGroup"]?.SelectNodes("TargetFramework"); + var nodes = document["Project"]?["PropertyGroup"]?.SelectNodes("TargetFramework"); - if (nodes == null || nodes.Count == 0) - { - return null; - } - - return nodes[0].InnerText.Trim(); + if (nodes == null || nodes.Count == 0) + { + return null; } - public async Task> GetDependencyListAsync(string filePath) - { - var result = new List(); + return nodes[0].InnerText.Trim(); + } - var document = await GetXmlDocumentAsync(filePath); + public async Task> GetDependencyListAsync(string filePath) + { + var result = new List(); - var packageReferenceNodes = document.SelectNodes($"/Project/ItemGroup/PackageReference"); - var projectReferenceNodes = document.SelectNodes($"/Project/ItemGroup/ProjectReference"); + var document = await GetXmlDocumentAsync(filePath); - if (packageReferenceNodes != null && packageReferenceNodes.Count > 0) - { - foreach (XmlNode packageReferenceNode in packageReferenceNodes) - { - result.Add( - new PackageDependency( - packageReferenceNode.Attributes["Include"].Value, - packageReferenceNode.Attributes["Version"].Value - ) - ); - } - } + var packageReferenceNodes = document.SelectNodes($"/Project/ItemGroup/PackageReference"); + var projectReferenceNodes = document.SelectNodes($"/Project/ItemGroup/ProjectReference"); - if (projectReferenceNodes != null && projectReferenceNodes.Count > 0) + if (packageReferenceNodes != null && packageReferenceNodes.Count > 0) + { + foreach (XmlNode packageReferenceNode in packageReferenceNodes) { - foreach (XmlNode projectReferenceNode in projectReferenceNodes) - { - result.Add( - new PackageDependency( - Path.GetFullPath(Path.Combine(Path.GetDirectoryName(filePath), projectReferenceNode.Attributes["Include"].Value)) - ) - ); - } + result.Add( + new PackageDependency( + packageReferenceNode.Attributes["Include"].Value, + packageReferenceNode.Attributes["Version"].Value + ) + ); } - - return result; } - private XmlNode GetOrCreateItemGroupNode(XmlDocument document) + if (projectReferenceNodes != null && projectReferenceNodes.Count > 0) { - var nodes = document["Project"].SelectNodes("ItemGroup"); - - if (nodes == null || nodes.Count < 1) + foreach (XmlNode projectReferenceNode in projectReferenceNodes) { - var newNode = document.CreateElement("ItemGroup"); - document["Project"].AppendChild(newNode); - return newNode; + result.Add( + new PackageDependency( + Path.GetFullPath(Path.Combine(Path.GetDirectoryName(filePath), projectReferenceNode.Attributes["Include"].Value)) + ) + ); } + } + + return result; + } + + private XmlNode GetOrCreateItemGroupNode(XmlDocument document) + { + var nodes = document["Project"].SelectNodes("ItemGroup"); + + if (nodes == null || nodes.Count < 1) + { + var newNode = document.CreateElement("ItemGroup"); + document["Project"].AppendChild(newNode); + return newNode; + } - foreach (XmlNode node in nodes) + foreach (XmlNode node in nodes) + { + if (node.SelectNodes("ProjectReference").Count > 0) { - if (node.SelectNodes("ProjectReference").Count > 0) - { - return node; - } + return node; } + } - foreach (XmlNode node in nodes) + foreach (XmlNode node in nodes) + { + if (node.SelectNodes("PackageReference").Count > 0) { - if (node.SelectNodes("PackageReference").Count > 0) - { - return node; - } + return node; } - - return nodes[0]; } + + return nodes[0]; } } diff --git a/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Modifying/IAbpModuleFileManager.cs b/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Modifying/IAbpModuleFileManager.cs index 7eb2060e48..99aeef2697 100644 --- a/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Modifying/IAbpModuleFileManager.cs +++ b/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Modifying/IAbpModuleFileManager.cs @@ -1,11 +1,10 @@ using System.Threading.Tasks; -namespace Volo.Abp.Studio.Packages.Modifying +namespace Volo.Abp.Studio.Packages.Modifying; + +public interface IAbpModuleFileManager { - public interface IAbpModuleFileManager - { - Task AddDependency(string filePath, string moduleToAdd); + Task AddDependency(string filePath, string moduleToAdd); - Task ExtractModuleNameWithNamespace(string filePath); - } + Task ExtractModuleNameWithNamespace(string filePath); } diff --git a/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Modifying/ICsprojFileManager.cs b/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Modifying/ICsprojFileManager.cs index af8c466c17..1fe903e78c 100644 --- a/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Modifying/ICsprojFileManager.cs +++ b/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Modifying/ICsprojFileManager.cs @@ -2,18 +2,17 @@ using System.Threading.Tasks; using Volo.Abp.Studio.Package; -namespace Volo.Abp.Studio.Packages.Modifying +namespace Volo.Abp.Studio.Packages.Modifying; + +public interface ICsprojFileManager { - public interface ICsprojFileManager - { - Task AddProjectReferenceAsync(string filePath, string projectToReference); + Task AddProjectReferenceAsync(string filePath, string projectToReference); - Task AddPackageReferenceAsync(string filePath, string packageName, string version); + Task AddPackageReferenceAsync(string filePath, string packageName, string version); - Task ConvertPackageReferenceToProjectReferenceAsync(string filePath, string projectToReference); + Task ConvertPackageReferenceToProjectReferenceAsync(string filePath, string projectToReference); - Task GetTargetFrameworkAsync(string filePath); + Task GetTargetFrameworkAsync(string filePath); - Task> GetDependencyListAsync(string filePath); - } + Task> GetDependencyListAsync(string filePath); } diff --git a/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Nuget/INugetSourceCodeStore.cs b/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Nuget/INugetSourceCodeStore.cs index 6fce22dbe0..36aeeb53e4 100644 --- a/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Nuget/INugetSourceCodeStore.cs +++ b/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Nuget/INugetSourceCodeStore.cs @@ -1,18 +1,17 @@ using System.Threading.Tasks; -namespace Volo.Abp.Studio.Nuget +namespace Volo.Abp.Studio.Nuget; + +public interface INugetSourceCodeStore { - public interface INugetSourceCodeStore - { - Task GetCachedSourceCodeFilePathAsync(string name, - string type, - string version = null, - bool includePreReleases = false); + Task GetCachedSourceCodeFilePathAsync(string name, + string type, + string version = null, + bool includePreReleases = false); - Task GetCachedDllFilePathAsync(string name, - string type, - string version = null, - bool includePreReleases = false, - bool includeDependencies = false); - } + Task GetCachedDllFilePathAsync(string name, + string type, + string version = null, + bool includePreReleases = false, + bool includeDependencies = false); } diff --git a/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Nuget/NugetPackageCacheManager.cs b/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Nuget/NugetPackageCacheManager.cs index b4a21560cb..053a9afaf0 100644 --- a/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Nuget/NugetPackageCacheManager.cs +++ b/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Nuget/NugetPackageCacheManager.cs @@ -5,32 +5,31 @@ using Volo.Abp.Cli.Utils; using Volo.Abp.DependencyInjection; using Volo.Abp.Studio.Helpers; -namespace Volo.Abp.Studio.Nuget -{ - public class NugetPackageCacheManager : ITransientDependency - { - private readonly ICmdHelper _cmdHelper; +namespace Volo.Abp.Studio.Nuget; - public NugetPackageCacheManager(ICmdHelper cmdHelper) - { - _cmdHelper = cmdHelper; - } +public class NugetPackageCacheManager : ITransientDependency +{ + private readonly ICmdHelper _cmdHelper; - public async Task CachePackageAsync(string packageName, string version, bool deleteAfter = true) - { - var temporaryFolder = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); + public NugetPackageCacheManager(ICmdHelper cmdHelper) + { + _cmdHelper = cmdHelper; + } - Directory.CreateDirectory(temporaryFolder); + public async Task CachePackageAsync(string packageName, string version, bool deleteAfter = true) + { + var temporaryFolder = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); - _cmdHelper.RunCmdAndGetOutput("dotnet new console -lang c#", temporaryFolder); - _cmdHelper.RunCmdAndGetOutput($"dotnet add package {packageName} --version {version}", temporaryFolder); + Directory.CreateDirectory(temporaryFolder); - if (deleteAfter) - { - Directory.Delete(temporaryFolder, true); - } + _cmdHelper.RunCmdAndGetOutput("dotnet new console -lang c#", temporaryFolder); + _cmdHelper.RunCmdAndGetOutput($"dotnet add package {packageName} --version {version}", temporaryFolder); - return temporaryFolder; + if (deleteAfter) + { + Directory.Delete(temporaryFolder, true); } + + return temporaryFolder; } } diff --git a/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Nuget/NugetSourceCodeStore.cs b/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Nuget/NugetSourceCodeStore.cs index c81d95b2dc..c518a966e3 100644 --- a/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Nuget/NugetSourceCodeStore.cs +++ b/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Nuget/NugetSourceCodeStore.cs @@ -9,155 +9,154 @@ using Volo.Abp.DependencyInjection; using Volo.Abp.Studio.Helpers; using Volo.Abp.Studio.Modules; -namespace Volo.Abp.Studio.Nuget +namespace Volo.Abp.Studio.Nuget; + +[Dependency(ReplaceServices = true)] +public class NugetSourceCodeStore : ISourceCodeStore, INugetSourceCodeStore, ITransientDependency { - [Dependency(ReplaceServices = true)] - public class NugetSourceCodeStore : ISourceCodeStore, INugetSourceCodeStore, ITransientDependency + private readonly NuGetService _nuGetService; + private readonly NugetPackageCacheManager _nugetPackageCacheManager; + private readonly ICmdHelper _cmdHelper; + + public NugetSourceCodeStore( + NuGetService nuGetService, + NugetPackageCacheManager nugetPackageCacheManager, + ICmdHelper cmdHelper) { - private readonly NuGetService _nuGetService; - private readonly NugetPackageCacheManager _nugetPackageCacheManager; - private readonly ICmdHelper _cmdHelper; - - public NugetSourceCodeStore( - NuGetService nuGetService, - NugetPackageCacheManager nugetPackageCacheManager, - ICmdHelper cmdHelper) - { - _nuGetService = nuGetService; - _nugetPackageCacheManager = nugetPackageCacheManager; - _cmdHelper = cmdHelper; - } - - public async Task GetAsync( - string name, - string type, - string version = null, - string templateSource = null, - bool includePreReleases = false) - { - name = GetNugetPackageName(name, type); + _nuGetService = nuGetService; + _nugetPackageCacheManager = nugetPackageCacheManager; + _cmdHelper = cmdHelper; + } - var latestVersion = await GetLatestVersionAsync(name, includePreReleases); + public async Task GetAsync( + string name, + string type, + string version = null, + string templateSource = null, + bool includePreReleases = false) + { + name = GetNugetPackageName(name, type); - version ??= latestVersion; + var latestVersion = await GetLatestVersionAsync(name, includePreReleases); - var localCachedFilePath = await GetLocalCacheSourceCodeFilePathInternal(name, version); + version ??= latestVersion; - if (localCachedFilePath == null) - { - return null; - } + var localCachedFilePath = await GetLocalCacheSourceCodeFilePathInternal(name, version); - return new TemplateFile(await File.ReadAllBytesAsync(localCachedFilePath), version, latestVersion, version); + if (localCachedFilePath == null) + { + return null; } - public async Task GetCachedSourceCodeFilePathAsync(string name, string type, string version = null, - bool includePreReleases = false) - { - name = GetNugetPackageName(name, type); + return new TemplateFile(await File.ReadAllBytesAsync(localCachedFilePath), version, latestVersion, version); + } + + public async Task GetCachedSourceCodeFilePathAsync(string name, string type, string version = null, + bool includePreReleases = false) + { + name = GetNugetPackageName(name, type); + + version ??= await GetLatestVersionAsync(name, includePreReleases); - version ??= await GetLatestVersionAsync(name, includePreReleases); + return await GetLocalCacheSourceCodeFilePathInternal(name, version); + } - return await GetLocalCacheSourceCodeFilePathInternal(name, version); + public async Task GetCachedDllFilePathAsync(string name, string type, string version = null, bool includePreReleases = false, bool includeDependencies = false) + { + if (type == SourceCodeTypes.Template) + { + name = TemplateNugetPackageInfoProvider.GetNugetPackageName(name); } - public async Task GetCachedDllFilePathAsync(string name, string type, string version = null, bool includePreReleases = false, bool includeDependencies = false) + version ??= await GetLatestVersionAsync(name, includePreReleases); + + var localDllFolder = Path.Combine( + GetLocalNugetCachePath(), + name, + version, + "lib"); + + if (!Directory.Exists(localDllFolder) || + (includeDependencies && !Directory.GetFiles(localDllFolder, $"*Volo.Abp.Studio.ModuleInstaller.dll", SearchOption.AllDirectories).Any())) { - if (type == SourceCodeTypes.Template) + if (includeDependencies) { - name = TemplateNugetPackageInfoProvider.GetNugetPackageName(name); - } + var temporaryFolder = await _nugetPackageCacheManager.CachePackageAsync(name, version, false); - version ??= await GetLatestVersionAsync(name, includePreReleases); + var outputFolder = Path.GetDirectoryName( + Directory + .GetFiles(localDllFolder, $"*{name}.dll", SearchOption.AllDirectories) + .First() + ); - var localDllFolder = Path.Combine( - GetLocalNugetCachePath(), - name, - version, - "lib"); + _cmdHelper.RunCmdAndGetOutput($"dotnet build -o {outputFolder}", temporaryFolder); - if (!Directory.Exists(localDllFolder) || - (includeDependencies && !Directory.GetFiles(localDllFolder, $"*Volo.Abp.Studio.ModuleInstaller.dll", SearchOption.AllDirectories).Any())) - { - if (includeDependencies) - { - var temporaryFolder = await _nugetPackageCacheManager.CachePackageAsync(name, version, false); - - var outputFolder = Path.GetDirectoryName( - Directory - .GetFiles(localDllFolder, $"*{name}.dll", SearchOption.AllDirectories) - .First() - ); - - _cmdHelper.RunCmdAndGetOutput($"dotnet build -o {outputFolder}", temporaryFolder); - - Directory.Delete(temporaryFolder, true); - } - else - { - await _nugetPackageCacheManager.CachePackageAsync(name, version); - } + Directory.Delete(temporaryFolder, true); } - - if (!Directory.Exists(localDllFolder)) + else { - return null; + await _nugetPackageCacheManager.CachePackageAsync(name, version); } - - return Directory.GetFiles(localDllFolder, $"{name}.dll", SearchOption.AllDirectories).FirstOrDefault(); } - private async Task GetLatestVersionAsync(string nugetPackage, bool includePreReleases) + if (!Directory.Exists(localDllFolder)) { - var v = await _nuGetService.GetLatestVersionOrNullAsync(nugetPackage, includePreReleases); - - return v.ToString(); + return null; } - private async Task GetLocalCacheSourceCodeFilePathInternal(string name, string version) - { - var localCacheFile = Path.Combine( - GetLocalNugetCachePath(), - name, - version, - "content", - $"{name}.zip"); + return Directory.GetFiles(localDllFolder, $"{name}.dll", SearchOption.AllDirectories).FirstOrDefault(); + } + private async Task GetLatestVersionAsync(string nugetPackage, bool includePreReleases) + { + var v = await _nuGetService.GetLatestVersionOrNullAsync(nugetPackage, includePreReleases); - if (!File.Exists(localCacheFile)) - { - await _nugetPackageCacheManager.CachePackageAsync(name, version); + return v.ToString(); + } - if (!File.Exists(localCacheFile)) - { - return null; - } - } + private async Task GetLocalCacheSourceCodeFilePathInternal(string name, string version) + { + var localCacheFile = Path.Combine( + GetLocalNugetCachePath(), + name, + version, + "content", + $"{name}.zip"); - return localCacheFile; - } - private string GetLocalNugetCachePath() + if (!File.Exists(localCacheFile)) { - return Path.Combine( - Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), - ".nuget", - "packages"); - } + await _nugetPackageCacheManager.CachePackageAsync(name, version); - private string GetNugetPackageName(string name, string type) - { - if (type == SourceCodeTypes.Template) + if (!File.Exists(localCacheFile)) { - return TemplateNugetPackageInfoProvider.GetNugetPackageName(name); + return null; } + } - if (type == SourceCodeTypes.Module) - { - return name + ModuleConsts.SourceCorePackagePostfix; - } + return localCacheFile; + } + + private string GetLocalNugetCachePath() + { + return Path.Combine( + Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), + ".nuget", + "packages"); + } - return name; + private string GetNugetPackageName(string name, string type) + { + if (type == SourceCodeTypes.Template) + { + return TemplateNugetPackageInfoProvider.GetNugetPackageName(name); + } + + if (type == SourceCodeTypes.Module) + { + return name + ModuleConsts.SourceCorePackagePostfix; } + + return name; } } diff --git a/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Nuget/TemplateNugetPackageInfoProvider.cs b/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Nuget/TemplateNugetPackageInfoProvider.cs index 03765f96c1..00a22e55e2 100644 --- a/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Nuget/TemplateNugetPackageInfoProvider.cs +++ b/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Nuget/TemplateNugetPackageInfoProvider.cs @@ -1,18 +1,17 @@ using System.Threading.Tasks; -namespace Volo.Abp.Studio.Nuget +namespace Volo.Abp.Studio.Nuget; + +public static class TemplateNugetPackageInfoProvider { - public static class TemplateNugetPackageInfoProvider + public static string GetNugetPackageName(string template) { - public static string GetNugetPackageName(string template) + switch (template) { - switch (template) - { - case "app": - return "Cotur.Abp.Basic.Template"; // todo: replace with real template! - default: - return null; - } + case "app": + return "Cotur.Abp.Basic.Template"; // todo: replace with real template! + default: + return null; } } } diff --git a/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Package/PackageDependency.cs b/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Package/PackageDependency.cs index 1a9d2e1396..f43c65e383 100644 --- a/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Package/PackageDependency.cs +++ b/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Package/PackageDependency.cs @@ -1,30 +1,29 @@ using System; using System.IO; -namespace Volo.Abp.Studio.Package +namespace Volo.Abp.Studio.Package; + +public class PackageDependency { - public class PackageDependency - { - public ReferenceType Type { get; } + public ReferenceType Type { get; } - public string Name { get; } + public string Name { get; } - public string Version { get; } + public string Version { get; } - public string Path { get; } + public string Path { get; } - public PackageDependency(string name, string version) - { - Type = ReferenceType.Package; - Name = name; - Version = version; - } + public PackageDependency(string name, string version) + { + Type = ReferenceType.Package; + Name = name; + Version = version; + } - public PackageDependency(string path) - { - Type = ReferenceType.Project; - Path = path; - Name = System.IO.Path.GetFileName(path).RemovePostFix(".csproj"); - } + public PackageDependency(string path) + { + Type = ReferenceType.Project; + Path = path; + Name = System.IO.Path.GetFileName(path).RemovePostFix(".csproj"); } } diff --git a/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Package/PackageTypes.cs b/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Package/PackageTypes.cs index cc5870f783..faa4405849 100644 --- a/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Package/PackageTypes.cs +++ b/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Package/PackageTypes.cs @@ -1,127 +1,127 @@ using System.Collections.Generic; -namespace Volo.Abp.Studio.Packages +namespace Volo.Abp.Studio.Packages; + +public static class PackageTypes { - public static class PackageTypes + public const string Domain = "lib.domain"; + public const string DomainShared = "lib.domain-shared"; + public const string Application = "lib.application"; + public const string ApplicationContracts = "lib.application-contracts"; + public const string EntityFrameworkCore = "lib.ef"; + public const string MongoDB = "lib.mongodb"; + public const string HttpApi = "lib.http-api"; + public const string HttpApiClient = "lib.http-api-client"; + public const string Mvc = "lib.mvc"; + public const string Blazor = "lib.blazor"; + public const string BlazorWebAssembly = "lib.blazor-wasm"; + public const string BlazorServer = "lib.blazor-server"; + public const string Test = "lib.test"; + + public const string HostHttpApi = "host.http-api"; + public const string HostMvc = "host.mvc"; + public const string HostBlazorWebAssembly = "host.blazor-wasm"; + public const string HostBlazorServer = "host.blazor-server"; + public const string HostApiGatewayOcelot = "host.api-gateway-ocelot"; + + public static string CalculateDefaultPackageNameForModule( + string moduleName, + string packageType) { - public const string Domain = "lib.domain"; - public const string DomainShared = "lib.domain-shared"; - public const string Application = "lib.application"; - public const string ApplicationContracts = "lib.application-contracts"; - public const string EntityFrameworkCore = "lib.ef"; - public const string MongoDB = "lib.mongodb"; - public const string HttpApi = "lib.http-api"; - public const string HttpApiClient = "lib.http-api-client"; - public const string Mvc = "lib.mvc"; - public const string Blazor = "lib.blazor"; - public const string BlazorWebAssembly = "lib.blazor-wasm"; - public const string BlazorServer = "lib.blazor-server"; - public const string Test = "lib.test"; - - public const string HostHttpApi = "host.http-api"; - public const string HostMvc = "host.mvc"; - public const string HostBlazorWebAssembly = "host.blazor-wasm"; - public const string HostBlazorServer = "host.blazor-server"; - public const string HostApiGatewayOcelot = "host.api-gateway-ocelot"; - - public static string CalculateDefaultPackageNameForModule( - string moduleName, - string packageType) + switch (packageType) { - switch (packageType) - { - case Domain: - return moduleName + ".Domain"; - case DomainShared: - return moduleName + ".Domain.Shared"; - case Application: - return moduleName + ".Application"; - case ApplicationContracts: - return moduleName + ".Application.Contracts"; - case EntityFrameworkCore: - return moduleName + ".EntityFrameworkCore"; - case HttpApi: - return moduleName + ".HttpApi"; - case HttpApiClient: - return moduleName + ".HttpApi.Client"; - case MongoDB: - return moduleName + ".MongoDB"; - case Mvc: - return moduleName + ".Web"; - case Blazor: - return moduleName + ".Blazor"; - case BlazorWebAssembly: - return moduleName + ".Blazor.WebAssembly"; - case BlazorServer: - return moduleName + ".Blazor.Server"; - case HostHttpApi: - return moduleName + ".HttpApi.Host"; - case HostMvc: - return moduleName + ".Web.Host"; - case HostBlazorWebAssembly: - return moduleName + ".Blazor.Client"; - case HostBlazorServer: - return moduleName + ".Blazor.Host"; - case HostApiGatewayOcelot: - return moduleName + ".Gateway"; - default: - throw new AbpStudioException(AbpStudioErrorCodes.PackageNameMustBeSpecified); - } + case Domain: + return moduleName + ".Domain"; + case DomainShared: + return moduleName + ".Domain.Shared"; + case Application: + return moduleName + ".Application"; + case ApplicationContracts: + return moduleName + ".Application.Contracts"; + case EntityFrameworkCore: + return moduleName + ".EntityFrameworkCore"; + case HttpApi: + return moduleName + ".HttpApi"; + case HttpApiClient: + return moduleName + ".HttpApi.Client"; + case MongoDB: + return moduleName + ".MongoDB"; + case Mvc: + return moduleName + ".Web"; + case Blazor: + return moduleName + ".Blazor"; + case BlazorWebAssembly: + return moduleName + ".Blazor.WebAssembly"; + case BlazorServer: + return moduleName + ".Blazor.Server"; + case HostHttpApi: + return moduleName + ".HttpApi.Host"; + case HostMvc: + return moduleName + ".Web.Host"; + case HostBlazorWebAssembly: + return moduleName + ".Blazor.Client"; + case HostBlazorServer: + return moduleName + ".Blazor.Host"; + case HostApiGatewayOcelot: + return moduleName + ".Gateway"; + default: + throw new AbpStudioException(AbpStudioErrorCodes.PackageNameMustBeSpecified); } + } - public static bool IsHostProject(string packageType) - { - return - packageType == HostMvc || - packageType == HostHttpApi || - packageType == HostBlazorWebAssembly || - packageType == HostBlazorServer || - packageType == HostApiGatewayOcelot; - } + public static bool IsHostProject(string packageType) + { + return + packageType == HostMvc || + packageType == HostHttpApi || + packageType == HostBlazorWebAssembly || + packageType == HostBlazorServer || + packageType == HostApiGatewayOcelot; + } - public static bool IsUiProject(string packageType) - { - return - packageType == Mvc || - packageType == BlazorWebAssembly || - packageType == BlazorServer; - } + public static bool IsUiProject(string packageType) + { + return + packageType == Mvc || + packageType == BlazorWebAssembly || + packageType == BlazorServer; + } - public static string GetHostTypeOfUi(string packageType, bool useHostBlazorServerForMvcPackages = false) + public static string GetHostTypeOfUi(string packageType, bool useHostBlazorServerForMvcPackages = false) + { + return packageType switch { - return packageType switch - { - Mvc => !useHostBlazorServerForMvcPackages ? HostMvc : HostBlazorServer, - BlazorWebAssembly => HostBlazorWebAssembly, - BlazorServer => HostBlazorServer, - _ => null - }; - } + Mvc => !useHostBlazorServerForMvcPackages ? HostMvc : HostBlazorServer, + BlazorWebAssembly => HostBlazorWebAssembly, + BlazorServer => HostBlazorServer, + _ => null + }; + } - public static List GetSuggestedInstallationType(string packageType) + public static List GetSuggestedInstallationType(string packageType) + { + if (packageType == DomainShared) { - if (packageType == DomainShared) - { - return new List() + return new List() { Domain, DomainShared, ApplicationContracts }; - } + } - if (packageType == Domain) - { - return new List() + if (packageType == Domain) + { + return new List() { Domain, Application }; - } + } - if (packageType == ApplicationContracts) - { - return new List() + if (packageType == ApplicationContracts) + { + return new List() { Application, ApplicationContracts, @@ -131,11 +131,11 @@ namespace Volo.Abp.Studio.Packages BlazorWebAssembly, HttpApi }; - } + } - if (packageType == Application) - { - return new List() + if (packageType == Application) + { + return new List() { Application, HostMvc, @@ -143,11 +143,11 @@ namespace Volo.Abp.Studio.Packages HostBlazorWebAssembly, HostHttpApi }; - } + } - if (packageType == EntityFrameworkCore) - { - return new List() + if (packageType == EntityFrameworkCore) + { + return new List() { EntityFrameworkCore, HostMvc, @@ -155,11 +155,11 @@ namespace Volo.Abp.Studio.Packages HostBlazorWebAssembly, HostHttpApi }; - } + } - if (packageType == MongoDB) - { - return new List() + if (packageType == MongoDB) + { + return new List() { MongoDB, HostMvc, @@ -167,11 +167,11 @@ namespace Volo.Abp.Studio.Packages HostBlazorWebAssembly, HostHttpApi }; - } + } - if (packageType == HttpApi) - { - return new List() + if (packageType == HttpApi) + { + return new List() { HttpApi, HostMvc, @@ -179,11 +179,11 @@ namespace Volo.Abp.Studio.Packages HostBlazorWebAssembly, HostHttpApi }; - } + } - if (packageType == HttpApiClient) - { - return new List() + if (packageType == HttpApiClient) + { + return new List() { HttpApiClient, HostMvc, @@ -191,54 +191,53 @@ namespace Volo.Abp.Studio.Packages HostBlazorWebAssembly, HostHttpApi }; - } + } - if (packageType == Mvc) - { - return new List() + if (packageType == Mvc) + { + return new List() { Mvc, HostMvc }; - } + } - if (packageType == Blazor) - { - return new List() + if (packageType == Blazor) + { + return new List() { Blazor, BlazorServer, BlazorWebAssembly }; - } + } - if (packageType == BlazorServer) - { - return new List() + if (packageType == BlazorServer) + { + return new List() { BlazorServer, HostBlazorServer }; - } + } - if (packageType == BlazorWebAssembly) - { - return new List() + if (packageType == BlazorWebAssembly) + { + return new List() { BlazorWebAssembly, HostBlazorWebAssembly }; - } + } - if (packageType == Test) - { - return new List() + if (packageType == Test) + { + return new List() { Test }; - } - - return new List(); } + + return new List(); } } diff --git a/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Package/ReferenceType.cs b/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Package/ReferenceType.cs index 5c4d83b2f9..81916c320b 100644 --- a/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Package/ReferenceType.cs +++ b/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Package/ReferenceType.cs @@ -1,8 +1,7 @@ -namespace Volo.Abp.Studio.Package +namespace Volo.Abp.Studio.Package; + +public enum ReferenceType { - public enum ReferenceType - { - Project = 1, - Package = 2 - } -} \ No newline at end of file + Project = 1, + Package = 2 +} diff --git a/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Solution/DotnetSlnFileModifierService.cs b/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Solution/DotnetSlnFileModifierService.cs index 5fadc93569..9b77e644a0 100644 --- a/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Solution/DotnetSlnFileModifierService.cs +++ b/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Solution/DotnetSlnFileModifierService.cs @@ -7,120 +7,119 @@ using System.Threading.Tasks; using Volo.Abp.DependencyInjection; using Volo.Abp.Studio.Helpers; -namespace Volo.Abp.Studio.Solution +namespace Volo.Abp.Studio.Solution; + +public class DotnetSlnFileModifierService : IDotnetSlnFileModifierService, ITransientDependency { - public class DotnetSlnFileModifierService : IDotnetSlnFileModifierService, ITransientDependency + public IFileSystem FileSystem { get; } + + public DotnetSlnFileModifierService(IFileSystem fileSystem) + { + FileSystem = fileSystem; + } + + public async Task AddProjectAsync(string slnFilePath, string projectPath, string slnTargetFolder = "src") { - public IFileSystem FileSystem { get; } + var projectName = FileSystem.Path.GetFileName(projectPath).RemovePostFix(".csproj"); + var folderId = await GetOrAddFolderIdAsync(slnFilePath, slnTargetFolder); + var slnFileLines = (await FileSystem.File.ReadAllTextAsync(slnFilePath)) + .Split(Environment.NewLine).ToList(); - public DotnetSlnFileModifierService(IFileSystem fileSystem) + if (slnFileLines.Any(l => l.Contains($"\"{projectName}\"") && l.Contains("9A19103F-16F7-4668-BE54-9A1E7A4F7556"))) { - FileSystem = fileSystem; + throw new AbpStudioException(AbpStudioErrorCodes.ProjectWithSameNameAlreadyExistInTheSolutionFile) + .WithData("Solution Path", slnFilePath) + .WithData("Project Name", projectName); } - public async Task AddProjectAsync(string slnFilePath, string projectPath, string slnTargetFolder = "src") - { - var projectName = FileSystem.Path.GetFileName(projectPath).RemovePostFix(".csproj"); - var folderId = await GetOrAddFolderIdAsync(slnFilePath, slnTargetFolder); - var slnFileLines = (await FileSystem.File.ReadAllTextAsync(slnFilePath)) - .Split(Environment.NewLine).ToList(); + var projectId = Guid.NewGuid().ToString(); + var relativeProjectPath = PathHelper.GetRelativePath(slnFilePath, projectPath).Replace("/", "\\"); + var newProjectLine = "Project(\"{9A19103F-16F7-4668-BE54-9A1E7A4F7556}\") = \"" + projectName + "\"," + + " \"" + relativeProjectPath + "\", \"{" + projectId + "}\"" + + Environment.NewLine + "EndProject"; - if (slnFileLines.Any(l => l.Contains($"\"{projectName}\"") && l.Contains("9A19103F-16F7-4668-BE54-9A1E7A4F7556"))) - { - throw new AbpStudioException(AbpStudioErrorCodes.ProjectWithSameNameAlreadyExistInTheSolutionFile) - .WithData("Solution Path", slnFilePath) - .WithData("Project Name", projectName); - } + slnFileLines.InsertAfter(l => l.Trim().Equals("EndProject"), newProjectLine); - var projectId = Guid.NewGuid().ToString(); - var relativeProjectPath = PathHelper.GetRelativePath(slnFilePath, projectPath).Replace("/", "\\"); - var newProjectLine = "Project(\"{9A19103F-16F7-4668-BE54-9A1E7A4F7556}\") = \"" + projectName + "\"," + - " \"" + relativeProjectPath + "\", \"{" + projectId + "}\"" - + Environment.NewLine + "EndProject"; + var newPostSolutionLine = + " {" + projectId + "}.Debug|Any CPU.ActiveCfg = Debug|Any CPU" + Environment.NewLine + + " {" + projectId + "}.Debug|Any CPU.Build.0 = Debug|Any CPU" + Environment.NewLine + + " {" + projectId + "}.Release|Any CPU.ActiveCfg = Release|Any CPU" + Environment.NewLine + + " {" + projectId + "}.Release|Any CPU.Build.0 = Release|Any CPU"; - slnFileLines.InsertAfter(l => l.Trim().Equals("EndProject"), newProjectLine); + if (!slnFileLines.Any(l => l.Contains("GlobalSection") && l.Contains("ProjectConfigurationPlatforms"))) + { + slnFileLines.InsertBefore(l => l.Trim().Equals("EndGlobal"), " GlobalSection(ProjectConfigurationPlatforms) = postSolution"); + slnFileLines.InsertBefore(l => l.Trim().Equals("EndGlobal"), " EndGlobalSection"); + } - var newPostSolutionLine = - " {" + projectId + "}.Debug|Any CPU.ActiveCfg = Debug|Any CPU" + Environment.NewLine + - " {" + projectId + "}.Debug|Any CPU.Build.0 = Debug|Any CPU" + Environment.NewLine + - " {" + projectId + "}.Release|Any CPU.ActiveCfg = Release|Any CPU" + Environment.NewLine + - " {" + projectId + "}.Release|Any CPU.Build.0 = Release|Any CPU"; + slnFileLines.InsertAfter(l => l.Contains("GlobalSection") && l.Contains("ProjectConfigurationPlatforms"), + newPostSolutionLine); - if (!slnFileLines.Any(l => l.Contains("GlobalSection") && l.Contains("ProjectConfigurationPlatforms"))) - { - slnFileLines.InsertBefore(l => l.Trim().Equals("EndGlobal"), " GlobalSection(ProjectConfigurationPlatforms) = postSolution"); - slnFileLines.InsertBefore(l => l.Trim().Equals("EndGlobal"), " EndGlobalSection"); - } + var newPreSolutionLine = + " {" + projectId + "} = {" + folderId + "}"; - slnFileLines.InsertAfter(l => l.Contains("GlobalSection") && l.Contains("ProjectConfigurationPlatforms"), - newPostSolutionLine); - var newPreSolutionLine = - " {" + projectId + "} = {" + folderId + "}"; + if (!slnFileLines.Any(l => l.Contains("GlobalSection") && l.Contains("NestedProjects"))) + { + slnFileLines.InsertBefore(l => l.Trim().Equals("EndGlobal"), " GlobalSection(NestedProjects) = preSolution"); + slnFileLines.InsertBefore(l => l.Trim().Equals("EndGlobal"), " EndGlobalSection"); + } + slnFileLines.InsertAfter(l => l.Contains("GlobalSection") && l.Contains("NestedProjects"), newPreSolutionLine); - if (!slnFileLines.Any(l => l.Contains("GlobalSection") && l.Contains("NestedProjects"))) - { - slnFileLines.InsertBefore(l => l.Trim().Equals("EndGlobal"), " GlobalSection(NestedProjects) = preSolution"); - slnFileLines.InsertBefore(l => l.Trim().Equals("EndGlobal"), " EndGlobalSection"); - } + await FileSystem.File.WriteAllTextAsync(slnFilePath, string.Join(Environment.NewLine, slnFileLines)); + } - slnFileLines.InsertAfter(l => l.Contains("GlobalSection") && l.Contains("NestedProjects"), newPreSolutionLine); + private async Task GetOrAddFolderIdAsync(string solutionFile, string folderName, string parentFolderId = null) + { + if (folderName.Contains("/") && parentFolderId == null) + { + var parents = folderName.Split("/").SkipLast(1).JoinAsString("/"); + folderName = folderName.Split("/").Last(); - await FileSystem.File.WriteAllTextAsync(slnFilePath, string.Join(Environment.NewLine, slnFileLines)); + parentFolderId = await GetOrAddFolderIdAsync(solutionFile, parents); } - private async Task GetOrAddFolderIdAsync(string solutionFile, string folderName, string parentFolderId = null) - { - if (folderName.Contains("/") && parentFolderId == null) - { - var parents = folderName.Split("/").SkipLast(1).JoinAsString("/"); - folderName = folderName.Split("/").Last(); - - parentFolderId = await GetOrAddFolderIdAsync(solutionFile, parents); - } + var file = await FileSystem.File.ReadAllTextAsync(solutionFile); + var lines = file.Split(Environment.NewLine).ToList(); + string folderId; - var file = await FileSystem.File.ReadAllTextAsync(solutionFile); - var lines = file.Split(Environment.NewLine).ToList(); - string folderId; + var folderLineIndex = lines.FindIndex(l => + l.Contains("2150E333-8FDC-42A3-9474-1A3956D46DE8") && l.Contains("\"" + folderName + "\"")); - var folderLineIndex = lines.FindIndex(l => - l.Contains("2150E333-8FDC-42A3-9474-1A3956D46DE8") && l.Contains("\"" + folderName + "\"")); + if (folderLineIndex < 0) + { + folderId = Guid.NewGuid().ToString(); + var newFolderLine = "Project(\"{2150E333-8FDC-42A3-9474-1A3956D46DE8}\") = \"" + folderName + "\", \"" + + folderName + "\", \"{" + folderId + "}\"" + + Environment.NewLine + "EndProject"; - if (folderLineIndex < 0) + if (lines.Any(l => l.Trim().Equals("EndProject"))) { - folderId = Guid.NewGuid().ToString(); - var newFolderLine = "Project(\"{2150E333-8FDC-42A3-9474-1A3956D46DE8}\") = \"" + folderName + "\", \"" + - folderName + "\", \"{" + folderId + "}\"" - + Environment.NewLine + "EndProject"; - - if (lines.Any(l => l.Trim().Equals("EndProject"))) - { - lines.InsertAfter(l => l.Trim().Equals("EndProject"), newFolderLine); - } - else - { - lines.InsertAfter(l => l.StartsWith("Microsoft Visual Studio Solution File"), newFolderLine); - } - - if (parentFolderId != null && lines.Any(l=>l.Contains("GlobalSection") && l.Contains("NestedProjects"))) - { - var newPreSolutionLine = - " {" + folderId + "} = {" + parentFolderId + "}"; - - lines.InsertAfter(l => l.Contains("GlobalSection") && l.Contains("NestedProjects"), - newPreSolutionLine); - } - - await FileSystem.File.WriteAllTextAsync(solutionFile, string.Join(Environment.NewLine, lines)); + lines.InsertAfter(l => l.Trim().Equals("EndProject"), newFolderLine); } else { - folderId = lines[folderLineIndex].Replace("\"", " ").Replace("{", " ").Replace("}", " ").TrimEnd() - .Split(" ").Last(); + lines.InsertAfter(l => l.StartsWith("Microsoft Visual Studio Solution File"), newFolderLine); } - return folderId; + if (parentFolderId != null && lines.Any(l => l.Contains("GlobalSection") && l.Contains("NestedProjects"))) + { + var newPreSolutionLine = + " {" + folderId + "} = {" + parentFolderId + "}"; + + lines.InsertAfter(l => l.Contains("GlobalSection") && l.Contains("NestedProjects"), + newPreSolutionLine); + } + + await FileSystem.File.WriteAllTextAsync(solutionFile, string.Join(Environment.NewLine, lines)); } + else + { + folderId = lines[folderLineIndex].Replace("\"", " ").Replace("{", " ").Replace("}", " ").TrimEnd() + .Split(" ").Last(); + } + + return folderId; } } diff --git a/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Solution/IDotnetSlnFileModifierService.cs b/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Solution/IDotnetSlnFileModifierService.cs index 5bb26bf9d9..8fe371c373 100644 --- a/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Solution/IDotnetSlnFileModifierService.cs +++ b/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Solution/IDotnetSlnFileModifierService.cs @@ -1,9 +1,8 @@ using System.Threading.Tasks; -namespace Volo.Abp.Studio.Solution +namespace Volo.Abp.Studio.Solution; + +public interface IDotnetSlnFileModifierService { - public interface IDotnetSlnFileModifierService - { - Task AddProjectAsync(string slnFile, string projectPath, string slnTargetFolder = "src"); - } + Task AddProjectAsync(string slnFile, string projectPath, string slnTargetFolder = "src"); } diff --git a/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Solution/ISolutionFileModuleAdder.cs b/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Solution/ISolutionFileModuleAdder.cs index 4f51330db7..16105c4698 100644 --- a/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Solution/ISolutionFileModuleAdder.cs +++ b/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Solution/ISolutionFileModuleAdder.cs @@ -1,9 +1,8 @@ using System.Threading.Tasks; -namespace Volo.Abp.Studio.Solution +namespace Volo.Abp.Studio.Solution; + +public interface ISolutionFileModuleAdder { - public interface ISolutionFileModuleAdder - { - Task AddAsync(string TargetModule, string ModuleName); - } + Task AddAsync(string TargetModule, string ModuleName); } diff --git a/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Solution/SolutionFileModuleAdder.cs b/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Solution/SolutionFileModuleAdder.cs index cafd0f9281..7f6f35f627 100644 --- a/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Solution/SolutionFileModuleAdder.cs +++ b/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Solution/SolutionFileModuleAdder.cs @@ -4,39 +4,38 @@ using System.Threading.Tasks; using Volo.Abp.DependencyInjection; using Volo.Abp.Studio.Modules; -namespace Volo.Abp.Studio.Solution +namespace Volo.Abp.Studio.Solution; + +public class SolutionFileModuleAdder : ISolutionFileModuleAdder, ITransientDependency { - public class SolutionFileModuleAdder : ISolutionFileModuleAdder, ITransientDependency + private readonly IDotnetSlnFileModifierService _dotnetSlnFileModifierService; + + public SolutionFileModuleAdder(IDotnetSlnFileModifierService dotnetSlnFileModifierService) { - private readonly IDotnetSlnFileModifierService _dotnetSlnFileModifierService; + _dotnetSlnFileModifierService = dotnetSlnFileModifierService; + } - public SolutionFileModuleAdder(IDotnetSlnFileModifierService dotnetSlnFileModifierService) - { - _dotnetSlnFileModifierService = dotnetSlnFileModifierService; - } + public async Task AddAsync(string TargetModule, string ModuleName) + { + var targetFolder = Path.Combine(Path.GetDirectoryName(TargetModule), "modules", ModuleName); ; + var slnFile = TargetModule.RemovePostFix(ModuleConsts.FileExtension) + ".sln"; + var moduleSrcFolder = Path.Combine(targetFolder, "src"); + var moduleTestFolder = Path.Combine(targetFolder, "test"); - public async Task AddAsync(string TargetModule, string ModuleName) - { - var targetFolder = Path.Combine(Path.GetDirectoryName(TargetModule), "modules", ModuleName);; - var slnFile = TargetModule.RemovePostFix(ModuleConsts.FileExtension) + ".sln"; - var moduleSrcFolder = Path.Combine(targetFolder, "src"); - var moduleTestFolder = Path.Combine(targetFolder, "test"); + await AddProjectsUnderDirectoryToSolutionFile(slnFile, moduleSrcFolder, $"modules/{ModuleName}"); + await AddProjectsUnderDirectoryToSolutionFile(slnFile, moduleTestFolder, $"test/{ModuleName}.Tests"); + } - await AddProjectsUnderDirectoryToSolutionFile(slnFile, moduleSrcFolder, $"modules/{ModuleName}"); - await AddProjectsUnderDirectoryToSolutionFile(slnFile, moduleTestFolder, $"test/{ModuleName}.Tests"); - } + private async Task AddProjectsUnderDirectoryToSolutionFile( + string slnFile, + string directory, + string slnTargetFolder) + { + var projects = Directory.GetFiles(directory, "*.csproj", SearchOption.AllDirectories); - private async Task AddProjectsUnderDirectoryToSolutionFile( - string slnFile, - string directory, - string slnTargetFolder) + foreach (var project in projects) { - var projects = Directory.GetFiles(directory, "*.csproj", SearchOption.AllDirectories); - - foreach (var project in projects) - { - await _dotnetSlnFileModifierService.AddProjectAsync(slnFile, project, slnTargetFolder); - } + await _dotnetSlnFileModifierService.AddProjectAsync(slnFile, project, slnTargetFolder); } } } diff --git a/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Xml/XmlFileManagerBase.cs b/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Xml/XmlFileManagerBase.cs index 74eb5379c2..e9066743c1 100644 --- a/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Xml/XmlFileManagerBase.cs +++ b/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Xml/XmlFileManagerBase.cs @@ -6,46 +6,45 @@ using System.Xml; using System.Xml.Linq; using Volo.Abp.Threading; -namespace Volo.Abp.Studio.Xml +namespace Volo.Abp.Studio.Xml; + +public abstract class XmlFileManagerBase { - public abstract class XmlFileManagerBase - { - public IFileSystem FileSystem { get; set; } + public IFileSystem FileSystem { get; set; } - public ICancellationTokenProvider CancellationTokenProvider { get; set; } + public ICancellationTokenProvider CancellationTokenProvider { get; set; } - protected async Task GetXmlDocumentAsync(string filePath) + protected async Task GetXmlDocumentAsync(string filePath) + { + try { - try - { - var doc = new XmlDocument() { PreserveWhitespace = true }; - doc.Load(GenerateStreamFromString(await FileSystem.File.ReadAllTextAsync(filePath))); - return doc; - } - catch (Exception ex) - { - throw new AbpException($"Error while reading {filePath} as XML document.", innerException: ex); - } + var doc = new XmlDocument() { PreserveWhitespace = true }; + doc.Load(GenerateStreamFromString(await FileSystem.File.ReadAllTextAsync(filePath))); + return doc; } - - protected async Task SaveXmlDocumentAsync(string filePath, XmlDocument rootNode) + catch (Exception ex) { - await SaveFileContentAsync(filePath, XDocument.Parse(rootNode.OuterXml).ToString()); + throw new AbpException($"Error while reading {filePath} as XML document.", innerException: ex); } + } - protected async Task SaveFileContentAsync(string filePath, string content) - { - await FileSystem.File.WriteAllTextAsync(filePath, content, CancellationTokenProvider.Token); - } + protected async Task SaveXmlDocumentAsync(string filePath, XmlDocument rootNode) + { + await SaveFileContentAsync(filePath, XDocument.Parse(rootNode.OuterXml).ToString()); + } - private MemoryStream GenerateStreamFromString(string s) - { - var stream = new MemoryStream(); - var writer = new StreamWriter(stream); - writer.Write(s); - writer.Flush(); - stream.Position = 0; - return stream; - } + protected async Task SaveFileContentAsync(string filePath, string content) + { + await FileSystem.File.WriteAllTextAsync(filePath, content, CancellationTokenProvider.Token); + } + + private MemoryStream GenerateStreamFromString(string s) + { + var stream = new MemoryStream(); + var writer = new StreamWriter(stream); + writer.Write(s); + writer.Flush(); + stream.Position = 0; + return stream; } } diff --git a/studio/src/Volo.Abp.Studio.Domain.Shared/Volo/Abp/Studio/AbpStudioDomainSharedModule.cs b/studio/src/Volo.Abp.Studio.Domain.Shared/Volo/Abp/Studio/AbpStudioDomainSharedModule.cs index 9693bc2577..7a66f31fff 100644 --- a/studio/src/Volo.Abp.Studio.Domain.Shared/Volo/Abp/Studio/AbpStudioDomainSharedModule.cs +++ b/studio/src/Volo.Abp.Studio.Domain.Shared/Volo/Abp/Studio/AbpStudioDomainSharedModule.cs @@ -1,13 +1,12 @@ using Volo.Abp.Cli; using Volo.Abp.Modularity; -namespace Volo.Abp.Studio +namespace Volo.Abp.Studio; + +[DependsOn( + typeof(AbpCliCoreModule) +)] +public class AbpStudioDomainSharedModule : AbpModule { - [DependsOn( - typeof(AbpCliCoreModule) - )] - public class AbpStudioDomainSharedModule : AbpModule - { - } } diff --git a/studio/src/Volo.Abp.Studio.Domain.Shared/Volo/Abp/Studio/AbpStudioErrorCodes.cs b/studio/src/Volo.Abp.Studio.Domain.Shared/Volo/Abp/Studio/AbpStudioErrorCodes.cs index 32bc670c6e..6b4613d487 100644 --- a/studio/src/Volo.Abp.Studio.Domain.Shared/Volo/Abp/Studio/AbpStudioErrorCodes.cs +++ b/studio/src/Volo.Abp.Studio.Domain.Shared/Volo/Abp/Studio/AbpStudioErrorCodes.cs @@ -1,32 +1,31 @@ -namespace Volo.Abp.Studio +namespace Volo.Abp.Studio; + +public static class AbpStudioErrorCodes { - public static class AbpStudioErrorCodes - { - public const string SolutionAlreadyExists = "AbpStudio:SolutionAlreadyExists"; - public const string ModuleAlreadyExistsInTheSolution = "AbpStudio:ModuleAlreadyExistsInTheSolution"; - public const string ModuleFileAlreadyExists = "AbpStudio:ModuleFileAlreadyExists"; - public const string IncorrectFileFormat = "AbpStudio:IncorrectFileFormat"; - public const string ModuleNotFound = "AbpStudio:ModuleNotFound"; - public const string SolutionNotFound = "AbpStudio:SolutionNotFound"; - public const string ModuleNotSpecified = "AbpStudio:ModuleNotSpecified"; - public const string SolutionNotSpecified = "AbpStudio:SolutionNotSpecified"; - public const string ProjectAlreadyExistInTheModule = "AbpStudio:ProjectAlreadyExistInTheModule"; - public const string IncorrectSolutionFileFormat = "AbpStudio:IncorrectSolutionFileFormat"; - public const string FolderNotFound = "AbpStudio:FolderNotFound"; - public const string ProjectWithSameNameAlreadyExistInTheSolutionFile = "AbpStudio:ProjectWithSameNameAlreadyExistInTheSolutionFile"; - public const string UndefinedPackageTemplate = "AbpStudio:UndefinedPackageTemplate"; - public const string PackageTemplateNotSpecified = "AbpStudio:PackageTemplateNotSpecified"; - public const string PackageNameMustBeSpecified = "AbpStudio:PackageNameMustBeSpecified"; - public const string FileAlreadyExists = "AbpStudio:FileAlreadyExists"; - public const string PackageNotSpecified = "AbpStudio:PackageNotSpecified"; - public const string DbmsMustBeSpecified = "AbpStudio:DbmsMustBeSpecified"; - public const string UserNotLoggedIn = "AbpStudio:UserNotLoggedIn"; - public const string PackageAlreadyExist = "AbpStudio:PackageAlreadyExist"; - public const string AbpModuleFileNotFound = "AbpStudio:AbpModuleFileNotFound"; - public const string DllNotFound = "AbpStudio:DllNotFound"; - public const string PackageNotFound = "AbpStudio:PackageNotFound"; - public const string FileNotFound = "AbpStudio:FileNotFound"; - public const string IncorrectFolderName = "AbpStudio:IncorrectFolderName"; - public const string ModuleAlreadyInstalled = "AbpStudio:ModuleAlreadyInstalled"; - } + public const string SolutionAlreadyExists = "AbpStudio:SolutionAlreadyExists"; + public const string ModuleAlreadyExistsInTheSolution = "AbpStudio:ModuleAlreadyExistsInTheSolution"; + public const string ModuleFileAlreadyExists = "AbpStudio:ModuleFileAlreadyExists"; + public const string IncorrectFileFormat = "AbpStudio:IncorrectFileFormat"; + public const string ModuleNotFound = "AbpStudio:ModuleNotFound"; + public const string SolutionNotFound = "AbpStudio:SolutionNotFound"; + public const string ModuleNotSpecified = "AbpStudio:ModuleNotSpecified"; + public const string SolutionNotSpecified = "AbpStudio:SolutionNotSpecified"; + public const string ProjectAlreadyExistInTheModule = "AbpStudio:ProjectAlreadyExistInTheModule"; + public const string IncorrectSolutionFileFormat = "AbpStudio:IncorrectSolutionFileFormat"; + public const string FolderNotFound = "AbpStudio:FolderNotFound"; + public const string ProjectWithSameNameAlreadyExistInTheSolutionFile = "AbpStudio:ProjectWithSameNameAlreadyExistInTheSolutionFile"; + public const string UndefinedPackageTemplate = "AbpStudio:UndefinedPackageTemplate"; + public const string PackageTemplateNotSpecified = "AbpStudio:PackageTemplateNotSpecified"; + public const string PackageNameMustBeSpecified = "AbpStudio:PackageNameMustBeSpecified"; + public const string FileAlreadyExists = "AbpStudio:FileAlreadyExists"; + public const string PackageNotSpecified = "AbpStudio:PackageNotSpecified"; + public const string DbmsMustBeSpecified = "AbpStudio:DbmsMustBeSpecified"; + public const string UserNotLoggedIn = "AbpStudio:UserNotLoggedIn"; + public const string PackageAlreadyExist = "AbpStudio:PackageAlreadyExist"; + public const string AbpModuleFileNotFound = "AbpStudio:AbpModuleFileNotFound"; + public const string DllNotFound = "AbpStudio:DllNotFound"; + public const string PackageNotFound = "AbpStudio:PackageNotFound"; + public const string FileNotFound = "AbpStudio:FileNotFound"; + public const string IncorrectFolderName = "AbpStudio:IncorrectFolderName"; + public const string ModuleAlreadyInstalled = "AbpStudio:ModuleAlreadyInstalled"; } diff --git a/studio/src/Volo.Abp.Studio.Domain.Shared/Volo/Abp/Studio/Modules/ModuleConsts.cs b/studio/src/Volo.Abp.Studio.Domain.Shared/Volo/Abp/Studio/Modules/ModuleConsts.cs index b2c9733720..f2e17d63bd 100644 --- a/studio/src/Volo.Abp.Studio.Domain.Shared/Volo/Abp/Studio/Modules/ModuleConsts.cs +++ b/studio/src/Volo.Abp.Studio.Domain.Shared/Volo/Abp/Studio/Modules/ModuleConsts.cs @@ -1,18 +1,17 @@ -namespace Volo.Abp.Studio.Modules +namespace Volo.Abp.Studio.Modules; + +public static class ModuleConsts { - public static class ModuleConsts - { - public const string FileExtension = ".abpmdl.json"; - public const string InstallerPackagePostfix = ".Installer"; - public const string SourceCorePackagePostfix = ".SourceCode"; - public const string Packages = "packages"; + public const string FileExtension = ".abpmdl.json"; + public const string InstallerPackagePostfix = ".Installer"; + public const string SourceCorePackagePostfix = ".SourceCode"; + public const string Packages = "packages"; - public static class Layers //TODO: Moving to PackageTypes - { - public const string Domain = "lib.domain"; - public const string DomainShared = "lib.domain.shared"; - public const string Application = "lib.application"; - public const string ApplicationContracts = "lib.application.contracts"; - } + public static class Layers //TODO: Moving to PackageTypes + { + public const string Domain = "lib.domain"; + public const string DomainShared = "lib.domain.shared"; + public const string Application = "lib.application"; + public const string ApplicationContracts = "lib.application.contracts"; } } diff --git a/studio/src/Volo.Abp.Studio.Domain.Shared/Volo/Abp/Studio/Package/PackageReferenceCompatibility.cs b/studio/src/Volo.Abp.Studio.Domain.Shared/Volo/Abp/Studio/Package/PackageReferenceCompatibility.cs index 70c51c36e2..cfb9c9da69 100644 --- a/studio/src/Volo.Abp.Studio.Domain.Shared/Volo/Abp/Studio/Package/PackageReferenceCompatibility.cs +++ b/studio/src/Volo.Abp.Studio.Domain.Shared/Volo/Abp/Studio/Package/PackageReferenceCompatibility.cs @@ -1,13 +1,12 @@ -namespace Volo.Abp.Studio.Packages.Referencing +namespace Volo.Abp.Studio.Packages.Referencing; + +public enum PackageReferenceCompatibility { - public enum PackageReferenceCompatibility - { - Unknown, - DDD_Compatible, - Compatible, - TestProject, - IndirectlyReferenced, - DirectlyReferenced, - CircularReference - } + Unknown, + DDD_Compatible, + Compatible, + TestProject, + IndirectlyReferenced, + DirectlyReferenced, + CircularReference } diff --git a/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/AbpStudioModuleInstallerAbstractionsModule.cs b/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/AbpStudioModuleInstallerAbstractionsModule.cs index c9e68ec940..dc634383ee 100644 --- a/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/AbpStudioModuleInstallerAbstractionsModule.cs +++ b/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/AbpStudioModuleInstallerAbstractionsModule.cs @@ -1,13 +1,12 @@ using Volo.Abp.Modularity; using Volo.Abp.Studio.Analyzing; -namespace Volo.Abp.Studio +namespace Volo.Abp.Studio; + +[DependsOn( + typeof(AbpStudioAnalyzingAbstractionsModule) +)] +public class AbpStudioModuleInstallerAbstractionsModule : AbpModule { - [DependsOn( - typeof(AbpStudioAnalyzingAbstractionsModule) - )] - public class AbpStudioModuleInstallerAbstractionsModule : AbpModule - { - } } diff --git a/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/Analyzing/AnalyzingOptions.cs b/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/Analyzing/AnalyzingOptions.cs index 7296dfce74..48f88ea6a6 100644 --- a/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/Analyzing/AnalyzingOptions.cs +++ b/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/Analyzing/AnalyzingOptions.cs @@ -1,45 +1,44 @@ using JetBrains.Annotations; -namespace Volo.Abp.Studio.Analyzing +namespace Volo.Abp.Studio.Analyzing; + +public class AnalyzingOptions { - public class AnalyzingOptions + public bool Force { get; set; } = false; + + [CanBeNull] + public string AnalyzeConfigurationFile { get; set; } + + [CanBeNull] + public string SettingNamePrefix { get; set; } + + [CanBeNull] + public string FeatureNamePrefix { get; set; } + + // Combines two options + // The second option has more priority + public static AnalyzingOptions Combine([CanBeNull] AnalyzingOptions first, [CanBeNull] AnalyzingOptions second) { - public bool Force { get; set; } = false; - - [CanBeNull] - public string AnalyzeConfigurationFile { get; set; } - - [CanBeNull] - public string SettingNamePrefix { get; set; } - - [CanBeNull] - public string FeatureNamePrefix { get; set; } - - // Combines two options - // The second option has more priority - public static AnalyzingOptions Combine([CanBeNull] AnalyzingOptions first, [CanBeNull] AnalyzingOptions second) + if (second == null && first == null) { - if (second == null && first == null) - { - return new AnalyzingOptions(); - } - - if (second == null) - { - return first; - } - - if (first == null) - { - return second; - } - - return new AnalyzingOptions - { - AnalyzeConfigurationFile = second.AnalyzeConfigurationFile ?? first.AnalyzeConfigurationFile, - SettingNamePrefix = second.SettingNamePrefix ?? first.SettingNamePrefix, - FeatureNamePrefix = second.FeatureNamePrefix ?? first.FeatureNamePrefix - }; + return new AnalyzingOptions(); } + + if (second == null) + { + return first; + } + + if (first == null) + { + return second; + } + + return new AnalyzingOptions + { + AnalyzeConfigurationFile = second.AnalyzeConfigurationFile ?? first.AnalyzeConfigurationFile, + SettingNamePrefix = second.SettingNamePrefix ?? first.SettingNamePrefix, + FeatureNamePrefix = second.FeatureNamePrefix ?? first.FeatureNamePrefix + }; } -} \ No newline at end of file +} diff --git a/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/ModuleInstalling/EfCoreConfigurationMethodDeclaration.cs b/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/ModuleInstalling/EfCoreConfigurationMethodDeclaration.cs index 5b69a49cbd..ac8dac7c79 100644 --- a/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/ModuleInstalling/EfCoreConfigurationMethodDeclaration.cs +++ b/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/ModuleInstalling/EfCoreConfigurationMethodDeclaration.cs @@ -1,18 +1,17 @@ using JetBrains.Annotations; -namespace Volo.Abp.Studio.ModuleInstalling -{ - public class EfCoreConfigurationMethodDeclaration - { - public string Namespace { get; } +namespace Volo.Abp.Studio.ModuleInstalling; - public string MethodName { get; } +public class EfCoreConfigurationMethodDeclaration +{ + public string Namespace { get; } - public EfCoreConfigurationMethodDeclaration([NotNull] string nameSpace, [NotNull] string methodName) - { - Namespace = Check.NotNullOrEmpty(nameSpace, nameof(nameSpace)); - MethodName = Check.NotNullOrEmpty(methodName, nameof(methodName)); - } + public string MethodName { get; } + public EfCoreConfigurationMethodDeclaration([NotNull] string nameSpace, [NotNull] string methodName) + { + Namespace = Check.NotNullOrEmpty(nameSpace, nameof(nameSpace)); + MethodName = Check.NotNullOrEmpty(methodName, nameof(methodName)); } + } diff --git a/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/ModuleInstalling/IModuleInstallingPipelineBuilder.cs b/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/ModuleInstalling/IModuleInstallingPipelineBuilder.cs index 1112328675..1ec35b5300 100644 --- a/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/ModuleInstalling/IModuleInstallingPipelineBuilder.cs +++ b/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/ModuleInstalling/IModuleInstallingPipelineBuilder.cs @@ -1,9 +1,8 @@ using System.Threading.Tasks; -namespace Volo.Abp.Studio.ModuleInstalling +namespace Volo.Abp.Studio.ModuleInstalling; + +public interface IModuleInstallingPipelineBuilder { - public interface IModuleInstallingPipelineBuilder - { - Task BuildAsync(ModuleInstallingContext context); - } + Task BuildAsync(ModuleInstallingContext context); } diff --git a/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/ModuleInstalling/ModuleInstallingContext.cs b/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/ModuleInstalling/ModuleInstallingContext.cs index 350359c551..83df73196a 100644 --- a/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/ModuleInstalling/ModuleInstallingContext.cs +++ b/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/ModuleInstalling/ModuleInstallingContext.cs @@ -4,86 +4,85 @@ using System.IO; using JetBrains.Annotations; using Volo.Abp.Studio.Packages; -namespace Volo.Abp.Studio.ModuleInstalling +namespace Volo.Abp.Studio.ModuleInstalling; + +public class ModuleInstallingContext { - public class ModuleInstallingContext - { - public string ModuleName { get; set; } + public string ModuleName { get; set; } - public string TargetModule { get; set; } + public string TargetModule { get; set; } - public bool WithSourceCode { get; set; } + public bool WithSourceCode { get; set; } - public bool AddToSolutionFile { get; set; } + public bool AddToSolutionFile { get; set; } - public string Version { get; set; } + public string Version { get; set; } - public List EfCoreConfigurationMethodDeclarations { get; } + public List EfCoreConfigurationMethodDeclarations { get; } - public List TargetModulePackages { get; protected set; } + public List TargetModulePackages { get; protected set; } - public List ReferenceModulePackages { get; protected set; } + public List ReferenceModulePackages { get; protected set; } - public Dictionary Options { get; } + public Dictionary Options { get; } - public IServiceProvider ServiceProvider { get; } + public IServiceProvider ServiceProvider { get; } - public ModuleInstallingContext( - string moduleName, - string targetModule, - bool withSourceCode, - bool addToSolutionFile, - string version, - Dictionary options, - IServiceProvider serviceProvider) - { - ModuleName = moduleName; - TargetModule = targetModule; - WithSourceCode = withSourceCode; - AddToSolutionFile = addToSolutionFile; - Version = version; - Options = options; + public ModuleInstallingContext( + string moduleName, + string targetModule, + bool withSourceCode, + bool addToSolutionFile, + string version, + Dictionary options, + IServiceProvider serviceProvider) + { + ModuleName = moduleName; + TargetModule = targetModule; + WithSourceCode = withSourceCode; + AddToSolutionFile = addToSolutionFile; + Version = version; + Options = options; - TargetModulePackages = new List(); - ReferenceModulePackages = new List(); + TargetModulePackages = new List(); + ReferenceModulePackages = new List(); - EfCoreConfigurationMethodDeclarations = new List(); + EfCoreConfigurationMethodDeclarations = new List(); - ServiceProvider = Check.NotNull(serviceProvider, nameof(serviceProvider)); - } + ServiceProvider = Check.NotNull(serviceProvider, nameof(serviceProvider)); + } - public void AddEfCoreConfigurationMethodDeclaration(params EfCoreConfigurationMethodDeclaration[] methodNames) + public void AddEfCoreConfigurationMethodDeclaration(params EfCoreConfigurationMethodDeclaration[] methodNames) + { + foreach (var methodName in methodNames) { - foreach (var methodName in methodNames) - { - Check.NotNull(methodName, nameof(methodName)); + Check.NotNull(methodName, nameof(methodName)); - EfCoreConfigurationMethodDeclarations.Add(methodName); - } + EfCoreConfigurationMethodDeclarations.Add(methodName); } + } - public void SetReferenceModulePackages([NotNull] List referenceModulePackages) - { - Check.NotNull(referenceModulePackages, nameof(referenceModulePackages)); + public void SetReferenceModulePackages([NotNull] List referenceModulePackages) + { + Check.NotNull(referenceModulePackages, nameof(referenceModulePackages)); - ReferenceModulePackages = referenceModulePackages; - } + ReferenceModulePackages = referenceModulePackages; + } - public void SetTargetModulePackages([NotNull] List targetModulePackages) - { - Check.NotNull(targetModulePackages, nameof(targetModulePackages)); + public void SetTargetModulePackages([NotNull] List targetModulePackages) + { + Check.NotNull(targetModulePackages, nameof(targetModulePackages)); - TargetModulePackages = targetModulePackages; - } + TargetModulePackages = targetModulePackages; + } - public string GetTargetSourceCodeFolder() - { - return CalculateTargetSourceCodeFolder(TargetModule, ModuleName); - } + public string GetTargetSourceCodeFolder() + { + return CalculateTargetSourceCodeFolder(TargetModule, ModuleName); + } - public static string CalculateTargetSourceCodeFolder(string targetModule, string moduleName) - { - return Path.Combine(Path.GetDirectoryName(targetModule), "modules", moduleName); - } + public static string CalculateTargetSourceCodeFolder(string targetModule, string moduleName) + { + return Path.Combine(Path.GetDirectoryName(targetModule), "modules", moduleName); } } diff --git a/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/ModuleInstalling/ModuleInstallingPipeline.cs b/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/ModuleInstalling/ModuleInstallingPipeline.cs index 4582a4ac8b..3d678a11b4 100644 --- a/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/ModuleInstalling/ModuleInstallingPipeline.cs +++ b/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/ModuleInstalling/ModuleInstallingPipeline.cs @@ -3,51 +3,50 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -namespace Volo.Abp.Studio.ModuleInstalling +namespace Volo.Abp.Studio.ModuleInstalling; + +public class ModuleInstallingPipeline { - public class ModuleInstallingPipeline - { - public ModuleInstallingContext Context { get; } + public ModuleInstallingContext Context { get; } - public List Steps { get; } + public List Steps { get; } - public ModuleInstallingPipeline(ModuleInstallingContext context) - { - Context = context; - Steps = new List(); - } + public ModuleInstallingPipeline(ModuleInstallingContext context) + { + Context = context; + Steps = new List(); + } - public async Task ExecuteAsync() + public async Task ExecuteAsync() + { + foreach (var step in Steps) { - foreach (var step in Steps) - { - await step.ExecuteAsync(Context); - } + await step.ExecuteAsync(Context); } + } - public void Add(ModuleInstallingPipelineStep step) - { - Steps.Add(step); - } + public void Add(ModuleInstallingPipelineStep step) + { + Steps.Add(step); + } - public void Remove(Type stepType) - { - Steps.RemoveAll(step => step.GetType() == stepType); - } + public void Remove(Type stepType) + { + Steps.RemoveAll(step => step.GetType() == stepType); + } - public void Replace(Type stepType, ModuleInstallingPipelineStep step) - { - Steps.ReplaceOne(step => step.GetType() == stepType , step); - } + public void Replace(Type stepType, ModuleInstallingPipelineStep step) + { + Steps.ReplaceOne(step => step.GetType() == stepType, step); + } - public void InsertAfter(Type stepType, ModuleInstallingPipelineStep step) - { - Steps.InsertAfter(step => step.GetType() == stepType , step); - } + public void InsertAfter(Type stepType, ModuleInstallingPipelineStep step) + { + Steps.InsertAfter(step => step.GetType() == stepType, step); + } - public void InsertBefore(Type stepType, ModuleInstallingPipelineStep step) - { - Steps.InsertBefore(step => step.GetType() == stepType , step); - } + public void InsertBefore(Type stepType, ModuleInstallingPipelineStep step) + { + Steps.InsertBefore(step => step.GetType() == stepType, step); } } diff --git a/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/ModuleInstalling/ModuleInstallingPipelineStep.cs b/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/ModuleInstalling/ModuleInstallingPipelineStep.cs index b98d32b32a..40b31c725c 100644 --- a/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/ModuleInstalling/ModuleInstallingPipelineStep.cs +++ b/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/ModuleInstalling/ModuleInstallingPipelineStep.cs @@ -1,9 +1,8 @@ using System.Threading.Tasks; -namespace Volo.Abp.Studio.ModuleInstalling +namespace Volo.Abp.Studio.ModuleInstalling; + +public abstract class ModuleInstallingPipelineStep { - public abstract class ModuleInstallingPipelineStep - { - public abstract Task ExecuteAsync(ModuleInstallingContext context); - } + public abstract Task ExecuteAsync(ModuleInstallingContext context); } diff --git a/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/ModuleInstalling/Options/IModuleInstallingOptionProvider.cs b/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/ModuleInstalling/Options/IModuleInstallingOptionProvider.cs index ac557d5a51..8c15f8a037 100644 --- a/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/ModuleInstalling/Options/IModuleInstallingOptionProvider.cs +++ b/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/ModuleInstalling/Options/IModuleInstallingOptionProvider.cs @@ -1,10 +1,9 @@ using System.Collections.Generic; using System.Threading.Tasks; -namespace Volo.Abp.Studio.ModuleInstalling.Options +namespace Volo.Abp.Studio.ModuleInstalling.Options; + +public interface IModuleInstallingOptionProvider { - public interface IModuleInstallingOptionProvider - { - Task> GetAsync(); - } + Task> GetAsync(); } diff --git a/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/ModuleInstalling/Options/ModuleInstallingOption.cs b/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/ModuleInstalling/Options/ModuleInstallingOption.cs index f8725e1e93..d16af1b882 100644 --- a/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/ModuleInstalling/Options/ModuleInstallingOption.cs +++ b/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/ModuleInstalling/Options/ModuleInstallingOption.cs @@ -1,28 +1,27 @@ using System.Collections.Generic; using JetBrains.Annotations; -namespace Volo.Abp.Studio.ModuleInstalling.Options +namespace Volo.Abp.Studio.ModuleInstalling.Options; + +public class ModuleInstallingOption { - public class ModuleInstallingOption - { - public string Name { get; set; } + public string Name { get; set; } - public string Description { get; set; } + public string Description { get; set; } - public ModuleInstallingOptionType Type { get; set; } + public ModuleInstallingOptionType Type { get; set; } - public Dictionary Values { get; set; } + public Dictionary Values { get; set; } - public ModuleInstallingOption( - [NotNull] string name, - [NotNull] string description, - [NotNull] ModuleInstallingOptionType type, - [CanBeNull] Dictionary values = null) - { - Name = Check.NotNullOrWhiteSpace(name, nameof(name)); - Description = Check.NotNullOrWhiteSpace(description, nameof(description)); - Type = type; - Values = values ?? new Dictionary(); - } + public ModuleInstallingOption( + [NotNull] string name, + [NotNull] string description, + [NotNull] ModuleInstallingOptionType type, + [CanBeNull] Dictionary values = null) + { + Name = Check.NotNullOrWhiteSpace(name, nameof(name)); + Description = Check.NotNullOrWhiteSpace(description, nameof(description)); + Type = type; + Values = values ?? new Dictionary(); } -} \ No newline at end of file +} diff --git a/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/ModuleInstalling/Options/ModuleInstallingOptionType.cs b/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/ModuleInstalling/Options/ModuleInstallingOptionType.cs index 140b1339df..e0305fc872 100644 --- a/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/ModuleInstalling/Options/ModuleInstallingOptionType.cs +++ b/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/ModuleInstalling/Options/ModuleInstallingOptionType.cs @@ -1,10 +1,9 @@ -namespace Volo.Abp.Studio.ModuleInstalling.Options +namespace Volo.Abp.Studio.ModuleInstalling.Options; + +public enum ModuleInstallingOptionType { - public enum ModuleInstallingOptionType - { - NotSpecified, - Checkbox, - FreeText, - ComboBox - } -} \ No newline at end of file + NotSpecified, + Checkbox, + FreeText, + ComboBox +} diff --git a/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/Package/PackageConsts.cs b/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/Package/PackageConsts.cs index 05a7abb16e..dff57b316b 100644 --- a/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/Package/PackageConsts.cs +++ b/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/Package/PackageConsts.cs @@ -1,9 +1,8 @@ -namespace Volo.Abp.Studio.Packages +namespace Volo.Abp.Studio.Packages; + +public static class PackageConsts { - public static class PackageConsts - { - public const string FileExtension = ".abppkg.json"; + public const string FileExtension = ".abppkg.json"; - public const string RoleProperty = "role"; - } + public const string RoleProperty = "role"; } diff --git a/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/Package/PackageHelper.cs b/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/Package/PackageHelper.cs index daae8d2f77..a4fb995c0b 100644 --- a/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/Package/PackageHelper.cs +++ b/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/Package/PackageHelper.cs @@ -2,17 +2,16 @@ using System.IO; using JetBrains.Annotations; -namespace Volo.Abp.Studio.Packages +namespace Volo.Abp.Studio.Packages; + +public static class PackageHelper { - public static class PackageHelper + public static string GetNameFromPath([NotNull] string path) { - public static string GetNameFromPath([NotNull] string path) - { - Check.NotNullOrWhiteSpace(path, nameof(path)); + Check.NotNullOrWhiteSpace(path, nameof(path)); - return Path - .GetFileName(path) - .RemovePostFix(StringComparison.OrdinalIgnoreCase, PackageConsts.FileExtension); - } + return Path + .GetFileName(path) + .RemovePostFix(StringComparison.OrdinalIgnoreCase, PackageConsts.FileExtension); } } diff --git a/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/Package/PackageInfo.cs b/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/Package/PackageInfo.cs index 0a6e939ded..9bcb4e3d0a 100644 --- a/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/Package/PackageInfo.cs +++ b/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/Package/PackageInfo.cs @@ -1,27 +1,26 @@ using JetBrains.Annotations; using Volo.Abp.Studio.Analyzing; -namespace Volo.Abp.Studio.Packages +namespace Volo.Abp.Studio.Packages; + +public class PackageInfo { - public class PackageInfo - { - [NotNull] - public string Path { get; } - - [NotNull] - public string Name { get; } - - [CanBeNull] - public string Role { get; } - - [CanBeNull] - public AnalyzingOptions AnalyzingOptions { get; set; } + [NotNull] + public string Path { get; } + + [NotNull] + public string Name { get; } - public PackageInfo([NotNull] string path, [CanBeNull] string role) - { - Path = Check.NotNullOrWhiteSpace(path, nameof(path)); - Name = PackageHelper.GetNameFromPath(path); - Role = role; - } + [CanBeNull] + public string Role { get; } + + [CanBeNull] + public AnalyzingOptions AnalyzingOptions { get; set; } + + public PackageInfo([NotNull] string path, [CanBeNull] string role) + { + Path = Check.NotNullOrWhiteSpace(path, nameof(path)); + Name = PackageHelper.GetNameFromPath(path); + Role = role; } -} \ No newline at end of file +} diff --git a/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/Package/PackageInfoWithAnalyze.cs b/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/Package/PackageInfoWithAnalyze.cs index efb7950fc2..6b4ced569d 100644 --- a/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/Package/PackageInfoWithAnalyze.cs +++ b/studio/src/Volo.Abp.Studio.ModuleInstaller.Abstractions/Volo/Abp/Studio/Package/PackageInfoWithAnalyze.cs @@ -1,28 +1,27 @@ using JetBrains.Annotations; using Volo.Abp.Studio.Analyzing.Models; -namespace Volo.Abp.Studio.Packages +namespace Volo.Abp.Studio.Packages; + +public class PackageInfoWithAnalyze { - public class PackageInfoWithAnalyze - { - [NotNull] - public string Path { get; } + [NotNull] + public string Path { get; } - [NotNull] - public string Name { get; } + [NotNull] + public string Name { get; } - [CanBeNull] - public string Role { get; } + [CanBeNull] + public string Role { get; } - [NotNull] - public PackageModel Analyze { get; } + [NotNull] + public PackageModel Analyze { get; } - public PackageInfoWithAnalyze([NotNull] string path, [CanBeNull] string role, [NotNull] PackageModel analyze) - { - Path = Check.NotNullOrWhiteSpace(path, nameof(path)); - Name = PackageHelper.GetNameFromPath(path); - Role = role; - Analyze = Check.NotNull(analyze, nameof(analyze)); - } + public PackageInfoWithAnalyze([NotNull] string path, [CanBeNull] string role, [NotNull] PackageModel analyze) + { + Path = Check.NotNullOrWhiteSpace(path, nameof(path)); + Name = PackageHelper.GetNameFromPath(path); + Role = role; + Analyze = Check.NotNull(analyze, nameof(analyze)); } } diff --git a/studio/src/Volo.Abp.Studio.ModuleInstaller/Volo/Abp/Studio/AbpStudioModuleInstallerModule.cs b/studio/src/Volo.Abp.Studio.ModuleInstaller/Volo/Abp/Studio/AbpStudioModuleInstallerModule.cs index 3450ab8a5c..627736a06d 100644 --- a/studio/src/Volo.Abp.Studio.ModuleInstaller/Volo/Abp/Studio/AbpStudioModuleInstallerModule.cs +++ b/studio/src/Volo.Abp.Studio.ModuleInstaller/Volo/Abp/Studio/AbpStudioModuleInstallerModule.cs @@ -1,16 +1,15 @@ using Volo.Abp.Modularity; -namespace Volo.Abp.Studio +namespace Volo.Abp.Studio; + +[DependsOn( + typeof(AbpStudioDomainCommonServicesModule), + typeof(AbpStudioModuleInstallerAbstractionsModule) + )] +public class AbpStudioModuleInstallerModule : AbpModule { - [DependsOn( - typeof(AbpStudioDomainCommonServicesModule), - typeof(AbpStudioModuleInstallerAbstractionsModule) - )] - public class AbpStudioModuleInstallerModule : AbpModule + public override void ConfigureServices(ServiceConfigurationContext context) { - public override void ConfigureServices(ServiceConfigurationContext context) - { - } } } diff --git a/studio/src/Volo.Abp.Studio.ModuleInstaller/Volo/Abp/Studio/ModuleInstalling/ModuleInstallingPipelineBuilderBase.cs b/studio/src/Volo.Abp.Studio.ModuleInstaller/Volo/Abp/Studio/ModuleInstalling/ModuleInstallingPipelineBuilderBase.cs index ba78031686..e03a67f428 100644 --- a/studio/src/Volo.Abp.Studio.ModuleInstaller/Volo/Abp/Studio/ModuleInstalling/ModuleInstallingPipelineBuilderBase.cs +++ b/studio/src/Volo.Abp.Studio.ModuleInstaller/Volo/Abp/Studio/ModuleInstalling/ModuleInstallingPipelineBuilderBase.cs @@ -1,32 +1,31 @@ using System.Linq; using Volo.Abp.Studio.ModuleInstalling.Steps; -namespace Volo.Abp.Studio.ModuleInstalling +namespace Volo.Abp.Studio.ModuleInstalling; + +public abstract class ModuleInstallingPipelineBuilderBase { - public abstract class ModuleInstallingPipelineBuilderBase + protected ModuleInstallingPipeline GetBasePipeline(ModuleInstallingContext context) { - protected ModuleInstallingPipeline GetBasePipeline(ModuleInstallingContext context) + var pipeline = new ModuleInstallingPipeline(context); + + if (context.WithSourceCode) { - var pipeline = new ModuleInstallingPipeline(context); + pipeline.Add(new SourceCodeDownloadStep()); - if (context.WithSourceCode) + if (context.AddToSolutionFile) { - pipeline.Add(new SourceCodeDownloadStep()); - - if (context.AddToSolutionFile) - { - pipeline.Add(new AddToSolutionFileStep()); - } + pipeline.Add(new AddToSolutionFileStep()); } + } - pipeline.Add(new PackageReferencingStep()); + pipeline.Add(new PackageReferencingStep()); - if (context.EfCoreConfigurationMethodDeclarations.Any()) - { - pipeline.Add(new AddEfCoreConfigurationMethodStep()); - } - - return pipeline; + if (context.EfCoreConfigurationMethodDeclarations.Any()) + { + pipeline.Add(new AddEfCoreConfigurationMethodStep()); } + + return pipeline; } } diff --git a/studio/src/Volo.Abp.Studio.ModuleInstaller/Volo/Abp/Studio/ModuleInstalling/Steps/AddEfCoreConfigurationMethodStep.cs b/studio/src/Volo.Abp.Studio.ModuleInstaller/Volo/Abp/Studio/ModuleInstalling/Steps/AddEfCoreConfigurationMethodStep.cs index 54d6ec2cee..05e0d2073c 100644 --- a/studio/src/Volo.Abp.Studio.ModuleInstaller/Volo/Abp/Studio/ModuleInstalling/Steps/AddEfCoreConfigurationMethodStep.cs +++ b/studio/src/Volo.Abp.Studio.ModuleInstaller/Volo/Abp/Studio/ModuleInstalling/Steps/AddEfCoreConfigurationMethodStep.cs @@ -9,35 +9,34 @@ using Volo.Abp.Studio.Packages; using Volo.Abp.Studio.Packages.Modifying; using Volo.Abp.Studio.Analyzing.Models.Module; -namespace Volo.Abp.Studio.ModuleInstalling.Steps +namespace Volo.Abp.Studio.ModuleInstalling.Steps; + +public class AddEfCoreConfigurationMethodStep : ModuleInstallingPipelineStep { - public class AddEfCoreConfigurationMethodStep : ModuleInstallingPipelineStep + public override async Task ExecuteAsync(ModuleInstallingContext context) { - public override async Task ExecuteAsync(ModuleInstallingContext context) - { - var efCoreProject = context.TargetModulePackages.FirstOrDefault(p => p.Role == PackageTypes.EntityFrameworkCore); + var efCoreProject = context.TargetModulePackages.FirstOrDefault(p => p.Role == PackageTypes.EntityFrameworkCore); - if (efCoreProject == null) - { - return; - } + if (efCoreProject == null) + { + return; + } - var efCoreProjectCsprojPath = efCoreProject.Path.RemovePostFix(PackageConsts.FileExtension) + ".csproj"; + var efCoreProjectCsprojPath = efCoreProject.Path.RemovePostFix(PackageConsts.FileExtension) + ".csproj"; - var _derivedClassFinder = context.ServiceProvider.GetRequiredService(); - var _dbContextFileBuilderConfigureAdder = context.ServiceProvider.GetRequiredService(); + var _derivedClassFinder = context.ServiceProvider.GetRequiredService(); + var _dbContextFileBuilderConfigureAdder = context.ServiceProvider.GetRequiredService(); - var dbContextFile = _derivedClassFinder.Find(efCoreProjectCsprojPath, "AbpDbContext").FirstOrDefault(); + var dbContextFile = _derivedClassFinder.Find(efCoreProjectCsprojPath, "AbpDbContext").FirstOrDefault(); - if (dbContextFile == null) - { - return; - } + if (dbContextFile == null) + { + return; + } - foreach (var declaration in context.EfCoreConfigurationMethodDeclarations) - { - _dbContextFileBuilderConfigureAdder.Add(dbContextFile, declaration.Namespace + ":" + declaration.MethodName); - } + foreach (var declaration in context.EfCoreConfigurationMethodDeclarations) + { + _dbContextFileBuilderConfigureAdder.Add(dbContextFile, declaration.Namespace + ":" + declaration.MethodName); } } } diff --git a/studio/src/Volo.Abp.Studio.ModuleInstaller/Volo/Abp/Studio/ModuleInstalling/Steps/AddToSolutionFileStep.cs b/studio/src/Volo.Abp.Studio.ModuleInstaller/Volo/Abp/Studio/ModuleInstalling/Steps/AddToSolutionFileStep.cs index 2739a62eaf..4d28f99089 100644 --- a/studio/src/Volo.Abp.Studio.ModuleInstaller/Volo/Abp/Studio/ModuleInstalling/Steps/AddToSolutionFileStep.cs +++ b/studio/src/Volo.Abp.Studio.ModuleInstaller/Volo/Abp/Studio/ModuleInstalling/Steps/AddToSolutionFileStep.cs @@ -2,15 +2,14 @@ using Microsoft.Extensions.DependencyInjection; using Volo.Abp.Studio.Solution; -namespace Volo.Abp.Studio.ModuleInstalling.Steps +namespace Volo.Abp.Studio.ModuleInstalling.Steps; + +public class AddToSolutionFileStep : ModuleInstallingPipelineStep { - public class AddToSolutionFileStep : ModuleInstallingPipelineStep + public override async Task ExecuteAsync(ModuleInstallingContext context) { - public override async Task ExecuteAsync(ModuleInstallingContext context) - { - var _solutionFileModuleAdder = context.ServiceProvider.GetRequiredService(); + var _solutionFileModuleAdder = context.ServiceProvider.GetRequiredService(); - await _solutionFileModuleAdder.AddAsync(context.TargetModule, context.ModuleName); - } + await _solutionFileModuleAdder.AddAsync(context.TargetModule, context.ModuleName); } } diff --git a/studio/src/Volo.Abp.Studio.ModuleInstaller/Volo/Abp/Studio/ModuleInstalling/Steps/PackageReferencingStep.cs b/studio/src/Volo.Abp.Studio.ModuleInstaller/Volo/Abp/Studio/ModuleInstalling/Steps/PackageReferencingStep.cs index bec9da5a1b..02ba1063fb 100644 --- a/studio/src/Volo.Abp.Studio.ModuleInstaller/Volo/Abp/Studio/ModuleInstalling/Steps/PackageReferencingStep.cs +++ b/studio/src/Volo.Abp.Studio.ModuleInstaller/Volo/Abp/Studio/ModuleInstalling/Steps/PackageReferencingStep.cs @@ -8,95 +8,94 @@ using Volo.Abp.Studio.Packages; using Volo.Abp.Studio.Packages.Modifying; using Volo.Abp.Studio.Analyzing.Models.Module; -namespace Volo.Abp.Studio.ModuleInstalling.Steps +namespace Volo.Abp.Studio.ModuleInstalling.Steps; + +public class PackageReferencingStep : ModuleInstallingPipelineStep { - public class PackageReferencingStep : ModuleInstallingPipelineStep + public override async Task ExecuteAsync(ModuleInstallingContext context) { - public override async Task ExecuteAsync(ModuleInstallingContext context) + var _abpModuleFileManager = context.ServiceProvider.GetRequiredService(); + + foreach (var referencePackage in context.ReferenceModulePackages) { - var _abpModuleFileManager = context.ServiceProvider.GetRequiredService(); + var targetPackages = GetTargetPackages(context.TargetModulePackages, referencePackage); - foreach (var referencePackage in context.ReferenceModulePackages) + foreach (var targetPackage in targetPackages) { - var targetPackages = GetTargetPackages(context.TargetModulePackages, referencePackage); + await AddReferenceAsync(context, targetPackage, referencePackage); - foreach (var targetPackage in targetPackages) - { - await AddReferenceAsync(context, targetPackage, referencePackage); + var targetAbpModulePath = FindAbpModuleFile(targetPackage.Path); - var targetAbpModulePath = FindAbpModuleFile(targetPackage.Path); - - await _abpModuleFileManager.AddDependency(targetAbpModulePath, FindAbpModuleName(referencePackage)); - } + await _abpModuleFileManager.AddDependency(targetAbpModulePath, FindAbpModuleName(referencePackage)); } } + } - private async Task AddReferenceAsync( - ModuleInstallingContext context, - PackageInfo targetPackage, - PackageInfoWithAnalyze referencePackage) + private async Task AddReferenceAsync( + ModuleInstallingContext context, + PackageInfo targetPackage, + PackageInfoWithAnalyze referencePackage) + { + var _csprojFileManager = context.ServiceProvider.GetRequiredService(); + var csprojFilePath = targetPackage.Path.RemovePostFix(PackageConsts.FileExtension) + ".csproj"; + + if (context.WithSourceCode) { - var _csprojFileManager = context.ServiceProvider.GetRequiredService(); - var csprojFilePath = targetPackage.Path.RemovePostFix(PackageConsts.FileExtension) + ".csproj"; + var referenceProjectPath = Directory.GetFiles(context.GetTargetSourceCodeFolder(), + $"*{referencePackage.Name}.csproj", + SearchOption.AllDirectories).FirstOrDefault(); - if (context.WithSourceCode) - { - var referenceProjectPath = Directory.GetFiles(context.GetTargetSourceCodeFolder(), - $"*{referencePackage.Name}.csproj", - SearchOption.AllDirectories).FirstOrDefault(); - - if (referenceProjectPath == null) - { - return; - } - - await _csprojFileManager.AddProjectReferenceAsync( - csprojFilePath, - referenceProjectPath); - } - else + if (referenceProjectPath == null) { - await _csprojFileManager.AddPackageReferenceAsync( - csprojFilePath, - referencePackage.Name, - context.Version); + return; } - } - private string FindAbpModuleFile(string targetPackagePath) + await _csprojFileManager.AddProjectReferenceAsync( + csprojFilePath, + referenceProjectPath); + } + else { - return Directory.GetFiles(Path.GetDirectoryName(targetPackagePath), "*Module.cs", - SearchOption.AllDirectories) - .FirstOrDefault(); + await _csprojFileManager.AddPackageReferenceAsync( + csprojFilePath, + referencePackage.Name, + context.Version); } + } - private string FindAbpModuleName(PackageInfoWithAnalyze package) - { - var abpModuleModel = package.Analyze.Contents.Where(y => - y.ContentType == AbpModuleModel.ContentTypeName - ).Cast().First(); + private string FindAbpModuleFile(string targetPackagePath) + { + return Directory.GetFiles(Path.GetDirectoryName(targetPackagePath), "*Module.cs", + SearchOption.AllDirectories) + .FirstOrDefault(); + } - return abpModuleModel.Namespace + "." + abpModuleModel.Name; - } + private string FindAbpModuleName(PackageInfoWithAnalyze package) + { + var abpModuleModel = package.Analyze.Contents.Where(y => + y.ContentType == AbpModuleModel.ContentTypeName + ).Cast().First(); - private List GetTargetPackages(List targetModulePackages, - PackageInfoWithAnalyze referencePackage) - { - if (PackageTypes.IsHostProject(referencePackage.Role)) - { - return new List(); - } + return abpModuleModel.Namespace + "." + abpModuleModel.Name; + } - if (PackageTypes.IsUiProject(referencePackage.Role)) - { - var useHostBlazorServerForMvcPackages = targetModulePackages.All(p => p.Role != PackageTypes.HostMvc); - var targetHostType = - PackageTypes.GetHostTypeOfUi(referencePackage.Role, useHostBlazorServerForMvcPackages); + private List GetTargetPackages(List targetModulePackages, + PackageInfoWithAnalyze referencePackage) + { + if (PackageTypes.IsHostProject(referencePackage.Role)) + { + return new List(); + } - return targetModulePackages.Where(p => p.Role == targetHostType).ToList(); - } + if (PackageTypes.IsUiProject(referencePackage.Role)) + { + var useHostBlazorServerForMvcPackages = targetModulePackages.All(p => p.Role != PackageTypes.HostMvc); + var targetHostType = + PackageTypes.GetHostTypeOfUi(referencePackage.Role, useHostBlazorServerForMvcPackages); - return targetModulePackages.Where(p => p.Role == referencePackage.Role).ToList(); + return targetModulePackages.Where(p => p.Role == targetHostType).ToList(); } + + return targetModulePackages.Where(p => p.Role == referencePackage.Role).ToList(); } } diff --git a/studio/src/Volo.Abp.Studio.ModuleInstaller/Volo/Abp/Studio/ModuleInstalling/Steps/SourceCodeDownloadStep.cs b/studio/src/Volo.Abp.Studio.ModuleInstaller/Volo/Abp/Studio/ModuleInstalling/Steps/SourceCodeDownloadStep.cs index f99186d216..2d0448e54e 100644 --- a/studio/src/Volo.Abp.Studio.ModuleInstaller/Volo/Abp/Studio/ModuleInstalling/Steps/SourceCodeDownloadStep.cs +++ b/studio/src/Volo.Abp.Studio.ModuleInstaller/Volo/Abp/Studio/ModuleInstalling/Steps/SourceCodeDownloadStep.cs @@ -6,34 +6,33 @@ using Microsoft.Extensions.DependencyInjection; using Volo.Abp.Cli.ProjectBuilding; using Volo.Abp.Studio.Nuget; -namespace Volo.Abp.Studio.ModuleInstalling.Steps +namespace Volo.Abp.Studio.ModuleInstalling.Steps; + +public class SourceCodeDownloadStep : ModuleInstallingPipelineStep { - public class SourceCodeDownloadStep : ModuleInstallingPipelineStep + public override async Task ExecuteAsync(ModuleInstallingContext context) { - public override async Task ExecuteAsync(ModuleInstallingContext context) - { - var _nugetSourceCodeStoreManager = context.ServiceProvider.GetRequiredService(); + var _nugetSourceCodeStoreManager = context.ServiceProvider.GetRequiredService(); - var zipFilePath = await _nugetSourceCodeStoreManager.GetCachedSourceCodeFilePathAsync( - context.ModuleName, - SourceCodeTypes.Module, - context.Version); + var zipFilePath = await _nugetSourceCodeStoreManager.GetCachedSourceCodeFilePathAsync( + context.ModuleName, + SourceCodeTypes.Module, + context.Version); - if (zipFilePath == null) - { - throw new AbpStudioException(message: $"Source code not found for {context.ModuleName} (v{context.Version})"); - } + if (zipFilePath == null) + { + throw new AbpStudioException(message: $"Source code not found for {context.ModuleName} (v{context.Version})"); + } - var targetFolder = context.GetTargetSourceCodeFolder(); + var targetFolder = context.GetTargetSourceCodeFolder(); - if (Directory.Exists(targetFolder)) - { - return; - } + if (Directory.Exists(targetFolder)) + { + return; + } - Directory.CreateDirectory(targetFolder); + Directory.CreateDirectory(targetFolder); - ZipFile.ExtractToDirectory(zipFilePath, targetFolder); - } + ZipFile.ExtractToDirectory(zipFilePath, targetFolder); } }