コード例 #1
0
        private static bool ParseLN(XDocument doc)
        {
            IEnumerable <XElement> xLn = (from x in doc.Descendants()
                                          where x.Name.LocalName == "LNodeType"
                                          select x).ToList();

            if (!xLn.Any())
            {
                Log.Log.Write("ParseDocunent.ParseLN: LNodeType == null", "Error   ");
                return(false);
            }

            foreach (var ln in xLn)
            {
                if (ln.Attribute("lnClass") != null && ln.Attribute("id") != null)
                {
                    ServerModel.ListTempLN.Add(new ServerModel.NodeLN(ln.Attribute("lnClass")?.Value, ln.Attribute("id")?.Value, ln.Attribute("desc") != null ? ln.Attribute("desc")?.Value : ""));

                    IEnumerable <XElement> xDoElements = (from x in ln.Descendants()
                                                          where x.Name.LocalName == "DO"
                                                          select x).ToList();

                    if (!xDoElements.Any())
                    {
                        Log.Log.Write("ParseDocunent.ParseLN: LNodeType == null", "Error   ");
                        return(false);
                    }

                    foreach (var DO in xDoElements)
                    {
                        if (DO.Attribute("name") != null && DO.Attribute("type") != null)
                        {
                            ServerModel.ListTempLN.Last().ListDO.Add(new ServerModel.NodeDO(DO.Attribute("name")?.Value, DO.Attribute("type")?.Value, DO.Attribute("desc") != null ? DO.Attribute("desc")?.Value : ""));
                        }
                        else
                        {
                            Log.Log.Write("ParseDocunent.ParseLN: DO.name == null or DO.type == null", "Error   ");
                            return(false);
                        }
                    }
                }
                else
                {
                    Log.Log.Write("ParseDocunent.ParseLN: LNodeType.lnClass == null or LNodeType.id == null", "Error   ");
                    return(false);
                }
            }

            return(true);
        }
コード例 #2
0
        private static bool ParseDO(XDocument doc)
        {
            IEnumerable <XElement> xDo = (from x in doc.Descendants()
                                          where x.Name.LocalName == "DOType"
                                          select x).ToList();

            if (!xDo.Any())
            {
                Log.Log.Write("ParseDocunent.ParseDO: DOType == null", "Error   ");
                return(false);
            }

            foreach (var DO in xDo)
            {
                if (DO.Attribute("id") == null || DO.Attribute("cdc") == null)
                {
                    Log.Log.Write("ParseDocunent.ParseDO: DO.id == null or DO.cdc", "Error   ");
                    return(false);
                }

                ServerModel.ListTempDO.Add(new ServerModel.NodeDO(DO.Attribute("id")?.Value, DO.Attribute("cdc")?.Value, DO.Attribute("desc") != null ? DO.Attribute("desc")?.Value : ""));

                IEnumerable <XElement> xDAElements = (from x in DO.Descendants()
                                                      where x.Name.LocalName == "DA"
                                                      select x).ToList();

                if (!xDAElements.Any())
                {
                    Log.Log.Write("ParseDocunent.ParseDO: DA == null", "Error   ");
                    continue;
                }

                foreach (var da in xDAElements)
                {
                    if (da.Attribute("name") != null && da.Attribute("bType")?.Value == "Class")
                    {
                        var nameDA = da.Attribute("name")?.Value;
                        var typeDA = da.Attribute("type") != null?da.Attribute("type")?.Value : da.Parent.Attribute("type") != null?da.Parent.Attribute("type")?.Value : null;

                        ServerModel.ListTempDO.Last().ListDO.Add(new ServerModel.NodeDO(nameDA, typeDA, da.Attribute("desc") != null ? da.Attribute("desc")?.Value : ""));
                    }
                    else
                    {
                        if (da.Attribute("name") == null || da.Attribute("bType") == null || da.Attribute("fc") == null)
                        {
                            Log.Log.Write("ParseDocunent.ParseDO: DA.name == null or DA.bType == null or DA.fc == null", "Warning ");
                            continue;
                        }

                        var nameDA  = da.Attribute("name")?.Value;
                        var fcDA    = da.Attribute("fc")?.Value;
                        var bTypeDA = da.Attribute("bType")?.Value;
                        var typeDA  = da.Attribute("type") != null?da.Attribute("type")?.Value : da.Parent.Attribute("type") != null?da.Parent.Attribute("type")?.Value : null;

                        var trgOpsDA = TriggerOptions.NONE;
                        var countDA  = da.Attribute("count") != null?da.Attribute("count")?.Value : "0";

                        if ((da.Attribute("dchg")?.Value ?? "false").ToLower() == "true")
                        {
                            trgOpsDA |= TriggerOptions.DATA_CHANGED;
                        }
                        if ((da.Attribute("qchg")?.Value ?? "false").ToLower() == "true")
                        {
                            trgOpsDA |= TriggerOptions.QUALITY_CHANGED;
                        }
                        if ((da.Attribute("dupd")?.Value ?? "false").ToLower() == "true")
                        {
                            trgOpsDA |= TriggerOptions.DATA_UPDATE;
                        }

                        ServerModel.ListTempDO.Last().ListDA.Add(new ServerModel.NodeDA(nameDA, fcDA, bTypeDA, typeDA, (byte)trgOpsDA, countDA));

                        if (da.Value != null)
                        {
                            ServerModel.ListTempDO.Last().ListDA.Last().Value = da.Value;
                        }
                    }
                }
            }

            return(true);
        }