public static Block Parse(XmlNode node, DFG <Block> dfg, ParserInfo parserInfo) { string id = ParseTools.ParseID(node); string output = ParseTools.ParseString(node, OUTPUT_FLUID_FIELD_NAME); Validator.CheckVariableName(id, output); parserInfo.AddVariable(id, VariableType.FLUID, output); XmlNode innerNode = node.GetInnerBlockNode(INPUT_FLUID_FIELD_NAME, parserInfo, new MissingBlockException(id, "Fluid is missing fluid definition blocks.")); if (innerNode != null) { switch (innerNode.GetAttributeValue(Block.TYPE_FIELD_NAME)) { case HeaterUsage.XML_TYPE_NAME: return(HeaterUsage.CreateHeater(output, innerNode, dfg, parserInfo)); case Mixer.XmlTypeName: return(Mixer.CreateMixer(output, innerNode, dfg, parserInfo)); case Union.XML_TYPE_NAME: return(Union.CreateUnion(output, innerNode, dfg, parserInfo)); default: return(CreateFluid(output, innerNode, dfg, parserInfo)); } } return(null); }
public void ParseHeaterBlock() { JSProgram program = new JSProgram(); program.AddHeaterSegment("a", "z", 173, 39, "b", 29, false); TestTools.ExecuteJS(program); XmlNode node = TestTools.GetWorkspace(); ParserInfo parserInfo = new ParserInfo(); parserInfo.EnterDFG(); parserInfo.AddVariable("", VariableType.FLUID, "b"); parserInfo.AddVariable("", VariableType.HEATER, "z"); HeaterUsage heater = (HeaterUsage)XmlParser.ParseBlock(node, null, parserInfo); Assert.AreEqual(0, parserInfo.ParseExceptions.Count, parserInfo.ParseExceptions.FirstOrDefault()?.Message); Assert.AreEqual("a", heater.OutputVariable); Assert.AreEqual(173, heater.Temperature); Assert.AreEqual(39, heater.Time); }