| | | 1 | | using System.Runtime.CompilerServices; |
| | | 2 | | using Elsa.Extensions; |
| | | 3 | | using Elsa.Workflows.Attributes; |
| | | 4 | | using Elsa.Workflows.Exceptions; |
| | | 5 | | using Elsa.Workflows.Models; |
| | | 6 | | using JetBrains.Annotations; |
| | | 7 | | // ReSharper disable ExplicitCallerInfoArgument |
| | | 8 | | |
| | | 9 | | namespace Elsa.Workflows.Activities; |
| | | 10 | | |
| | | 11 | | /// <summary> |
| | | 12 | | /// Faults the workflow. |
| | | 13 | | /// </summary> |
| | | 14 | | [Activity("Elsa", "Primitives", "Faults the workflow.")] |
| | | 15 | | [PublicAPI] |
| | | 16 | | public class Fault : Activity |
| | | 17 | | { |
| | | 18 | | /// <inheritdoc /> |
| | 106 | 19 | | public Fault([CallerFilePath] string? source = null, [CallerLineNumber] int? line = null) : base(source, line) |
| | | 20 | | { |
| | 106 | 21 | | } |
| | | 22 | | |
| | | 23 | | /// <summary> |
| | | 24 | | /// Creates a fault activity. |
| | | 25 | | /// </summary> |
| | | 26 | | public static Fault Create(string code, string category, string type, string? message = null, [CallerFilePath] strin |
| | | 27 | | { |
| | 17 | 28 | | return new(source, line) |
| | 17 | 29 | | { |
| | 17 | 30 | | Code = new(code), |
| | 17 | 31 | | Message = new(message), |
| | 17 | 32 | | Category = new(category), |
| | 17 | 33 | | FaultType = new(type) |
| | 17 | 34 | | }; |
| | | 35 | | } |
| | | 36 | | |
| | | 37 | | /// <summary> |
| | | 38 | | /// Code to categorize the fault. |
| | | 39 | | /// </summary> |
| | | 40 | | [Input(Description = "Code to categorize the fault.")] |
| | 353 | 41 | | public Input<string> Code { get; set; } = null!; |
| | | 42 | | |
| | | 43 | | /// <summary> |
| | | 44 | | /// Category to categorize the fault. Examples: HTTP, Alteration, Azure, etc. |
| | | 45 | | /// </summary> |
| | | 46 | | [Input(Description = "Category to categorize the fault. Examples: HTTP, Alteration, Azure, etc.")] |
| | 353 | 47 | | public Input<string> Category { get; set; } = null!; |
| | | 48 | | |
| | | 49 | | /// <summary> |
| | | 50 | | /// The type of fault. Examples: System, Business, Integration, etc. |
| | | 51 | | /// </summary> |
| | | 52 | | [Input( |
| | | 53 | | DisplayName = "Type", |
| | | 54 | | Description = "The type of fault. Examples: System, Business, Integration, etc." |
| | | 55 | | )] |
| | 353 | 56 | | public Input<string> FaultType { get; set; } = null!; |
| | | 57 | | |
| | | 58 | | /// <summary> |
| | | 59 | | /// The message to include with the fault. |
| | | 60 | | /// </summary> |
| | | 61 | | [Input(Description = "The message to include with the fault.")] |
| | 388 | 62 | | public Input<string?> Message { get; set; } = null!; |
| | | 63 | | |
| | | 64 | | /// <inheritdoc /> |
| | | 65 | | protected override void Execute(ActivityExecutionContext context) |
| | | 66 | | { |
| | 18 | 67 | | var code = Code.GetOrDefault(context) ?? "0"; |
| | 18 | 68 | | var category = Category.GetOrDefault(context) ?? "General"; |
| | 18 | 69 | | var type = FaultType.GetOrDefault(context) ?? "System"; |
| | 18 | 70 | | var message = Message.GetOrDefault(context); |
| | 18 | 71 | | throw new FaultException(code, category, type, message); |
| | | 72 | | } |
| | | 73 | | } |