mirror of https://github.com/abpframework/abp.git
53 changed files with 192 additions and 132 deletions
@ -0,0 +1,87 @@ |
|||
using System; |
|||
using System.IO; |
|||
using System.Net.Http; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.Extensions.Logging; |
|||
using Microsoft.Extensions.Logging.Abstractions; |
|||
using Microsoft.Extensions.Options; |
|||
using Volo.Abp.Cli.ProjectBuilding.Building; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Http; |
|||
using Volo.Abp.IO; |
|||
using Volo.Abp.Json; |
|||
using Volo.Abp.Threading; |
|||
|
|||
namespace Volo.Abp.Cli.ProjectBuilding |
|||
{ |
|||
public class AbpIoTemplateStore : ITemplateStore, ITransientDependency |
|||
{ |
|||
public ILogger<AbpIoTemplateStore> Logger { get; set; } |
|||
|
|||
protected CliOptions Options { get; } |
|||
protected IJsonSerializer JsonSerializer { get; } |
|||
protected ICancellationTokenProvider CancellationTokenProvider { get; } |
|||
|
|||
public AbpIoTemplateStore( |
|||
IOptions<CliOptions> options, |
|||
IJsonSerializer jsonSerializer, |
|||
ICancellationTokenProvider cancellationTokenProvider) |
|||
{ |
|||
JsonSerializer = jsonSerializer; |
|||
CancellationTokenProvider = cancellationTokenProvider; |
|||
Options = options.Value; |
|||
|
|||
Logger = NullLogger<AbpIoTemplateStore>.Instance; |
|||
} |
|||
|
|||
public async Task<TemplateFile> GetAsync( |
|||
string name, |
|||
string version, |
|||
DatabaseProvider databaseProvider, |
|||
string projectName) |
|||
{ |
|||
var localCacheFolder = Path.Combine(CliPaths.TemplateCache, version); |
|||
DirectoryHelper.CreateIfNotExists(localCacheFolder); |
|||
|
|||
var localCacheFile = Path.Combine(localCacheFolder, name + ".zip"); |
|||
if (File.Exists(localCacheFile)) |
|||
{ |
|||
Logger.LogInformation("Using cached template: " + name + ", version: " + version); |
|||
return new TemplateFile(File.ReadAllBytes(localCacheFile)); |
|||
} |
|||
|
|||
Logger.LogInformation("Downloading template: " + name + ", version: " + version); |
|||
|
|||
using (var client = new System.Net.Http.HttpClient()) |
|||
{ |
|||
client.Timeout = TimeSpan.FromMinutes(5); |
|||
var downloadUrl = Options.AbpIoWwwUrlRoot + "api/download/template/"; |
|||
|
|||
var serializedPostDataAsString = JsonSerializer.Serialize(new |
|||
{ |
|||
name = name, |
|||
version = version, |
|||
databaseProvider = databaseProvider, |
|||
projectName = projectName |
|||
}); |
|||
|
|||
var responseMessage = await client.PostAsync( |
|||
downloadUrl, |
|||
new StringContent(serializedPostDataAsString, Encoding.UTF8, MimeTypes.Application.Json), |
|||
CancellationTokenProvider.Token |
|||
); |
|||
|
|||
if (!responseMessage.IsSuccessStatusCode) |
|||
{ |
|||
throw new Exception("Remote server returns error! HTTP status code: " + responseMessage.StatusCode); |
|||
} |
|||
|
|||
var fileContent = await responseMessage.Content.ReadAsByteArrayAsync(); |
|||
|
|||
File.WriteAllBytes(localCacheFile, fileContent); |
|||
return new TemplateFile(fileContent); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -1,4 +1,4 @@ |
|||
namespace Volo.Abp.ProjectBuilding.Building |
|||
namespace Volo.Abp.Cli.ProjectBuilding.Building |
|||
{ |
|||
public enum DatabaseProvider |
|||
{ |
|||
@ -1,6 +1,6 @@ |
|||
using System; |
|||
|
|||
namespace Volo.Abp.ProjectBuilding.Building |
|||
namespace Volo.Abp.Cli.ProjectBuilding.Building |
|||
{ |
|||
public class GithubRepositoryInfo |
|||
{ |
|||
@ -1,7 +1,7 @@ |
|||
using JetBrains.Annotations; |
|||
using Volo.Abp.ProjectBuilding.Files; |
|||
using Volo.Abp.Cli.ProjectBuilding.Files; |
|||
|
|||
namespace Volo.Abp.ProjectBuilding.Building |
|||
namespace Volo.Abp.Cli.ProjectBuilding.Building |
|||
{ |
|||
public class ProjectBuildContext |
|||
{ |
|||
@ -1,8 +1,8 @@ |
|||
using System; |
|||
using System.Linq; |
|||
using Volo.Abp.ProjectBuilding.Files; |
|||
using Volo.Abp.Cli.ProjectBuilding.Files; |
|||
|
|||
namespace Volo.Abp.ProjectBuilding.Building |
|||
namespace Volo.Abp.Cli.ProjectBuilding.Building |
|||
{ |
|||
public static class ProjectBuildContextExtensions |
|||
{ |
|||
@ -1,6 +1,6 @@ |
|||
using System.Collections.Generic; |
|||
|
|||
namespace Volo.Abp.ProjectBuilding.Building |
|||
namespace Volo.Abp.Cli.ProjectBuilding.Building |
|||
{ |
|||
public class ProjectBuildPipeline |
|||
{ |
|||
@ -1,6 +1,6 @@ |
|||
using Volo.Abp.ProjectBuilding.Building.Steps; |
|||
using Volo.Abp.Cli.ProjectBuilding.Building.Steps; |
|||
|
|||
namespace Volo.Abp.ProjectBuilding.Building |
|||
namespace Volo.Abp.Cli.ProjectBuilding.Building |
|||
{ |
|||
public static class ProjectBuildPipelineBuilder |
|||
{ |
|||
@ -1,4 +1,4 @@ |
|||
namespace Volo.Abp.ProjectBuilding.Building |
|||
namespace Volo.Abp.Cli.ProjectBuilding.Building |
|||
{ |
|||
public abstract class ProjectBuildPipelineStep |
|||
{ |
|||
@ -1,4 +1,4 @@ |
|||
namespace Volo.Abp.ProjectBuilding.Building |
|||
namespace Volo.Abp.Cli.ProjectBuilding.Building |
|||
{ |
|||
public class ProjectResult |
|||
{ |
|||
@ -1,8 +1,8 @@ |
|||
using Ionic.Zip; |
|||
using Volo.Abp.ProjectBuilding.Files; |
|||
using Volo.Abp.ProjectBuilding.Zipping; |
|||
using Volo.Abp.Cli.ProjectBuilding.Files; |
|||
using Volo.Abp.Cli.ProjectBuilding.Zipping; |
|||
|
|||
namespace Volo.Abp.ProjectBuilding.Building.Steps |
|||
namespace Volo.Abp.Cli.ProjectBuilding.Building.Steps |
|||
{ |
|||
public class CreateProjectResultZipStep : ProjectBuildPipelineStep |
|||
{ |
|||
@ -1,9 +1,9 @@ |
|||
using System.IO; |
|||
using Ionic.Zip; |
|||
using Volo.Abp.ProjectBuilding.Files; |
|||
using Volo.Abp.ProjectBuilding.Zipping; |
|||
using Volo.Abp.Cli.ProjectBuilding.Files; |
|||
using Volo.Abp.Cli.ProjectBuilding.Zipping; |
|||
|
|||
namespace Volo.Abp.ProjectBuilding.Building.Steps |
|||
namespace Volo.Abp.Cli.ProjectBuilding.Building.Steps |
|||
{ |
|||
public class FileEntryListReadStep : ProjectBuildPipelineStep |
|||
{ |
|||
@ -1,9 +1,9 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using Volo.Abp.ProjectBuilding.Files; |
|||
using Volo.Abp.Cli.ProjectBuilding.Files; |
|||
|
|||
namespace Volo.Abp.ProjectBuilding.Building.Steps |
|||
namespace Volo.Abp.Cli.ProjectBuilding.Building.Steps |
|||
{ |
|||
public class SolutionRenameStep : ProjectBuildPipelineStep |
|||
{ |
|||
@ -1,7 +1,7 @@ |
|||
using System; |
|||
using Volo.Abp.ProjectBuilding.Files; |
|||
using Volo.Abp.Cli.ProjectBuilding.Files; |
|||
|
|||
namespace Volo.Abp.ProjectBuilding.Building.Steps |
|||
namespace Volo.Abp.Cli.ProjectBuilding.Building.Steps |
|||
{ |
|||
public class SwitchEntityFrameworkCoreToMongoDbStep : ProjectBuildPipelineStep |
|||
{ |
|||
@ -1,6 +1,6 @@ |
|||
using Volo.Abp.ProjectBuilding.Files; |
|||
using Volo.Abp.Cli.ProjectBuilding.Files; |
|||
|
|||
namespace Volo.Abp.ProjectBuilding.Building.Steps |
|||
namespace Volo.Abp.Cli.ProjectBuilding.Building.Steps |
|||
{ |
|||
public class TemplateCodeDeleteStep : ProjectBuildPipelineStep |
|||
{ |
|||
@ -1,9 +1,9 @@ |
|||
using System.ComponentModel.DataAnnotations; |
|||
using System.ComponentModel.DataAnnotations.Schema; |
|||
using Volo.Abp.Cli.ProjectBuilding.Building; |
|||
using Volo.Abp.Domain.Entities.Auditing; |
|||
using Volo.Abp.ProjectBuilding.Building; |
|||
|
|||
namespace Volo.Abp.ProjectBuilding |
|||
namespace Volo.Abp.Cli.ProjectBuilding |
|||
{ |
|||
[Table("Downloads")] |
|||
public class DownloadInfo : CreationAuditedAggregateRoot<int> |
|||
@ -1,6 +1,6 @@ |
|||
using System.Collections.Generic; |
|||
|
|||
namespace Volo.Abp.ProjectBuilding.Files |
|||
namespace Volo.Abp.Cli.ProjectBuilding.Files |
|||
{ |
|||
public static class FileEntryExtensions |
|||
{ |
|||
@ -1,6 +1,6 @@ |
|||
using System.Collections.Generic; |
|||
|
|||
namespace Volo.Abp.ProjectBuilding.Files |
|||
namespace Volo.Abp.Cli.ProjectBuilding.Files |
|||
{ |
|||
public class FileEntryList : List<FileEntry> |
|||
{ |
|||
@ -1,7 +1,7 @@ |
|||
using System; |
|||
using Ionic.Zip; |
|||
|
|||
namespace Volo.Abp.ProjectBuilding.Files |
|||
namespace Volo.Abp.Cli.ProjectBuilding.Files |
|||
{ |
|||
public static class FileEntryListExtensions |
|||
{ |
|||
@ -1,7 +1,7 @@ |
|||
using System; |
|||
using Newtonsoft.Json; |
|||
|
|||
namespace Volo.Abp.ProjectBuilding.Github |
|||
namespace Volo.Abp.Cli.ProjectBuilding.Github |
|||
{ |
|||
[JsonObject] |
|||
public class GithubRelease |
|||
@ -1,6 +1,6 @@ |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Volo.Abp.ProjectBuilding |
|||
namespace Volo.Abp.Cli.ProjectBuilding |
|||
{ |
|||
public interface IProjectBuilder |
|||
{ |
|||
@ -1,6 +1,6 @@ |
|||
using Volo.Abp.ProjectBuilding.Building; |
|||
using Volo.Abp.Cli.ProjectBuilding.Building; |
|||
|
|||
namespace Volo.Abp.ProjectBuilding |
|||
namespace Volo.Abp.Cli.ProjectBuilding |
|||
{ |
|||
public interface ITemplateInfoProvider |
|||
{ |
|||
@ -0,0 +1,15 @@ |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Cli.ProjectBuilding.Building; |
|||
|
|||
namespace Volo.Abp.Cli.ProjectBuilding |
|||
{ |
|||
public interface ITemplateStore |
|||
{ |
|||
Task<TemplateFile> GetAsync( |
|||
string name, |
|||
string version, |
|||
DatabaseProvider databaseProvider, |
|||
string projectName |
|||
); |
|||
} |
|||
} |
|||
@ -1,7 +1,7 @@ |
|||
using JetBrains.Annotations; |
|||
using Volo.Abp.ProjectBuilding.Building; |
|||
using Volo.Abp.Cli.ProjectBuilding.Building; |
|||
|
|||
namespace Volo.Abp.ProjectBuilding |
|||
namespace Volo.Abp.Cli.ProjectBuilding |
|||
{ |
|||
public class ProjectBuildArgs |
|||
{ |
|||
@ -1,4 +1,4 @@ |
|||
namespace Volo.Abp.ProjectBuilding |
|||
namespace Volo.Abp.Cli.ProjectBuilding |
|||
{ |
|||
public class ProjectBuildResult |
|||
{ |
|||
@ -1,6 +1,6 @@ |
|||
using System; |
|||
|
|||
namespace Volo.Abp.ProjectBuilding |
|||
namespace Volo.Abp.Cli.ProjectBuilding |
|||
{ |
|||
public class SolutionName |
|||
{ |
|||
@ -1,4 +1,4 @@ |
|||
namespace Volo.Abp.ProjectBuilding |
|||
namespace Volo.Abp.Cli.ProjectBuilding |
|||
{ |
|||
public class TemplateFile |
|||
{ |
|||
@ -1,9 +1,9 @@ |
|||
using System; |
|||
using Volo.Abp.Cli.ProjectBuilding.Building; |
|||
using Volo.Abp.Cli.ProjectBuilding.Templates; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.ProjectBuilding.Building; |
|||
using Volo.Abp.ProjectBuilding.Templates; |
|||
|
|||
namespace Volo.Abp.ProjectBuilding |
|||
namespace Volo.Abp.Cli.ProjectBuilding |
|||
{ |
|||
public class TemplateInfoProvider : ITemplateInfoProvider, ITransientDependency |
|||
{ |
|||
@ -1,8 +1,8 @@ |
|||
using System.Collections.Generic; |
|||
using Volo.Abp.ProjectBuilding.Building; |
|||
using Volo.Abp.ProjectBuilding.Building.Steps; |
|||
using Volo.Abp.Cli.ProjectBuilding.Building; |
|||
using Volo.Abp.Cli.ProjectBuilding.Building.Steps; |
|||
|
|||
namespace Volo.Abp.ProjectBuilding.Templates |
|||
namespace Volo.Abp.Cli.ProjectBuilding.Templates |
|||
{ |
|||
public class MvcApplicationTemplate : TemplateInfo |
|||
{ |
|||
@ -1,6 +1,6 @@ |
|||
using Volo.Abp.ProjectBuilding.Building; |
|||
using Volo.Abp.Cli.ProjectBuilding.Building; |
|||
|
|||
namespace Volo.Abp.ProjectBuilding.Templates |
|||
namespace Volo.Abp.Cli.ProjectBuilding.Templates |
|||
{ |
|||
public class MvcModuleTemplate : TemplateInfo |
|||
{ |
|||
@ -1,6 +1,6 @@ |
|||
using Volo.Abp.ProjectBuilding.Building; |
|||
using Volo.Abp.Cli.ProjectBuilding.Building; |
|||
|
|||
namespace Volo.Abp.ProjectBuilding.Templates |
|||
namespace Volo.Abp.Cli.ProjectBuilding.Templates |
|||
{ |
|||
public class ServiceTemplate : TemplateInfo |
|||
{ |
|||
@ -1,6 +1,6 @@ |
|||
using System.Collections.Generic; |
|||
|
|||
namespace Volo.Abp.ProjectModification |
|||
namespace Volo.Abp.Cli.ProjectModification |
|||
{ |
|||
public class ModuleInfo |
|||
{ |
|||
@ -1,4 +1,4 @@ |
|||
namespace Volo.Abp.ProjectModification |
|||
namespace Volo.Abp.Cli.ProjectModification |
|||
{ |
|||
public class NpmPackageInfo |
|||
{ |
|||
@ -1,4 +1,4 @@ |
|||
namespace Volo.Abp.ProjectModification |
|||
namespace Volo.Abp.Cli.ProjectModification |
|||
{ |
|||
public class NugetPackageInfo |
|||
{ |
|||
@ -1,4 +1,4 @@ |
|||
namespace Volo.Abp.ProjectModification |
|||
namespace Volo.Abp.Cli.ProjectModification |
|||
{ |
|||
public enum NugetPackageTarget : byte |
|||
{ |
|||
@ -1,45 +0,0 @@ |
|||
using System; |
|||
using System.IO; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.Extensions.Logging; |
|||
using Microsoft.Extensions.Logging.Abstractions; |
|||
using Volo.Abp.Cli; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.IO; |
|||
|
|||
namespace Volo.Abp.ProjectBuilding |
|||
{ |
|||
public class AbpIoTemplateStore : ITemplateStore, ITransientDependency |
|||
{ |
|||
public ILogger<AbpIoTemplateStore> Logger { get; set; } |
|||
|
|||
public AbpIoTemplateStore() |
|||
{ |
|||
Logger = NullLogger<AbpIoTemplateStore>.Instance; |
|||
} |
|||
|
|||
public async Task<TemplateFile> GetAsync(string templateName, string version) |
|||
{ |
|||
var localCacheFolder = Path.Combine(CliPaths.TemplateCache, version); |
|||
DirectoryHelper.CreateIfNotExists(localCacheFolder); |
|||
|
|||
var localCacheFile = Path.Combine(localCacheFolder, templateName + ".zip"); |
|||
if (File.Exists(localCacheFile)) |
|||
{ |
|||
Logger.LogInformation("Using cached template: " + templateName + ", version: " + version); |
|||
return new TemplateFile(File.ReadAllBytes(localCacheFile)); |
|||
} |
|||
|
|||
Logger.LogInformation("Downloading template: " + templateName + ", version: " + version); |
|||
|
|||
using (var client = new System.Net.Http.HttpClient()) |
|||
{ |
|||
client.Timeout = TimeSpan.FromMinutes(5); |
|||
var downloadUrl = "https://abp.io/downloads/templates/" + version + "/" + templateName + ".zip"; |
|||
var fileContents = await client.GetByteArrayAsync(downloadUrl); |
|||
File.WriteAllBytes(localCacheFile, fileContents); |
|||
return new TemplateFile(fileContents); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -1,9 +0,0 @@ |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Volo.Abp.ProjectBuilding |
|||
{ |
|||
public interface ITemplateStore |
|||
{ |
|||
Task<TemplateFile> GetAsync(string templateInfoName, string version); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue