コード例 #1
0
 public static Dictionary <string, bool> ReadVars(string path, Communicator communicator)
 {
     try
     {
         Dictionary <string, bool> content = new Dictionary <string, bool>(StringComparer.OrdinalIgnoreCase);
         using (StreamReader sr = new StreamReader(path, Encoding.UTF8))
             using (XmlReader reader = XmlReader.Create(sr))
             {
                 foreach (var v in XmlHelpers.GetXmlGroupItems(reader: reader, tag: TAGS.VAR).Values)
                 {
                     if (!content.TryAdd(XmlHelpers.RemoveCData(v.GetOrEmpty(TAGS.NAME)),
                                         v.GetOrEmpty(TAGS.MONETARY) != "0"))
                     {
                         communicator.ReportError(new Communicator.ErrorInfo()
                         {
                             isWarning = true,
                             message   = $"{Path.GetFileName(path)}: double definition of variable {XmlHelpers.RemoveCData(v.GetOrEmpty(TAGS.NAME))} - second definition is ignored"
                         });
                     }
                 }
             }
         return(content);
     }
     catch (Exception exception)
     {
         throw new Exception($"Failure reading file {path}{Environment.NewLine}{exception.Message}");
     }
 }
コード例 #2
0
        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);
                        }
                    }
                }
            }
        }
コード例 #3
0
        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
                        }
                    }
                }
            }
        }
コード例 #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);
                }
            }
        }