-
Notifications
You must be signed in to change notification settings - Fork 11
/
EssentialsTimeout.cs
57 lines (51 loc) · 1.94 KB
/
EssentialsTimeout.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System;
using System.Collections.Generic;
using Dynamo.Graph.Nodes;
using ProtoCore.AST.AssociativeAST;
using NodeModelsEssentials.Functions;
using System.Linq;
using Newtonsoft.Json;
namespace NodeModelsEssentials
{
// <summary>
// Sample Node Model called MultiplyMulti.
// It returns the product of two numbers and a verbose string.
// </summary>
[NodeName("Essentials.Timeout")]
[NodeDescription("Sleeps for a bit and throws an error if the sleeping times out. Determine the maximum duration a node can run for (and time out if it surpasses it).")]
[NodeCategory("NodeModelsEssentials")]
[InPortNames("Sleep", "Timeout")]
[InPortTypes("int", "int")]
[InPortDescriptions("Sleep duration.", "Timeout duration")]
[OutPortNames("Message")]
[OutPortTypes("string")]
[OutPortDescriptions("Resulting string.")]
[IsDesignScriptCompatible]
public class Timeout : NodeModel
{
[JsonConstructor]
private Timeout(IEnumerable<PortModel> inPorts, IEnumerable<PortModel> outPorts) : base(inPorts, outPorts)
{
}
public Timeout()
{
RegisterAllPorts();
}
public override IEnumerable<AssociativeNode> BuildOutputAst(List<AssociativeNode> inputAsNodes)
{
if (!InPorts[0].Connectors.Any() || !InPorts[1].Connectors.Any())
{
return new[] {
AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), AstFactory.BuildNullNode())
};
}
var timeoutFunctionNode =
AstFactory.BuildFunctionCall(
new Func<int, int, string>(NodeModelsEssentialsFunctions.Timeout),
new List<AssociativeNode> { inputAsNodes[0], inputAsNodes[1] });
return new[] {
AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), timeoutFunctionNode)
};
}
}
}