Ejemplo n.º 1
0
        private static void GetCountryInfo(ExeXml.CAO cao, Dictionary <string, Dictionary <string, string> > xmlCountry)
        {
            if (xmlCountry.Count == 0)
            {
                throw new Exception($"tag {TAGS.COUNTRY} not found");                        // must be a faulty xml-file
            }
            Dictionary <string, string> cc = xmlCountry.First().Value;

            cao.shortName = cc.GetOrEmpty(TAGS.SHORT_NAME);
        }
        private static void GetFunInfo(string sysId,
                                       Dictionary <string, Dictionary <string, string> > funs,
                                       Dictionary <string, Dictionary <string, string> > sysFuns,
                                       Dictionary <string, Dictionary <string, string> > refPols,
                                       bool ignorePrivate,
                                       ExeXml.CAO cao, out List <string> errors,
                                       bool readComment = false)
        {
            errors = new List <string>();

            foreach (Dictionary <string, string> sf in sysFuns.Values)       // loop over <SYS_FUNs>
            {
                if (sf.ContainsKey(TAGS.SYS_ID) && sf[TAGS.SYS_ID] == sysId) // consider only <SYS_FUN> with the appropriate <SYS_ID>
                {
                    ExeXml.Fun fun   = new ExeXml.Fun();
                    string     funId = sf.GetOrEmpty(TAGS.FUN_ID);

                    if (funId == string.Empty)
                    {
                        continue;
                    }

                    if (!funs.ContainsKey(funId))
                    {
                        errors.Add($"No <{TAGS.FUN}> corresponds to <{TAGS.SYS_FUN}> with <{TAGS.FUN_ID}> {funId}"); continue;
                    }

                    if (ignorePrivate)
                    {
                        string priv = funs[funId].GetOrEmpty(TAGS.PRIVATE);
                        if (priv != null && priv == DefPar.Value.YES)
                        {
                            continue;                                           // ignore if private
                        }
                    }

                    fun.Name = funs[funId].GetOrEmpty(TAGS.NAME); // get Name and PolId from <FUNs>
                    if (readComment)
                    {
                        fun.comment = XmlHelpers.RemoveCData(funs[funId].GetOrEmpty(TAGS.COMMENT));
                    }
                    string polId = funs[funId].GetOrEmpty(TAGS.POL_ID);

                    bool?on = DefPar.Value.IsOn(sf.GetOrEmpty(TAGS.SWITCH));
                    if (on == null &&                              // ignore if switched to n/a ...
                        fun.Name != DefFun.AddOn_Applic)
                    {
                        continue;                                  // ... except the AddOn_Applic-function of policy AO_control_*
                    }
                    fun.on = on == true;

                    fun.order = GetOrder(sf, out string orderError);
                    if (orderError != null)
                    {
                        errors.Add(orderError);
                    }

                    // assign the function to the corresponding policy (respectively policies - considering reference policies)
                    foreach (var pol in cao.pols)
                    {
                        if (pol.Key == polId ||
                            (refPols.ContainsKey(pol.Key) && refPols[pol.Key].GetOrEmpty(TAGS.REFPOL_ID) == polId))
                        {
                            pol.Value.funs.TryAdd(funId, fun);
                        }
                    }
                }
            }
        }
        private static void GetParInfo(string sysId,
                                       Dictionary <string, Dictionary <string, string> > pars,
                                       Dictionary <string, Dictionary <string, string> > sysPars,
                                       bool ignorePrivate,
                                       ExeXml.CAO cao, out List <string> errors,
                                       bool readComment = false)
        {
            errors = new List <string>();

            foreach (Dictionary <string, string> sp in sysPars.Values)       // loop over <SYS_PARs>
            {
                if (sp.ContainsKey(TAGS.SYS_ID) && sp[TAGS.SYS_ID] == sysId) // consider only <SYS_PAR> with the appropriate <SYS_ID>
                {
                    ExeXml.Par par   = new ExeXml.Par();
                    string     parId = sp.GetOrEmpty(TAGS.PAR_ID);

                    if (parId == string.Empty)
                    {
                        continue;
                    }

                    if (!pars.ContainsKey(parId))
                    {
                        errors.Add($"No <{TAGS.PAR}> corresponds to <{TAGS.SYS_PAR}> with <{TAGS.PAR_ID}> {parId}"); continue;
                    }

                    if (ignorePrivate)
                    {
                        string priv = pars[parId].GetOrEmpty(TAGS.PRIVATE);
                        if (priv != null && priv == DefPar.Value.YES)
                        {
                            continue;                                           // ignore if private
                        }
                    }

                    //par.val = EM_Helpers.AdaptDecimalSign(XmlHelpers.RemoveCData(sp.GetOrEmpty(TAGS.VALUE)));
                    par.val = XmlHelpers.RemoveCData(sp.GetOrEmpty(TAGS.VALUE));
                    if (par.val == DefPar.Value.NA)
                    {
                        continue;                                 // ignore n/a
                    }
                    par.order = sp.GetOrEmpty(TAGS.ORDER);        // get <Order> for error messages (otherwise irrelevant for executable)

                    par.Name = pars[parId].GetOrEmpty(TAGS.NAME); // get Name, Group and FunId from <PARs>
                    if (readComment)
                    {
                        par.comment = XmlHelpers.RemoveCData(pars[parId].GetOrEmpty(TAGS.COMMENT));
                    }
                    string funId = pars[parId].GetOrEmpty(TAGS.FUN_ID);
                    par.Group = pars[parId].GetOrEmpty(TAGS.GROUP);

                    par.val = allowInnerWhitespace.Contains(par.Name.ToLower()) ? par.val.ToLower().Trim()
                                                                                : EM_Helpers.RemoveWhitespace(par.val.ToLower());

                    // assign the parameter to the corresponding function
                    foreach (var pol in cao.pols)                          // note that 'TryAdd' is actually necessary for parameters of
                    {
                        if (pol.Value.funs.ContainsKey(funId))             // reference policies, because the policies actually contain the
                        {
                            pol.Value.funs[funId].pars.TryAdd(parId, par); // same functions, not just copies of the same functions
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        private static void GetPolInfo(string sysId,
                                       Dictionary <string, Dictionary <string, string> > pols,
                                       Dictionary <string, Dictionary <string, string> > sysPols,
                                       Dictionary <string, Dictionary <string, string> > refPols,
                                       bool ignorePrivate,
                                       ExeXml.CAO cao, out List <string> errors, bool readComment = false)
        {
            errors = new List <string>();

            foreach (Dictionary <string, string> sp in sysPols.Values)       // loop over <SYS_POLs>
            {
                if (sp.ContainsKey(TAGS.SYS_ID) && sp[TAGS.SYS_ID] == sysId) // consider only <SYS_POL> with the appropriate <SYS_ID>
                {
                    ExeXml.Pol pol   = new ExeXml.Pol();
                    string     polId = sp.GetOrEmpty(TAGS.POL_ID);

                    bool?on = DefPar.Value.IsOn(sp.GetOrEmpty(TAGS.SWITCH));
                    if (on == null)
                    {
                        continue;             // ignore if switched to n/a
                    }
                    pol.on = on == true;

                    pol.order = GetOrder(sp, out string orderError);
                    if (orderError != null)
                    {
                        errors.Add(orderError);
                    }

                    if (polId == string.Empty)
                    {
                        continue;
                    }

                    string rPolId = polId; // reference policies: the info must come from the referenced pol, but the id from the reference
                    if (refPols.ContainsKey(polId))
                    {
                        rPolId = refPols[polId].GetOrEmpty(TAGS.REFPOL_ID);
                    }
                    if (pols.ContainsKey(rPolId))
                    {
                        pol.name = pols[rPolId].GetOrEmpty(TAGS.NAME); // get policy-name from <POLs>
                        if (readComment)
                        {
                            pol.comment = XmlHelpers.RemoveCData(pols[rPolId].GetOrEmpty(TAGS.COMMENT));
                        }

                        if (ignorePrivate)
                        {
                            string priv = pols[rPolId].GetOrEmpty(TAGS.PRIVATE);
                            if (priv != null && priv == DefPar.Value.YES)
                            {
                                continue;                                           // ignore if private
                            }
                        }
                    }

                    cao.pols.Add(polId, pol);
                }
            }
        }