private void ProcessAdvancedFactorItems(Component leaf, List <FactorItem> factorItems, bool folderlevel, string simulationPath) { List <string> variableTypes = new List <string>(); LoadVariableTypes(Types.Instance.MetaDataNode("Factor", "FactorVariables"), variableTypes); //add any childnodes that are factors var result = (from c in leaf.ChildNodes where c.Type == "factor" && c.ContentsAsXML.SelectSingleNode("targets") != null select c); foreach (var factor in result) { List <string> targets = new List <string>(); string spath = simulationPath + "/"; foreach (XmlNode node in factor.ContentsAsXML.SelectSingleNode("//targets").ChildNodes) { if (node.InnerText.Contains(spath)) { targets.Add(node.InnerText); } } if (targets.Count > 0) { //manager factor or normal if (factor.ChildNodes.Count == 1 && variableTypes.Contains(factor.ChildNodes[0].Type.ToLower())) { XmlNodeList varNodes = factor.ContentsAsXML.SelectNodes("//vars/*"); foreach (XmlNode node in varNodes) { ManagerFactorItem item = new ManagerFactorItem(this); item.Targets = targets; item.FactorComponent = factor; item.Variable = node; string[] pars = node.InnerText.Split(new char[] { ',' }); var unique_pars = new HashSet <string>(pars.Select(x => x.Trim(new char[] { '\"', ' ' }))); item.Parameters = unique_pars.OrderBy(a => a).ToList <string>(); if ((from f in factorItems where f.getDesc() == item.getDesc() select f).Count() == 0) { if (factorItems.Count > 0) { item.NextItem = factorItems[0]; } factorItems.Insert(0, item); } } } else { FactorItem item = new FactorItem(this); item.Targets = targets; item.FactorComponent = factor; if ((from f in factorItems where f.getDesc() == item.getDesc() select f).Count() == 0) { if (factorItems.Count > 0) { item.NextItem = factorItems[0]; } factorItems.Insert(0, item); } } } } if (leaf.Parent != null && leaf.Parent.Parent != null) {//PArent.Parent is to check against the root node if (leaf.Parent.Type == "folder" && folderlevel) { //parent is a factorfolder FactorItem item = new FactorItem(this); //item.Targets = targets; item.FactorComponent = leaf.Parent; item.FolderLevel = leaf.Name; if ((from f in factorItems where f.getDesc() == item.getDesc() select f).Count() == 0) { if (factorItems.Count > 0) { item.NextItem = factorItems[0]; } factorItems.Insert(0, item); } } ProcessAdvancedFactorItems(leaf.Parent, factorItems, !folderlevel, simulationPath); } }
public void ProcessFactorNodes(Component parentComponent, ref FactorItem lastItem, ref List <FactorItem> items, string SimulationPath) { foreach (Component comp in parentComponent.ChildNodes) { if (comp.Type == "factor") { List <string> targets = new List <string>(); XmlNode varNode = comp.ContentsAsXML.SelectSingleNode("//targets"); if (varNode != null) { foreach (XmlNode target in varNode.ChildNodes) { string spath = SimulationPath + "/"; if (target.InnerText.Contains(spath)) { targets.Add(target.InnerText); } } } if (targets.Count > 0) { List <string> variableTypes = new List <string>(); LoadVariableTypes(Types.Instance.MetaDataNode("Factor", "FactorVariables"), variableTypes); if (comp.ChildNodes.Count == 1 && variableTypes.Contains(comp.ChildNodes[0].Type.ToLower())) {//(comp.ChildNodes[0].Type == "manager" || comp.ChildNodes[0].Type == "rule" || comp.ChildNodes[0].Type == "cropui")) //process variables within manager code XmlNodeList varNodes = comp.ContentsAsXML.SelectNodes("//vars/*"); foreach (XmlNode node in varNodes) { ManagerFactorItem item = new ManagerFactorItem(this); item.Targets = targets; item.FactorComponent = comp; item.Variable = node; string[] pars = node.InnerText.Split(new char[] { ',' }); pars = pars.Select(x => x.Trim(new char[] { '\"', ' ' })).ToArray(); var unique_pars = new HashSet <string>(pars); item.Parameters = unique_pars.OrderBy(a => a).ToList <string>(); if (lastItem == null) { items.Add(item); } else { lastItem.NextItem = item; } lastItem = item; } } else { FactorItem item = new FactorItem(this); item.Targets = targets; item.FactorComponent = comp; if (lastItem == null) { items.Add(item); } else { lastItem.NextItem = item; } lastItem = item; } } } else { ProcessFactorNodes(comp, ref lastItem, ref items, SimulationPath); } } }