Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/AbpHelper.Core/AbpHelper.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Elsa" Version="1.2.2.29" />
<PackageReference Include="Elsa" Version="2.8.2" />
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.0.1" />
<PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" Version="6.0.*" />
Expand Down
10 changes: 0 additions & 10 deletions src/AbpHelper.Core/AbpHelperCoreModule.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Reflection;
using EasyAbp.AbpHelper.Core.Extensions;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders;
using Volo.Abp.Autofac;
Expand All @@ -15,7 +14,6 @@ public class AbpHelperCoreModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
ConfigureElsaActivities(context);
ConfigureTemplateFiles(context);
ConfigureVirtualFileSystem();
}
Expand All @@ -28,14 +26,6 @@ private void ConfigureVirtualFileSystem()
});
}

private void ConfigureElsaActivities(ServiceConfigurationContext context)
{
context.Services
.AddElsa()
.AddAllActivities()
;
}

private void ConfigureTemplateFiles(ServiceConfigurationContext context)
{
context.Services.AddSingleton<IFileProvider>(sp => new ManifestEmbeddedFileProvider(Assembly.GetExecutingAssembly()));
Expand Down
58 changes: 31 additions & 27 deletions src/AbpHelper.Core/Commands/CommandWithOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
using System.Reflection;
using System.Threading.Tasks;
using EasyAbp.AbpHelper.Core.Attributes;
using EasyAbp.AbpHelper.Core.Extensions;
using EasyAbp.AbpHelper.Core.Services;
using EasyAbp.AbpHelper.Core.Steps.Abp;
using Elsa.Activities;
using Elsa.Expressions;
using Elsa.Activities.Primitives;
using Elsa.Builders;
using Elsa.Models;
using Elsa.Scripting.JavaScript;
using Elsa.Services;
using Elsa.Services.Models;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
Expand All @@ -22,7 +21,8 @@ namespace EasyAbp.AbpHelper.Core.Commands
{
public abstract class CommandWithOption<TOption> : CommandBase where TOption : CommandOptionsBase
{
public CommandWithOption(IServiceProvider serviceProvider, string name, string? description = null) : base(serviceProvider, name, description)
public CommandWithOption(IServiceProvider serviceProvider, string name, string? description = null) : base(
serviceProvider, name, description)
{
Logger = NullLogger<CommandWithOption<TOption>>.Instance;

Expand All @@ -34,6 +34,7 @@ public CommandWithOption(IServiceProvider serviceProvider, string name, string?
protected virtual string OptionVariableName => CommandConsts.OptionVariableName;
protected virtual string BaseDirectoryVariableName => CommandConsts.BaseDirectoryVariableName;
protected virtual string ExcludeDirectoriesVariableName => CommandConsts.ExcludeDirectoriesVariableName;
protected virtual string OverwriteVariableName => CommandConsts.OverwriteVariableName;

public ILogger<CommandWithOption<TOption>> Logger { get; set; }

Expand All @@ -46,25 +47,28 @@ public virtual async Task RunCommand(TOption option)
await RunWorkflow(builder =>
{
var activityBuilder = builder
.StartWith<SetVariable>(
step =>
.StartWith<SetVariable>(
step =>
{
step.Set(x => x.VariableName, OptionVariableName);
step.Set(x => x.Value, option);
})
.Then<SetVariable>(
step =>
{
step.Set(x => x.VariableName, BaseDirectoryVariableName);
step.Set(x => x.Value, option.Directory);
})
.Then<SetVariable>(
step =>
{
step.Set(x => x.VariableName, ExcludeDirectoriesVariableName);
step.Set(x => x.Value, option.Exclude);
})
.Then<ProjectInfoProviderStep>(step =>
{
step.VariableName = OptionVariableName;
step.ValueExpression = new JavaScriptExpression<TOption>($"({option.ToJson()})");
step.Set(x => x.ExcludeDirectories, option.Exclude);
})
.Then<SetVariable>(
step =>
{
step.VariableName = BaseDirectoryVariableName;
step.ValueExpression = new LiteralExpression(option.Directory);
})
.Then<SetVariable>(
step =>
{
step.VariableName = ExcludeDirectoriesVariableName;
step.ValueExpression = new JavaScriptExpression<string[]>($"{OptionVariableName}.{nameof(CommandOptionsBase.Exclude)}");
})
.Then<ProjectInfoProviderStep>()
;

return ConfigureBuild(option, activityBuilder).Build();
Expand Down Expand Up @@ -93,23 +97,23 @@ protected virtual string GetBaseDirectory(string directory)
return directory;
}

protected async Task RunWorkflow(Func<IWorkflowBuilder, WorkflowDefinitionVersion> builder)
protected async Task RunWorkflow(Func<IWorkflowBuilder, IWorkflowBlueprint> builder)
{
var workflowBuilderFactory = ServiceProvider.GetRequiredService<Func<IWorkflowBuilder>>();
var workflowBuilder = workflowBuilderFactory();

var workflowDefinition = builder(workflowBuilder);
// Start the workflow.
Logger.LogInformation($"Command '{Name}' started.");
var invoker = ServiceProvider.GetRequiredService<IWorkflowInvoker>();
var ctx = await invoker.StartAsync(workflowDefinition);
if (ctx.Workflow.Status == WorkflowStatus.Finished)
var invoker = ServiceProvider.GetRequiredService<IStartsWorkflow>();
var ctx = await invoker.StartWorkflowAsync(workflowDefinition);
if (ctx.WorkflowInstance?.WorkflowStatus == WorkflowStatus.Finished)
{
Logger.LogInformation($"Command '{Name}' finished successfully.");
}
else
{
Logger.LogError("Error activity: " + ctx.CurrentActivity.State);
Logger.LogError("Error activity: " + ctx.ActivityId);
}
}

Expand Down
24 changes: 13 additions & 11 deletions src/AbpHelper.Core/Commands/Ef/Migrations/Add/AddCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
using EasyAbp.AbpHelper.Core.Steps.Common;
using EasyAbp.AbpHelper.Core.Workflow;
using EasyAbp.AbpHelper.Core.Workflow.Common;
using Elsa.Activities;
using Elsa.Expressions;
using Elsa.Scripting.JavaScript;
using Elsa.Services;
using Elsa.Activities.ControlFlow;
using Elsa.Activities.Primitives;
using Elsa.Builders;

namespace EasyAbp.AbpHelper.Core.Commands.Ef.Migrations.Add
{
public class AddCommand : CommandWithOption<AddCommandOption>
{
private const string AddCommandDescription = @"Adds a new migration. The usage is the same as `dotnet ef migrations add`,
private const string AddCommandDescription =
@"Adds a new migration. The usage is the same as `dotnet ef migrations add`,
except providing the default value for the `--project` and `--startup-project` options.";

public AddCommand(IServiceProvider serviceProvider) : base(serviceProvider, "add", AddCommandDescription)
Expand All @@ -20,18 +20,20 @@ public AddCommand(IServiceProvider serviceProvider) : base(serviceProvider, "add

protected override IActivityBuilder ConfigureBuild(AddCommandOption option, IActivityBuilder activityBuilder)
{
string efOptions = option.EfOptions == null ? String.Empty : string.Join(" ", option.EfOptions);
var efOptions = option.EfOptions == null ? string.Empty : string.Join(" ", option.EfOptions);
return base.ConfigureBuild(option, activityBuilder)
.Then<SetVariable>(step =>
{
step.VariableName = "EfOptions";
step.ValueExpression = new LiteralExpression(efOptions);

step.Set(x => x.VariableName, "EfOptions");
step.Set(x => x.Value, efOptions);
})
.AddConfigureMigrationProjectsWorkflow(ActivityNames.AddMigration)
.Then<RunCommandStep>(
step => step.Command = new JavaScriptExpression<string>("`dotnet ef migrations add ${Option.Name} -p \"${MigrationProjectFile}\" -s \"${StartupProjectFile}\" ${EfOptions || ''}`")
).WithName(ActivityNames.AddMigration)
step =>
{
step.Set(x => x.Command,
"dotnet ef migrations add {Option.Name} -p \"{MigrationProjectFile}\" -s \"{StartupProjectFile}\" {EfOptions || ''}");
}).WithName(ActivityNames.AddMigration)
;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ public class AddCommandOption : MigrationsCommandOption
public string Name { get; set; } = null!;

[Argument("ef-options", Description = "Other options to `dotnet ef migrations add`")]
public string[] EfOptions { get; set; } = null!;
public string[]? EfOptions { get; set; } = null;
}
}
28 changes: 16 additions & 12 deletions src/AbpHelper.Core/Commands/Ef/Migrations/Remove/RemoveCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,40 @@
using EasyAbp.AbpHelper.Core.Steps.Common;
using EasyAbp.AbpHelper.Core.Workflow;
using EasyAbp.AbpHelper.Core.Workflow.Common;
using Elsa.Activities;
using Elsa.Expressions;
using Elsa.Scripting.JavaScript;
using Elsa.Services;
using Elsa.Activities.ControlFlow;
using Elsa.Builders;
using Elsa.Activities.Primitives;
using IActivityBuilder = Elsa.Builders.IActivityBuilder;

namespace EasyAbp.AbpHelper.Core.Commands.Ef.Migrations.Remove
{
public class RemoveCommand : CommandWithOption<RemoveCommandOption>
{
private const string RemoveCommandDescription = @"Removes the last migration. The usage is the same as `dotnet ef migrations remove`,
private const string RemoveCommandDescription =
@"Removes the last migration. The usage is the same as `dotnet ef migrations remove`,
except providing the default value for the `--project` and `--startup-project` options.";

public RemoveCommand(IServiceProvider serviceProvider) : base(serviceProvider, "remove", RemoveCommandDescription)
public RemoveCommand(IServiceProvider serviceProvider) : base(serviceProvider, "remove",
RemoveCommandDescription)
{
}

protected override IActivityBuilder ConfigureBuild(RemoveCommandOption option, IActivityBuilder activityBuilder)
{
string efOptions = option.EfOptions == null ? String.Empty : string.Join(" ", option.EfOptions);
var efOptions = option.EfOptions == null ? string.Empty : string.Join(" ", option.EfOptions);
return base.ConfigureBuild(option, activityBuilder)
.Then<SetVariable>(step =>
{
step.VariableName = "EfOptions";
step.ValueExpression = new LiteralExpression(efOptions);

step.Set(x => x.VariableName, "EfOptions");
step.Set(x => x.Value, efOptions);
})
.AddConfigureMigrationProjectsWorkflow(ActivityNames.RemoveMigration)
.Then<RunCommandStep>(
step => step.Command = new JavaScriptExpression<string>("`dotnet ef migrations remove -p \"${MigrationProjectFile}\" -s \"${StartupProjectFile}\" ${EfOptions || ''}`")
).WithName(ActivityNames.RemoveMigration)
step =>
{
step.Set(x => x.Command,
"dotnet ef migrations remove -p \"{MigrationProjectFile}\" -s \"{StartupProjectFile}\" {EfOptions || ''}");
}).WithName(ActivityNames.RemoveMigration)
;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ namespace EasyAbp.AbpHelper.Core.Commands.Ef.Migrations.Remove
public class RemoveCommandOption : MigrationsCommandOption
{
[Argument("ef-options", Description = "Other options to `dotnet ef migrations remove`")]
public string[] EfOptions { get; set; } = null!;
public string[]? EfOptions { get; set; } = null;
}
}
Loading