Esempio n. 1
0
        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);
            }
        }