From 398bc741218580d3babc7fc5f4b3a4e6805fc21e Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Tue, 31 Aug 2021 15:37:44 +0300 Subject: [PATCH] Studio: created SourceCodeDownloadStep (Basic) --- .../ModuleInstallingContext.cs | 10 +++++- .../ModuleInstallingPipelineBuilderBase.cs | 5 +++ .../Steps/SourceCodeDownloadStep.cs | 35 +++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 studio/src/Volo.Abp.Studio.ModuleInstaller/Volo/Abp/Studio/ModuleInstalling/Steps/SourceCodeDownloadStep.cs 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 06393b210e..581b0c28cd 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 @@ -7,6 +7,10 @@ namespace Volo.Abp.Studio.ModuleInstalling { public class ModuleInstallingContext { + public string ModuleName { get; set; } + + public string TargetModule { get; set; } + public bool WithSourceCode { get; set; } public bool AddToSolutionFile { get; set; } @@ -22,12 +26,16 @@ namespace Volo.Abp.Studio.ModuleInstalling 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; @@ -45,7 +53,7 @@ namespace Volo.Abp.Studio.ModuleInstalling ReferenceModulePackages = referenceModulePackages; } - + public void SetTargetModulePackages([NotNull] List targetModulePackages) { Check.NotNull(targetModulePackages, nameof(targetModulePackages)); 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 8bc8a65304..883c34df28 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 @@ -8,6 +8,11 @@ namespace Volo.Abp.Studio.ModuleInstalling { var pipeline = new ModuleInstallingPipeline(context); + if (context.WithSourceCode) + { + pipeline.Steps.Add(new SourceCodeDownloadStep()); + } + pipeline.Steps.Add(new PackageReferencingStep()); return pipeline; 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 new file mode 100644 index 0000000000..5844e55272 --- /dev/null +++ b/studio/src/Volo.Abp.Studio.ModuleInstaller/Volo/Abp/Studio/ModuleInstalling/Steps/SourceCodeDownloadStep.cs @@ -0,0 +1,35 @@ +using System.IO; +using System.IO.Compression; +using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.Cli.ProjectBuilding; +using Volo.Abp.Studio.Nuget; + +namespace Volo.Abp.Studio.ModuleInstalling.Steps +{ + public class SourceCodeDownloadStep : ModuleInstallingPipelineStep + { + public override async Task ExecuteAsync(ModuleInstallingContext context) + { + var _nugetSourceCodeStoreManager = context.ServiceProvider.GetRequiredService(); + + var sourceCodePackageName = $"{context.ModuleName}.SourceCode"; + + var zipFilePath = await _nugetSourceCodeStoreManager.GetCachedSourceCodeFilePathAsync( + sourceCodePackageName, + SourceCodeTypes.Module, + context.Version); + + var targetFolder = + Path.Combine(Path.GetDirectoryName(context.TargetModule), "modules", context.ModuleName); + + using (ZipArchive archive = ZipFile.OpenRead(zipFilePath)) + { + foreach (var entry in archive.Entries) + { + entry.ExtractToFile(Path.Combine(targetFolder, entry.FullName)); + } + } + } + } +}