Exemple #1
0
        public static EquationLibrary CreateLibraryFromDatabase(ContentManager contentManager,
                                                                SqLiteContentDatabase database, IList <TblEqLibSectionNode_Row> sectionNodeRows,
                                                                IList <TblEqLibEquation_Row> equationRows, IList <TblEqLibVariable_Row> variableRows)
        {
            EquationLibrary equationLibrary = new EquationLibrary();

            equationLibrary.CreateFromDatabase(contentManager, database, sectionNodeRows,
                                               equationRows, variableRows);
            return(equationLibrary);
        }
Exemple #2
0
        public void CreateFromDatabase(ContentManager contentManager,
                                       SqLiteContentDatabase database, IList <TblEqLibSectionNode_Row> sectionNodeRows,
                                       IList <TblEqLibEquation_Row> equationRows, IList <TblEqLibVariable_Row> variableRows)
        {
            Name        = database.GetInfoVal("EquationLibraryName");
            Description = database.GetInfoVal("EquationLibraryDescription");

            // ----------- Read all the section nodes
            IDictionary <int, Tuple <TblEqLibSectionNode_Row, SectionNode> > allSectionNodes
                = new Dictionary <int, Tuple <TblEqLibSectionNode_Row, SectionNode> >();                       // Key is TblEqLibSectionNode_Row.SectionNodeID

            foreach (var nodeRow in sectionNodeRows)
            {
                SectionNode sectionNode = new SectionNode(nodeRow.Name)
                {
                    Description = nodeRow.Description
                };
                allSectionNodes.Add(nodeRow.SectionNodeID, new Tuple <TblEqLibSectionNode_Row, SectionNode>(nodeRow, sectionNode));
            }

            // ----------- Connect the parents
            foreach (var nodeTpl in allSectionNodes)
            {
                TblEqLibSectionNode_Row nodeRow     = nodeTpl.Value.Item1;
                SectionNode             sectionNode = nodeTpl.Value.Item2;

                if (nodeRow.ParentNodeID > 0)
                {
                    int parentNodeID = nodeRow.ParentNodeID;
                    if (allSectionNodes.ContainsKey(parentNodeID))
                    {
                        sectionNode.Parent = allSectionNodes[parentNodeID].Item2;
                    }
                    else
                    {
                        int iDbg = 0;   // TODO
                    }
                }
                else
                {
                    TopSectionNodes.Add(sectionNode);
                }
            }

            // ----------- Check for duplications or loops... TODO

            // ----------- Store the EquationDetails
            IDictionary <int, Tuple <TblEqLibEquation_Row, EquationDetails> > allEquationDetails
                = new Dictionary <int, Tuple <TblEqLibEquation_Row, EquationDetails> >();                       // Key is TblEqLibEquation_Row.EquationID

            foreach (var eqnRow in equationRows)
            {
                EquationDetails ed = new EquationDetails(eqnRow.Name, eqnRow.EquationAsText);
                allEquationDetails.Add(eqnRow.EquationID, new Tuple <TblEqLibEquation_Row, EquationDetails>(eqnRow, ed));
            }

            // ----------- Add the variables to the EquationDetails
            foreach (var varRow in variableRows)
            {
                string    paramTypName = varRow.ParamType?.ToLower();
                ParamType paramType    = null;
                if (contentManager.ParamTypes.ContainsKey(paramTypName))
                {
                    paramType = contentManager.ParamTypes[paramTypName];
                }
                else
                {
                    int iDbg = 0;   // TODO
                }

                VarInfo vi = new VarInfo(varRow.Name, varRow.Description, paramType);

                int equationID = varRow.EquationID;
                if (allEquationDetails.ContainsKey(equationID))
                {
                    allEquationDetails[equationID].Item2.VariableInfos.Add(vi); // TODO: Check for duplicate names
                }
                else
                {
                    int iDbg = 0;   // TODO
                }
            }

            // ----------- Create the EquationCalcs in the section nodes
            foreach (var eqTpl in allEquationDetails)
            {
                TblEqLibEquation_Row eqnRow = eqTpl.Value.Item1;
                EquationDetails      ed     = eqTpl.Value.Item2;

                int sectionNodeID = eqnRow.SectionNodeID;
                if (allSectionNodes.ContainsKey(sectionNodeID))
                {
                    AddEquationToSectionNode(contentManager, allSectionNodes[sectionNodeID].Item2, ed);
                }
                else
                {
                    int iDbg = 0;   // TODO
                }
            }
        }