• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lucaslorentz / durabletask-extensions / 5835751495

pending completion
5835751495

push

github

lucaslorentz
Add husky and apply some code fixes

2502 of 2502 new or added lines in 91 files covered. (100.0%)

2286 of 2792 relevant lines covered (81.88%)

143.14 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

81.82
/src/LLL.DurableTask.Worker/Orchestrations/MethodTaskOrchestration.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Reflection;
4
using System.Runtime.ExceptionServices;
5
using System.Threading.Tasks;
6
using DurableTask.Core;
7
using DurableTask.Core.Serializing;
8
using LLL.DurableTask.Core.Serializing;
9

10
namespace LLL.DurableTask.Worker.Orchestrations;
11

12
public class MethodTaskOrchestration : TaskOrchestration
13
{
14
    private readonly MethodInfo _methodInfo;
15
    private readonly DataConverter _dataConverter;
16
    private ExtendedOrchestrationContext _extendedContext;
17

18
    public MethodTaskOrchestration(
15✔
19
        object instance,
15✔
20
        MethodInfo methodInfo)
15✔
21
    {
22
        Instance = instance;
15✔
23
        _methodInfo = methodInfo;
15✔
24
        _dataConverter = new TypelessJsonDataConverter();
15✔
25
    }
26

27
    public object Instance { get; }
15✔
28

29
    public override async Task<string> Execute(OrchestrationContext context, string input)
30
    {
31
        context.MessageDataConverter = new TypelessJsonDataConverter();
15✔
32
        context.ErrorDataConverter = new TypelessJsonDataConverter();
15✔
33

34
        var parameters = PrepareParameters(input, new Dictionary<Type, Func<object>>
15✔
35
        {
15✔
36
            [typeof(OrchestrationContext)] = () => context,
19✔
37
            [typeof(ExtendedOrchestrationContext)] = () => _extendedContext = new ExtendedOrchestrationContext(context),
20✔
38
        });
15✔
39

40
        try
41
        {
42
            var result = _methodInfo.Invoke(Instance, parameters);
15✔
43
            return await SerializeResult(result);
14✔
44
        }
45
        catch (TargetInvocationException ex)
46
        {
47
            ExceptionDispatchInfo.Capture(ex.InnerException).Throw();
1✔
48
            throw;
×
49
        }
50
    }
51

52
    public override string GetStatus()
53
    {
54
        return _extendedContext?.StatusProvider?.Invoke();
22✔
55
    }
56

57
    public override void RaiseEvent(OrchestrationContext context, string name, string input)
58
    {
59
        _extendedContext?.RaiseEvent(name, input);
7✔
60
    }
61

62
    private object[] PrepareParameters(
63
        string input,
64
        Dictionary<Type, Func<object>> factories)
65
    {
66
        var parameters = new List<object>();
15✔
67

68
        foreach (var p in _methodInfo.GetParameters())
48✔
69
        {
70
            object value;
71

72
            if (factories.TryGetValue(p.ParameterType, out var factory))
9✔
73
            {
74
                value = factory();
9✔
75
            }
76
            else if (input != null)
×
77
            {
78
                value = _dataConverter.Deserialize(input, p.ParameterType);
×
79
            }
80
            else if (p.HasDefaultValue)
×
81
            {
82
                value = p.DefaultValue;
×
83
            }
84
            else
85
                throw new Exception($"Orchestration input was not provided.");
×
86

87
            parameters.Add(value);
9✔
88
        }
89

90
        return parameters.ToArray();
15✔
91
    }
92

93
    private async Task<string> SerializeResult(object result)
94
    {
95
        if (result is Task task)
14✔
96
        {
97
            if (_methodInfo.ReturnType.IsGenericType)
10✔
98
            {
99
                result = await (dynamic)task;
100
            }
101
            else
102
            {
103
                await task;
104
                result = null;
105
            }
106
        }
107

108
        var serializedResult = _dataConverter.Serialize(result);
109

110
        return serializedResult;
111
    }
112
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc