-
Notifications
You must be signed in to change notification settings - Fork 11
/
EssentialsError.cs
58 lines (52 loc) · 1.73 KB
/
EssentialsError.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
58
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.Error")]
[NodeDescription("Throw a custom warning when something fails.")]
[NodeCategory("NodeModelsEssentials")]
[InPortNames("In")]
[InPortTypes("string")]
[InPortDescriptions("A string.")]
[OutPortNames("Out")]
[OutPortTypes("string")]
[OutPortDescriptions(
"Resulting string.")]
[IsDesignScriptCompatible]
public class Error : NodeModel
{
[JsonConstructor]
private Error(IEnumerable<PortModel> inPorts, IEnumerable<PortModel> outPorts) : base(inPorts, outPorts)
{
}
public Error()
{
RegisterAllPorts();
}
public override IEnumerable<AssociativeNode> BuildOutputAst(List<AssociativeNode> inputAsNodes)
{
if (!InPorts[0].Connectors.Any())
{
return new[] {
AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), AstFactory.BuildNullNode())
};
}
var errorFunctionNode =
AstFactory.BuildFunctionCall(
new Func<string, string>(NodeModelsEssentialsFunctions.Error),
new List<AssociativeNode> { inputAsNodes[0] });
return new[] {
AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), errorFunctionNode)
};
}
}
}