/// <summary> /// Calculate and realise outputs for the node /// </summary> public void CalculateOutput() { // Get input values IList <IDataTypeContainer> nodeInputList = new List <IDataTypeContainer>(); for (int i = 0; i < NodeInputs.Count; i++) { IDataTypeContainer inputValue = (IDataTypeContainer)Activator.CreateInstance(NodeInputs[i].DataType); inputValue.SetValue(NodeInputs[i].GetValue.GetDataAsString()); nodeInputList.Add(inputValue); } // Process inputs and realise the outputs List <IDataTypeContainer> result; NodeBase node; // If node is executable we need to make sure we pass the query state to it if (NodeType.IsSubclassOf(typeof(ExecutableNode))) { node = (ExecutableNode)Activator.CreateInstance(NodeType, new object[] { GraphManager.QueryState }); } else { node = (NodeBase)Activator.CreateInstance(NodeType); } // Forward input values to the instantiated node for (int i = 0; i < NodeInputs.Count; i++) { int fieldCounter = 0; foreach (FieldInfo field in node.GetType().GetFields()) { foreach (Attribute attribute in field.GetCustomAttributes()) { if (attribute.GetType() == typeof(ExposedInput)) { if (fieldCounter++ == i) { field.SetValue(node, NodeInputs[i].GetValue); } } } } } // Ready to calculate the output node.NodeFunction(); result = new List <IDataTypeContainer>(); // Extract the newly calculated output from the node for (int i = 0; i < NodeOutputs.Count; i++) { int fieldCounter = 0; foreach (FieldInfo field in node.GetType().GetFields()) { foreach (Attribute attribute in field.GetCustomAttributes()) { if (attribute.GetType() == typeof(ExposedOutput)) { if (fieldCounter++ == i) { result.Add(field.GetValue(node) as IDataTypeContainer); } } } } } // And set the outputs in the graph model for (int i = 0; i < result.Count; i++) { NodeOutputs[i].OutputValue = result[i]; NodeOutputs[i].OutputRealised = true; } if (node is ExecutableNode) { ExecutionPath = (node as ExecutableNode).GetExecutionPath(); } }