protected virtual NodeStep EvaluateNode(Node node) { NodeStep step; Log.Trace("Entering node {0}", node.GetType().Name); try { step = node.Evaluate(); } catch { step = new NodeStep(NodeResult.Fail, null); } if (evaluating) { Log.Trace("Exiting node {0} with result {1}{2}", node.GetType().Name, step.Result, step.Slot == null ? "" : (" by slot " + step.Slot.Name)); } return(step); }
protected virtual NodeStep EvaluateNode(Node node) { NodeStep step; Log.Trace("Entering node {0}", node.GetType().Name); try { step = node.Evaluate(); } catch { step = new NodeStep(NodeResult.Fail, null); } if (evaluating) Log.Trace("Exiting node {0} with result {1}{2}", node.GetType().Name, step.Result, step.Slot == null ? "" : (" by slot " + step.Slot.Name)); return step; }
public static XDocument Save(XFlow flow) { XElement propertiesElement, nodesElement; XDocument document = new XDocument( new XElement("Flow", propertiesElement = new XElement("Properties"), nodesElement = new XElement("Nodes") ) ); // Save references Assembly[] assemblies = flow.Nodes.Select(n => Assembly.GetAssembly(n.GetType())) .Except(new [] { Assembly.GetAssembly(typeof(Flow)) }) .Distinct() .ToArray(); if (assemblies.Length > 0) { XElement referencesElement = new XElement("References"); propertiesElement.Add(referencesElement); string binaryPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)); foreach (Assembly assembly in assemblies) { string location = assembly.Location; location = Utilities.MakeRelativePath(binaryPath, location); referencesElement.Add(new XElement("Assembly", new XAttribute("Path", location))); } } // Save nodes for (int i = 0; i < flow.Nodes.Count; i++) { Node node = flow.Nodes[i]; XElement inputsElement, outputsElement, metadataElement; XElement nodeElement = new XElement("Node", new XAttribute("Type", node.GetType().FullName), new XAttribute("Id", i), inputsElement = new XElement("Inputs"), outputsElement = new XElement("Outputs"), metadataElement = new XElement("Metadata") ); // Inputs foreach (Variable input in node.Inputs) { if (input.Linked != null) { inputsElement.Add(new XAttribute(input.Name, "$" + input.Linked.Name)); } else if (input.Value != input.DefaultValue) { TypeConverter typeConverter = TypeDescriptor.GetConverter(input.Type); string value; if (typeConverter != null && typeConverter.CanConvertTo(typeof(string))) { value = typeConverter.ConvertToString(input.Value); } else { value = input.Value.ToString(); } inputsElement.Add(new XAttribute(input.Name, value)); } } // Outputs foreach (Variable output in node.Outputs) { if (output.Linked != null) { outputsElement.Add(new XAttribute(output.Name, "$" + output.Linked.Name)); } } // Metadata foreach (var pair in node.Metadata) { metadataElement.Add(new XAttribute(pair.Key, pair.Value.ToString())); } // Slots Slot[] slots = node.Slots.ToArray(); for (int j = 0; j < slots.Length; j++) { if (slots[j].Nodes.Count == 0) { continue; } XElement slotElement = new XElement("Slot"); if (slots.Length > 1) { slotElement.Add(new XAttribute("Index", j)); } foreach (Node subNode in slots[j].Nodes) { int id = flow.Nodes.IndexOf(subNode); slotElement.Add(new XElement("Node", new XAttribute("Id", id))); } nodeElement.Add(slotElement); } // Clean empty elements if (!inputsElement.HasAttributes) { inputsElement.Remove(); } if (!outputsElement.HasAttributes) { outputsElement.Remove(); } if (!metadataElement.HasAttributes) { metadataElement.Remove(); } nodesElement.Add(nodeElement); } return(document); }