diff --git a/backend/extensions/Squidex.Extensions/Actions/SignalR/SignalRAction.cs b/backend/extensions/Squidex.Extensions/Actions/SignalR/SignalRAction.cs index 6f247f1ab..7bd6e3923 100644 --- a/backend/extensions/Squidex.Extensions/Actions/SignalR/SignalRAction.cs +++ b/backend/extensions/Squidex.Extensions/Actions/SignalR/SignalRAction.cs @@ -19,12 +19,12 @@ namespace Squidex.Extensions.Actions.SignalR IconImage = "", IconColor = "#1566BF", Display = "Send to Azure SignalR", - Description = "Send an message to azure SignalR.", + Description = "Send a message to Azure SignalR.", ReadMore = "https://azure.microsoft.com/fr-fr/services/signalr-service/")] public sealed record SignalRAction : RuleAction { [LocalizedRequired] - [Display(Name = "Connection", Description = "The connection string to the Signal R Azure.")] + [Display(Name = "Connection", Description = "The connection string to the Azure SignalR.")] [Editor(RuleFieldEditor.Text)] [Formattable] public string ConnectionString { get; set; } @@ -36,14 +36,14 @@ namespace Squidex.Extensions.Actions.SignalR public string HubName { get; set; } [LocalizedRequired] - [Display(Name = "Action", Description = "Broadcast = send to all User, User = send to specific user(s) specified in the 'Target' field, Group = send to specific group(s) specified in the 'Target' field")] + [Display(Name = "Action", Description = "* Broadcast = send to all users.\n * User = send to all target users(s).\n * Group = send to all target group(s).")] public ActionTypeEnum Action { get; set; } - [Display(Name = "Methode Name", Description = "Set the Name of the hub method received by the customer, default value 'push.")] + [Display(Name = "Methode Name", Description = "Set the Name of the hub method received by the customer.")] [Editor(RuleFieldEditor.Text)] public string MethodName { get; set; } - [Display(Name = "Target (Optional)", Description = "Defines a user, group or target list by an id or name. For a list, define one value per line. Not necessary with the 'Broadcast' action")] + [Display(Name = "Target (Optional)", Description = "Define target users or groups by id or name. One item per line. Not needed for Broadcast action.")] [Editor(RuleFieldEditor.TextArea)] [Formattable] public string Target { get; set; } @@ -55,12 +55,12 @@ namespace Squidex.Extensions.Actions.SignalR protected override IEnumerable CustomValidate() { - if (!string.IsNullOrWhiteSpace(HubName) && !Regex.IsMatch(HubName, "^[a-z][a-z0-9]{2,}(\\-[a-z0-9]+)*$")) + if (HubName != null && !Regex.IsMatch(HubName, "^[a-z][a-z0-9]{2,}(\\-[a-z0-9]+)*$")) { yield return new ValidationError("Hub must be valid azure hub name.", nameof(HubName)); } - if ((Action == ActionTypeEnum.User || Action == ActionTypeEnum.Group) && string.IsNullOrWhiteSpace(Target)) + if (Action != ActionTypeEnum.Broadcast && string.IsNullOrWhiteSpace(Target)) { yield return new ValidationError("Target must be specified with 'User' or 'Group' Action.", nameof(HubName)); } diff --git a/backend/extensions/Squidex.Extensions/Actions/SignalR/SignalRActionHandler.cs b/backend/extensions/Squidex.Extensions/Actions/SignalR/SignalRActionHandler.cs index f4ae61ac7..5d07128b0 100644 --- a/backend/extensions/Squidex.Extensions/Actions/SignalR/SignalRActionHandler.cs +++ b/backend/extensions/Squidex.Extensions/Actions/SignalR/SignalRActionHandler.cs @@ -30,6 +30,7 @@ namespace Squidex.Extensions.Actions.SignalR option.ServiceTransportType = ServiceTransportType.Transient; }) .Build(); + return serviceManager; }); } @@ -49,26 +50,20 @@ namespace Squidex.Extensions.Actions.SignalR requestBody = ToEnvelopeJson(@event); } - string[] targetArray = new string[0]; - string target = string.Empty; - target = await FormatAsync(action.Target, @event); - if (!string.IsNullOrEmpty(target)) - { - targetArray = target.Split('\n'); - } + var target = (await FormatAsync(action.Target, @event)) ?? string.Empty; var ruleDescription = $"Send SignalRJob to signalR hub '{hubName}'"; var ruleJob = new SignalRJob { + Action = action.Action, ConnectionString = action.ConnectionString, HubName = hubName, - Action = action.Action, MethodName = action.MethodName, - Target = target, - TargetArray = targetArray, - Payload = requestBody + MethodPayload = requestBody, + Targets = target.Split("\n"), }; + return (ruleDescription, ruleJob); } @@ -76,22 +71,20 @@ namespace Squidex.Extensions.Actions.SignalR { var signalR = await clients.GetClientAsync((job.ConnectionString, job.HubName)); - await using (var signalRContext = await signalR.CreateHubContextAsync(job.HubName)) + await using (var signalRContext = await signalR.CreateHubContextAsync(job.HubName, cancellationToken: ct)) { var methodeName = !string.IsNullOrWhiteSpace(job.MethodName) ? job.MethodName : "push"; switch (job.Action) { case ActionTypeEnum.Broadcast: - await signalRContext.Clients.All.SendAsync(methodeName, job.Payload); + await signalRContext.Clients.All.SendAsync(methodeName, job.MethodPayload, ct); break; case ActionTypeEnum.User: - await signalRContext.Clients.Users(job.TargetArray).SendAsync(methodeName, job.Payload); - + await signalRContext.Clients.Users(job.Targets).SendAsync(methodeName, job.MethodPayload, ct); break; case ActionTypeEnum.Group: - await signalRContext.Clients.Groups(job.TargetArray).SendAsync(methodeName, job.Payload); - + await signalRContext.Clients.Groups(job.Targets).SendAsync(methodeName, job.MethodPayload, ct); break; } } @@ -110,10 +103,8 @@ namespace Squidex.Extensions.Actions.SignalR public string MethodName { get; set; } - public string Target { get; set; } - - public string[] TargetArray { get; set; } + public string MethodPayload { get; set; } - public string Payload { get; set; } + public string[] Targets { get; set; } } } diff --git a/frontend/app/features/rules/shared/actions/generic-action.component.html b/frontend/app/features/rules/shared/actions/generic-action.component.html index 8f7a31cb2..1d88103b6 100644 --- a/frontend/app/features/rules/shared/actions/generic-action.component.html +++ b/frontend/app/features/rules/shared/actions/generic-action.component.html @@ -37,7 +37,7 @@ - {{property.description}} + You can use advanced formatting: Documentation