Esempio n. 1
0
        public async Task ExpressionEvNode()
        {
            var padContract = new Engine.Contracts.PadContract()
            {
                Id   = 1,
                Name = "test"
            };

            var constant1 = new Engine.Contracts.NodeBaseContract()
            {
                Id       = 1,
                NodeId   = 1,
                OutNodes = new List <long>()
                {
                    4
                },
                Type     = NodeType.Input,
                MetaData = new NodeMetaData()
                {
                    NodeData = new NodeMetaDataAttribute()
                    {
                        NodeClass = typeof(ConstantNode)
                    },
                    FieldsMetaData = new List <FieldMetaDataAttribute>()
                    {
                        new FieldMetaDataAttribute()
                        {
                            Name      = "Value",
                            ValueType = typeof(int)
                        },
                        new FieldMetaDataAttribute()
                        {
                            Name      = "ConstantType",
                            ValueType = typeof(ConstantType)
                        }
                    }
                }
            };

            var constant2 = new Engine.Contracts.NodeBaseContract()
            {
                Id       = 2,
                NodeId   = 2,
                OutNodes = new List <long>()
                {
                    4
                },
                Type     = NodeType.Input,
                MetaData = new NodeMetaData()
                {
                    NodeData = new Engine.NodeMetaDataAttribute()
                    {
                        NodeClass = typeof(ConstantNode)
                    },
                    FieldsMetaData = new List <FieldMetaDataAttribute>()
                    {
                        new FieldMetaDataAttribute()
                        {
                            Name      = "Value",
                            ValueType = typeof(int)
                        },
                        new FieldMetaDataAttribute()
                        {
                            Name      = "ConstantType",
                            ValueType = typeof(ConstantType)
                        }
                    }
                }
            };


            var constant3 = new Engine.Contracts.NodeBaseContract()
            {
                Id       = 3,
                NodeId   = 3,
                OutNodes = new List <long>()
                {
                    4
                },
                Type     = NodeType.Input,
                MetaData = new NodeMetaData()
                {
                    NodeData = new Engine.NodeMetaDataAttribute()
                    {
                        NodeClass = typeof(ConstantNode)
                    },
                    FieldsMetaData = new List <FieldMetaDataAttribute>()
                    {
                        new FieldMetaDataAttribute()
                        {
                            Name      = "Value",
                            ValueType = typeof(int)
                        },
                        new FieldMetaDataAttribute()
                        {
                            Name      = "ConstantType",
                            ValueType = typeof(ConstantType)
                        }
                    }
                }
            };

            var expressionNode = new Engine.Contracts.NodeBaseContract()
            {
                Id      = 4,
                NodeId  = 4,
                InNodes = new List <long>()
                {
                    1, 2, 3
                },
                Type     = NodeType.Output,
                MetaData = new NodeMetaData()
                {
                    NodeData = new NodeMetaDataAttribute()
                    {
                        NodeClass = typeof(ExpressionEvaluatorNode)
                    },
                    FieldsMetaData = new List <FieldMetaDataAttribute>()
                    {
                        new FieldMetaDataAttribute()
                        {
                            Name            = "Value",
                            MappedNodeId    = 1,
                            MappedFieldName = "Value"
                        },
                        new FieldMetaDataAttribute()
                        {
                            Name            = "Value",
                            MappedNodeId    = 2,
                            MappedFieldName = "Value"
                        },
                        new FieldMetaDataAttribute()
                        {
                            Name            = "Value",
                            MappedNodeId    = 3,
                            MappedFieldName = "Value"
                        },
                        new FieldMetaDataAttribute()
                        {
                            Name      = "Expression",
                            ValueType = typeof(string)
                        }
                    }
                }
            };

            padContract.Nodes = new List <Engine.Contracts.NodeBaseContract>()
            {
                constant1, constant2, constant3, expressionNode
            };

            List <InstanceMapping> mappings = new List <InstanceMapping>()
            {
                new InstanceMapping()
                {
                    NodeId        = 1,
                    FieldMappings = new List <FieldMapping>()
                    {
                        new FieldMapping()
                        {
                            FieldName = "Value", Value = "2"
                        },
                        new FieldMapping()
                        {
                            FieldName = "ConstantType", Value = "Int"
                        },
                    }
                },
                new InstanceMapping()
                {
                    NodeId        = 2,
                    FieldMappings = new List <FieldMapping>()
                    {
                        new FieldMapping()
                        {
                            FieldName = "Value", Value = "10"
                        },
                        new FieldMapping()
                        {
                            FieldName = "ConstantType", Value = "Int"
                        },
                    }
                },
                new InstanceMapping()
                {
                    NodeId        = 3,
                    FieldMappings = new List <FieldMapping>()
                    {
                        new FieldMapping()
                        {
                            FieldName = "Value", Value = "1"
                        },
                        new FieldMapping()
                        {
                            FieldName = "ConstantType", Value = "Int"
                        },
                    }
                },
                new InstanceMapping()
                {
                    NodeId        = 4,
                    FieldMappings = new List <FieldMapping>()
                    {
                        new FieldMapping()
                        {
                            FieldName = "Expression", Value = "{{Value_1}} * {{Value_2}} + {{Value_3}}"
                        },
                    }
                }
            };
            var instance = new Instances(mappings);

            var json = JsonConvert.SerializeObject(instance);

            var pad = PadFactory.CreateInstance(padContract, ExecutionMode.Normal, instance);
            await pad.Init();

            await pad.Execute(pad.Context, instance);

            Assert.Equal(ExecutionStatus.Success, pad.Context.Status);
            Assert.Equal(21, pad.Context.Result);
        }
Esempio n. 2
0
        public async System.Threading.Tasks.Task PadNodeExeTestAsync()
        {
            var padContract = new Engine.Contracts.PadContract()
            {
                Id   = 1,
                Name = "test"
            };

            var constant1 = new Engine.Contracts.NodeBaseContract()
            {
                Id       = 1,
                NodeId   = 1,
                OutNodes = new List <long>()
                {
                    3
                },
                Type     = NodeType.Input,
                MetaData = new NodeMetaData()
                {
                    NodeData = new NodeMetaDataAttribute()
                    {
                        NodeClass = typeof(ConstantNode)
                    },
                    FieldsMetaData = new List <FieldMetaDataAttribute>()
                    {
                        new FieldMetaDataAttribute()
                        {
                            Name      = "Value",
                            ValueType = typeof(int)
                        },
                        new FieldMetaDataAttribute()
                        {
                            Name      = "ConstantType",
                            ValueType = typeof(ConstantType)
                        }
                    }
                }
            };

            var constant2 = new NodeBaseContract()
            {
                Id       = 2,
                NodeId   = 2,
                OutNodes = new List <long>()
                {
                    3
                },
                Type     = NodeType.Input,
                MetaData = new NodeMetaData()
                {
                    NodeData = new NodeMetaDataAttribute()
                    {
                        NodeClass = typeof(ConstantNode)
                    },
                    FieldsMetaData = new List <FieldMetaDataAttribute>()
                    {
                        new FieldMetaDataAttribute()
                        {
                            Name      = "Value",
                            ValueType = typeof(int)
                        },
                        new FieldMetaDataAttribute()
                        {
                            Name      = "ConstantType",
                            ValueType = typeof(ConstantType)
                        }
                    }
                }
            };

            var add = new NodeBaseContract()
            {
                Id      = 3,
                NodeId  = 3,
                InNodes = new List <long>()
                {
                    1, 2
                },
                Type     = NodeType.Output,
                MetaData = new NodeMetaData()
                {
                    NodeData = new NodeMetaDataAttribute()
                    {
                        NodeClass = typeof(AddNode)
                    },
                    FieldsMetaData = new List <FieldMetaDataAttribute>()
                    {
                        new FieldMetaDataAttribute()
                        {
                            Name            = "Left",
                            Direction       = FieldDirection.Input,
                            MappedNodeId    = 1,
                            MappedFieldName = "Value"
                        },
                        new FieldMetaDataAttribute()
                        {
                            Name         = "Right",
                            MappedNodeId = 2,
                            Direction    = FieldDirection.Input,
                        }
                    }
                }
            };

            padContract.Nodes = new List <NodeBaseContract>()
            {
                constant1, constant2, add
            };

            List <InstanceMapping> mappings = new List <InstanceMapping>()
            {
                new InstanceMapping()
                {
                    NodeId        = 1,
                    FieldMappings = new List <FieldMapping>()
                    {
                        new FieldMapping()
                        {
                            FieldName = "Value", Value = "1"
                        },
                        new FieldMapping()
                        {
                            FieldName = "ConstantType", Value = "Int"
                        },
                    }
                },
                new InstanceMapping()
                {
                    NodeId        = 2,
                    FieldMappings = new List <FieldMapping>()
                    {
                        new FieldMapping()
                        {
                            FieldName = "Value", Value = "1"
                        },
                        new FieldMapping()
                        {
                            FieldName = "ConstantType", Value = "Int"
                        },
                    }
                }
            };
            var instance = new Instances(mappings);


            var padnodeContract = new Engine.Contracts.PadContract()
            {
                Id   = 1,
                Name = "test"
            };

            var padNode = new NodeBaseContract()
            {
                Id       = 1,
                NodeId   = 1,
                Type     = NodeType.Input,
                OutNodes = new List <long>()
                {
                    2
                },
                MetaData = new NodeMetaData()
                {
                    NodeData = new NodeMetaDataAttribute()
                    {
                        NodeClass = typeof(PadNode)
                    },
                    FieldsMetaData = new List <FieldMetaDataAttribute>()
                    {
                        new FieldMetaDataAttribute()
                        {
                            Name      = "PadContract",
                            ValueType = typeof(Engine.Contracts.PadContract)
                        },
                        new FieldMetaDataAttribute()
                        {
                            Name      = "PadMode",
                            ValueType = typeof(ExecutionMode)
                        },
                        new FieldMetaDataAttribute()
                        {
                            Name      = "Instance",
                            ValueType = typeof(Instances)
                        }
                    }
                }
            };
            var constantOutput = new NodeBaseContract()
            {
                Id       = 2,
                NodeId   = 2,
                Type     = NodeType.Output,
                MetaData = new NodeMetaData()
                {
                    NodeData = new NodeMetaDataAttribute()
                    {
                        NodeClass = typeof(ConstantNode)
                    },
                    FieldsMetaData = new List <FieldMetaDataAttribute>()
                    {
                        new FieldMetaDataAttribute()
                        {
                            Name         = "Value",
                            MappedNodeId = 1,
                            Direction    = FieldDirection.Input,
                        },
                        new FieldMetaDataAttribute()
                        {
                            Name      = "ConstantType",
                            ValueType = typeof(ConstantType)
                        }
                    }
                }
            };

            padnodeContract.Nodes = new List <NodeBaseContract>()
            {
                padNode, constantOutput
            };

            var padInstance = new Instances(
                new List <InstanceMapping>()
            {
                new InstanceMapping()
                {
                    NodeId        = 1,
                    FieldMappings = new List <FieldMapping>()
                    {
                        new FieldMapping()
                        {
                            FieldName = "PadContract", Value = JsonConvert.SerializeObject(padContract)
                        },
                        new FieldMapping()
                        {
                            FieldName = "PadMode", Value = "Normal"
                        },
                        new FieldMapping()
                        {
                            FieldName = "Instance", Value = JsonConvert.SerializeObject(instance)
                        },
                    }
                }
            });

            var pad = PadFactory.CreateInstance(padnodeContract, ExecutionMode.Normal, padInstance);
            await pad.Init();

            await pad.Execute(pad.Context, instance);

            Assert.Equal(ExecutionStatus.Success, pad.Context.Status);
            Assert.Equal(2.0, pad.Context.Result);
        }
Esempio n. 3
0
        public async Task ObjectNodeTestAsync()
        {
            var padContract = new Engine.Contracts.PadContract()
            {
                Id   = 1,
                Name = "test"
            };

            var objectNode = new Engine.Contracts.NodeBaseContract()
            {
                Id       = 1,
                NodeId   = 1,
                OutNodes = new List <long>()
                {
                    2
                },
                Type     = NodeType.Input,
                MetaData = new NodeMetaData()
                {
                    NodeData = new NodeMetaDataAttribute()
                    {
                        NodeClass = typeof(ObjectNode)
                    },
                    FieldsMetaData = new List <FieldMetaDataAttribute>()
                    {
                        new FieldMetaDataAttribute()
                        {
                            Name      = "Schema",
                            ValueType = typeof(string)
                        },
                        new FieldMetaDataAttribute()
                        {
                            Name      = "JsonString",
                            ValueType = typeof(string)
                        }
                    }
                }
            };

            var constant1 = new Engine.Contracts.NodeBaseContract()
            {
                Id     = 2,
                NodeId = 2,
                // OutNodes = new List<long>() { 3 },
                Type     = NodeType.Output,
                MetaData = new NodeMetaData()
                {
                    NodeData = new NodeMetaDataAttribute()
                    {
                        NodeClass = typeof(ConstantNode)
                    },
                    FieldsMetaData = new List <FieldMetaDataAttribute>()
                    {
                        new FieldMetaDataAttribute()
                        {
                            Name            = "Value",
                            ValueType       = typeof(object),
                            Direction       = FieldDirection.Input,
                            MappedNodeId    = 1,
                            MappedFieldName = "__Result__"
                        },
                        new FieldMetaDataAttribute()
                        {
                            Name      = "ConstantType",
                            ValueType = typeof(ConstantType)
                        }
                    }
                }
            };

            padContract.Nodes = new List <Engine.Contracts.NodeBaseContract>()
            {
                objectNode, constant1
            };

            var contractString = JsonConvert.SerializeObject(padContract);

            JSchemaGenerator generator = new JSchemaGenerator();
            JSchema          schema    = generator.Generate(typeof(Account));
            var schemaString           = schema.ToString();
            var account = new Account
            {
                Email     = "*****@*****.**",
                Name      = "Johe Doe",
                Age       = 20,
                DateBrith = new DateTimeOffset(1980, 1, 1, 12, 1, 2, new TimeSpan(-6, 0, 0)),
                Address   = new Address {
                    Line1 = "Mobile AL"
                },
                Duration  = new TimeSpan(12, 0, 1),
                LastLogin = DateTime.Now
            };

            List <InstanceMapping> mappings = new List <InstanceMapping>()
            {
                new InstanceMapping()
                {
                    NodeId        = 1,
                    FieldMappings = new List <FieldMapping>()
                    {
                        new FieldMapping()
                        {
                            FieldName = "Schema", Value = schema.ToString()
                        },
                        new FieldMapping()
                        {
                            FieldName = "JsonString", Value = JsonConvert.SerializeObject(account)
                        },
                    }
                }
            };
            var instance = new Instances(mappings);
            var json     = JsonConvert.SerializeObject(instance);
            var pad      = PadFactory.CreateInstance(padContract, ExecutionMode.Normal, instance);
            await pad.Init();

            await pad.Execute(pad.Context, instance);

            Assert.Equal(ExecutionStatus.Success, pad.Context.Status);
            Assert.NotNull(pad.Context.Result);

            await Task.CompletedTask;
        }
Esempio n. 4
0
        public async System.Threading.Tasks.Task MultiplyNodeConstantTestAsync()
        {
            var padContract = new Engine.Contracts.PadContract()
            {
                Id   = 1,
                Name = "test"
            };

            var constant1 = new Engine.Contracts.NodeBaseContract()
            {
                Id       = 1,
                NodeId   = 1,
                OutNodes = new List <long>()
                {
                    3
                },
                Type     = NodeType.Input,
                MetaData = new NodeMetaData()
                {
                    NodeData = new Engine.NodeMetaDataAttribute()
                    {
                        NodeClass = typeof(ConstantNode)
                    },
                    FieldsMetaData = new List <FieldMetaDataAttribute>()
                    {
                        new FieldMetaDataAttribute()
                        {
                            Name      = "Value",
                            ValueType = typeof(int)
                        },
                        new FieldMetaDataAttribute()
                        {
                            Name      = "ConstantType",
                            ValueType = typeof(ConstantType)
                        }
                    }
                }
            };

            var constant2 = new Engine.Contracts.NodeBaseContract()
            {
                Id       = 2,
                NodeId   = 2,
                OutNodes = new List <long>()
                {
                    3
                },
                Type     = NodeType.Input,
                MetaData = new NodeMetaData()
                {
                    NodeData = new Engine.NodeMetaDataAttribute()
                    {
                        NodeClass = typeof(ConstantNode)
                    },
                    FieldsMetaData = new List <FieldMetaDataAttribute>()
                    {
                        new FieldMetaDataAttribute()
                        {
                            Name      = "Value",
                            ValueType = typeof(double)
                        },
                        new FieldMetaDataAttribute()
                        {
                            Name      = "ConstantType",
                            ValueType = typeof(ConstantType)
                        }
                    }
                }
            };

            var add = new Engine.Contracts.NodeBaseContract()
            {
                Id      = 3,
                NodeId  = 3,
                InNodes = new List <long>()
                {
                    1, 2
                },
                Type     = NodeType.Output,
                MetaData = new NodeMetaData()
                {
                    NodeData = new Engine.NodeMetaDataAttribute()
                    {
                        NodeClass = typeof(MultiplyNode)
                    },
                    FieldsMetaData = new List <FieldMetaDataAttribute>()
                    {
                        new FieldMetaDataAttribute()
                        {
                            Name            = "Left",
                            Direction       = FieldDirection.Input,
                            MappedNodeId    = 1,
                            MappedFieldName = "Value"
                        },
                        new FieldMetaDataAttribute()
                        {
                            Name         = "Right",
                            MappedNodeId = 2,
                            Direction    = FieldDirection.Input,
                        }
                    }
                }
            };

            padContract.Nodes = new List <Engine.Contracts.NodeBaseContract>()
            {
                constant1, constant2, add
            };

            List <InstanceMapping> mappings = new List <InstanceMapping>()
            {
                new InstanceMapping()
                {
                    NodeId        = 1,
                    FieldMappings = new List <FieldMapping>()
                    {
                        new FieldMapping()
                        {
                            FieldName = "Value", Value = "10"
                        },
                        new FieldMapping()
                        {
                            FieldName = "ConstantType", Value = "Int"
                        },
                    }
                },
                new InstanceMapping()
                {
                    NodeId        = 2,
                    FieldMappings = new List <FieldMapping>()
                    {
                        new FieldMapping()
                        {
                            FieldName = "Value", Value = "1.1"
                        },
                        new FieldMapping()
                        {
                            FieldName = "ConstantType", Value = "Number"
                        },
                    }
                }
            };
            var instance = new Instances(mappings);


            var pad = PadFactory.CreateInstance(padContract, ExecutionMode.Normal, instance);
            await pad.Init();

            await pad.Execute(pad.Context, instance);

            Assert.Equal(ExecutionStatus.Success, pad.Context.Status);
            Assert.Equal(11.0, pad.Context.Result);
        }
Esempio n. 5
0
        public async Task OrNode()
        {
            var padContract = new Engine.Contracts.PadContract()
            {
                Id   = 1,
                Name = "test"
            };

            var constant1 = new Engine.Contracts.NodeBaseContract()
            {
                Id       = 1,
                NodeId   = 1,
                OutNodes = new List <long>()
                {
                    3
                },
                Type     = NodeType.Input,
                MetaData = new NodeMetaData()
                {
                    NodeData = new NodeMetaDataAttribute()
                    {
                        NodeClass = typeof(ConstantNode)
                    },
                    FieldsMetaData = new List <FieldMetaDataAttribute>()
                    {
                        new FieldMetaDataAttribute()
                        {
                            Name      = "Value",
                            ValueType = typeof(bool)
                        },
                        new FieldMetaDataAttribute()
                        {
                            Name      = "ConstantType",
                            ValueType = typeof(ConstantType)
                        }
                    }
                }
            };

            var constant2 = new Engine.Contracts.NodeBaseContract()
            {
                Id       = 2,
                NodeId   = 2,
                OutNodes = new List <long>()
                {
                    3
                },
                Type     = NodeType.Input,
                MetaData = new NodeMetaData()
                {
                    NodeData = new Engine.NodeMetaDataAttribute()
                    {
                        NodeClass = typeof(ConstantNode)
                    },
                    FieldsMetaData = new List <FieldMetaDataAttribute>()
                    {
                        new FieldMetaDataAttribute()
                        {
                            Name      = "Value",
                            ValueType = typeof(bool)
                        },
                        new FieldMetaDataAttribute()
                        {
                            Name      = "ConstantType",
                            ValueType = typeof(ConstantType)
                        }
                    }
                }
            };

            var add = new Engine.Contracts.NodeBaseContract()
            {
                Id      = 3,
                NodeId  = 3,
                InNodes = new List <long>()
                {
                    1, 2
                },
                Type     = NodeType.Output,
                MetaData = new NodeMetaData()
                {
                    NodeData = new Engine.NodeMetaDataAttribute()
                    {
                        NodeClass = typeof(OrNode)
                    },
                    FieldsMetaData = new List <FieldMetaDataAttribute>()
                    {
                        new FieldMetaDataAttribute()
                        {
                            Name            = "Left",
                            Direction       = FieldDirection.Input,
                            MappedNodeId    = 1,
                            MappedFieldName = "Value"
                        },
                        new FieldMetaDataAttribute()
                        {
                            Name         = "Right",
                            MappedNodeId = 2,
                            Direction    = FieldDirection.Input,
                        }
                    }
                }
            };

            padContract.Nodes = new List <Engine.Contracts.NodeBaseContract>()
            {
                constant1, constant2, add
            };

            List <InstanceMapping> mappings = new List <InstanceMapping>()
            {
                new InstanceMapping()
                {
                    NodeId        = 1,
                    FieldMappings = new List <FieldMapping>()
                    {
                        new FieldMapping()
                        {
                            FieldName = "Value", Value = "True"
                        },
                        new FieldMapping()
                        {
                            FieldName = "ConstantType", Value = "Boolean"
                        },
                    }
                },
                new InstanceMapping()
                {
                    NodeId        = 2,
                    FieldMappings = new List <FieldMapping>()
                    {
                        new FieldMapping()
                        {
                            FieldName = "Value", Value = "False"
                        },
                        new FieldMapping()
                        {
                            FieldName = "ConstantType", Value = "Boolean"
                        },
                    }
                }
            };
            var instance = new Instances(mappings);

            var json = JsonConvert.SerializeObject(instance);

            var pad = PadFactory.CreateInstance(padContract, ExecutionMode.Normal, instance);
            await pad.Init();

            await pad.Execute(pad.Context, instance);

            Assert.Equal(ExecutionStatus.Success, pad.Context.Status);
            Assert.Equal(true, pad.Context.Result);
        }