-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/patch/3.2.x'
- Loading branch information
Showing
34 changed files
with
202 additions
and
313 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/framework/Elsa.Studio.Core/Services/BlazorScopedProxyApi.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System.Reflection; | ||
using Elsa.Studio.Contracts; | ||
|
||
namespace Elsa.Studio.Services; | ||
|
||
/// <summary> | ||
/// Decorates an API client with a Blazor service accessor, ensuring that the service provider is available to the API client when calling DI-resolved delegating handlers. | ||
/// </summary> | ||
public class BlazorScopedProxyApi<T> : DispatchProxy | ||
{ | ||
private T _decoratedApi = default!; | ||
private IBlazorServiceAccessor _blazorServiceAccessor = default!; | ||
private IServiceProvider _serviceProvider = default!; | ||
|
||
internal void Initialize(T decoratedApi, IBlazorServiceAccessor blazorServiceAccessor, IServiceProvider serviceProvider) | ||
{ | ||
_decoratedApi = decoratedApi; | ||
_blazorServiceAccessor = blazorServiceAccessor; | ||
_serviceProvider = serviceProvider; | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override object? Invoke(MethodInfo? targetMethod, object?[]? args) | ||
{ | ||
_blazorServiceAccessor.Services = _serviceProvider; | ||
return targetMethod?.Invoke(_decoratedApi, args); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 1 addition & 95 deletions
96
src/framework/Elsa.Studio.Shared/Components/StudioComponentBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,102 +1,8 @@ | ||
using Elsa.Studio.Contracts; | ||
using Elsa.Studio.Services; | ||
using Microsoft.AspNetCore.Components; | ||
|
||
namespace Elsa.Studio.Components; | ||
|
||
/// Base class for components. This class sets the <see cref="BlazorServiceAccessor.Services"/> property to the <see cref="IServiceProvider"/> instance. | ||
/// See https://learn.microsoft.com/en-us/aspnet/core/blazor/fundamentals/dependency-injection?view=aspnetcore-7.0#access-server-side-blazor-services-from-a-different-di-scope | ||
public abstract class StudioComponentBase : ComponentBase, IHandleEvent, IHandleAfterRender | ||
{ | ||
private bool _hasCalledOnAfterRender; | ||
|
||
/// Gets the current IServiceProvider. | ||
[Inject] protected IServiceProvider Services { get; set; } = default!; | ||
|
||
/// Gets the current <see cref="IBlazorServiceAccessor"/>. | ||
[Inject] protected IBlazorServiceAccessor BlazorServiceAccessor { get; set; } = default!; | ||
|
||
/// <inheritdoc /> | ||
public override Task SetParametersAsync(ParameterView parameters) => InvokeWithBlazorServiceContext(() => base.SetParametersAsync(parameters)); | ||
|
||
Task IHandleEvent.HandleEventAsync(EventCallbackWorkItem callback, object? arg) | ||
{ | ||
return InvokeWithBlazorServiceContext(() => | ||
{ | ||
var task = callback.InvokeAsync(arg); | ||
var shouldAwaitTask = task.Status != TaskStatus.RanToCompletion && task.Status != TaskStatus.Canceled; | ||
StateHasChanged(); | ||
return shouldAwaitTask ? CallStateHasChangedOnAsyncCompletion(task) : Task.CompletedTask; | ||
}); | ||
} | ||
|
||
Task IHandleAfterRender.OnAfterRenderAsync() | ||
{ | ||
return InvokeWithBlazorServiceContext(() => | ||
{ | ||
var firstRender = !_hasCalledOnAfterRender; | ||
_hasCalledOnAfterRender = true; | ||
OnAfterRender(firstRender); | ||
return OnAfterRenderAsync(firstRender); | ||
}); | ||
} | ||
|
||
private async Task CallStateHasChangedOnAsyncCompletion(Task task) | ||
{ | ||
try | ||
{ | ||
await task; | ||
} | ||
catch | ||
{ | ||
if (task.IsCanceled) | ||
{ | ||
return; | ||
} | ||
|
||
throw; | ||
} | ||
|
||
StateHasChanged(); | ||
} | ||
|
||
/// <summary> | ||
/// Invokes the given function with the Blazor service context. | ||
/// </summary> | ||
/// <param name="func">The function to be invoked.</param> | ||
/// <returns>A task that represents the asynchronous operation.</returns> | ||
protected async Task InvokeWithBlazorServiceContext(Func<Task> func) | ||
{ | ||
try | ||
{ | ||
BlazorServiceAccessor.Services = Services; | ||
await func(); | ||
} | ||
finally | ||
{ | ||
BlazorServiceAccessor.Services = null!; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Invokes the given function with the Blazor service context. | ||
/// </summary> | ||
/// <param name="func">The function to be invoked.</param> | ||
/// <returns>A task that represents the asynchronous operation.</returns> | ||
protected async Task<T> InvokeWithBlazorServiceContext<T>(Func<Task<T>> func) | ||
{ | ||
try | ||
{ | ||
BlazorServiceAccessor.Services = Services; | ||
return await func(); | ||
} | ||
finally | ||
{ | ||
BlazorServiceAccessor.Services = null!; | ||
} | ||
} | ||
} | ||
public abstract class StudioComponentBase : ComponentBase; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
src/modules/Elsa.Studio.Workflows.Core/Domain/Notifications/WorkflowDefinitionPublished.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
using Elsa.Api.Client.Resources.WorkflowDefinitions.Models; | ||
using Elsa.Studio.Contracts; | ||
|
||
namespace Elsa.Studio.Workflows.Domain.Notifications; | ||
|
||
/// Represents a notification sent when a workflow definition is published. | ||
public record WorkflowDefinitionPublished(string WorkflowDefinitionId) : INotification; | ||
public record WorkflowDefinitionPublished(WorkflowDefinition WorkflowDefinition) : INotification; |
3 changes: 2 additions & 1 deletion
3
src/modules/Elsa.Studio.Workflows.Core/Domain/Notifications/WorkflowDefinitionPublishing.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
using Elsa.Api.Client.Resources.WorkflowDefinitions.Models; | ||
using Elsa.Studio.Contracts; | ||
|
||
namespace Elsa.Studio.Workflows.Domain.Notifications; | ||
|
||
/// Represents a notification sent when a workflow definition is about to be published. | ||
public record WorkflowDefinitionPublishing(string WorkflowDefinitionId) : INotification; | ||
public record WorkflowDefinitionPublishing(WorkflowDefinition WorkflowDefinition) : INotification; |
6 changes: 5 additions & 1 deletion
6
...les/Elsa.Studio.Workflows.Core/Domain/Notifications/WorkflowDefinitionPublishingFailed.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
using Elsa.Api.Client.Resources.WorkflowDefinitions.Models; | ||
using Elsa.Studio.Contracts; | ||
using Elsa.Studio.Workflows.Domain.Models; | ||
|
||
namespace Elsa.Studio.Workflows.Domain.Notifications; | ||
|
||
public record WorkflowDefinitionPublishingFailed(WorkflowDefinitionVersion WorkflowDefinitionVersion, ValidationErrors Errors) : INotification; | ||
/// <summary> | ||
/// A notification sent when a workflow definition failed to publish. | ||
/// </summary> | ||
public record WorkflowDefinitionPublishingFailed(WorkflowDefinition WorkflowDefinition, ValidationErrors Errors) : INotification; |
4 changes: 2 additions & 2 deletions
4
src/modules/Elsa.Studio.Workflows.Core/Domain/Notifications/WorkflowDefinitionSaved.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
using Elsa.Api.Client.Resources.WorkflowDefinitions.Models; | ||
using Elsa.Studio.Contracts; | ||
using Elsa.Studio.Workflows.Domain.Models; | ||
|
||
namespace Elsa.Studio.Workflows.Domain.Notifications; | ||
|
||
/// Represents a notification sent when a workflow definition has been saved. | ||
public record WorkflowDefinitionSaved(WorkflowDefinitionVersion WorkflowDefinitionVersion) : INotification; | ||
public record WorkflowDefinitionSaved(WorkflowDefinition WorkflowDefinition) : INotification; |
4 changes: 2 additions & 2 deletions
4
src/modules/Elsa.Studio.Workflows.Core/Domain/Notifications/WorkflowDefinitionSaving.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
using Elsa.Api.Client.Resources.WorkflowDefinitions.Models; | ||
using Elsa.Studio.Contracts; | ||
using Elsa.Studio.Workflows.Domain.Models; | ||
|
||
namespace Elsa.Studio.Workflows.Domain.Notifications; | ||
|
||
/// Represents a notification sent when a workflow definition is about to be saved. | ||
public record WorkflowDefinitionSaving(WorkflowDefinitionVersion WorkflowDefinitionVersion) : INotification; | ||
public record WorkflowDefinitionSaving(WorkflowDefinition WorkflowDefinition) : INotification; |
6 changes: 5 additions & 1 deletion
6
...modules/Elsa.Studio.Workflows.Core/Domain/Notifications/WorkflowDefinitionSavingFailed.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
using Elsa.Api.Client.Resources.WorkflowDefinitions.Models; | ||
using Elsa.Studio.Contracts; | ||
using Elsa.Studio.Workflows.Domain.Models; | ||
|
||
namespace Elsa.Studio.Workflows.Domain.Notifications; | ||
|
||
public record WorkflowDefinitionSavingFailed(WorkflowDefinitionVersion WorkflowDefinitionVersion, ValidationErrors Errors) : INotification; | ||
/// <summary> | ||
/// A notification sent when a workflow definition failed to save. | ||
/// </summary> | ||
public record WorkflowDefinitionSavingFailed(WorkflowDefinition WorkflowDefinition, ValidationErrors Errors) : INotification; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.